示例#1
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
示例#2
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
示例#3
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

        try:    
            video_urls = video_cache.get_video_urls(video_id)
        except models.Video.DoesNotExist:
            video_cache.invalidate_video_id(video_url)
            video_id = video_cache.get_video_id(video_url)
            video_urls = video_cache.get_video_urls(video_id)

        return_value = {
            'video_id' : video_id,
            'subtitles': None,
        }
        return_value['video_urls']= video_urls
        
        if additional_video_urls is not None:
            for url in additional_video_urls:
                video_cache.associate_extra_url(url, video_id)

        st_widget_view_statistic_update.delay(video_id=video_id)
        
        add_general_settings(request, return_value)
        if request.user.is_authenticated():
            return_value['username'] = request.user.username

        return_value['drop_down_contents'] = \
            video_cache.get_video_languages(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)
                lang_pk = video_cache.pk_for_default_language(video_id, lang_code)
            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_pk = video_cache.pk_for_default_language(video_id, autoplay_language)
                if autoplay_language is not None:
                    subtitles = self._autoplay_subtitles(
                        request.user, video_id, language_pk, None)
                    return_value['subtitles'] = subtitles
        return return_value
示例#4
0
    def show_widget(self,
                    request,
                    video_url,
                    is_remote,
                    base_state=None,
                    additional_video_urls=None):
        try:
            video_id = video_cache.get_video_id(video_url)
        except Exception as e:
            # for example, private youtube video or private widgets
            return {"error_msg": unicode(e)}

        if video_id is None:
            return None

        error = self._check_visibility_policy_for_widget(request, video_id)

        if error:
            return error

        video_urls, video_id, error = self._get_video_urls_for_widget(
            video_url, video_id)

        if error:
            return error

        resp = {
            'video_id': video_id,
            'subtitles': None,
            'video_urls': video_urls,
            'is_moderated': video_cache.get_is_moderated(video_id),
            'filename': video_cache.get_download_filename(video_id),
        }

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

        add_general_settings(request, resp)

        if request.user.is_authenticated():
            resp['username'] = request.user.username

        resp['drop_down_contents'] = video_cache.get_video_languages(video_id)
        resp['my_languages'] = get_user_languages_from_request(request)
        resp['subtitles'] = self._get_subtitles_for_widget(
            request, base_state, video_id, is_remote)
        return resp
示例#5
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

        try:
            video_urls = video_cache.get_video_urls(video_id)
        except models.Video.DoesNotExist:
            video_cache.invalidate_video_id(video_url)
            video_id = video_cache.get_video_id(video_url)
            video_urls = video_cache.get_video_urls(video_id)

        return_value = {"video_id": video_id, "subtitles": None}
        return_value["video_urls"] = video_urls
        return_value["is_moderated"] = video_cache.get_is_moderated(video_id)
        if additional_video_urls is not None:
            for url in additional_video_urls:
                video_cache.associate_extra_url(url, video_id)

        add_general_settings(request, return_value)
        if request.user.is_authenticated():
            return_value["username"] = request.user.username

        return_value["drop_down_contents"] = video_cache.get_video_languages(video_id)

        return_value["my_languages"] = get_user_languages_from_request(request)

        # keeping both forms valid as backwards compatibility layer
        lang_code = base_state and base_state.get("language_code", base_state.get("language", None))
        if base_state is not None and lang_code is not None:
            lang_pk = base_state.get("language_pk", None)
            if lang_pk is None:
                lang_pk = video_cache.pk_for_default_language(video_id, lang_code)
            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_pk = video_cache.pk_for_default_language(video_id, autoplay_language)
                if autoplay_language is not None:
                    subtitles = self._autoplay_subtitles(request.user, video_id, language_pk, None)
                    return_value["subtitles"] = subtitles
        return return_value