Example #1
0
 def test_bliptv_twice(self):
     VIDEO_FILE = 'http://blip.tv/file/get/Kipkay-AirDusterOfficeWeaponry223.m4v'
     old_video_file_url = blip.video_file_url
     blip.video_file_url = lambda x: VIDEO_FILE
     Video.get_or_create_for_url('http://blip.tv/file/4395490')
     blip.video_file_url = old_video_file_url
     # this test passes if the following line executes without throwing an error.
     Video.get_or_create_for_url(VIDEO_FILE)
Example #2
0
def _create_videos(video_data, users):
    videos = []

    for x in video_data:
        shuffle(users)
        video = Video(title=x['title'])
        video.save()
        if len(users) > 0:
            video.user = users[0]
        url = x['url'] + "&blah=%s" % time.time()
        vt = video_type_registrar.video_type_for_url(url)
        if vt is None:
            continue
        video_url, created = VideoUrl.objects.get_or_create(
            video=video, type=vt.abbreviation, url=url)
        video_url.original = True
        video_url.primary = True
        video_url.video = video
        video_url.save()
        # now we loop over languages:
        _add_langs_to_video(video, x['langs'])
        if len(x['langs']) > 0:
            video.is_subtitled = True
        video.save()
        videos.append(video)

    return videos
Example #3
0
    def test_subtitles_saving(self):
        youtube_url = 'http://www.youtube.com/watch?v=L4XpSM87VUk'

        test_utils.youtube_get_subtitled_languages.return_value = [{
            'lang_code':
            'en',
            'name':
            'My Subtitles'
        }]
        vt = self.vt(youtube_url)
        video, created = Video.get_or_create_for_url(youtube_url)

        langs = vt.get_subtitled_languages()
        lang = None
        for candidate in langs:
            if candidate['lang_code'] == 'en':
                lang = candidate
                break
        self.assertTrue(
            lang,
            "This video must have an 'en' language whose last sub is 'Thanks'")

        save_subtitles_for_lang(lang, video.pk,
                                video.videourl_set.all()[0].videoid)

        sl = video.subtitle_language(lang['lang_code'])

        subtitles = sl.get_tip().get_subtitles()
        self.assertTrue(len(subtitles))
        self.assertEqual(list(subtitles)[-1][2], u'English subtitles.')
Example #4
0
    def test_type(self):
        url = 'http://someurl.com/video.ogv?val=should&val1=be#removed'
        clean_url = 'http://someurl.com/video.ogv'

        video, created = Video.get_or_create_for_url(url)
        vu = video.videourl_set.all()[:1].get()

        self.assertEqual(vu.url, clean_url)
        self.assertEqual(self.vt.video_url(vu), vu.url)

        self.assertTrue(self.vt.matches_video_url(url))
        self.assertTrue(
            self.vt.matches_video_url('http://someurl.com/video.ogg'))
        self.assertTrue(
            self.vt.matches_video_url('http://someurl.com/video.mp4'))
        self.assertTrue(
            self.vt.matches_video_url('http://someurl.com/video.m4v'))
        self.assertTrue(
            self.vt.matches_video_url('http://someurl.com/video.webm'))

        self.assertFalse(self.vt.matches_video_url('http://someurl.ogv'))
        self.assertFalse(self.vt.matches_video_url(''))
        #for this is other type
        self.assertFalse(
            self.vt.matches_video_url('http://someurl.com/video.flv'))
        self.assertFalse(
            self.vt.matches_video_url('http://someurl.com/ogv.video'))
Example #5
0
    def test_type(self):
        url = 'http://cdnbakmi.kaltura.com/p/1492321/sp/149232100/serveFlavor/entryId/1_zr7niumr/flavorId/1_djpnqf7y/name/a'

        video, created = Video.get_or_create_for_url(url)
        vu = video.videourl_set.get()
        self.assertEquals(vu.type, 'K')
        self.assertEquals(vu.kaltura_id(), '1_zr7niumr')
