diff options
-rw-r--r-- | README.md | 3 | ||||
-rw-r--r-- | devscripts/youtube_genalgo.py | 76 | ||||
-rwxr-xr-x | test/test_youtube_sig.py | 14 | ||||
-rw-r--r-- | youtube_dl/extractor/youtube.py | 23 | ||||
-rw-r--r-- | youtube_dl/version.py | 2 |
5 files changed, 100 insertions, 18 deletions
@@ -116,7 +116,8 @@ which means you can modify it, redistribute it or use it however you like. -F, --list-formats list all available formats (currently youtube only) --write-sub write subtitle file (currently youtube only) - --write-auto-sub write automatic subtitle file (currently youtube only) + --write-auto-sub write automatic subtitle file (currently youtube + only) --only-sub [deprecated] alias of --skip-download --all-subs downloads all the available subtitles of the video (currently youtube only) diff --git a/devscripts/youtube_genalgo.py b/devscripts/youtube_genalgo.py new file mode 100644 index 000000000..b168cea77 --- /dev/null +++ b/devscripts/youtube_genalgo.py @@ -0,0 +1,76 @@ +#!/usr/bin/env python + +# Generate youtube signature algorithm from test cases + +import sys + +tests = [ + ("qwertyuioplkjhgfdsazxcvbnm1234567890QWERTYUIOPLKJHGFDSAZXCVBNM!@#$%^&*()_-+={[]}|:;?/>.<", + "J:|}][{=+-_)(*&;%$#@>MNBVCXZASDFGH^KLPOIUYTREWQ0987654321mnbvcxzasdfghrklpoiuytej"), + ("qwertyuioplkjhgfdsazxcvbnm1234567890QWERTYUIOPLKJHGFDSAZXCVBNM!@#$^&*()_-+={[]}|:;?/>.<", + "!?;:|}][{=+-_)(*&^$#@/MNBVCXZASqFGHJKLPOIUYTREWQ0987654321mnbvcxzasdfghjklpoiuytr"), + ("qwertyuioplkjhgfdsazxcvbnm1234567890QWERTYUIOPLKJHGFDSAZXCVBNM!@#$%^&*()_-+={[|};?/>.<", + "ertyuioplkjhgfdsazxcvbnm1234567890QWERTYUIOPLKJHGFDSAZXCVBNM!/#$%^&*()_-+={[|};?@"), + ("qwertyuioplkjhgfdsazxcvbnm1234567890QWERTYUIOPLKJHGFDSAZXCVBNM!@#$%^&*()_-+={[};?/>.<", + "{>/?;}[.=+-_)(*&^%$#@!MqBVCXZASDFwHJKLPOIUYTREWQ0987654321mnbvcxzasdfghjklpoiuytr"), + ("qwertyuioplkjhgfdsazxcvbnm1234567890QWERTYUIOPLKJHGFDSAZXCVBNM!@#$%^&*()_-+={[};?>.<", + "<.>?;}[{=+-_)(*&^%$#@!MNBVCXZASDFGHJKLPOIUYTREWe098765432rmnbvcxzasdfghjklpoiuyt1"), + ("qwertyuioplkjhgfdsazxcvbnm1234567890QWERTYUIOPLKJHGFDSAZXCVBNM!#$%^&*()_+={[};?/>.<", + "D.>/?;}[{=+_)(*&^%$#!MNBVCXeAS<FGHJKLPOIUYTREWZ0987654321mnbvcxzasdfghjklpoiuytrQ"), + ("qwertyuioplkjhgfdsazxcvbnm1234567890QWERTYUIOPLKHGFDSAZXCVBNM!@#$%^&*(-+={[};?/>.<", + "Q>/?;}[{=+-(*<^%$#@!MNBVCXZASDFGHKLPOIUY8REWT0q&7654321mnbvcxzasdfghjklpoiuytrew9"), +] + +def find_matching(wrong, right): + idxs = [wrong.index(c) for c in right] + return compress(idxs) + return ('s[%d]' % i for i in idxs) + +def compress(idxs): + def _genslice(start, end, step): + starts = '' if start == 0 else str(start) + ends = ':%d' % (end+step) + steps = '' if step == 1 else (':%d' % step) + return 's[%s%s%s]' % (starts, ends, steps) + + step = None + for i, prev in zip(idxs[1:], idxs[:-1]): + if step is not None: + if i - prev == step: + continue + yield _genslice(start, prev, step) + step = None + continue + if i - prev in [-1, 1]: + step = i - prev + start = prev + continue + else: + yield 's[%d]' % prev + if step is None: + yield 's[%d]' % i + else: + yield _genslice(start, i, step) + +def _assert_compress(inp, exp): + res = list(compress(inp)) + if res != exp: + print('Got %r, expected %r' % (res, exp)) + assert res == exp +_assert_compress([0,2,4,6], ['s[0]', 's[2]', 's[4]', 's[6]']) +_assert_compress([0,1,2,4,6,7], ['s[:3]', 's[4]', 's[6:8]']) +_assert_compress([8,0,1,2,4,7,6,9], ['s[8]', 's[:3]', 's[4]', 's[7:5:-1]', 's[9]']) + +def gen(wrong, right, indent): + code = ' + '.join(find_matching(wrong, right)) + return 'if len(s) == %d:\n%s return %s\n' % (len(wrong), indent, code) + +def genall(tests): + indent = ' ' * 8 + return indent + (indent + 'el').join(gen(wrong, right, indent) for wrong,right in tests) + +def main(): + print(genall(tests)) + +if __name__ == '__main__': + main() diff --git a/test/test_youtube_sig.py b/test/test_youtube_sig.py index 5f23fabab..e87b6259b 100755 --- a/test/test_youtube_sig.py +++ b/test/test_youtube_sig.py @@ -22,32 +22,32 @@ class TestYoutubeSig(unittest.TestCase): wrong = "qwertyuioplkjhgfdsazxcvbnm1234567890QWERTYUIOPLKJHGFDSAZXCVBNM!@#$%^&*()_-+={[]}|:;?/>.<" right = "J:|}][{=+-_)(*&;%$#@>MNBVCXZASDFGH^KLPOIUYTREWQ0987654321mnbvcxzasdfghrklpoiuytej" self.assertEqual(sig(wrong), right) - + def test_87(self): wrong = "qwertyuioplkjhgfdsazxcvbnm1234567890QWERTYUIOPLKJHGFDSAZXCVBNM!@#$^&*()_-+={[]}|:;?/>.<" right = "!?;:|}][{=+-_)(*&^$#@/MNBVCXZASqFGHJKLPOIUYTREWQ0987654321mnbvcxzasdfghjklpoiuytr" self.assertEqual(sig(wrong), right) - + def test_86(self): wrong = "qwertyuioplkjhgfdsazxcvbnm1234567890QWERTYUIOPLKJHGFDSAZXCVBNM!@#$%^&*()_-+={[|};?/>.<" - right = "ertyuioplkjhgfdqazxcvbnm1234567890QWERT}UIOPLKJHGFDSAZXCVBNM!@#$%^&*()_-+={[|/;?Y" + right = "ertyuioplkjhgfdsazxcvbnm1234567890QWERTYUIOPLKJHGFDSAZXCVBNM!/#$%^&*()_-+={[|};?@" self.assertEqual(sig(wrong), right) - + def test_85(self): wrong = "qwertyuioplkjhgfdsazxcvbnm1234567890QWERTYUIOPLKJHGFDSAZXCVBNM!@#$%^&*()_-+={[};?/>.<" right = "{>/?;}[.=+-_)(*&^%$#@!MqBVCXZASDFwHJKLPOIUYTREWQ0987654321mnbvcxzasdfghjklpoiuytr" self.assertEqual(sig(wrong), right) - + def test_84(self): wrong = "qwertyuioplkjhgfdsazxcvbnm1234567890QWERTYUIOPLKJHGFDSAZXCVBNM!@#$%^&*()_-+={[};?>.<" right = "<.>?;}[{=+-_)(*&^%$#@!MNBVCXZASDFGHJKLPOIUYTREWe098765432rmnbvcxzasdfghjklpoiuyt1" self.assertEqual(sig(wrong), right) - + def test_83(self): wrong = "qwertyuioplkjhgfdsazxcvbnm1234567890QWERTYUIOPLKJHGFDSAZXCVBNM!#$%^&*()_+={[};?/>.<" right = "D.>/?;}[{=+_)(*&^%$#!MNBVCXeAS<FGHJKLPOIUYTREWZ0987654321mnbvcxzasdfghjklpoiuytrQ" self.assertEqual(sig(wrong), right) - + def test_82(self): wrong = "qwertyuioplkjhgfdsazxcvbnm1234567890QWERTYUIOPLKHGFDSAZXCVBNM!@#$%^&*(-+={[};?/>.<" right = "Q>/?;}[{=+-(*<^%$#@!MNBVCXZASDFGHKLPOIUY8REWT0q&7654321mnbvcxzasdfghjklpoiuytrew9" diff --git a/youtube_dl/extractor/youtube.py b/youtube_dl/extractor/youtube.py index b2ecc87e7..c7922c533 100644 --- a/youtube_dl/extractor/youtube.py +++ b/youtube_dl/extractor/youtube.py @@ -131,23 +131,22 @@ class YoutubeIE(InfoExtractor): def _decrypt_signature(self, s): """Decrypt the key the two subkeys must have a length of 43""" - if self._downloader.params.get('verbose'): - self.to_screen('encrypted signature length %d' % (len(s))) if len(s) == 88: - return s[48] + s[81] + s[80] + s[79] + s[78] + s[77] + s[76] + s[75] + s[74] + s[73] + s[72] + s[71] + s[70] + s[69] + s[68] + s[82] + s[66] + s[65] + s[64] + s[63] + s[85] + s[61] + s[60] + s[59] + s[58] + s[57] + s[56] + s[55] + s[54] + s[53] + s[52] + s[51] + s[50] + s[49] + s[67] + s[47] + s[46] + s[45] + s[44] + s[43] + s[42] + s[41] + s[40] + s[39] + s[38] + s[37] + s[36] + s[35] + s[34] + s[33] + s[32] + s[31] + s[30] + s[29] + s[28] + s[27] + s[26] + s[25] + s[24] + s[23] + s[22] + s[21] + s[20] + s[19] + s[18] + s[17] + s[16] + s[15] + s[14] + s[13] + s[3] + s[11] + s[10] + s[9] + s[8] + s[7] + s[6] + s[5] + s[4] + s[2] + s[12] + return s[48] + s[81:67:-1] + s[82] + s[66:62:-1] + s[85] + s[61:48:-1] + s[67] + s[47:12:-1] + s[3] + s[11:3:-1] + s[2] + s[12] elif len(s) == 87: - return s[62] + s[82] + s[81] + s[80] + s[79] + s[78] + s[77] + s[76] + s[75] + s[74] + s[73] + s[72] + s[71] + s[70] + s[69] + s[68] + s[67] + s[66] + s[65] + s[64] + s[63] + s[83] + s[61] + s[60] + s[59] + s[58] + s[57] + s[56] + s[55] + s[54] + s[53] + s[0] + s[51] + s[50] + s[49] + s[48] + s[47] + s[46] + s[45] + s[44] + s[43] + s[42] + s[41] + s[40] + s[39] + s[38] + s[37] + s[36] + s[35] + s[34] + s[33] + s[32] + s[31] + s[30] + s[29] + s[28] + s[27] + s[26] + s[25] + s[24] + s[23] + s[22] + s[21] + s[20] + s[19] + s[18] + s[17] + s[16] + s[15] + s[14] + s[13] + s[12] + s[11] + s[10] + s[9] + s[8] + s[7] + s[6] + s[5] + s[4] + s[3] + return s[62] + s[82:62:-1] + s[83] + s[61:52:-1] + s[0] + s[51:2:-1] elif len(s) == 86: - return s[2] + s[3] + s[4] + s[5] + s[6] + s[7] + s[8] + s[9] + s[10] + s[11] + s[12] + s[13] + s[14] + s[15] + s[16] + s[0] + s[18] + s[19] + s[20] + s[21] + s[22] + s[23] + s[24] + s[25] + s[26] + s[27] + s[28] + s[29] + s[30] + s[31] + s[32] + s[33] + s[34] + s[35] + s[36] + s[37] + s[38] + s[39] + s[40] + s[79] + s[42] + s[43] + s[44] + s[45] + s[46] + s[47] + s[48] + s[49] + s[50] + s[51] + s[52] + s[53] + s[54] + s[55] + s[56] + s[57] + s[58] + s[59] + s[60] + s[61] + s[62] + s[63] + s[64] + s[65] + s[66] + s[67] + s[68] + s[69] + s[70] + s[71] + s[72] + s[73] + s[74] + s[75] + s[76] + s[77] + s[78] + s[82] + s[80] + s[81] + s[41] + return s[2:63] + s[82] + s[64:82] + s[63] elif len(s) == 85: - return s[76] + s[82] + s[81] + s[80] + s[79] + s[78] + s[77] + s[83] + s[75] + s[74] + s[73] + s[72] + s[71] + s[70] + s[69] + s[68] + s[67] + s[66] + s[65] + s[64] + s[63] + s[62] + s[61] + s[0] + s[59] + s[58] + s[57] + s[56] + s[55] + s[54] + s[53] + s[52] + s[51] + s[1] + s[49] + s[48] + s[47] + s[46] + s[45] + s[44] + s[43] + s[42] + s[41] + s[40] + s[39] + s[38] + s[37] + s[36] + s[35] + s[34] + s[33] + s[32] + s[31] + s[30] + s[29] + s[28] + s[27] + s[26] + s[25] + s[24] + s[23] + s[22] + s[21] + s[20] + s[19] + s[18] + s[17] + s[16] + s[15] + s[14] + s[13] + s[12] + s[11] + s[10] + s[9] + s[8] + s[7] + s[6] + s[5] + s[4] + s[3] + return s[76] + s[82:76:-1] + s[83] + s[75:60:-1] + s[0] + s[59:50:-1] + s[1] + s[49:2:-1] elif len(s) == 84: - return s[83] + s[82] + s[81] + s[80] + s[79] + s[78] + s[77] + s[76] + s[75] + s[74] + s[73] + s[72] + s[71] + s[70] + s[69] + s[68] + s[67] + s[66] + s[65] + s[64] + s[63] + s[62] + s[61] + s[60] + s[59] + s[58] + s[57] + s[56] + s[55] + s[54] + s[53] + s[52] + s[51] + s[50] + s[49] + s[48] + s[47] + s[46] + s[45] + s[44] + s[43] + s[42] + s[41] + s[40] + s[39] + s[38] + s[37] + s[2] + s[35] + s[34] + s[33] + s[32] + s[31] + s[30] + s[29] + s[28] + s[27] + s[3] + s[25] + s[24] + s[23] + s[22] + s[21] + s[20] + s[19] + s[18] + s[17] + s[16] + s[15] + s[14] + s[13] + s[12] + s[11] + s[10] + s[9] + s[8] + s[7] + s[6] + s[5] + s[4] + s[26] + return s[83:36:-1] + s[2] + s[35:26:-1] + s[3] + s[25:3:-1] + s[26] elif len(s) == 83: - return s[52] + s[81] + s[80] + s[79] + s[78] + s[77] + s[76] + s[75] + s[74] + s[73] + s[72] + s[71] + s[70] + s[69] + s[68] + s[67] + s[66] + s[65] + s[64] + s[63] + s[62] + s[61] + s[60] + s[59] + s[58] + s[57] + s[56] + s[2] + s[54] + s[53] + s[82] + s[51] + s[50] + s[49] + s[48] + s[47] + s[46] + s[45] + s[44] + s[43] + s[42] + s[41] + s[40] + s[39] + s[38] + s[37] + s[55] + s[35] + s[34] + s[33] + s[32] + s[31] + s[30] + s[29] + s[28] + s[27] + s[26] + s[25] + s[24] + s[23] + s[22] + s[21] + s[20] + s[19] + s[18] + s[17] + s[16] + s[15] + s[14] + s[13] + s[12] + s[11] + s[10] + s[9] + s[8] + s[7] + s[6] + s[5] + s[4] + s[3] + s[36] + return s[52] + s[81:55:-1] + s[2] + s[54:52:-1] + s[82] + s[51:36:-1] + s[55] + s[35:2:-1] + s[36] elif len(s) == 82: - return s[36] + s[79] + s[78] + s[77] + s[76] + s[75] + s[74] + s[73] + s[72] + s[71] + s[70] + s[69] + s[68] + s[81] + s[66] + s[65] + s[64] + s[63] + s[62] + s[61] + s[60] + s[59] + s[58] + s[57] + s[56] + s[55] + s[54] + s[53] + s[52] + s[51] + s[50] + s[49] + s[48] + s[47] + s[46] + s[45] + s[44] + s[43] + s[42] + s[41] + s[33] + s[39] + s[38] + s[37] + s[40] + s[35] + s[0] + s[67] + s[32] + s[31] + s[30] + s[29] + s[28] + s[27] + s[26] + s[25] + s[24] + s[23] + s[22] + s[21] + s[20] + s[19] + s[18] + s[17] + s[16] + s[15] + s[14] + s[13] + s[12] + s[11] + s[10] + s[9] + s[8] + s[7] + s[6] + s[5] + s[4] + s[3] + s[2] + s[1] + s[34] + return s[36] + s[79:67:-1] + s[81] + s[66:40:-1] + s[33] + s[39:36:-1] + s[40] + s[35] + s[0] + s[67] + s[32:0:-1] + s[34] + else: raise ExtractorError(u'Unable to decrypt signature, subkeys length %d not supported; retrying might work' % (len(s))) @@ -519,6 +518,12 @@ class YoutubeIE(InfoExtractor): if 'sig' in url_data: url += '&signature=' + url_data['sig'][0] elif 's' in url_data: + if self._downloader.params.get('verbose'): + s = url_data['s'][0] + player = self._search_regex(r'html5player-(.+?)\.js', video_webpage, + 'html5 player', fatal=False) + self.to_screen('encrypted signature length %d (%d.%d), itag %s, html5 player %s' % + (len(s), len(s.split('.')[0]), len(s.split('.')[1]), url_data['itag'][0], player)) signature = self._decrypt_signature(url_data['s'][0]) url += '&signature=' + signature if 'ratebypass' not in url: diff --git a/youtube_dl/version.py b/youtube_dl/version.py index 3b456e934..d1e848284 100644 --- a/youtube_dl/version.py +++ b/youtube_dl/version.py @@ -1,2 +1,2 @@ -__version__ = '2013.06.33' +__version__ = '2013.06.34' |