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
def _get_video_urls_for_widget(self, video_url, video_id): """Return the video URLs, 'cleaned' video id, and error.""" try: video_urls = video_cache.get_video_urls(video_id) except models.Video.DoesNotExist: video_cache.invalidate_video_id(video_url) try: video_id = video_cache.get_video_id(video_url) except Exception as e: return None, None, {"error_msg": unicode(e)} video_urls = video_cache.get_video_urls(video_id) return video_urls, video_id, None
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 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
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 test_video_url_remove(self): test_utils.invalidate_widget_video_cache.run_original_for_test() self._login() secondary_vurl = VideoURLFactory(video=self.video) self.assertEqual(self.video.videourl_set.count(), 2) # make sure get is not allowed url = reverse('videos:video_url_remove') data = {'id': secondary_vurl.id} response = self.client.get(url, data) self.assertEqual(response.status_code, 405) # check post response = self.client.post(url, data) self.assertEqual(response.status_code, 200) self.assertEqual(self.video.videourl_set.count(), 1) delete_actions = self.video.activity.filter(type='video-url-deleted') self.assertEqual(delete_actions.count(), 1) # assert cache is invalidated cached_video_urls = video_cache.get_video_urls(self.video.video_id) self.assertEqual(len(cached_video_urls), 1)
def test_get_cache_url_no_exceptions(self): try: res = video_cache.get_video_urls("bad key") except models.Video.DoesNotExist: self.fail("bad cache key shouldn't fail") self.assertTrue(len(res) == 0)