Example #6
0
 def create_video(self, **kwargs):
     try:
         v = VideoUrlFactory(**kwargs).video
     except IntegrityError:
         v, _ = Video.get_or_create_for_url(video_url=kwargs['url'])
     self.logger.info('Video: %s' % v.video_id)
     return v
Example #7
0
 def test_type(self):
     url = 'http://link.brightcove.com/services/player/bcpid955357260001?bckey=AQ~~,AAAA3ijeRPk~,jc2SmUL6QMyqTwfTFhUbWr3dg6Oi980j&bctid=956115196001'
     video, created = Video.get_or_create_for_url(url)
     vu = video.videourl_set.all()[:1].get()
     self.assertTrue(vu.type == VIDEO_TYPE_BRIGHTCOVE ==
                     BrightcoveVideoType.abbreviation)
     self.assertTrue(self.vt.video_url(vu))
     self.assertTrue(self.vt.matches_video_url(url))
Example #8
0
def _create_videos(video_data, users):
    videos = []
    
    
    for x in video_data:
        shuffle(users)
        video = Video(title=x['title'])
        video.save()
        if len(users) > 0:
            video.user = users[0]
        url = x['url'] + "&blah=%s" % time.time()
        vt =  video_type_registrar.video_type_for_url(url)
        if vt is None:
            continue
        video_url, created  = VideoUrl.objects.get_or_create(video=video, type=vt.abbreviation, url=url)
        video_url.original = True
        video_url.primary = True
        video_url.video = video
        video_url.save()
         # now we loop over languages:
        _add_langs_to_video(video, x['langs'])
        if len(x['langs']) > 0:
            video.is_subtitled = True
        video.save()    
        videos.append(video)
       
   
    return videos
Example #9
0
 def setUp(self):
     self.video = Video.get_or_create_for_url("http://example.com/hey.mp4")[0]
     site = Site.objects.get_current()
     site.domain = "www.amara.org"
     site.save()
     # on production our domain might have www,
     # make sure we have such domain and that
     # www is not present
     self.short_url = shortlink_for_video(self.video)
     Site.objects.clear_cache()
Example #10
0
    def test_set_values(self):
        youtbe_url = 'http://www.youtube.com/watch?v=_ShmidkrcY0'

        video, created = Video.get_or_create_for_url(youtbe_url)
        vu = video.videourl_set.all()[:1].get()

        self.assertEqual(vu.videoid, '_ShmidkrcY0')
        self.assertTrue(video.title)
        self.assertEqual(video.duration, 79)
        self.assertTrue(video.thumbnail)
Example #11
0
 def video_with_two_followers():
     v, c = Video.get_or_create_for_url(
         "http://blip.tv/file/get/Miropcf-AboutUniversalSubtitles847.ogv"
     )
     f1 = User.objects.all()[0]
     f2 = User.objects.all()[1]
     f1.notify_by_email = f2.notify_by_email = True
     f1.save()
     f2.save()
     v.followers.add(f1, f2)
     return v
Example #12
0
    def test_type(self):
        url = 'http://vimeo.com/15786066?some_param=111'

        video, created = Video.get_or_create_for_url(url)
        vu = video.videourl_set.all()[:1].get()

        self.assertEqual(vu.videoid, '15786066')
        self.assertTrue(self.vt.video_url(vu))

        self.assertTrue(self.vt.matches_video_url(url))

        self.assertFalse(self.vt.matches_video_url('http://vimeo.com'))
        self.assertFalse(self.vt.matches_video_url(''))
