Youtube2Audio: Difference between revisions
Jump to navigation
Jump to search
(2 intermediate revisions by the same user not shown) | |||
Line 65: | Line 65: | ||
done | done | ||
== Download Youtube Songs of an interpret as MP3 with ID3 Tags from a list | == Download Youtube Songs of an interpret as MP3 with ID3 Tags from a list == | ||
List in otherwise empty current directory looks like this: | List (songs.txt) in otherwise empty current directory looks like this: | ||
Album - Title: youtube link | Album - Title: youtube link | ||
Command to download all songs in the list | Command to download all songs in the list: | ||
conda activate yt-dlp | conda activate yt-dlp | ||
python3 -m pip install -U yt-dlp | python3 -m pip install -U yt-dlp | ||
Line 84: | Line 84: | ||
t=${l##* - }; t=${t%%:*}; | t=${l##* - }; t=${t%%:*}; | ||
echo "$a - $t"; | echo "$a - $t"; | ||
mkdir -p "$a"; | mkdir -p "$i/$a"; | ||
ffmpeg -v 0 -i "$f" -acodec mp3 "$a/$i - $t.mp3" </dev/null; | ffmpeg -v 0 -i "$f" -acodec mp3 "$i/$a/$i - $t.mp3" </dev/null; | ||
id3v2 --album "$a" --artist "$i" --song "$t" --comment "youtu.be/watch?v=$v" "$i/$a/$i - $t.mp3"; | |||
done | done |
Latest revision as of 15:09, 18 August 2024
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 python3 -m pip install -U yt-dlp # or pip install --upgrade yt-dlp # or yt-dlp -U 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
Check id3v2 tags
id3v2 - Stevie\ Wonder\ and\ Jeff\ Beck\ -\ Superstition\ \(live\).mp3
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
Download Youtube Songs of an interpret as MP3 with ID3 Tags from a list
List (songs.txt) in otherwise empty current directory looks like this:
Album - Title: youtube link
Command to download all songs in the list:
conda activate yt-dlp python3 -m pip install -U yt-dlp i="your interpret name" cat songs.txt | fgrep : | sed 's/[^:]*: //' | while read u; do echo $u; yt-dlp --extract-audio --keep-video "$u"; done for f in *.opus; do v=${f##*[}; v=${v%*]*}; l=`fgrep -- "$v" songs.txt`; a=${l% - *}; t=${l##* - }; t=${t%%:*}; echo "$a - $t"; mkdir -p "$i/$a"; ffmpeg -v 0 -i "$f" -acodec mp3 "$i/$a/$i - $t.mp3" </dev/null; id3v2 --album "$a" --artist "$i" --song "$t" --comment "youtu.be/watch?v=$v" "$i/$a/$i - $t.mp3"; done