Ejemplo n.º 1
0
 def setUp(self):
     YouTubeTestCase.setUp(self)
     self.loader = VideoInfoLoader(self.url)
Ejemplo n.º 2
0
 def setUp(self):
     YouTubeTestCase.setUp(self)
     self.loader = VideoInfoLoader(self.url)
Ejemplo n.º 3
0
class YouTubeScrapeTestCase(YouTubeTestCase):
    def setUp(self):
        YouTubeTestCase.setUp(self)
        self.loader = VideoInfoLoader(self.url)

    def test_get_url(self):
        scrape_url = self.loader.get_url()
        self.assertEqual(
            scrape_url,
            ('http://www.youtube.com/get_video_info?video_id=J_DV9b0x7v4&'
             'el=embedded&ps=default&eurl='))

    def test_get_video_data(self):
        scrape_file = self.get_data_file('youtube/video_info.txt')
        response = self.get_response(scrape_file.read())
        data = self.loader.get_video_data(response)
        self.assertEqual(set(data), self.loader.fields)
        expected_data = {
            'title': u'CaramellDansen (Full Version + Lyrics)',
            'thumbnail_url': 'http://i3.ytimg.com/vi/J_DV9b0x7v4/hqdefault.jpg',
            'tags': [u'caramell', u'dance', u'dansen', u'hip', u'hop',
                     u's\xfcchtig', u'geil', u'cool', u'lustig', u'manga',
                     u'schweden', u'anime', u'musik', u'music', u'funny',
                     u'caramelldansen', u'U-U-U-Aua', u'Dance'],
            'files': [VideoFile(url='http://r10---sn-nx57yn7k.c.youtube.com/videoplayback?upn=p0pWpkfxwq4&sparams=cp%2Cgcr%2Cid%2Cip%2Cipbits%2Citag%2Cratebypass%2Csource%2Cupn%2Cexpire&fexp=919330%2C916611%2C920704%2C912806%2C928001%2C922403%2C922405%2C929901%2C913605%2C929104%2C913546%2C913556%2C908496%2C920201%2C913302%2C919009%2C911116%2C901451%2C902556&key=yt1&expire=1356417961&source=youtube&ipbits=8&itag=18&gcr=us&sver=3&signature=7D1D4A9CF0626C3B2A10F6567390165729FA00B8.89C64C08C8B1CA689E4CE21169531E34A56761C1&ratebypass=yes&mt=1356395169&mv=m&ms=au&ip=74.61.34.250&cp=U0hUS1RMVV9LS0NONF9MRllKOmZQN1JFU3lOX2Js&id=27f0d5f5bd31eefe',
                                width=640,
                                height=360,
                                expires=datetime.datetime(2012, 12, 25, 6, 46, 1),
                                mime_type=u'video/mp4'),
                      VideoFile(url='http://r15---sn-nx57yn7r.c.youtube.com/videoplayback?upn=p0pWpkfxwq4&sparams=algorithm%2Cburst%2Ccp%2Cfactor%2Cgcr%2Cid%2Cip%2Cipbits%2Citag%2Csource%2Cupn%2Cexpire&fexp=919330%2C916611%2C920704%2C912806%2C928001%2C922403%2C922405%2C929901%2C913605%2C929104%2C913546%2C913556%2C908496%2C920201%2C913302%2C919009%2C911116%2C901451%2C902556&key=yt1&algorithm=throttle-factor&itag=34&ipbits=8&burst=40&gcr=us&sver=3&signature=9DAA96CCF4CA172A92C78907B0ECE241BAFB07D6.09AF4B0F7C6558D1B9B184A5F60232EDC296FF95&mv=m&mt=1356395169&ip=74.61.34.250&expire=1356417961&source=youtube&ms=au&factor=1.25&cp=U0hUS1RMVV9LS0NONF9MRllKOmZQN1JFU3lOX2Js&id=27f0d5f5bd31eefe',
                                width=640,
                                height=360,
                                expires=datetime.datetime(2012, 12, 25, 6, 46, 1),
                                mime_type=u'video/x-flv'),
                      VideoFile(url='http://r2---sn-nx57yn7d.c.youtube.com/videoplayback?upn=p0pWpkfxwq4&sparams=algorithm%2Cburst%2Ccp%2Cfactor%2Cgcr%2Cid%2Cip%2Cipbits%2Citag%2Csource%2Cupn%2Cexpire&fexp=919330%2C916611%2C920704%2C912806%2C928001%2C922403%2C922405%2C929901%2C913605%2C929104%2C913546%2C913556%2C908496%2C920201%2C913302%2C919009%2C911116%2C901451%2C902556&key=yt1&algorithm=throttle-factor&itag=5&ipbits=8&burst=40&gcr=us&sver=3&signature=A909DD7537DD821A0F5AE14FF1E83C87DD7C4EDF.4FCE8516F456B96DD45DB35A7AB8624A1A45498F&mv=m&mt=1356395169&ip=74.61.34.250&expire=1356417961&source=youtube&ms=au&factor=1.25&cp=U0hUS1RMVV9LS0NONF9MRllKOmZQN1JFU3lOX2Js&id=27f0d5f5bd31eefe',
                                width=400,
                                height=240,
                                expires=datetime.datetime(2012, 12, 25, 6, 46, 1),
                                mime_type=u'video/x-flv'),
                      VideoFile(url='http://r11---sn-nx57yn76.c.youtube.com/videoplayback?upn=p0pWpkfxwq4&sparams=cp%2Cgcr%2Cid%2Cip%2Cipbits%2Citag%2Cratebypass%2Csource%2Cupn%2Cexpire&fexp=919330%2C916611%2C920704%2C912806%2C928001%2C922403%2C922405%2C929901%2C913605%2C929104%2C913546%2C913556%2C908496%2C920201%2C913302%2C919009%2C911116%2C901451%2C902556&key=yt1&expire=1356417961&source=youtube&ipbits=8&itag=43&gcr=us&sver=3&signature=7D0403EBD72E0A28695B35F7BD542A88BC9FE4FA.C4D2BFDD22BBFDC002F8C67CF66363BCC93501EC&ratebypass=yes&mt=1356395169&mv=m&ms=au&ip=74.61.34.250&cp=U0hUS1RMVV9LS0NONF9MRllKOmZQN1JFU3lOX2Js&id=27f0d5f5bd31eefe',
                                width=640,
                                height=360,
                                expires=datetime.datetime(2012, 12, 25, 6, 46, 1),
                                mime_type=u'video/webm')]
        }
        self.assertDictEqual(data, expected_data)

    def test_get_video_data__fail_150(self):
        scrape_file = self.get_data_file('youtube/video_info2.txt')
        response = self.get_response(scrape_file.read())
        data = self.loader.get_video_data(response)
        self.assertDictEqual(data, {'is_embeddable': False})

    def test_get_video_data__fail_other(self):
        scrape_file = self.get_data_file('youtube/video_info2.txt')
        scrape_data = scrape_file.read().replace('150', 'other')
        response = self.get_response(scrape_data)
        data = self.loader.get_video_data(response)
        self.assertEqual(data, {})

    def test_get_video_data__402(self):
        response = self.get_response('', code=402)
        data = self.loader.get_video_data(response)
        self.assertEqual(data, {})

    def test_get_video_data__no_files(self):
        scrape_file = self.get_data_file('youtube/video_info_no_files.txt')
        response = self.get_response(scrape_file.read())
        data = self.loader.get_video_data(response)
        expected_data = {
            'files': [],
            'thumbnail_url': 'http://i1.ytimg.com/vi/8SCZaB3ZtAE/hqdefault.jpg',
            'tags': [u'Atlanta SEO services', u'Atlanta SEO Company', u'AL Loise',
                     u'Audience Targeting', u'SEO Target', u'Online Business',
                     u'Onli'],
            'title': u'Audience Targeting'
        }
        self.assertEqual(data, expected_data)
