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)
         else:
             self.send_response(500, 'Unknown build method "%s"' % action)
     else:
         self.send_response(500, 'Malformed URL')
示例#2
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,
         }
示例#3
0
    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)
示例#4
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)