youtube-dl & alternatives
#1
youtube-dl & alternatives
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:
  1. it was a deliberate change by YouTube
  2. it could be worked around but youtube-dl hadn't been updated to do so
  3. 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.

SGI:  Indigo, Indigo2, Octane, Origin 300
Sun:  SPARCstation 20 (x4), Ultra 2, Blade 2500, T5240
HP:  9000/380, 425e, C8000
Digital: DECstation 5000/125, PWS 600au
jpstewart
Developer

Trade Count: (1)
Posts: 444
Threads: 6
Joined: May 2018
Location: SW Ontario, CA
Find Reply
04-19-2022, 11:41 PM
#2
RE: youtube-dl & alternatives
When I can, I'll update Nekoware for dlp Smile

I'm the system admin of this site. Private security technician, licensed locksmith, hack of a c developer and vintage computer enthusiast. 

https://contrib.irixnet.org/raion/ -- contributions and pieces that I'm working on currently. 

https://codeberg.org/SolusRaion -- Code repos I control

Technical problems should be sent my way.
Raion
Chief IRIX Officer

Trade Count: (9)
Posts: 4,240
Threads: 533
Joined: Nov 2017
Location: Eastern Virginia
Website Find Reply
04-19-2022, 11:45 PM
#3
RE: youtube-dl & alternatives
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
(This post was last modified: 04-20-2022, 12:54 AM by lunatic.)
lunatic
insane in the mainframe

Trade Count: (0)
Posts: 150
Threads: 1
Joined: Apr 2019
Find Reply
04-20-2022, 12:53 AM
#4
RE: youtube-dl & alternatives
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.

SGI:  Indigo, Indigo2, Octane, Origin 300
Sun:  SPARCstation 20 (x4), Ultra 2, Blade 2500, T5240
HP:  9000/380, 425e, C8000
Digital: DECstation 5000/125, PWS 600au
jpstewart
Developer

Trade Count: (1)
Posts: 444
Threads: 6
Joined: May 2018
Location: SW Ontario, CA
Find Reply
04-20-2022, 11:26 PM
#5
RE: youtube-dl & alternatives
(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.
lunatic
insane in the mainframe

Trade Count: (0)
Posts: 150
Threads: 1
Joined: Apr 2019
Find Reply
04-21-2022, 12:22 AM


Forum Jump:


Users browsing this thread: 1 Guest(s)