Example #13
0
    def run(self):
        try:
            api_key = self.get_working_api_key()
            if not api_key:
                raise Exception('Usable Api Key currently unavailable!')

            response = self.get_response(api_key)
            status_code = response.status_code
            if status_code == 200:
                data = response.json()
                videos_map = {}
                for item in data.get('items', []):
                    try:
                        snippet = item['snippet']
                        video_id = item['id']['videoId']
                        published_at = parse(snippet['publishedAt'])
                        obj = Video(**{
                            'video_id': video_id,
                            'channel_id': snippet['channelId'],
                            'title': snippet['title'],
                            'description': snippet['description'],
                            'published_at': published_at,
                            'thumbnail_default': snippet['thumbnails']['default']['url'],
                            'thumbnail_medium': snippet['thumbnails']['medium']['url'],
                            'thumbnail_high': snippet['thumbnails']['high']['url'],
                        })
                        videos_map[video_id] = obj
                    except KeyError as e:
                        logger.info('Skipping an item due to KeyError({})'.format(e))

                video_ids = list(videos_map.keys())
                existing_videos = list(Video.objects.filter(video_id__in=video_ids).values_list('video_id', flat=True))
                if existing_videos:
                    logger.error('Found {} existing videos.'.format(len(existing_videos)))
                for video_id in existing_videos:
                    del videos_map[video_id]

                if videos_map:
                    videos = list(videos_map.values())
                    logger.info('Inserting {} new videos.'.format(len(videos)))
                    Video.objects.bulk_create(videos)
            elif status_code == 403:
                logger.error('[Response StatusCode: {}] {}'.format(status_code, response.json()))
                error_data = response.json()
                for error in error_data['error']['errors']:
                    if error['reason'] == 'quotaExceeded':
                        self.get_working_api_key(api_key)
            else:
                logger.error('[Response StatusCode: {}] {}'.format(status_code, response.json()))
        except Exception as e:
            logger.error('[Unhandled Exception] {}'.format(e))
Example #14
0
    def test1(self):
        #For this video Vimeo API returns response with strance error
        #But we can get data from this response. See vidscraper.sites.vimeo.get_shortmem
        #So if this test is failed - maybe API was just fixed and other response is returned
        # FIXME: restablish when vimeo api is back!
        return
        url = u'http://vimeo.com/22070806'
        video, created = Video.get_or_create_for_url(url)

        self.assertNotEqual(video.title, '')
        self.assertNotEqual(video.description, '')
        vu = video.videourl_set.all()[:1].get()

        self.assertEqual(vu.videoid, '22070806')
        self.assertTrue(self.vt.video_url(vu))
Example #15
0
 def setUp(self):
     original_video, created = Video.get_or_create_for_url(
         "http://www.example.com/original.mp4")
     original_video.duration = 10
     original_video.save()
     self.original_video = original_video
     self.language = SubtitleLanguage.objects.create(video=original_video,
                                                     language_code='en',
                                                     is_forked=True)
     self.version = pipeline.add_subtitles(
         self.original_video,
         self.language.language_code,
         [],
         created=datetime.datetime.now(),
     )
Example #16
0
    def test_type(self):
        url = 'http://someurl.com/audio.mp3?val=should&val1=be#removed'
        clean_url = 'http://someurl.com/audio.mp3'

        video, created = Video.get_or_create_for_url(url)
        vu = video.videourl_set.all()[:1].get()

        self.assertEqual(vu.url, clean_url)
        self.assertEqual(self.vt.video_url(vu), vu.url)

        self.assertTrue(self.vt.matches_video_url(url))

        self.assertTrue(
            self.vt.matches_video_url('http://someurl.com/audio.mp3'))
        self.assertFalse(
            self.vt.matches_video_url('http://someurl.com/mp3.audio'))
Example #17
0
    def test_type(self):
        url = 'http://www.dailymotion.com/video/x7u2ww_juliette-drums_lifestyle#hp-b-l'

        video, created = Video.get_or_create_for_url(url)
        vu = video.videourl_set.all()[:1].get()

        self.assertEqual(vu.videoid, 'x7u2ww')
        self.assertTrue(video.title)
        self.assertTrue(video.thumbnail)
        self.assertEqual(vu.url, 'http://dailymotion.com/video/x7u2ww')
        self.assertTrue(self.vt.video_url(vu))

        self.assertTrue(self.vt.matches_video_url(url))
        self.assertFalse(self.vt.matches_video_url(''))
        self.assertFalse(
            self.vt.matches_video_url('http://www.dailymotion.com'))
