youtube-dl & alternatives -
jpstewart - 04-19-2022
There have been at least a couple of threads here discussing youtube-dl in the past, so I thought I'd pass along a tip I wish I'd known about sooner.
In recent months YouTube has done something leading to youtube-dl being throttled to about 70 KB/sec download speed. I put up with it for a while before doing some Google searching to find out what to do about it. That's when I found out that:
- it was a deliberate change by YouTube
- it could be worked around but youtube-dl hadn't been updated to do so
- there's a more actively-matined fork called yt-dlp that has the necessary changes
So, if anyone else out there is still using the original youtube-dl, I recommend you at least check out yt-dlp instead. It's mostly compatible and it's man page clearly documents that changes they've made.
RE: youtube-dl & alternatives -
Raion - 04-19-2022
When I can, I'll update Nekoware for dlp
RE: youtube-dl & alternatives -
lunatic - 04-20-2022
a good opportunity to post this once more:
Code:
#!/bin/bash
# /usr/local/bin/yt2mp3
# A very simple bash script to download a YouTube video
# and extract the music as an mp3 file.
# use as: yt2mp3 https://www.youtube.com/watch?v=ytvideoid
address=$1
regex='v=(.*)'
if [[ $address =~ $regex ]]; then
video_id=${BASH_REMATCH[1]}
video_id=$(echo $video_id | cut -d'&' -f1)
#video_title="$(youtube-dl --get-title $address)"
video_title="$(yt-dlp --get-title $address)"
#youtube-dl --id $address
yt-dlp --id $address
ffmpeg -i "$video_id".* "$video_title".wav
lame -b 256 -h "$video_title".wav "$video_title".mp3
rm "$video_id".* "$video_title".wav
else
echo "Sorry but the system encountered a problem."
fi
RE: youtube-dl & alternatives -
jpstewart - 04-20-2022
I hate to say it, lunatic, but that script seems like an unnecessarily and overly complicated way of extracting audio from a YouTube video. There's no need to use ffmpeg to convert to wav and then lame to encode to mp3; ffmpeg can create the mp3 directly. There's no need to manually call ffmpeg; both youtube-dl and yt-dlp have built in options for post-processing downloads. YouTube even offers downloads of the audio and video already separated. And there's no need to use those shell expansions to get the title; there are formatting options for that.
If m4a audio will suit you, you could simply do:
Code:
yt-dlp --format m4a https://www.youtube.com/watch?v=ytvideoid
If you really want mp3, the entire script can be replaced with:
Code:
yt-dlp --format bestaudio --extract-audio --audio-format mp3 --postprocessor-args "ExtractAudio:-b:a 256k" -o "%(title)s.%(ext)s" https://www.youtube.com/watch?v=ytvideoid
(NOTE: watch for line-wrapping in the forum. The above examples are each a single command line.)
The '--format bestaudio' part will download only the highest quality audio that YouTube has to offer, without the video. Then '--extract-audio --audio-format mp3' will cause yt-dlp to automatically call ffmpeg and convert the downloaded audio to mp3. Next, the '--postprocessor-args "ExtractAudio:-b:a 256k"' part ensures it creates a 256 kbps mp3 file, just like the '-b 256' in your lame command. Finally '-o "%(title)s.%(ext)s"' causes yt-dlp to name the file just like your script would have, without the need for the extra parsing.
RE: youtube-dl & alternatives -
lunatic - 04-21-2022
(04-20-2022, 11:26 PM)jpstewart Wrote: I hate to say it, lunatic, but that script seems like an unnecessarily and overly complicated way of extracting audio from a YouTube video. There's no need to use ffmpeg to convert to wav and then lame to encode to mp3; ffmpeg can create the mp3 directly. There's no need to manually call ffmpeg; both youtube-dl and yt-dlp have built in options for post-processing downloads. YouTube even offers downloads of the audio and video already separated. And there's no need to use those shell expansions to get the title; there are formatting options for that.
I did not know that. That is great indeed. This little shell script may be from a time before these features existed.