Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[youtube] Decrypt signature in dash manifest urls #2393

Closed
jaimeMF opened this issue Feb 16, 2014 · 9 comments
Closed

[youtube] Decrypt signature in dash manifest urls #2393

jaimeMF opened this issue Feb 16, 2014 · 9 comments

Comments

@jaimeMF
Copy link
Collaborator

@jaimeMF jaimeMF commented 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)

@Elite
Copy link

@Elite Elite commented Feb 16, 2014

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

@jaimeMF
Copy link
Collaborator Author

@jaimeMF jaimeMF commented 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.

@Elite
Copy link

@Elite Elite commented 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
Copy link

@Elite Elite commented 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.

@m0vie
Copy link
Contributor

@m0vie m0vie commented 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

@jaimeMF
Copy link
Collaborator Author

@jaimeMF jaimeMF commented 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.

@m0vie
Copy link
Contributor

@m0vie m0vie commented 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
Copy link
Contributor

@m0vie m0vie commented 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.

@jaimeMF
Copy link
Collaborator Author

@jaimeMF jaimeMF commented Feb 21, 2014

Fixed with d68f0cd

@jaimeMF jaimeMF closed this Feb 21, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

3 participants
You can’t perform that action at this time.