• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python models.Video类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: forwards

    def forwards(self, orm):
        try:
            from videos.models import Video
        except ImportError:
            return        
        
        try:
            from statistic import video_view_counter, sub_fetch_total_counter, \
                widget_views_total_counter
        except ImportError:
            if settings.DEBUG:
                return
            raise Exception('Some redis utilits is unavailable, maybe this migration was not updated after refactoring. You can ignore this migration with: python manage.py migrate statistic 0074 --fake, but all statistic data will be lost.')

        try:
            video_view_counter.r.ping()
        except ConnectionError:
            if settings.DEBUG:
                return
            raise Exception('Redis server is unavailable. You can ignore this migration with: python manage.py migrate statistic 00074 --fake, but all statistic data will be lost.')
        
        video_view_counter.delete()
        sub_fetch_total_counter.delete()
        widget_views_total_counter.delete()
        for obj in orm.Video.objects.all():
            video_counter = Video.view_counter(obj.video_id)
            video_counter.delete()
            video_counter.set(obj.view_count)
            video_view_counter.incr(obj.view_count)
            sub_fetch_total_counter.incr(obj.subtitles_fetched_count)
            widget_views_total_counter.incr(Video.widget_views_counter(obj.video_id).get())
开发者ID:MechanisM,项目名称:mirosubs,代码行数:31,代码来源:0074_migrate_view_counter_to_redis.py


示例2: init_cocreate

def init_cocreate(cocreate, generate_slug):
    if len(cocreate.videos) <= 0:
        return
    
    if not cocreate.output_video:
        slug = generate_slug(SLUG_LENGTH)
        video = Video(title=cocreate.title, slug=slug, description=cocreate.description, uploader=cocreate.owner)
        video.save()
        cocreate.output_video = video
        cocreate.save()
    else:
        # reset video status to encoding
        video_status = cocreate.output_video.get_video_status()
        video_status.set_to_encoding()

    #create outline from the sections
    VideoOutline.objects.filter(video=cocreate.output_video).delete()
    outline = VideoOutline.objects.create(video=cocreate.output_video)
    asections = cocreate.available_sections
    for i in xrange(len(asections)):
        outline.videooutlinepin_set.create(text=asections[i],
                                           current_time=Decimal(str(i)))

    # enqueue on cocreate task queue
    enqueue_cocreate(cocreate)
开发者ID:465060874,项目名称:screenbird,代码行数:25,代码来源:utils.py


示例3: _create_video

 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,代码行数:7,代码来源:tests.py


示例4: main

def main():
    parsed = feedparser.parse(file("mostravideolivre.atom").read())
    for i in parsed.entries:
        mp4_url = i.content[0].src
        ogg_url = mp4_url.replace(".mp4", ".ogg")
        ogg_url = ogg_url.replace(".MP4", ".ogg")
        thumb = ogg_url + ".png"

        video = Video()
        video.title = i.title
        video.creation_date = datetime.now()
        video.summary = i.get("summary", "")
        video.author = i.author
        video.license_name = "Creative Commons - Atribuição - Partilha nos Mesmos " + "Termos 3.0 Não Adaptada"
        video.license_link = "http://creativecommons.org/licenses/by-sa/3.0/"
        video.thumb_url = thumb
        video.save()

        tag = Tag.objects.get_or_create(name="mvl2010")[0]
        tag.save()
        video.tags.add(tag.id)

        url = Url()
        url.url = mp4_url
        url.content_type = 'video/mp4; codecs="avc1.42E01E, mp4a.40.2"'
        url.video = video
        url.save()

        url = Url()
        url.url = ogg_url
        url.content_type = 'video/ogg; codecs="theora, vorbis"'
        url.video = video
        url.save()
开发者ID:gabinetedigital,项目名称:videre,代码行数:33,代码来源:import2010.py


示例5: test_delete_index

 def test_delete_index(self):
     app_config = apps.get_app_config('videos')
     create_index(app_config, 'Video')
     self.assertTrue(index_exists(Video.get_index_name()))
     delete_index(Video.get_index_name())
     with self.assertRaises(IndexNotFound):
         get_index(Video.get_index_name())