Example #18
0
def _create_videos(video_data, users):
    videos = []

    for x in video_data:
        shuffle(users)
        video, created = Video.get_or_create_for_url(x["url"])
        video.title = x["title"]
        video.save()
        if len(users) > 0:
            video.user = users[0]

        _add_langs_to_video(video, x["langs"])
        if len(x["langs"]) > 0:
            video.is_subtitled = True
        video.save()
        videos.append(video)

    return videos
Example #19
0
    def setUp(self):
        self.user_1 = User.objects.create(username='******')
        self.user_2 = User.objects.create(username='******')

        self.video = video = Video.get_or_create_for_url(
            "http://www.example.com/video.mp4")[0]
        video.primary_audio_language_code = 'en'
        video.user = self.user_1
        video.save()
        mail.outbox = []
        self.original_language = SubtitleLanguage.objects.create(
            video=video, language_code='en')
        subs = SubtitleSet.from_list('en', [
            (1000, 2000, "1"),
            (2000, 3000, "2"),
            (3000, 4000, "3"),
        ])
        self.original_language.add_version(subtitles=subs)
Example #20
0
def _create_videos(video_data, users):
    videos = []

    for x in video_data:
        shuffle(users)
        video, created = Video.get_or_create_for_url(x['url'])
        video.title = x['title']
        video.save()
        if len(users) > 0:
            video.user = users[0]

        _add_langs_to_video(video, x['langs'])
        if len(x['langs']) > 0:
            video.is_subtitled = True
        video.save()
        videos.append(video)

    return videos
Example #21
0
    def test_type(self):
        url = 'http://blip.tv/day9tv/day-9-daily-438-p3-build-orders-made-easy-newbie-tuesday-6066868'
        video, created = Video.get_or_create_for_url(url)
        vu = video.videourl_set.all()[:1].get()

        # this is the id used to embed videos
        self.assertEqual(vu.videoid, 'hdljgvKmGAI')
        self.assertTrue(video.title)
        self.assertTrue(video.thumbnail)
        self.assertTrue(vu.url)

        self.assertTrue(self.vt.matches_video_url(url))
        self.assertTrue(
            self.vt.matches_video_url(
                'http://blip.tv/day9tv/day-9-daily-438-p3-build-orders-made-easy-newbie-tuesday-6066868'
            ))
        self.assertFalse(self.vt.matches_video_url('http://blip.tv'))
        self.assertFalse(self.vt.matches_video_url(''))
Example #22
0
def make_video_3():
    video, _ = Video.get_or_create_for_url(VIDEO_URL_3)
    return video
Example #23
0
 def save(self):
     video_url = self.cleaned_data['video_url']
     obj, created = Video.get_or_create_for_url(video_url, self._video_type, self.user)
     self.created = created
     return obj
Example #24
0
 def _create_team_video(self, video_url, team, user):
     v, c = Video.get_or_create_for_url(video_url)
     tv, c = TeamVideo.objects.get_or_create(video=v,
                                             team=team,
                                             defaults={'added_by': user})
     return tv
Example #25
0
def get_video(n=1, user=None, url=None):
    if not url:
        url = VIDEO_URLS[n]
    video, _ = Video.get_or_create_for_url(url, user=user)
    return video
Example #26
0
 def test_blip_type(self):
     url = 'http://blip.tv/file/get/Coldguy-SpineBreakersLiveAWizardOfEarthsea210.FLV'
     video, created = Video.get_or_create_for_url(url)
     video_url = video.videourl_set.all()[0]
     self.assertEqual(self.vt.abbreviation, video_url.type)
Example #27
0
 def _create_rdm_video(self, i):
     video, created = Video.get_or_create_for_url("http://www.example.com/%s.mp4" % i)
     return video
