示例#1
0
文件: rpc.py 项目: huberth/mirosubs
    def start_editing(self, request, video_id, 
                      base_version_no=None, language_code=None, 
                      editing=False):
        """Called by subtitling widget when subtitling or translation 
        is to commence or recommence on a video.
        """

        self._maybe_add_video_session(request)

        language, can_writelock = self._get_language_for_editing(
            request, video_id, language_code)

        if not can_writelock:
            return { "can_edit": False, 
                     "locked_by" : language.writelock_owner_name }

        version = self._get_version_for_editing(request.user, language, base_version_no)

        existing_subtitles = \
            [s.to_json_dict(is_dependent_translation=language_code is not None)
             for s in version.subtitle_set.all()]

        return_dict = { "can_edit" : True,
                        "version" : version.version_no,
                        "existing" : existing_subtitles }
        if editing and language_code is not None:
            return_dict['existing_captions'] = \
                self.fetch_subtitles(request, video_id)
            return_dict['languages'] = \
                [widget.language_to_map(lang[0], lang[1]) 
                 for lang in LANGUAGES]
        return return_dict
示例#2
0
 def show_widget(self, request, video_url, base_state=None):
     owner = request.user if request.user.is_authenticated() else None
     video, created = models.Video.get_or_create_for_url(video_url, owner)
     video.widget_views_count += 1
     video.save()
 
     return_value = {
         'video_id' : video.video_id,
         'writelock_expiration' : models.WRITELOCK_EXPIRATION 
         }
     if video.video_type == models.VIDEO_TYPE_BLIPTV:
         return_value['flv_url'] = video.bliptv_flv_url
     return_value['initial_tab'] = \
         self._initial_video_tab(request.user, video)
     translation_language_codes = \
         self._initial_language_codes(request.user, video)
     return_value['translation_languages'] = \
         [widget.language_to_map(code, LANGUAGES_MAP[code]) for 
          code in translation_language_codes]
     if base_state is not None:
         return_value['subtitles'] = self._autoplay_subtitles(
             request.user, video, 
             base_state.get('language', None),
             base_state.get('revision', None))
     if request.user.is_authenticated():
         return_value['username'] = request.user.username
     return_value['embed_version'] = settings.EMBED_JS_VERSION
     return return_value
示例#3
0
文件: rpc.py 项目: jcdean/mirosubs
def finished_translations_null(request, video_id, language_code, version_no, 
                               inserted, updated):
    if not request.user.is_authenticated():
        return { "response" : "not_logged_in" }
    video = models.Video.objects.get(video_id=video_id)
    null_translations = save_translations_null_impl(request, video, language_code, 
                                                    inserted, updated)
    null_translations.is_complete = True
    null_translations.save()
    video = models.Video.objects.get(video_id=video_id)
    return { 'response' : 'ok',
             'available_languages': 
             [widget.language_to_map(code, LANGUAGES_MAP[code]) for
              code in video.null_translation_language_codes(request.user)] }
示例#4
0
文件: rpc.py 项目: jcdean/mirosubs
def finished_translations(request, video_id, language_code, version_no, 
                          inserted, updated):
    translation_language = models.Video.objects.get(
        video_id=video_id).translation_language(language_code)
    if not translation_language.can_writelock(request.session[VIDEO_SESSION_KEY]):
        return { 'response' : 'unlockable' }
    last_version = save_translations_impl(request, translation_language,
                                          version_no, inserted, updated)
    last_version.is_complete = True
    last_version.save()
    translation_language.release_writelock()
    translation_language.save()
    video = models.Video.objects.get(video_id=video_id)
    return { 'response' : 'ok',
             'available_languages': 
             [widget.language_to_map(code, LANGUAGES_MAP[code]) for
              code in video.translation_language_codes()] }
示例#5
0
文件: rpc.py 项目: annasob/mirosubs
 def finished_subtitles(self, request, video_id, deleted, inserted, updated, language_code=None):
     language = models.Video.objects.get(video_id=video_id).subtitle_language(language_code)
     if not language.can_writelock(request):
         return {"response": "unlockable"}
     self._save_subtitles_impl(request, language, deleted, inserted, updated)
     last_version = language.latest_version()
     last_version.finished = True
     last_version.user = request.user
     last_version.save()
     language = models.SubtitleLanguage.objects.get(pk=language.pk)
     language.release_writelock()
     language.save()
     return_dict = {"response": "ok"}
     if language_code is not None:
         return_dict["available_languages"] = [
             widget.language_to_map(code, LANGUAGES_MAP[code])
             for code in language.video.translation_language_codes()
         ]
     return return_dict
示例#6
0
 def start_editing(self, request, video_id, language_code=None, editing=False, base_version_no=None):
     version_no = 0
     if not request.user.is_authenticated():
         subtitles = []
     else:
         video = models.Video.objects.get(video_id=video_id)
         null_subtitles, created = self._get_null_subtitles_for_editing(
             request.user, video, language_code)
         subtitles = \
             [s.to_json_dict(is_dependent_translation=
                             language_code is not None) 
              for s in null_subtitles.subtitle_set.all()]
         version_no = 0 if created else 1
     return_dict = { 'can_edit': True,
                     'version': version_no,
                     'existing': subtitles }
     if editing and language_code is not None:
         return_dict['existing_captions'] = \
             self.fetch_subtitles(request, video_id)
         return_dict['languages'] = \
             [widget.language_to_map(lang[0], lang[1])
              for lang in LANGUAGES]
     return return_dict
示例#7
0
文件: rpc.py 项目: annasob/mirosubs
 def fetch_subtitles_and_open_languages(self, request, video_id):
     return {
         "captions": self.fetch_subtitles(request, video_id),
         "languages": [widget.language_to_map(lang[0], lang[1]) for lang in LANGUAGES],
     }
示例#8
0
文件: rpc.py 项目: jcdean/mirosubs
def fetch_captions_and_open_languages_null(request, video_id):
    return { 'captions': fetch_captions_null(request, video_id),
             'languages': [widget.language_to_map(lang[0], lang[1]) 
                           for lang in LANGUAGES]}