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())
示例#2
0
    def show_widget(self,
                    request,
                    video_url,
                    is_remote,
                    base_state=None,
                    additional_video_urls=None):
        video_id = video_cache.get_video_id(video_url)
        if video_id is None:  # for example, private youtube video.
            return None

        if additional_video_urls is not None:
            for url in additional_video_urls:
                video_cache.associate_extra_url(url, video_id)

        models.Video.widget_views_counter(video_id).incr()
        widget_views_total_counter.incr()

        return_value = {
            'video_id': video_id,
            'subtitles': None,
        }
        add_general_settings(request, return_value)
        if request.user.is_authenticated():
            return_value['username'] = request.user.username

        return_value['video_urls'] = video_cache.get_video_urls(video_id)

        return_value['drop_down_contents'] = \
            self._drop_down_contents(video_id)

        if base_state is not None and base_state.get("language_code",
                                                     None) is not None:
            lang_pk = base_state.get('language_pk', None)
            if lang_pk is None:
                lang_code = base_state.get('language_code', None)
                language = models.SubtitleLanguage.objects.get(
                    video_id=video_id, language=lang_code)

                if language:
                    lang_pk = language.pk

            subtitles = self._autoplay_subtitles(
                request.user, video_id, lang_pk,
                base_state.get('revision', None))
            return_value['subtitles'] = subtitles
        else:
            if is_remote:
                autoplay_language = self._find_remote_autoplay_language(
                    request)
                language = models.Video.objects.get(
                    video_id=video_id).subtitle_language()
                if language is not None:
                    language_pk = language.pk
                else:
                    language_pk = None
                if autoplay_language is not None:
                    subtitles = self._autoplay_subtitles(
                        request.user, video_id, language_pk, None)
                    return_value['subtitles'] = subtitles
        return return_value
示例#3
0
文件: rpc.py 项目: brettle/mirosubs
    def show_widget(self, request, video_url, is_remote, base_state=None, additional_video_urls=None):
        video_id = video_cache.get_video_id(video_url)
        if video_id is None: # for example, private youtube video.
            return None

        if additional_video_urls is not None:
            for url in additional_video_urls:
                video_cache.associate_extra_url(url, video_id)

        models.Video.widget_views_counter(video_id).incr()
        widget_views_total_counter.incr()
        
        return_value = {
            'video_id' : video_id,
            'subtitles': None,
            }
        add_general_settings(request, return_value)
        if request.user.is_authenticated():
            return_value['username'] = request.user.username

        return_value['video_urls'] = video_cache.get_video_urls(video_id)

        return_value['drop_down_contents'] = \
            self._drop_down_contents(video_id)

        if base_state is not None and base_state.get("language_code", None) is not None:
            lang_pk = base_state.get('language_pk', None)
            if lang_pk is  None:
                lang_code = base_state.get('language_code', None)
                language = models.SubtitleLanguage.objects.get(video_id=video_id,language=lang_code)

                if language:
                    lang_pk = language.pk

            subtitles = self._autoplay_subtitles(
                request.user, video_id, 
                lang_pk,
                base_state.get('revision', None))
            return_value['subtitles'] = subtitles
        else:
            if is_remote:
                autoplay_language = self._find_remote_autoplay_language(request)
                language = models.Video.objects.get(video_id=video_id).subtitle_language()
                if language is not None:
                    language_pk = language.pk
                else:
                    language_pk = None
                if autoplay_language is not None:
                    subtitles = self._autoplay_subtitles(
                        request.user, video_id, language_pk, None)
                    return_value['subtitles'] = subtitles
        return return_value
    def forwards(self, orm):
        from redis.exceptions import ConnectionError
        try:
            from videos.models import Video
        except ImportError:
            return

        try:
            from statistic import st_video_view_handler, st_sub_fetch_handler, \
                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:
            widget_views_total_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.'
            )

        st_video_view_handler.total_key.delete()
        st_sub_fetch_handler.total_key.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)
            st_video_view_handler.total_key.incr(obj.view_count)
            st_sub_fetch_handler.total_key.incr(obj.subtitles_fetched_count)
            widget_views_total_counter.incr(
                Video.widget_views_counter(obj.video_id).get())