]> git.bitcoin.ninja Git - youtube-dl/commitdiff
Merge remote-tracking branch 'JohnyMoSwag/master'
authorPhilipp Hagemeister <phihag@phihag.de>
Thu, 27 Jun 2013 15:52:41 +0000 (17:52 +0200)
committerPhilipp Hagemeister <phihag@phihag.de>
Thu, 27 Jun 2013 15:52:41 +0000 (17:52 +0200)
README.md
devscripts/youtube_genalgo.py [new file with mode: 0644]
test/test_youtube_sig.py
youtube_dl/extractor/youtube.py
youtube_dl/version.py

index d63c5bbe7990354b9f4c64908dd6525991248908..81b86e264c117954bfddae70f8ba4feb2e16a198 100644 (file)
--- a/README.md
+++ b/README.md
@@ -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 (file)
index 0000000..b168cea
--- /dev/null
@@ -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()
index 5f23fababd9a6c78b79a7a4da6a1f74b61e0c02f..e87b6259bef3841e900ae0c9d98c03d6c30e0f20 100755 (executable)
@@ -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"
index b2ecc87e78de1ad96f73575bf9dc06bf9ec44a67..c7922c533343ca162c922659d34dc867d6839864 100644 (file)
@@ -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:
index 3b456e934c9fb83a987c787f076bc577c3926bad..d1e848284e7b779637ecb663242d5d8d6cb88990 100644 (file)
@@ -1,2 +1,2 @@
 
-__version__ = '2013.06.33'
+__version__ = '2013.06.34'