[youtube] Decrypt signature in dash manifest urls #1869

Closed
opened 2026-02-21 00:08:16 -05:00 by deekerman · 9 comments
Owner

Originally created by @jaimeMF on GitHub (Feb 16, 2014).

The url contains /s/B38340F3A368A1038B2F9A2698C3F52390282B9D2B1.1702A8F0F542DCB59484A235159267866D0A0F6CF6C, there should be some way of decrypting it. I have tried with the following change:

diff --git a/youtube_dl/extractor/youtube.py b/youtube_dl/extractor/youtube.py
index a810368..c3b4bf4 100644
--- a/youtube_dl/extractor/youtube.py
+++ b/youtube_dl/extractor/youtube.py
@@ -1369,8 +1369,14 @@ class YoutubeIE(YoutubeBaseInfoExtractor, SubtitlesInfoExtractor):
         if (dash_manifest_url_lst and dash_manifest_url_lst[0] and
                 self._downloader.params.get('youtube_include_dash_manifest', False)):
             try:
+                dash_manifest_url = dash_manifest_url_lst[0]
+                def decrypt_sig(mobj):
+                    s = mobj.group(1)
+                    dec_s = self._decrypt_signature(s, video_id, player_url, age_gate)
+                    return '/signature/%s' % dec_s
+                dash_manifest_url = re.sub(r'/s/([\w\.]+)', decrypt_sig, dash_manifest_url)
                 dash_doc = self._download_xml(
-                    dash_manifest_url_lst[0], video_id,
+                    dash_manifest_url, video_id,
                     note=u'Downloading DASH manifest',
                     errnote=u'Could not download DASH manifest')
                 for r in dash_doc.findall(u'.//{urn:mpeg:DASH:schema:MPD:2011}Representation'):

But it sill gives a 403 error when trying to download it, I've also tried using the static algorithms from the current version and older.

