def _create_video(self, video_url): video, created = Video.get_or_create_for_url(video_url, self.user) self.failUnless(video) self.failUnless(created) more_video, created = Video.get_or_create_for_url(video_url, self.user) self.failIf(created) self.failUnlessEqual(video, more_video)
def save(self): if self.cleaned_data.get('save_feed'): for feed_url in self.feed_urls: self.save_feed_url(feed_url) for vt in self.video_types: Video.get_or_create_for_url(vt=vt, user=self.user) return len(self.video_types)
def test_bliptv_twice(self): VIDEO_FILE = 'http://blip.tv/file/get/Kipkay-AirDusterOfficeWeaponry223.m4v' from vidscraper.sites import blip 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)
def test_youtube_subs_response(self): import os from videos.types.youtube import YoutubeVideoType import urllib def urlopen_mockup(url, *args, **kwargs): path = os.path.join(os.path.dirname(__file__), 'fixtures/youtube_subs_response.json') return open(path) _urlopen = urllib.urlopen urllib.urlopen = urlopen_mockup vt = YoutubeVideoType('http://www.youtube.com/watch?v=GcjgWov7mTM') video, create = Video.get_or_create_for_url('http://www.youtube.com/watch?v=GcjgWov7mTM', vt) vt._get_subtitles_from_youtube(video) video = Video.objects.get(pk=video.pk) version = video.version(language_code='en') self.assertFalse(version is None) self.assertTrue(len(version.subtitles())) self.assertEqual(version.subtitles()[0].text, 'I think what is probably the most misunderstood\nconcept in all of science and as we all know') subs = version.subtitles() subs.sort(key=lambda s: s.start_time) for i in range(1, len(subs)): self.assertTrue(subs[i].sub_order > subs[i - 1].sub_order) urllib.urlopen = _urlopen
def create(request): if request.method == 'POST': video_form = VideoForm(request.POST, label_suffix="") if video_form.is_valid(): owner = request.user if request.user.is_authenticated() else None video_url = video_form.cleaned_data['video_url'] try: video, created = Video.get_or_create_for_url(video_url, owner) except VidscraperError: vidscraper_error = True return render_to_response('videos/create.html', locals(), context_instance=RequestContext(request)) messages.info(request, message=u'''Here is the subtitle workspace for your video. You can share the video with friends, or get an embed code for your site. To add or improve subtitles, click the button below the video''') return redirect(video) #if not video.owner or video.owner == request.user or video.allow_community_edits: # return HttpResponseRedirect('{0}?autosub=true'.format(reverse( # 'videos:video', kwargs={'video_id':video.video_id}))) #else: # # TODO: better error page? # return HttpResponse('You are not allowed to add transcriptions to this video.') else: video_form = VideoForm(label_suffix="") return render_to_response('videos/create.html', locals(), context_instance=RequestContext(request))
def subtitles(request): callback = request.GET.get('callback') video_url = request.GET.get('video_url') language = request.GET.get('language') revision = request.GET.get('revision') format = request.GET.get('format', 'json') if video_url is None: return {'is_error': True, 'message': 'video_url not specified' } video, created = Video.get_or_create_for_url(video_url) if not video: return {'is_error': True, 'message': 'unsuported video url' } if format == 'json': output = [s.for_json() for s in video.subtitles(version_no=revision, language_code = language)] if callback: result = json.dumps(output) return HttpResponse('%s(%s);' % (callback, result), 'text/javascript') else: return output else: handler = GenerateSubtitlesHandler.get(format) if not handler: return {'is_error': True, 'message': 'undefined format' } subtitles = [s.for_generator() for s in video.subtitles(version_no=revision, language_code = language)] h = handler(subtitles, video) return HttpResponse(unicode(h))
def import_videos(self): if not self.should_import_videos(): return video_ids = google.get_uploaded_video_ids(self.channel_id) if not video_ids: return for video_id in video_ids: if video_id == self.last_import_video_id: break video_url = 'http://youtube.com/watch?v={}'.format(video_id) if self.type == ExternalAccount.TYPE_USER: Video.get_or_create_for_url(video_url, user=self.user) elif self.import_team: video, created = Video.get_or_create_for_url(video_url) TeamVideo.objects.create(video=video, team=self.import_team) self.last_import_video_id = video_ids[0] self.save()
def save(self): if self.cleaned_data.get('save_feed'): for feed_url, last_entry_url in self.feed_urls: self.save_feed_url(feed_url, last_entry_url) for vt, info in self.video_types: video, created = Video.get_or_create_for_url(vt=vt, user=self.user) return len(self.video_types)
def _api_subtitles_json(request): video_url = request.GET.get('video_url', None) language = request.GET.get('language', None) revision = request.GET.get('revision', None) if video_url is None: return {'is_error': True, 'message': 'video_url not specified' } video, created = Video.get_or_create_for_url(video_url) return [s.__dict__ for s in video.subtitles( version_no=revision, language_code = language)]
def test_video_cache_busted_on_delete(self): start_url = 'http://videos.mozilla.org/firefox/3.5/switch/switch.ogv' video, created = Video.get_or_create_for_url(start_url) video_url = video.get_video_url() video_pk = video.pk # cache_id_1 = video_cache.get_video_id(video_url) self.assertTrue(cache_id_1) video.delete() self.assertEqual(Video.objects.filter(pk=video_pk).count() , 0) # when cache is not cleared this will return arn cache_id_2 = video_cache.get_video_id(video_url) self.assertNotEqual(cache_id_1, cache_id_2) # create a new video with the same url, has to have same# key video2, created= Video.get_or_create_for_url(start_url) video_url = video2.get_video_url() cache_id_3 = video_cache.get_video_id(video_url) self.assertEqual(cache_id_3, cache_id_2)
def clean(self, value): self.vt = None self.video = None super(UniSubBoundVideoField, self).clean(value) video_url = value if not video_url: return video_url host = Site.objects.get_current().domain url_start = 'http://' + host if video_url.startswith(url_start): # UniSub URL locale, path = strip_path(video_url[len(url_start):]) video_url = url_start + path try: video_url = self.format_url(video_url) func, args, kwargs = resolve(video_url.replace(url_start, '')) if not 'video_id' in kwargs: raise forms.ValidationError( _('This URL does not contain video id.')) try: self.video = Video.objects.get(video_id=kwargs['video_id']) except Video.DoesNotExist: raise forms.ValidationError(_('Videos does not exist.')) except Http404: raise forms.ValidationError(_('Incorrect URL.')) else: # URL from other site try: self.vt = video_type_registrar.video_type_for_url(video_url) if hasattr(self, 'user'): user = self.user else: user = None if self.vt: self.video, created = Video.get_or_create_for_url( vt=self.vt, user=user) except VideoTypeError, e: self.video = None raise forms.ValidationError(e) if not self.video: raise forms.ValidationError( mark_safe( _(u"""Universal Subtitles does not support that website or video format. If you'd like to us to add support for a new site or format, or if you think there's been some mistake, <a href="mailto:%s">contact us</a>!""") % settings.FEEDBACK_EMAIL))
def test_cache_has_right_value(self): video_url = VideoUrl.objects.all()[0] tv = TeamVideo(video=video_url.video, team=self.team,added_by=self.user) tv.save() res = self._get_widget_moderation_status(video_url.url) self.assertFalse(res["is_moderated"]) video, created = Video.get_or_create_for_url(video_url.url) add_moderation(video, self.team, self.user) res = self._get_widget_moderation_status(video_url.url) self.assertTrue(res["is_moderated"])
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()
def _create_video(self, video_type, info, entry): from videos.models import Video video, created = Video.get_or_create_for_url(vt=video_type, user=self.user) if info: for name, value in info.items(): setattr(video, name, value) video.save() if created: self._created_videos.append(video)
def save(self): if self.cleaned_data.get('save_feed'): for feed_url, last_entry_url in self.feed_urls: self.save_feed_url(feed_url, last_entry_url) videos = [] for vt, info in self.video_types: videos.append(Video.get_or_create_for_url(vt=vt, user=self.user)) return videos
def test_add_new(self): """Submit a new video for the team. """ test_url = 'http://www.youtube.com/watch?v=i_0DXxNeaQ0' self.videos_tab.log_in(self.admin.username, 'password') self.videos_tab.open_videos_tab(self.team.slug) self.videos_tab.add_video(url=test_url) self.videos_tab.open_videos_tab(self.team.slug) video, _ = Video.get_or_create_for_url(test_url) self.assertTrue(self.videos_tab.video_present(video.title))
def read(self, request): """ Return subtitles for video. Send in request: <b>video url:</b> video_url <b>video id:</b> video_id <b>language:</b> language of video <b>revision:</b> revision of subtitles <b>sformat</b>: format of subtitles(srt, ass, ssa, ttml, sbv) By default format of response is 'plain', so you get raw subtitles content in response. If 'sformat' exists in request - format will be 'plain'. If 'callback' exists in request - format will be 'json'. curl http://127.0.0.1:8000/api/1.0/subtitles/ -d 'video_url=http://www.youtube.com/watch?v=YMBdMtbth0o' -G curl http://127.0.0.1:8000/api/1.0/subtitles/ -d 'video_url=http://www.youtube.com/watch?v=YMBdMtbth0o' -d 'callback=callback' -G curl http://127.0.0.1:8000/api/1.0/subtitles/ -d 'video_url=http://www.youtube.com/watch?v=YMBdMtbth0o' -d 'sformat=srt' -G curl http://127.0.0.1:8000/api/1.0/subtitles/ -d 'video_url=http://www.youtube.com/watch?v=YMBdMtbth0o' -d 'sformat=srt' -G curl http://127.0.0.1:8000/api/1.0/subtitles/ -d 'video_id=7Myc2QAeBco9' -G """ video_url = request.GET.get('video_url') language = request.GET.get('language') revision = request.GET.get('revision') sformat = request.GET.get('sformat') video_id = request.GET.get('video_id') if not video_url and not video_id: return rc.BAD_REQUEST if video_id: try: video = Video.objects.get(video_id=video_id) except Video.DoesNotExist: return rc.NOT_FOUND else: video, created = Video.get_or_create_for_url(video_url) if not video: return rc.NOT_FOUND if not sformat: output = [s.for_json() for s in video.subtitles(version_no=revision, language_code = language)] return output else: handler = GenerateSubtitlesHandler.get(sformat) if not handler: return rc.BAD_REQUEST subtitles = [s.for_generator() for s in video.subtitles(version_no=revision, language_code = language)] h = handler(subtitles, video) return unicode(h)
def test_set_values(self): youtbe_url = 'http://www.youtube.com/watch?v=_ShmidkrcY0' vt = self.vt(youtbe_url) 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)
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
def test_empty_id_show_widget(self): url = "http://videos-cdn.mozilla.net/serv/mozhacks/demos/screencasts/londonproject/screencast.ogv" cache_key = video_cache._video_id_key(url) video, create = Video.get_or_create_for_url(url) video_cache.cache.set(cache_key, "", video_cache.TIMEOUT) # we have a bogus url video_id = video_cache.get_video_id(url) self.assertTrue(bool(video_id)) try: Video.objects.get(video_id=video_id) except Video.DoesNotExist: self.fail("Should not point to a non existing video")
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.matches_video_url(url)) self.assertFalse(self.vt.matches_video_url('http://vimeo.com')) self.assertFalse(self.vt.matches_video_url(''))
def test_rpc(self): video_url = 'http://www.youtube.com/watch?v=z2U_jf0urVQ' video, created = Video.get_or_create_for_url(video_url) url = reverse('widget:rpc', args=['show_widget']) data = { 'is_remote': u'false', 'base_state': u'{"language_pk":%s,"language_code":"en"}', 'video_url': u'"%s"' % video_url } response = self.client.post(url, data=data) self.assertEqual(response.status_code, 200)
def clean(self, value): self.vt = None self.video = None super(UniSubBoundVideoField, self).clean(value) video_url = value if not video_url: return video_url host = Site.objects.get_current().domain url_start = 'http://'+host if video_url.startswith(url_start): # UniSub URL locale, path = strip_path(video_url[len(url_start):]) video_url = url_start+path try: video_url = self.format_url(video_url) func, args, kwargs = resolve(video_url.replace(url_start, '')) if not 'video_id' in kwargs: raise forms.ValidationError(_('This URL does not contain video id.')) try: self.video = Video.objects.get(video_id=kwargs['video_id']) except Video.DoesNotExist: raise forms.ValidationError(_('Videos does not exist.')) except Http404: raise forms.ValidationError(_('Incorrect URL.')) else: # URL from other site try: self.vt = video_type_registrar.video_type_for_url(video_url) if hasattr(self, 'user'): user = self.user else: user = None if self.vt: self.video, created = Video.get_or_create_for_url(vt=self.vt, user=user) except VideoTypeError, e: self.video = None raise forms.ValidationError(e) if not self.video: raise forms.ValidationError(mark_safe(_(u"""Universal Subtitles does not support that website or video format. If you'd like to us to add support for a new site or format, or if you think there's been some mistake, <a href="mailto:%s">contact us</a>!""") % settings.FEEDBACK_EMAIL))
def _create_video(self, video_type, info, entry): from videos.models import Video video, created = Video.get_or_create_for_url( vt=video_type, user=self.user) # created should always be True, since we filtered out existing items # already, but check it anyways if created: if info: for name, value in info.items(): setattr(video, name, value) video.save() self._created_videos.append(video)
def test_resolve_ownership(self): tpa = test_factories.create_third_party_account(self.vurl) # test with a video that should be linked to an account owner = ThirdPartyAccount.objects.resolve_ownership(self.vurl) self.assertEquals(owner, tpa) # test with a video that shouldn't be linked to an account video, _ = Video.get_or_create_for_url( 'http://www.youtube.com/watch?v=pQ9qX8lcaBQ') video_url = video.get_primary_videourl_obj() owner = ThirdPartyAccount.objects.resolve_ownership(video_url) self.assertEquals(owner, None)
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(''))
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.matches_video_url(url)) self.assertFalse(self.vt.matches_video_url('')) self.assertFalse(self.vt.matches_video_url('http://www.dailymotion.com'))
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 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))
def test_type(self): url = 'http://blip.tv/file/4297824?utm_source=featured_ep&utm_medium=featured_ep' video, created = Video.get_or_create_for_url(url) vu = video.videourl_set.all()[:1].get() self.assertEqual(vu.videoid, '4297824') 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/file/4297824')) self.assertFalse(self.vt.matches_video_url('http://blip.tv')) self.assertFalse(self.vt.matches_video_url(''))
def _create_video(self, video_type, info, entry): from videos.models import Video from teams.models import TeamVideo from teams.signals import api_teamvideo_new video, created = Video.get_or_create_for_url( vt=video_type, user=self.user) if info: for name, value in info.items(): setattr(video, name, value) video.save() if created and self.team is not None: tv = TeamVideo.objects.create( video=video, team=self.team, added_by=self.user, description=video.description) api_teamvideo_new.send(tv)
def test_set_values(self): youtbe_url = 'http://www.youtube.com/watch?v=_ShmidkrcY0' vt = self.vt(youtbe_url) 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) language = video.subtitlelanguage_set.all()[0] version = language.latest_version() self.assertEqual(len(version.subtitles()), 26) self.assertEqual(self.vt.video_url(vu), youtbe_url)
def test_set_values(self, mock_get_video_info): video_info = google.VideoInfo('test-channel-id', 'title', 'description', 100, 'http://example.com/thumb.png') mock_get_video_info.return_value = video_info video, created = Video.get_or_create_for_url( 'http://www.youtube.com/watch?v=_ShmidkrcY0') vu = video.videourl_set.all()[:1].get() self.assertEqual(vu.videoid, '_ShmidkrcY0') self.assertEqual(video.title, video_info.title) self.assertEqual(video.description, video_info.description) self.assertEqual(video.duration, video_info.duration) self.assertEqual(video.thumbnail, video_info.thumbnail_url)
def test_type(self): url = 'http://someurl.com/video.flv?val=should&val1=be#removed' clean_url = 'http://someurl.com/video.flv' 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.assertFalse(self.vt.matches_video_url('http://someurl.flv')) self.assertFalse(self.vt.matches_video_url('')) self.assertFalse(self.vt.matches_video_url('http://someurl.com/flv.video'))
def read(self, request): """ Return inforamiton about avilable subtitles languages. Send in request: <b>video url:</b> video_url <b>video id:</b> video_id curl http://127.0.0.1:8000/api/1.0/subtitles/languages/ -d 'video_id=7Myc2QAeBco9' -G <pre>[ { "id": 12, "code": "it", "name": "Italian", "is_original": true } ]</pre> """ video_url = request.GET.get('video_url') video_id = request.GET.get('video_id') if not video_url and not video_id: return rc.BAD_REQUEST if video_id: try: video = Video.objects.get(video_id=video_id) except Video.DoesNotExist: return rc.NOT_FOUND else: video, created = Video.get_or_create_for_url(video_url) if not video: return rc.NOT_FOUND output = [] for item in video.subtitlelanguage_set.all(): output.append({ 'id': item.id, 'code': item.language, 'name': item.get_language_display(), 'is_original': item.is_original, "completion": complete_indicator(item) }) return output
def create(self, validated_data): set_values = {} for key in ('title', 'description', 'duration', 'thumbnail', 'primary_audio_language_code', 'metadata'): if key in validated_data: set_values[key] = validated_data[key] video, created = Video.get_or_create_for_url( validated_data['video_url'], user=self.context['user'], set_values=set_values, ) if video is None: self.fail('invalid-url', url=validated_data['video_url']) if not created: self.fail('video-exists', url=validated_data['video_url']) self._update_team(video, validated_data) return video
def test_type(self): url = 'http://www.dailymotion.com/video/x7u2ww_juliette-drums_lifestyle#hp-b-l' vt = self.vt(url) 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'))
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
def get_video_id(video_url): cache_key = _video_id_key(video_url) value = cache.get(cache_key) if value is not None: return value else: from videos.models import Video try: video, create = Video.get_or_create_for_url(video_url) except VideoTypeError: return None if not video: return None video_id = video.video_id cache.set(cache_key, video_id, TIMEOUT) return video_id
def test_get_video_info_exception(self, mock_get_video_info): video_info = google.VideoInfo('test-channel-id', 'title', 'description', 100, 'http://example.com/thumb.png') mock_get_video_info.side_effect = google.APIError() video, created = Video.get_or_create_for_url( 'http://www.youtube.com/watch?v=_ShmidkrcY0') vu = video.videourl_set.all()[:1].get() self.assertEqual(vu.videoid, '_ShmidkrcY0') self.assertEqual(video.description, '') self.assertEqual(video.duration, None) self.assertEqual(video.thumbnail, '') # since get_video_info failed, we don't know the channel id of our # video URL. We should use a dummy value to make it easier to fix the # issue in the future self.assertEqual(vu.owner_username, None)
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)
def get_video_id(video_url): cache_key = _video_id_key(video_url) value = cache.get(cache_key) if bool(value): return value else: from videos.models import Video try: video, create = Video.get_or_create_for_url(video_url) except VideoTypeError: return None if not video: return None video_id = video.video_id cache.set(cache_key, video_id, TIMEOUT) return video_id
def create(request): if request.method == 'POST': video_form = VideoForm(request.POST, label_suffix="") if video_form.is_valid(): video_url = video_form.cleaned_data['video_url'] try: video, created = Video.get_or_create_for_url(video_url) except (VidscraperError, RequestError): vidscraper_error = True return render_to_response('videos/create.html', locals(), context_instance=RequestContext(request)) messages.info(request, message=u'''Here is the subtitle workspace for your video. You can share the video with friends, or get an embed code for your site. To add or improve subtitles, click the button below the video''') return redirect(video) else: video_form = VideoForm(label_suffix="") return render_to_response('videos/create.html', locals(), context_instance=RequestContext(request))
def subtitle_existence(request): video_url = request.GET.get('video_url') if video_url is None: return {'is_error': True, 'message': 'video_url not specified' } video, created = Video.get_or_create_for_url(video_url) if not video: return {'is_error': True, 'message': 'unsuported video url' } output = [] for item in video.subtitlelanguage_set.all(): output.append({ 'code': item.language, 'name': item.get_language_display(), 'is_original': item.is_original }) return output
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
def _assert(self, start_url, end_url): from videos.models import VIDEO_TYPE_HTML5 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)
def test_video_title(self): url = 'http://blip.tv/file/4914074' video, created = Video.get_or_create_for_url(url) #really this should be jsut not failed self.assertTrue(video.get_absolute_url())
def _create_rdm_video(self, i): video, created = Video.get_or_create_for_url("http://www.example.com/%s.mp4" % i) return video
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)