当前位置: 首页>>代码示例>>Python>>正文


Python Video.get_or_create_for_url方法代码示例

本文整理汇总了Python中videos.models.Video.get_or_create_for_url方法的典型用法代码示例。如果您正苦于以下问题:Python Video.get_or_create_for_url方法的具体用法?Python Video.get_or_create_for_url怎么用?Python Video.get_or_create_for_url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在videos.models.Video的用法示例。


在下文中一共展示了Video.get_or_create_for_url方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _create_video

# 需要导入模块: from videos.models import Video [as 别名]
# 或者: from videos.models.Video import get_or_create_for_url [as 别名]
 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)        
开发者ID:huberth,项目名称:mirosubs,代码行数:9,代码来源:tests.py

示例2: save

# 需要导入模块: from videos.models import Video [as 别名]
# 或者: from videos.models.Video import get_or_create_for_url [as 别名]
 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)
开发者ID:rhemmanur,项目名称:mirosubs,代码行数:10,代码来源:forms.py

示例3: test_bliptv_twice

# 需要导入模块: from videos.models import Video [as 别名]
# 或者: from videos.models.Video import get_or_create_for_url [as 别名]
 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)
开发者ID:MechanisM,项目名称:mirosubs,代码行数:11,代码来源:tests.py

示例4: test_youtube_subs_response

# 需要导入模块: from videos.models import Video [as 别名]
# 或者: from videos.models.Video import get_or_create_for_url [as 别名]
    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
开发者ID:MechanisM,项目名称:mirosubs,代码行数:28,代码来源:tests.py

示例5: create

# 需要导入模块: from videos.models import Video [as 别名]
# 或者: from videos.models.Video import get_or_create_for_url [as 别名]
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))
开发者ID:annasob,项目名称:mirosubs,代码行数:28,代码来源:views.py

示例6: subtitles

# 需要导入模块: from videos.models import Video [as 别名]
# 或者: from videos.models.Video import get_or_create_for_url [as 别名]
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))
开发者ID:MechanisM,项目名称:mirosubs,代码行数:35,代码来源:views.py

示例7: _api_subtitles_json

# 需要导入模块: from videos.models import Video [as 别名]
# 或者: from videos.models.Video import get_or_create_for_url [as 别名]
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)]
开发者ID:joedeveloper,项目名称:mirosubs,代码行数:11,代码来源:views.py

示例8: test_video_cache_busted_on_delete

# 需要导入模块: from videos.models import Video [as 别名]
# 或者: from videos.models.Video import get_or_create_for_url [as 别名]
 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)
开发者ID:axitkhurana,项目名称:mirosubs,代码行数:20,代码来源:tests.py

示例9: save

# 需要导入模块: from videos.models import Video [as 别名]
# 或者: from videos.models.Video import get_or_create_for_url [as 别名]
    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
开发者ID:adncentral,项目名称:unisubs,代码行数:12,代码来源:forms.py

示例10: test_cache_has_right_value

# 需要导入模块: from videos.models import Video [as 别名]
# 或者: from videos.models.Video import get_or_create_for_url [as 别名]
 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"])
开发者ID:adncentral,项目名称:unisubs,代码行数:12,代码来源:moderation_test.py

示例11: test_set_values

# 需要导入模块: from videos.models import Video [as 别名]
# 或者: from videos.models.Video import get_or_create_for_url [as 别名]
 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)
开发者ID:axitkhurana,项目名称:mirosubs,代码行数:13,代码来源:tests.py

示例12: read

# 需要导入模块: from videos.models import Video [as 别名]
# 或者: from videos.models.Video import get_or_create_for_url [as 别名]
    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)
开发者ID:MechanisM,项目名称:mirosubs,代码行数:56,代码来源:handlers.py

示例13: clean

# 需要导入模块: from videos.models import Video [as 别名]
# 或者: from videos.models.Video import get_or_create_for_url [as 别名]
    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))
开发者ID:pombredanne,项目名称:unisubs,代码行数:55,代码来源:unisub_video_form.py

示例14: test_type

# 需要导入模块: from videos.models import Video [as 别名]
# 或者: from videos.models.Video import get_or_create_for_url [as 别名]
    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(''))
开发者ID:MechanisM,项目名称:mirosubs,代码行数:15,代码来源:tests.py

示例15: test1

# 需要导入模块: from videos.models import Video [as 别名]
# 或者: from videos.models.Video import get_or_create_for_url [as 别名]
    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))
开发者ID:brettle,项目名称:mirosubs,代码行数:16,代码来源:tests.py


注:本文中的videos.models.Video.get_or_create_for_url方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。