Ejemplo n.º 4
0
class YouTubeScrapeTestCase(YouTubeTestCase):
    def setUp(self):
        YouTubeTestCase.setUp(self)
        self.loader = VideoInfoLoader(self.url)

    def test_get_url(self):
        scrape_url = self.loader.get_url()
        self.assertEqual(
            scrape_url, ("http://www.youtube.com/get_video_info?video_id=J_DV9b0x7v4&" "el=embedded&ps=default&eurl=")
        )

    def test_get_video_data(self):
        scrape_file = self.get_data_file("youtube/video_info.txt")
        response = self.get_response(scrape_file.read())
        data = self.loader.get_video_data(response)
        self.assertEqual(set(data), self.loader.fields)
        expected_data = {
            "title": u"CaramellDansen (Full Version + Lyrics)",
            "thumbnail_url": "http://i3.ytimg.com/vi/J_DV9b0x7v4/hqdefault.jpg",
            "tags": [
                u"caramell",
                u"dance",
                u"dansen",
                u"hip",
                u"hop",
                u"s\xfcchtig",
                u"geil",
                u"cool",
                u"lustig",
                u"manga",
                u"schweden",
                u"anime",
                u"musik",
                u"music",
                u"funny",
                u"caramelldansen",
                u"U-U-U-Aua",
                u"Dance",
            ],
            "files": [
                VideoFile(
                    url="http://r10---sn-nx57yn7k.c.youtube.com/videoplayback?upn=p0pWpkfxwq4&sparams=cp%2Cgcr%2Cid%2Cip%2Cipbits%2Citag%2Cratebypass%2Csource%2Cupn%2Cexpire&fexp=919330%2C916611%2C920704%2C912806%2C928001%2C922403%2C922405%2C929901%2C913605%2C929104%2C913546%2C913556%2C908496%2C920201%2C913302%2C919009%2C911116%2C901451%2C902556&key=yt1&expire=1356417961&source=youtube&ipbits=8&itag=18&gcr=us&sver=3&signature=7D1D4A9CF0626C3B2A10F6567390165729FA00B8.89C64C08C8B1CA689E4CE21169531E34A56761C1&ratebypass=yes&mt=1356395169&mv=m&ms=au&ip=74.61.34.250&cp=U0hUS1RMVV9LS0NONF9MRllKOmZQN1JFU3lOX2Js&id=27f0d5f5bd31eefe",
                    width=640,
                    height=360,
                    expires=datetime.datetime(2012, 12, 25, 6, 46, 1),
                    mime_type=u"video/mp4",
                ),
                VideoFile(
                    url="http://r15---sn-nx57yn7r.c.youtube.com/videoplayback?upn=p0pWpkfxwq4&sparams=algorithm%2Cburst%2Ccp%2Cfactor%2Cgcr%2Cid%2Cip%2Cipbits%2Citag%2Csource%2Cupn%2Cexpire&fexp=919330%2C916611%2C920704%2C912806%2C928001%2C922403%2C922405%2C929901%2C913605%2C929104%2C913546%2C913556%2C908496%2C920201%2C913302%2C919009%2C911116%2C901451%2C902556&key=yt1&algorithm=throttle-factor&itag=34&ipbits=8&burst=40&gcr=us&sver=3&signature=9DAA96CCF4CA172A92C78907B0ECE241BAFB07D6.09AF4B0F7C6558D1B9B184A5F60232EDC296FF95&mv=m&mt=1356395169&ip=74.61.34.250&expire=1356417961&source=youtube&ms=au&factor=1.25&cp=U0hUS1RMVV9LS0NONF9MRllKOmZQN1JFU3lOX2Js&id=27f0d5f5bd31eefe",
                    width=640,
                    height=360,
                    expires=datetime.datetime(2012, 12, 25, 6, 46, 1),
                    mime_type=u"video/x-flv",
                ),
                VideoFile(
                    url="http://r2---sn-nx57yn7d.c.youtube.com/videoplayback?upn=p0pWpkfxwq4&sparams=algorithm%2Cburst%2Ccp%2Cfactor%2Cgcr%2Cid%2Cip%2Cipbits%2Citag%2Csource%2Cupn%2Cexpire&fexp=919330%2C916611%2C920704%2C912806%2C928001%2C922403%2C922405%2C929901%2C913605%2C929104%2C913546%2C913556%2C908496%2C920201%2C913302%2C919009%2C911116%2C901451%2C902556&key=yt1&algorithm=throttle-factor&itag=5&ipbits=8&burst=40&gcr=us&sver=3&signature=A909DD7537DD821A0F5AE14FF1E83C87DD7C4EDF.4FCE8516F456B96DD45DB35A7AB8624A1A45498F&mv=m&mt=1356395169&ip=74.61.34.250&expire=1356417961&source=youtube&ms=au&factor=1.25&cp=U0hUS1RMVV9LS0NONF9MRllKOmZQN1JFU3lOX2Js&id=27f0d5f5bd31eefe",
                    width=400,
                    height=240,
                    expires=datetime.datetime(2012, 12, 25, 6, 46, 1),
                    mime_type=u"video/x-flv",
                ),
                VideoFile(
                    url="http://r11---sn-nx57yn76.c.youtube.com/videoplayback?upn=p0pWpkfxwq4&sparams=cp%2Cgcr%2Cid%2Cip%2Cipbits%2Citag%2Cratebypass%2Csource%2Cupn%2Cexpire&fexp=919330%2C916611%2C920704%2C912806%2C928001%2C922403%2C922405%2C929901%2C913605%2C929104%2C913546%2C913556%2C908496%2C920201%2C913302%2C919009%2C911116%2C901451%2C902556&key=yt1&expire=1356417961&source=youtube&ipbits=8&itag=43&gcr=us&sver=3&signature=7D0403EBD72E0A28695B35F7BD542A88BC9FE4FA.C4D2BFDD22BBFDC002F8C67CF66363BCC93501EC&ratebypass=yes&mt=1356395169&mv=m&ms=au&ip=74.61.34.250&cp=U0hUS1RMVV9LS0NONF9MRllKOmZQN1JFU3lOX2Js&id=27f0d5f5bd31eefe",
                    width=640,
                    height=360,
                    expires=datetime.datetime(2012, 12, 25, 6, 46, 1),
                    mime_type=u"video/webm",
                ),
            ],
        }
        self.assertDictEqual(data, expected_data)

    def test_get_video_data__fail_150(self):
        scrape_file = self.get_data_file("youtube/video_info2.txt")
        response = self.get_response(scrape_file.read())
        data = self.loader.get_video_data(response)
        self.assertDictEqual(data, {"is_embeddable": False})

    def test_get_video_data__fail_other(self):
        scrape_file = self.get_data_file("youtube/video_info2.txt")
        scrape_data = scrape_file.read().replace("150", "other")
        response = self.get_response(scrape_data)
        data = self.loader.get_video_data(response)
        self.assertEqual(data, {})

    def test_get_video_data__402(self):
        response = self.get_response("", code=402)
        data = self.loader.get_video_data(response)
        self.assertEqual(data, {})

    def test_get_video_data__no_files(self):
        scrape_file = self.get_data_file("youtube/video_info_no_files.txt")
        response = self.get_response(scrape_file.read())
        data = self.loader.get_video_data(response)
        expected_data = {
            "files": [],
            "thumbnail_url": "http://i1.ytimg.com/vi/8SCZaB3ZtAE/hqdefault.jpg",
            "tags": [
                u"Atlanta SEO services",
                u"Atlanta SEO Company",
                u"AL Loise",
                u"Audience Targeting",
                u"SEO Target",
                u"Online Business",
                u"Onli",
            ],
            "title": u"Audience Targeting",
        }
        self.assertEqual(data, expected_data)