]>
Raphaƫl G. Git Repositories - youtubedl/blob - test/test_youtube_signature.py
3 # Allow direct execution
7 sys
.path
.insert(0, os
.path
.dirname(os
.path
.dirname(os
.path
.abspath(__file__
))))
9 from test
.helper
import global_setup
17 from youtube_dl
.extractor
import YoutubeIE
18 from youtube_dl
.utils
import compat_str
, compat_urlretrieve
22 u
'https://s.ytimg.com/yts/jsbin/html5player-vflHOr_nV.js',
25 u
'>=<;:/.-[+*)(\'&%$#"!ZYX0VUTSRQPONMLKJIHGFEDCBA\\yxwvutsrqponmlkjihgfedcba987654321',
28 u
'https://s.ytimg.com/yts/jsbin/html5player-vfldJ8xgI.js',
31 u
'3456789a0cdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRS[UVWXYZ!"#$%&\'()*+,-./:;<=>?@',
34 u
'https://s.ytimg.com/yts/swfbin/watch_as3-vflg5GhxU.swf',
37 u
':/.-,+*)=\'&%$#"!ZYX0VUTSRQPONMLKJIHGFEDCBAzyxw>utsrqponmlkjihgfedcba987654321'
42 class TestSignature(unittest
.TestCase
):
44 TEST_DIR
= os
.path
.dirname(os
.path
.abspath(__file__
))
45 self
.TESTDATA_DIR
= os
.path
.join(TEST_DIR
, 'testdata')
46 if not os
.path
.exists(self
.TESTDATA_DIR
):
47 os
.mkdir(self
.TESTDATA_DIR
)
50 def make_tfunc(url
, stype
, sig_length
, expected_sig
):
51 basename
= url
.rpartition('/')[2]
52 m
= re
.match(r
'.*-([a-zA-Z0-9_-]+)\.[a-z]+$', basename
)
53 assert m
, '%r should follow URL format' % basename
57 fn
= os
.path
.join(self
.TESTDATA_DIR
, basename
)
59 if not os
.path
.exists(fn
):
60 compat_urlretrieve(url
, fn
)
64 with io
.open(fn
, encoding
='utf-8') as testf
:
66 func
= ie
._parse
_sig
_js
(jscode
)
69 with open(fn
, 'rb') as testf
:
70 swfcode
= testf
.read()
71 func
= ie
._parse
_sig
_swf
(swfcode
)
72 src_sig
= compat_str(string
.printable
[:sig_length
])
73 got_sig
= func(src_sig
)
74 self
.assertEqual(got_sig
, expected_sig
)
76 test_func
.__name
__ = str('test_signature_' + stype
+ '_' + test_id
)
77 setattr(TestSignature
, test_func
.__name
__, test_func
)
79 for test_spec
in _TESTS
:
80 make_tfunc(*test_spec
)
83 if __name__
== '__main__':