Youtube2Audio: Difference between revisions

From JoBaPedia
Jump to navigation Jump to search
Line 41: Line 41:
The redirects are necessary because ffmpeg encoders seem to read from stdin and garble the "while read f" loop input
The redirects are necessary because ffmpeg encoders seem to read from stdin and garble the "while read f" loop input


Add pictures as mp3 tag
== Use id3v2 if above didn't work ==
 
id3v2 \
  --artist "Stevie Wonder and Jeff Beck" \
  --album "Rock and Roll Hall of Fame 25th Anniversary" \
  --song "Superstition" \
  --comment "https://www.youtube.com/watch?v=_zz1RzTDzoE" \
  Stevie\ Wonder\ and\ Jeff\ Beck\ -\ Superstition\ \(live\).mp3
 
== Add pictures as mp3 tag ==


  for f in *.mp3; do  
  for f in *.mp3; do  

Revision as of 17:13, 21 January 2023

Youtube to Audio

yt-dlp

Faster (as of 2022-04-22) alternative fork on https://github.com/yt-dlp/yt-dlp

VID='PGCTQTZXGXs'
conda create -n yt-dlp yt-dlp
conda activate yt-dlp
yt-dlp --extract-audio --keep-video "https://www.youtube.com/watch?v=$VID"

Download youtube-dl or update to latest

sudo youtube-dl -U

Commands for DL a playlist

mkdir -p artist/album
cd artist/album
youtube-dl --extract-audio --keep-video 'album-playlist-url'

Option --embed-thumbnail seems useful, but did not work. Maybe retry later...

Commands for adding metadata

will need adapting to actual yt title audio formats. This playlist only contained video with opus (ogg vorbis) audio tracks.

mkdir meta
find . -name '*.opus' -print | while read f; do
  t=${f%-???????????.opus}
  t=${t/Roger Waters - /}
  t=${t#*/}
  a=${t%/*}
  t=${t#*/}
  echo "<$a><$t>"
  mkdir -p "meta/$a"
  ffmpeg -v 0 -i "$f" -acodec copy -metadata title="$t" -metadata artist="Roger Waters" -metadata album="$a" "meta/$a/$t.opus" </dev/zero
  ffmpeg -v 0 -i "$f" -acodec mp3  -metadata title="$t" -metadata artist="Roger Waters" -metadata album="$a" "meta/$a/$t.mp3" </dev/zero
done

The redirects are necessary because ffmpeg encoders seem to read from stdin and garble the "while read f" loop input

Use id3v2 if above didn't work

id3v2 \
  --artist "Stevie Wonder and Jeff Beck" \
  --album "Rock and Roll Hall of Fame 25th Anniversary" \
  --song "Superstition" \
  --comment "https://www.youtube.com/watch?v=_zz1RzTDzoE" \
  Stevie\ Wonder\ and\ Jeff\ Beck\ -\ Superstition\ \(live\).mp3 

Add pictures as mp3 tag

for f in *.mp3; do 
  b=${f/.mp3/}; 
  echo $b; 
  id3v2 --APIC `cat "../$b.jpg"` "$f"; 
done