开发者ID:Tuss4,项目名称:trickfeed,代码行数:7,代码来源:tests.py


示例6: save

 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,代码行数:8,代码来源:forms.py


示例7: handle

    def handle(self, *args, **kwargs):
        try:
            sub_fetch_keys_set.r.ping()
        except:
            if settings.DEBUG:
                raise
            self.handle_error('Statistic update error', '', sys.exc_info())     
            return
        
        count = sub_fetch_keys_set.scard()
        
        while count:
            count -= 1
            key = sub_fetch_keys_set.spop()
            
            if not key:
                break
            
            print 'Handle key: %s' % key
            
            parts = key.split(':')
            d = date(int(parts[-1]), int(parts[-2]), int(parts[-3]))
            
            if len(parts) == 6:
                lang = parts[2]
            else:
                lang = ''
            
            try:
                video = Video.objects.get(video_id=parts[1])
            except Video.DoesNotExist:
                print 'Video does not exist'
                default_connection.delete(key)
                continue
            
            counter_obj, created = SubtitleFetchCounters.objects.get_or_create(date=d, video=video, language=lang)
            counter_obj.count += int(default_connection.getset(key, 0))
            counter_obj.save()
            
        count = changed_video_set.scard()
        
        while count:
            count -= 1

            video_id = changed_video_set.spop()

            if not video_id:
                break
            
            print 'Update statistic for video: %s' % video_id
            
            subtitles_fetched_counter = Video.subtitles_fetched_counter(video_id, True)
            widget_views_counter = Video.widget_views_counter(video_id, True)
            view_counter = Video.view_counter(video_id, True)
            
            Video.objects.filter(video_id=video_id).update(view_count=F('view_count')+view_counter.getset(0))
            Video.objects.update(widget_views_count=F('widget_views_count')+widget_views_counter.getset(0))
            Video.objects.update(subtitles_fetched_count=F('subtitles_fetched_count')+subtitles_fetched_counter.getset(0))
开发者ID:MechanisM,项目名称:mirosubs,代码行数:58,代码来源:update_statistic.py


示例8: test_bliptv_twice

 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,代码行数:9,代码来源:tests.py


示例9: create

    def create(self, validated_data):
        # logged in required
        user = ContextUtils(self.context).logged_in_user()

        # create video
        video = Video(**validated_data)
        video.user = user
        video.save()

        # add video tags
        tags = TagBuilder.get_or_create_tags(validated_data['title'])
        for tag in tags:
            video.tags.add(tag)

        return video
开发者ID:lotube,项目名称:lotube,代码行数:15,代码来源:serializers.py


示例10: subtitles

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,代码行数:33,代码来源:views.py


示例11: create

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,代码行数:26,代码来源:views.py


示例12: test_youtube_subs_response

    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,代码行数:26,代码来源:tests.py


示例13: test_video_cache_busted_on_delete

 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,代码行数:18,代码来源:tests.py


示例14: _api_subtitles_json

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,代码行数:9,代码来源:views.py


示例15: test_cache_has_right_value

 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,代码行数:10,代码来源:moderation_test.py


示例16: 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)

        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,代码行数:10,代码来源:forms.py


示例17: read

    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,代码行数:54,代码来源:handlers.py


示例18: test_get_document

 def test_get_document(self):
     app_config = apps.get_app_config('videos')
     create_index(app_config, 'Video')
     self.assertTrue(index_exists(Video.get_index_name()))
     time.sleep(1)
     v = Video.objects.create(
         title="Test Video",
         video_id="Leg1tVid1D",
         thumbnail_url="http://example.com/legitthumbnail.jpeg")
     doc = get_document(v)
     self.assertTrue(isinstance(doc, dict))
开发者ID:Tuss4,项目名称:trickfeed,代码行数:11,代码来源:tests.py


示例19: test_set_values

 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,代码行数:11,代码来源:tests.py


示例20: clean

    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,代码行数:53,代码来源:unisub_video_form.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python view.invalidate_cache函数代码示例发布时间:2022-05-26
下一篇:
Python models.SubtitleLanguage类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap