Exemplo n.º 1
0
    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, [])

        result = get_ids({'playlist_items': '3-10'})
        self.assertEqual(result, [3, 4])

        result = get_ids({'playlist_items': '2-4,3-4,3'})
        self.assertEqual(result, [2, 3, 4])
Exemplo n.º 2
0
    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, [])

        result = get_ids({'playlist_items': '3-10'})
        self.assertEqual(result, [3, 4])

        result = get_ids({'playlist_items': '2-4,3-4,3'})
        self.assertEqual(result, [2, 3, 4])
 def do_GET(self):
     path = compat_urlparse.urlparse(self.path)
     paramDict = dict([
         (key, value[0])
         for key, value in compat_urlparse.parse_qs(path.query).items()
     ])
     action, _, path = path.path.strip('/').partition('/')
     if path:
         path = path.split('/')
         if action in self.actionDict:
             try:
                 builder = self.actionDict[action](path=path,
                                                   handler=self,
                                                   **paramDict)
                 builder.start()
                 try:
                     builder.build()
                 finally:
                     builder.close()
             except BuildError as e:
                 self.send_response(e.code)
                 msg = compat_str(e).encode('UTF-8')
                 self.send_header('Content-Type',
                                  'text/plain; charset=UTF-8')
                 self.send_header('Content-Length', len(msg))
                 self.end_headers()
                 self.wfile.write(msg)
             except HTTPError as e:
                 self.send_response(e.code, str(e))
         else:
             self.send_response(500, 'Unknown build method "%s"' % action)
     else:
         self.send_response(500, 'Malformed URL')
Exemplo n.º 4
0
 def do_GET(self):
     path = compat_urlparse.urlparse(self.path)
     paramDict = dict([(key, value[0]) for key, value in compat_urlparse.parse_qs(path.query).items()])
     action, _, path = path.path.strip('/').partition('/')
     if path:
         path = path.split('/')
         if action in self.actionDict:
             try:
                 builder = self.actionDict[action](path=path, handler=self, **paramDict)
                 builder.start()
                 try:
                     builder.build()
                 finally:
                     builder.close()
             except BuildError as e:
                 self.send_response(e.code)
                 msg = compat_str(e).encode('UTF-8')
                 self.send_header('Content-Type', 'text/plain; charset=UTF-8')
                 self.send_header('Content-Length', len(msg))
                 self.end_headers()
                 self.wfile.write(msg)
             except HTTPError as e:
                 self.send_response(e.code, str(e))
         else:
             self.send_response(500, 'Unknown build method "%s"' % action)
     else:
         self.send_response(500, 'Malformed URL')
Exemplo n.º 5
0
 def _entries(self):
     for n in range(3):
         video_id = compat_str(n)
         yield {
             '_type': 'url_transparent',
             'ie_key': VideoIE.ie_key(),
             'id': video_id,
             'url': 'video:%s' % video_id,
             'title': 'Video Transparent %s' % video_id,
         }
    def test_func(self):
        basename = 'player-%s.js' % test_id
        fn = os.path.join(self.TESTDATA_DIR, basename)

        if not os.path.exists(fn):
            compat_urlretrieve(url, fn)

        ydl = FakeYDL()
        ie = YoutubeIE(ydl)
        with io.open(fn, encoding='utf-8') as testf:
            jscode = testf.read()
        func = ie._parse_sig_js(jscode)
        src_sig = (compat_str(string.printable[:sig_input]) if isinstance(
            sig_input, int) else sig_input)
        got_sig = func(src_sig)
        self.assertEqual(got_sig, expected_sig)
Exemplo n.º 7
0
    def test_func(self):
        basename = 'player-%s.%s' % (test_id, stype)
        fn = os.path.join(self.TESTDATA_DIR, basename)

        if not os.path.exists(fn):
            compat_urlretrieve(url, fn)

        ie = YoutubeIE()
        if stype == 'js':
            with io.open(fn, encoding='utf-8') as testf:
                jscode = testf.read()
            func = ie._parse_sig_js(jscode)
        else:
            assert stype == 'swf'
            with open(fn, 'rb') as testf:
                swfcode = testf.read()
            func = ie._parse_sig_swf(swfcode)
        src_sig = (compat_str(string.printable[:sig_input]) if isinstance(
            sig_input, int) else sig_input)
        got_sig = func(src_sig)
        self.assertEqual(got_sig, expected_sig)
Exemplo n.º 8
0
    def test_func(self):
        basename = 'player-%s.%s' % (test_id, stype)
        fn = os.path.join(self.TESTDATA_DIR, basename)

        if not os.path.exists(fn):
            compat_urlretrieve(url, fn)

        ie = YoutubeIE()
        if stype == 'js':
            with io.open(fn, encoding='utf-8') as testf:
                jscode = testf.read()
            func = ie._parse_sig_js(jscode)
        else:
            assert stype == 'swf'
            with open(fn, 'rb') as testf:
                swfcode = testf.read()
            func = ie._parse_sig_swf(swfcode)
        src_sig = (
            compat_str(string.printable[:sig_input])
            if isinstance(sig_input, int) else sig_input)
        got_sig = func(src_sig)
        self.assertEqual(got_sig, expected_sig)
Exemplo n.º 9
0
    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_downloaded_info_dicts(params):
            ydl = YDL(params)
            # make a deep copy because the dictionary and nested entries
            # can be modified
            ydl.process_ie_result(copy.deepcopy(playlist))
            return ydl.downloaded_info_dicts

        def get_ids(params):
            return [int(v['id']) for v in get_downloaded_info_dicts(params)]

        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, [])

        result = get_ids({'playlist_items': '3-10'})
        self.assertEqual(result, [3, 4])

        result = get_ids({'playlist_items': '2-4,3-4,3'})
        self.assertEqual(result, [2, 3, 4])

        # Tests for https://github.com/ytdl-org/youtube-dl/issues/10591
        # @{
        result = get_downloaded_info_dicts({'playlist_items': '2-4,3-4,3'})
        self.assertEqual(result[0]['playlist_index'], 2)
        self.assertEqual(result[1]['playlist_index'], 3)

        result = get_downloaded_info_dicts({'playlist_items': '2-4,3-4,3'})
        self.assertEqual(result[0]['playlist_index'], 2)
        self.assertEqual(result[1]['playlist_index'], 3)
        self.assertEqual(result[2]['playlist_index'], 4)

        result = get_downloaded_info_dicts({'playlist_items': '4,2'})
        self.assertEqual(result[0]['playlist_index'], 4)
        self.assertEqual(result[1]['playlist_index'], 2)
Exemplo n.º 10
0
Arquivo: s.py Projeto: tanyhuan02/yts
def _signature_cache_id(example_sig):
    """ Return a string representation of a signature """
    return '.'.join(compat_str(len(part)) for part in example_sig.split('.'))
def signature(jscode, sig_input):
    func = YoutubeIE(FakeYDL())._parse_sig_js(jscode)
    src_sig = (compat_str(string.printable[:sig_input]) if isinstance(
        sig_input, int) else sig_input)
    return func(src_sig)