• The forum software that supports hummy.tv has been upgraded to XenForo 2.3!

    Please bear with us as we continue to tweak things, and feel free to post any questions, issues or suggestions in the upgrade thread.

[youtube-dl] Download files from youtube.com or other video platforms

The version that worked for a few milliseconds yesterday needs this patch in case it sees YT JS player b12cc44b. Expect the patch to be rolled into a commit later today and new nightly version 2024.08.07, all being well. Maybe we need a ClownStrike-style code injector that bypasses the build and test cycle.
 
It seems we're behind in the arms race again:

Code:
30/12/2024 14:26:02 - Starting queued download URL https://youtu.be/XV3EBLPwHrU Options -x --audio-format wav QID 15277
30/12/2024 14:27:16 - [youtube] XV3EBLPwHrU: Downloading webpage
30/12/2024 14:27:22 - [youtube] XV3EBLPwHrU: Downloading player 03dbdfab
30/12/2024 14:29:01 - Caught error: WARNING: [youtube] XV3EBLPwHrU: Signature extraction failed: Some formats may be missing
ERROR: No video formats found; please report this issue on https://github.com/ytdl-org/youtube-dl/issues , using the appropriate issue template. Make sure you are using the latest version; see  https://github.com/ytdl-org/youtube-dl/#user-content-installation  on how to update. Be sure to call youtube-dl with the --verbose option and include the complete output.
30/12/2024 14:29:01 - -code 1 -level 0 -errorinfo {::qtube::dequeue /mod/webif/plugin/qtube/queue.hook 29 {exec youtube --newline -x --audio-format wav https://youtu.be/XV3EBLPwHrU | awk {{print strftime("%d/%m/%Y %H:%M:%S -"), $0; fflush(); }} >@::aio.handle13} ::auto::runplugin {} 1 {::qtube::dequeue ::<reference.<queue__>.00000000000000000004> https://youtu.be/XV3EBLPwHrU} {} /mod/webif/lib/auto/deq 205 {::auto::runplugin qtube dequeue ::<reference.<queue__>.00000000000000000004> https://youtu.be/XV3EBLPwHrU}} -errorcode {CHILDSTATUS 12594 1}
 
Aside from any funky options, even the basic doesn't work:
Code:
humax# youtube -v https://youtu.be/XV3EBLPwHrU
[debug] System config: [u'--restrict-filenames', u'--prefer-ffmpeg', u'--hls-prefer-ffmpeg', u'--hls-use-mpegts', u'--external-downloader-args', u'-mpegts_m2ts_mode true', u'-f', u'best[height<=?1080][fps<=?60][protocol^=m3u8]', u'-o', u'/mnt/hd2/My Video/%(title)s.%(ext)s']
[debug] User config: []
[debug] Custom config: []
[debug] Command-line args: [u'--external-downloader', u'wget', u'--hls-prefer-ffmpeg', u'--cache-dir', u'/mod/.cache/youtube-dl', u'-v', u'https://youtu.be/XV3EBLPwHrU']
[debug] Encodings: locale ASCII, fs ASCII, out ASCII, pref ASCII
[debug] youtube-dl version 2024.12.31
[debug] Python 2.7.1 (CPython 7405b0-smp 32bit) - Linux-2.6.18-7.1-7405b0-smp-with-libc0 - OpenSSL 1.0.0a 1 Jun 2010 - libc 0
[debug] exe versions: ffmpeg 4.1, ffprobe 4.1
[debug] Proxy map: {}
[youtube] XV3EBLPwHrU: Downloading webpage
[youtube] XV3EBLPwHrU: Downloading API JSON
[debug] [youtube] Extracting signature function js_03dbdfab_107
[debug] [youtube] Decrypted nsig IjnUVrQ5tNc77QXqw => IcAHoKl5qI5fmw
[debug] [youtube] Decrypted nsig Vv55ScZ1pTJvtCr6q => QXNIedAQbNT9Iw
[debug] [youtube] Extracting signature function js_03dbdfab_103
ERROR: requested format not available
Traceback (most recent call last):
  File "/mod/lib/python2.7/dist-packages/youtube-dl/youtube_dl/YoutubeDL.py", line 875, in wrapper
    return func(self, *args, **kwargs)
  File "/mod/lib/python2.7/dist-packages/youtube-dl/youtube_dl/YoutubeDL.py", line 982, in __extract_info
    return self.process_ie_result(ie_result, download, extra_info)
  File "/mod/lib/python2.7/dist-packages/youtube-dl/youtube_dl/YoutubeDL.py", line 1016, in process_ie_result
    return self.process_video_result(ie_result, download=download)
  File "/mod/lib/python2.7/dist-packages/youtube-dl/youtube_dl/YoutubeDL.py", line 1852, in process_video_result
    expected=True)
ExtractorError: requested format not available
 
With the extractor version that's in 2025.01.01:
Code:
$ python -m youtube_dl -vF 'https://youtu.be/XV3EBLPwHrU'
[debug] System config: [u'--prefer-ffmpeg']
[debug] User config: []
[debug] Custom config: []
[debug] Command-line args: [u'-vF', u'https://youtu.be/XV3EBLPwHrU']
[debug] Encodings: locale UTF-8, fs UTF-8, out UTF-8, pref UTF-8
[debug] youtube-dl version 2021.12.17
[debug] Git HEAD: 176fc2cb0
[debug] Python 2.7.18 (CPython i686 32bit) - Linux-4.4.0-210-generic-i686-with-Ubuntu-16.04-xenial - OpenSSL 1.1.1w  11 Sep 2023 - glibc 2.15
[debug] exe versions: avconv 4.3, avprobe 4.3, ffmpeg 4.3, ffprobe 4.3
[debug] Proxy map: {}
[youtube] XV3EBLPwHrU: Downloading webpage
[youtube] XV3EBLPwHrU: Downloading API JSON
[debug] [youtube] Extracting signature function js_03dbdfab_103
[debug] [youtube] Decrypted nsig gInDaRZXvlxX3JUrU => FNoTly3j7UC08g
[debug] [youtube] Extracting signature function js_03dbdfab_107
[debug] [youtube] Decrypted nsig PI-cp_NQH4m_tlgMs => 2bHin7TAML2jeA
[info] Available formats for XV3EBLPwHrU:
format code  extension  resolution note
599          m4a        audio only audio_quality_ultralow   30k , m4a_dash container, mp4a.40.5@ 30k (22050Hz), 838.02KiB
600          webm       audio only audio_quality_ultralow   34k , webm_dash container, opus @ 34k (48000Hz), 948.57KiB
249          webm       audio only audio_quality_low   51k , webm_dash container, opus @ 51k (48000Hz), 1.37MiB
250          webm       audio only audio_quality_low   68k , webm_dash container, opus @ 68k (48000Hz), 1.82MiB
140          m4a        audio only audio_quality_medium  129k , m4a_dash container, mp4a.40.2@129k (44100Hz), 3.44MiB
251          webm       audio only audio_quality_medium  134k , webm_dash container, opus @134k (48000Hz), 3.56MiB
598          webm       144x144    144p   19k , webm_dash container, vp9@  19k, 13fps, video only, 536.96KiB
597          mp4        144x144    144p   20k , mp4_dash container, avc1.4d400a@  20k, 13fps, video only, 548.43KiB
160          mp4        144x144    144p   21k , mp4_dash container, avc1.4d400b@  21k, 25fps, video only, 591.16KiB
278          webm       144x144    144p   26k , webm_dash container, vp9@  26k, 25fps, video only, 710.02KiB
133          mp4        240x240    240p   44k , mp4_dash container, avc1.4d400c@  44k, 25fps, video only, 1.19MiB
242          webm       240x240    240p   45k , webm_dash container, vp9@  45k, 25fps, video only, 1.22MiB
243          webm       360x360    360p   79k , webm_dash container, vp9@  79k, 25fps, video only, 2.11MiB
134          mp4        360x360    360p   84k , mp4_dash container, avc1.4d4015@  84k, 25fps, video only, 2.24MiB
244          webm       480x480    480p  127k , webm_dash container, vp9@ 127k, 25fps, video only, 3.38MiB
135          mp4        480x480    480p  135k , mp4_dash container, avc1.4d401e@ 135k, 25fps, video only, 3.59MiB
136          mp4        720x720    720p  215k , mp4_dash container, avc1.64001f@ 215k, 25fps, video only, 5.72MiB
247          webm       720x720    720p  264k , webm_dash container, vp9@ 264k, 25fps, video only, 7.02MiB
137          mp4        1080x1080  1080p  367k , mp4_dash container, avc1.640020@ 367k, 25fps, video only, 9.74MiB
248          webm       1080x1080  1080p  457k , webm_dash container, vp9@ 457k, 25fps, video only, 12.14MiB
18           mp4        360x360    360p  171k , avc1.42001E, 25fps, mp4a.40.2 (44100Hz), 4.55MiB (best)
$
Because of the above-mentioned arms race, the tactics that the extractor uses may not always be able to find a combined format (like 18, one that has both audio and video in the same stream), or one that matches other selection constraints. The default format selection has been bestvideo+bestaudio/best for years because YT offered (unwillingly, maybe) better quality from the individual streams, but now it's also necessary in case no suitable combined format is available. So maybe (bestvideo+bestaudio/best)[additional ?constraints].

The additional constraint [protocol^=m3u8] causes the selection not to match, since there are no formats beginning m3u8. HLS formats could be banished with [protocol!=m3u8], and that is a satisfiable constraint.

As to elves: https://github.com/ytdl-org/ytdl-nightly/releases/tag/2025.01.01
 
As I typically only want the audio (but not always), is there an options incantation I can use to only grab the highest quality audio stream and not bother with video format?
 
-f 'bestaudio/best' -x --audio-format mp3 or -f 'bestaudio/best' -x --audio-format aac, depending on preference. In the second case ffmpeg should work out that it doesn't need to transcode the audio.
 
Updated package uploaded. Be warned, it takes bliddy ages to run.
Done on my real computer is somewhat quicker:
Code:
$ time youtube-dl -vf 18 -x --audio-format wav https://youtu.be/XV3EBLPwHrU
...
real    0m6.683s
You need to generate the updated version yourself though - I have a 'nice' script that does it.
 
Last edited:
  • Like
Reactions: /df
You can just download the nightly release POSIX build (example linked above) that will run on any such system with a python executable on the PATH (so you may have to link to /wherever/python3), or the Windows (>=XP) version that has its own Python 3.4.4 built in.
 
I download the master.zip from ytdl-org/youtube-dl and process that. I was unaware of ytdl-nightly until now, but that also requires knowledge of the version date or doing it manually. The script just works (for me anyway).
It's interesting that the Windows version still requires the MSVCR100.dll runtime library, which is from VS2010. Even VS2013 could still generate XP compatible executables with the platform toolset set to v120_xp.
 
The nightly is just a clone of the master, but it's the best solution for someone who wants a running version on a laptop/desktop/etc.

In the Windows build, Python is the only Windows executable, so I assume it was built with VS2010 (Python 3.4: 2014-2019, VS2013 being too new in 2014). I'm very reluctant to change anything about the Windows build unless someone reports it as not working since I don't have a usable local Windows dev/test machine. Since M$ actively maintains backward application compatibility, the Windows build lives in the past to help people who can't stretch to current Windows kit.
 
Updated package uploaded. Be warned, it takes bliddy ages to run.
It took 11 minutes to resolve the download, 19 seconds to download, and 32 seconds for ffmpeg to extract the wav. Not too bad, and as long as it works it doesn't really matter how long it takes.
 
Just starting Python and loading the yt-dl code (it's already extracted now, IIRC) takes a minute or 2. The majority of the remaining execution time, I'm sure, is spent executing the n-sig challenge JS. If we had a native ES6 JavaScript interpreter on the platform it might be a lot quicker, but I doubt that deno would be buildable and there aren't many alternatives, so that's not going to happen. Already YT is making it harder with tweaks like making us check some external variable that's in scope when the player JS runs the challenge.
 
Back
Top