Example #28
0
 def create_team_video():
     v, c = Video.get_or_create_for_url(video_url)
     tv, c = TeamVideo.objects.get_or_create(
         video=v, team=team, defaults={'added_by': owner.user})
     return tv
Example #29
0
 def test_video_title(self):
     url = 'http://blip.tv/day9tv/day-9-daily-100-my-life-of-starcraft-3505715'
     video, created = Video.get_or_create_for_url(url)
     #really this should be jsut not failed
     self.assertTrue(video.get_absolute_url())
Example #30
0
    def test_email_diff_subtitles(self):
        initial_count = len(mail.outbox)
        # set a user who can receive notification
        # make sure we have a different author, else he won't get notified
        author = User(username='******',
                      email='*****@*****.**',
                      notify_by_email=True,
                      valid_email=True)
        author.save(send_email_confirmation=False)
        # bypass logic from hell
        author.valid_email = True
        author.save()

        # this is needed for the non_editor template check
        user2 = User(username='******',
                     email='*****@*****.**',
                     notify_by_email=True,
                     valid_email=True)
        user2.save(send_email_confirmation=False)
        # bypass logic from hell
        user2.valid_email = True
        user2.save()
        # version is indentical to previous one
        video = Video.get_or_create_for_url(
            "http://wwww.example.com/video-diff.mp4")[0]
        video.followers.add(author)
        video.followers.add(user2)

        language = SubtitleLanguage(video=video, language_code='en')
        language.save()
        subs_data = [
            [0, 1000, '1'],
            [1000, 2000, '2'],
        ]

        subtitles_1 = SubtitleSet.from_list('en', subs_data)
        old_version = language.add_version(subtitles=subtitles_1,
                                           author=author)

        # now we change the text on the second sub
        subs_data[1][2] = '2 changed'
        # add a regular sub
        subs_data.append([2000, 3000, 'new sub'])
        # add an unsyced
        subs_data.append([None, None, 'no sync'])
        subtitles_2 = SubtitleSet.from_list('en', subs_data)
        new_version = language.add_version(subtitles=subtitles_2)
        self.assertTrue(len(video.notification_list()) > 0)

        res = send_new_version_notification(new_version.pk)
        self.assertNotEqual(res, None)
        # we expect two emails, one is the new-edits-non-editor, and
        # the other for mail_notification.html
        self.assertEqual(len(mail.outbox), initial_count + 2)
        for email_number, email_msg in enumerate(mail.outbox):
            # make sure this is the right message
            self.assertIn("New edits to ", email_msg.subject)
            self.assertIn("video-diff.mp4", email_msg.subject)
            html = BeautifulSoup(email_msg.body)
            html_text = "".join(html.body(text=True)).replace("\n", "")
            if email_number == 0:
                # assert text and timing changes are correct
                self.assertIn('67% of the text', html_text)
                self.assertIn('33% of the timing was changed.', html_text)
            # find the listed text changes to make sure they match
            diff_table = html.findAll('table', attrs={'class': 'diffs'})[0]
            old_version_changes = []
            new_version_changes = []
            for i, node in enumerate(diff_table.findAll('td')):
                if i % 2 == 0:
                    old_version_changes.append(node.text)
                else:
                    new_version_changes.append(node.text)
            self.assertEqual(old_version_changes, [u'2', u'', u''])
            self.assertEqual(new_version_changes, [
                u'2 changed',
                u'new sub',
                u'no sync',
            ])
Example #31
0
 def _assert(self, start_url, end_url):
     video, created = Video.get_or_create_for_url(start_url)
     vu = video.videourl_set.all()[:1].get()
     self.assertEquals(VIDEO_TYPE_HTML5, vu.type)
     self.assertEquals(end_url, vu.url)
Example #32
0
 def test_creating(self):
     # this test is for ticket: https://www.pivotaltracker.com/story/show/12996607
     url = 'http://blip.tv/day9tv/day-9-daily-1-flash-vs-hero-3515432'
     video, created = Video.get_or_create_for_url(url)