diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/test_YoutubeDL.py | 46 | ||||
| -rw-r--r-- | test/test_aes.py | 4 | ||||
| -rw-r--r-- | test/test_compat.py | 25 | ||||
| -rw-r--r-- | test/test_subtitles.py | 2 | ||||
| -rw-r--r-- | test/test_utils.py | 39 | 
5 files changed, 91 insertions, 25 deletions
diff --git a/test/test_YoutubeDL.py b/test/test_YoutubeDL.py index 82b827536..a13c09ef4 100644 --- a/test/test_YoutubeDL.py +++ b/test/test_YoutubeDL.py @@ -12,6 +12,7 @@ import copy  from test.helper import FakeYDL, assertRegexpMatches  from youtube_dl import YoutubeDL +from youtube_dl.compat import compat_str  from youtube_dl.extractor import YoutubeIE  from youtube_dl.postprocessor.common import PostProcessor  from youtube_dl.utils import match_filter_func @@ -507,6 +508,51 @@ class TestYoutubeDL(unittest.TestCase):          res = get_videos(f)          self.assertEqual(res, ['1']) +    def test_playlist_items_selection(self): +        entries = [{ +            'id': compat_str(i), +            'title': compat_str(i), +            'url': TEST_URL, +        } for i in range(1, 5)] +        playlist = { +            '_type': 'playlist', +            'id': 'test', +            'entries': entries, +            'extractor': 'test:playlist', +            'extractor_key': 'test:playlist', +            'webpage_url': 'http://example.com', +        } + +        def get_ids(params): +            ydl = YDL(params) +            # make a copy because the dictionary can be modified +            ydl.process_ie_result(playlist.copy()) +            return [int(v['id']) for v in ydl.downloaded_info_dicts] + +        result = get_ids({}) +        self.assertEqual(result, [1, 2, 3, 4]) + +        result = get_ids({'playlistend': 10}) +        self.assertEqual(result, [1, 2, 3, 4]) + +        result = get_ids({'playlistend': 2}) +        self.assertEqual(result, [1, 2]) + +        result = get_ids({'playliststart': 10}) +        self.assertEqual(result, []) + +        result = get_ids({'playliststart': 2}) +        self.assertEqual(result, [2, 3, 4]) + +        result = get_ids({'playlist_items': '2-4'}) +        self.assertEqual(result, [2, 3, 4]) + +        result = get_ids({'playlist_items': '2,4'}) +        self.assertEqual(result, [2, 4]) + +        result = get_ids({'playlist_items': '10'}) +        self.assertEqual(result, []) +  if __name__ == '__main__':      unittest.main() diff --git a/test/test_aes.py b/test/test_aes.py index 4dc7de7b5..315a3f5ae 100644 --- a/test/test_aes.py +++ b/test/test_aes.py @@ -39,7 +39,7 @@ class TestAES(unittest.TestCase):          encrypted = base64.b64encode(              intlist_to_bytes(self.iv[:8]) +              b'\x17\x15\x93\xab\x8d\x80V\xcdV\xe0\t\xcdo\xc2\xa5\xd8ksM\r\xe27N\xae' -        ) +        ).decode('utf-8')          decrypted = (aes_decrypt_text(encrypted, password, 16))          self.assertEqual(decrypted, self.secret_msg) @@ -47,7 +47,7 @@ class TestAES(unittest.TestCase):          encrypted = base64.b64encode(              intlist_to_bytes(self.iv[:8]) +              b'\x0b\xe6\xa4\xd9z\x0e\xb8\xb9\xd0\xd4i_\x85\x1d\x99\x98_\xe5\x80\xe7.\xbf\xa5\x83' -        ) +        ).decode('utf-8')          decrypted = (aes_decrypt_text(encrypted, password, 32))          self.assertEqual(decrypted, self.secret_msg) diff --git a/test/test_compat.py b/test/test_compat.py index 1eb454e06..c3ba8ad2e 100644 --- a/test/test_compat.py +++ b/test/test_compat.py @@ -14,6 +14,8 @@ from youtube_dl.utils import get_filesystem_encoding  from youtube_dl.compat import (      compat_getenv,      compat_expanduser, +    compat_urllib_parse_unquote, +    compat_urllib_parse_unquote_plus,  ) @@ -42,5 +44,28 @@ class TestCompat(unittest.TestCase):              dir(youtube_dl.compat))) - set(['unicode_literals'])          self.assertEqual(all_names, sorted(present_names)) +    def test_compat_urllib_parse_unquote(self): +        self.assertEqual(compat_urllib_parse_unquote('abc%20def'), 'abc def') +        self.assertEqual(compat_urllib_parse_unquote('%7e/abc+def'), '~/abc+def') +        self.assertEqual(compat_urllib_parse_unquote(''), '') +        self.assertEqual(compat_urllib_parse_unquote('%'), '%') +        self.assertEqual(compat_urllib_parse_unquote('%%'), '%%') +        self.assertEqual(compat_urllib_parse_unquote('%%%'), '%%%') +        self.assertEqual(compat_urllib_parse_unquote('%2F'), '/') +        self.assertEqual(compat_urllib_parse_unquote('%2f'), '/') +        self.assertEqual(compat_urllib_parse_unquote('%E6%B4%A5%E6%B3%A2'), '津波') +        self.assertEqual( +            compat_urllib_parse_unquote('''<meta property="og:description" content="%E2%96%81%E2%96%82%E2%96%83%E2%96%84%25%E2%96%85%E2%96%86%E2%96%87%E2%96%88" /> +%<a href="https://ar.wikipedia.org/wiki/%D8%AA%D8%B3%D9%88%D9%86%D8%A7%D9%85%D9%8A">%a'''), +            '''<meta property="og:description" content="▁▂▃▄%▅▆▇█" /> +%<a href="https://ar.wikipedia.org/wiki/تسونامي">%a''') +        self.assertEqual( +            compat_urllib_parse_unquote('''%28%5E%E2%97%A3_%E2%97%A2%5E%29%E3%81%A3%EF%B8%BB%E3%83%87%E2%95%90%E4%B8%80    %E2%87%80    %E2%87%80    %E2%87%80    %E2%87%80    %E2%87%80    %E2%86%B6%I%Break%25Things%'''), +            '''(^◣_◢^)っ︻デ═一    ⇀    ⇀    ⇀    ⇀    ⇀    ↶%I%Break%Things%''') + +    def test_compat_urllib_parse_unquote_plus(self): +        self.assertEqual(compat_urllib_parse_unquote_plus('abc%20def'), 'abc def') +        self.assertEqual(compat_urllib_parse_unquote_plus('%7e/abc+def'), '~/abc def') +  if __name__ == '__main__':      unittest.main() diff --git a/test/test_subtitles.py b/test/test_subtitles.py index 891ee620b..c4e3adb67 100644 --- a/test/test_subtitles.py +++ b/test/test_subtitles.py @@ -266,7 +266,7 @@ class TestNRKSubtitles(BaseTestSubtitles):          self.DL.params['allsubtitles'] = True          subtitles = self.getSubtitles()          self.assertEqual(set(subtitles.keys()), set(['no'])) -        self.assertEqual(md5(subtitles['no']), '1d221e6458c95c5494dcd38e6a1f129a') +        self.assertEqual(md5(subtitles['no']), '544fa917d3197fcbee64634559221cc2')  class TestRaiSubtitles(BaseTestSubtitles): diff --git a/test/test_utils.py b/test/test_utils.py index 032d3656a..65692a9fb 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -40,7 +40,6 @@ from youtube_dl.utils import (      read_batch_urls,      sanitize_filename,      sanitize_path, -    sanitize_url_path_consecutive_slashes,      prepend_extension,      replace_extension,      shell_quote, @@ -176,26 +175,6 @@ class TestUtil(unittest.TestCase):          self.assertEqual(sanitize_path('./abc'), 'abc')          self.assertEqual(sanitize_path('./../abc'), '..\\abc') -    def test_sanitize_url_path_consecutive_slashes(self): -        self.assertEqual( -            sanitize_url_path_consecutive_slashes('http://hostname/foo//bar/filename.html'), -            'http://hostname/foo/bar/filename.html') -        self.assertEqual( -            sanitize_url_path_consecutive_slashes('http://hostname//foo/bar/filename.html'), -            'http://hostname/foo/bar/filename.html') -        self.assertEqual( -            sanitize_url_path_consecutive_slashes('http://hostname//'), -            'http://hostname/') -        self.assertEqual( -            sanitize_url_path_consecutive_slashes('http://hostname/foo/bar/filename.html'), -            'http://hostname/foo/bar/filename.html') -        self.assertEqual( -            sanitize_url_path_consecutive_slashes('http://hostname/'), -            'http://hostname/') -        self.assertEqual( -            sanitize_url_path_consecutive_slashes('http://hostname/abc//'), -            'http://hostname/abc/') -      def test_prepend_extension(self):          self.assertEqual(prepend_extension('abc.ext', 'temp'), 'abc.temp.ext')          self.assertEqual(prepend_extension('abc.ext', 'temp', 'ext'), 'abc.temp.ext') @@ -345,6 +324,7 @@ class TestUtil(unittest.TestCase):          self.assertEqual(parse_duration('02:03:04'), 7384)          self.assertEqual(parse_duration('01:02:03:04'), 93784)          self.assertEqual(parse_duration('1 hour 3 minutes'), 3780) +        self.assertEqual(parse_duration('87 Min.'), 5220)      def test_fix_xml_ampersands(self):          self.assertEqual( @@ -621,7 +601,7 @@ ffmpeg version 2.4.4 Copyright (c) 2000-2014 the FFmpeg ...'''), '2.4.4')                  <div xml:lang="en">                      <p begin="0" end="1">The following line contains Chinese characters and special symbols</p>                      <p begin="1" end="2">第二行<br/>♪♪</p> -                    <p begin="2" end="3"><span>Third<br/>Line</span></p> +                    <p begin="2" dur="1"><span>Third<br/>Line</span></p>                  </div>              </body>              </tt>''' @@ -642,6 +622,21 @@ Line  '''          self.assertEqual(dfxp2srt(dfxp_data), srt_data) +        dfxp_data_no_default_namespace = '''<?xml version="1.0" encoding="UTF-8"?> +            <tt xml:lang="en" xmlns:tts="http://www.w3.org/ns/ttml#parameter"> +            <body> +                <div xml:lang="en"> +                    <p begin="0" end="1">The first line</p> +                </div> +            </body> +            </tt>''' +        srt_data = '''1 +00:00:00,000 --> 00:00:01,000 +The first line + +''' +        self.assertEqual(dfxp2srt(dfxp_data_no_default_namespace), srt_data) +  if __name__ == '__main__':      unittest.main()  | 
