mirror of
https://github.com/soimort/you-get.git
synced 2025-03-13 11:24:02 +03:00
YouTube: decrypt ciphered signature, temporarily fix #203
This commit is contained in:
parent
8e2165af47
commit
6c1be0f936
@ -78,13 +78,24 @@ def parse_video_info(raw_info):
|
|||||||
for item in
|
for item in
|
||||||
raw_info.split('&')])
|
raw_info.split('&')])
|
||||||
|
|
||||||
|
# Imported from youtube-dl
|
||||||
|
def _decrypt_signature(s):
|
||||||
|
"""Decrypt the key the two subkeys must have a length of 43"""
|
||||||
|
(a, b) = s.split('.')
|
||||||
|
if len(a) != 43 or len(b) != 43:
|
||||||
|
raise Exception('Unable to decrypt signature, subkeys lengths not valid')
|
||||||
|
b = ''.join([b[:8], a[0], b[9:18], b[-4], b[19:39], b[18]])[0:40]
|
||||||
|
a = a[-40:]
|
||||||
|
s_dec = '.'.join((a, b))[::-1]
|
||||||
|
return s_dec
|
||||||
|
|
||||||
def youtube_download_by_id(id, title = None, output_dir = '.', merge = True, info_only = False):
|
def youtube_download_by_id(id, title = None, output_dir = '.', merge = True, info_only = False):
|
||||||
|
|
||||||
raw_info = request.urlopen('http://www.youtube.com/get_video_info?video_id=%s' % id).read().decode('utf-8')
|
raw_info = request.urlopen('http://www.youtube.com/get_video_info?video_id=%s' % id).read().decode('utf-8')
|
||||||
|
|
||||||
video_info = parse_video_info(raw_info)
|
video_info = parse_video_info(raw_info)
|
||||||
|
|
||||||
if video_info['status'] == 'ok': # use get_video_info data
|
if video_info['status'] == 'ok' and not video_info['use_cipher_signature'] == 'True': # use get_video_info data
|
||||||
|
|
||||||
title = parse.unquote(video_info['title'].replace('+', ' '))
|
title = parse.unquote(video_info['title'].replace('+', ' '))
|
||||||
|
|
||||||
@ -118,7 +129,7 @@ def youtube_download_by_id(id, title = None, output_dir = '.', merge = True, inf
|
|||||||
url = r1(r'url=([^\\]+)', fmt)
|
url = r1(r'url=([^\\]+)', fmt)
|
||||||
url = unicodize(url)
|
url = unicodize(url)
|
||||||
url = parse.unquote(url)
|
url = parse.unquote(url)
|
||||||
sig = r1(r'sig=([^\\]+)', fmt)
|
sig = r1(r'sig=([^\\]+)', fmt) or _decrypt_signature(r1(r's=([^\\]+)', fmt))
|
||||||
url = url + '&signature=' + sig
|
url = url + '&signature=' + sig
|
||||||
break
|
break
|
||||||
try:
|
try:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user