Downloading it would probably allow to get more formats (see #1955)

Originally created by @jaimeMF on GitHub (Feb 16, 2014). The url contains `/s/B38340F3A368A1038B2F9A2698C3F52390282B9D2B1.1702A8F0F542DCB59484A235159267866D0A0F6CF6C`, there should be some way of decrypting it. I have tried with the following change: ``` diff diff --git a/youtube_dl/extractor/youtube.py b/youtube_dl/extractor/youtube.py index a810368..c3b4bf4 100644 --- a/youtube_dl/extractor/youtube.py +++ b/youtube_dl/extractor/youtube.py @@ -1369,8 +1369,14 @@ class YoutubeIE(YoutubeBaseInfoExtractor, SubtitlesInfoExtractor): if (dash_manifest_url_lst and dash_manifest_url_lst[0] and self._downloader.params.get('youtube_include_dash_manifest', False)): try: + dash_manifest_url = dash_manifest_url_lst[0] + def decrypt_sig(mobj): + s = mobj.group(1) + dec_s = self._decrypt_signature(s, video_id, player_url, age_gate) + return '/signature/%s' % dec_s + dash_manifest_url = re.sub(r'/s/([\w\.]+)', decrypt_sig, dash_manifest_url) dash_doc = self._download_xml( - dash_manifest_url_lst[0], video_id, + dash_manifest_url, video_id, note=u'Downloading DASH manifest', errnote=u'Could not download DASH manifest') for r in dash_doc.findall(u'.//{urn:mpeg:DASH:schema:MPD:2011}Representation'): ``` But it sill gives a 403 error when trying to download it, I've also tried using the static algorithms from the current version and older. Downloading it would probably allow to get more formats (see #1955)
Author
Owner

@Elite commented on GitHub (Feb 16, 2014):

Wouldn't looking at this code http://userscripts.org/scripts/review/25105 help, it's working there.

@Elite commented on GitHub (Feb 16, 2014): Wouldn't looking at this code http://userscripts.org/scripts/review/25105 help, it's working there.
Author
Owner

@jaimeMF commented on GitHub (Feb 16, 2014):

I think is licensed under the MIT, so I don't really know if we can directly take the code and implement it in python.

@jaimeMF commented on GitHub (Feb 16, 2014): I think is licensed under the MIT, so I don't really know if we can directly take the code and implement it in python.
Author
Owner

@Elite commented on GitHub (Feb 16, 2014):

I checked the above userscript with almost 10 videos now and every one of them is showing 256kbps stream and is getting downloaded fine.

@Elite commented on GitHub (Feb 16, 2014): I checked the above userscript with almost 10 videos now and every one of them is showing 256kbps stream and is getting downloaded fine.
Author
Owner

@Elite commented on GitHub (Feb 16, 2014):

@jaimeMF I guess it would be fine to learn how that script is decrypting things and implement a version of it here. After all that's what open-source is for.

@Elite commented on GitHub (Feb 16, 2014): @jaimeMF I guess it would be fine to learn how that script is decrypting things and implement a version of it here. After all that's what open-source is for.
Author
Owner

@m0vie commented on GitHub (Feb 20, 2014):

Applying the diff above does work for me. No 403 error anymore and the manifest and the actual files are downloaded just fine.
I tried with this one: 07FYdnEawAQ

@m0vie commented on GitHub (Feb 20, 2014): Applying the diff above does work for me. No 403 error anymore and the manifest and the actual files are downloaded just fine. I tried with this one: 07FYdnEawAQ
Author
Owner

@jaimeMF commented on GitHub (Feb 20, 2014):

You're right, but for example IB3lcPjvWLA fails, do you know of other urls that work?
It's a bit strange because I always get the same signature for the manifest.

@jaimeMF commented on GitHub (Feb 20, 2014): You're right, but for example IB3lcPjvWLA fails, do you know of other urls that work? It's a bit strange because I always get the same signature for the manifest.
Author
Owner

@m0vie commented on GitHub (Feb 20, 2014):

I've checked a bit more: The one I tried (07FYdnEawAQ) is age restricted, the other one (IB3lcPjvWLA) is not. youtube-dl uses different code paths for these two cases (lines 1136).
When I force the age-restricted code path also for the other one, everything works, and the dash manifest is found!

So I can only assume the problem lies here:
The default variant:
for el_type in ['&el=embedded', '&el=detailpage', '&el=vevo', '']: video_info_url = ('https://www.youtube.com/get_video_info?&video_id=%s%s&ps=default&eurl=&gl=US&hl=en'

does not work properly to get the right manifest, while the other one does.

@m0vie commented on GitHub (Feb 20, 2014): I've checked a bit more: The one I tried (07FYdnEawAQ) is age restricted, the other one (IB3lcPjvWLA) is not. youtube-dl uses different code paths for these two cases (lines 1136). When I force the age-restricted code path also for the other one, everything works, and the dash manifest is found! So I can only assume the problem lies here: The default variant: `for el_type in ['&el=embedded', '&el=detailpage', '&el=vevo', '']: video_info_url = ('https://www.youtube.com/get_video_info?&video_id=%s%s&ps=default&eurl=&gl=US&hl=en'` does not work properly to get the right manifest, while the other one does.
Author
Owner

@m0vie commented on GitHub (Feb 20, 2014):

Ok, the above is not quite correct, the actual problem is in the signature decoding:

When I set
age_gate = True
everything works.

In this case the player_url is not fetched, which in turn causes a fallback to _static_decrypt_signature().

So the static signature decoding seems to work, while the other one does not.

@m0vie commented on GitHub (Feb 20, 2014): Ok, the above is not quite correct, the actual problem is in the signature decoding: When I set `age_gate = True` everything works. In this case the `player_url` is not fetched, which in turn causes a fallback to `_static_decrypt_signature()`. So the static signature decoding seems to work, while the other one does not.
Author
Owner

@jaimeMF commented on GitHub (Feb 21, 2014):

Fixed with d68f0cdb23

@jaimeMF commented on GitHub (Feb 21, 2014): Fixed with d68f0cdb238edc552a285135bc2684b6709f4f56
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/youtube-dl-ytdl-org#1869
No description provided.