示例#1
0
文件: views.py 项目: crodjer/mirosubs
def _add_lang_to_video(video, props, translated_from=None):

    if props.get('is_original', False):
        video.subtitle_language().delete()
    sub_lang = SubtitleLanguage(
        video=video,
        is_original=props.get('is_original', False),
        is_complete=props.get('is_complete', False),
        language=props.get('code'),
        has_version=True,
        had_version=True,
        is_forked=True,
    )
    sub_lang.save()
    num_subs = props.get("num_subs", 0)

    if not translated_from:
        _add_subtitles(sub_lang, num_subs)

    if translated_from:
        sub_lang.is_original = False
        sub_lang.is_forked = False
        sub_lang.standard_language = translated_from
        sub_lang.save()
        _copy_subtitles(translated_from, sub_lang, num_subs)

    for translation_prop in props.get("translations", []):
        _add_lang_to_video(video, translation_prop, translated_from=sub_lang)

    sub_lang.is_complete = props.get("is_complete", False)
    sub_lang.save()
    from videos.tasks import video_changed_tasks
    video_changed_tasks.delay(sub_lang.video.id)
    return sub_lang
示例#2
0
def _add_lang_to_video(video, props,  translated_from=None):

    sub_lang = SubtitleLanguage(
        video=video,
        is_original = props.get('is_original', False),
        is_complete = props.get('is_complete', False),
        language = props.get('code'),
        has_version=True,
        had_version=True,
        is_forked=True,
    )
    sub_lang.save()
    num_subs = props.get("num_subs", 0)

    if not translated_from:
        _add_subtitles(sub_lang, num_subs)

    if translated_from:
        sub_lang.is_original = False
        sub_lang.is_forked = False
        sub_lang.standard_language = translated_from
        sub_lang.save()
        _copy_subtitles(translated_from ,sub_lang,  num_subs)

    for translation_prop in props.get("translations", []):
        _add_lang_to_video(video, translation_prop, translated_from=sub_lang)


    sub_lang.update_percent_done()
    print 'adding lang ', sub_lang
    sub_lang.save()
    return sub_lang    
示例#3
0
    def test_detail_contents_unrelated_video(self):
        from videos.models import SubtitleLanguage

        team, new_team_video = self._create_new_team_video()
        en = SubtitleLanguage(video=new_team_video.video, language='en')
        en.is_original = True
        en.is_complete = True
        en.save()
        self._set_my_languages('en', 'ru')
        # now add a Russian video with no subtitles.
        self._add_team_video(
            team, u'ru',
            u'http://upload.wikimedia.org/wikipedia/commons/6/61/CollateralMurder.ogv')

        reset_solr()

        team = Team.objects.get(id=team.id)

        self.assertEqual(2, team.teamvideo_set.count())

        # both videos should be in the list
        search_record_list = self._tv_search_record_list(team)
        self.assertEqual(2, len(search_record_list))

        # but the one with en subs should be second, since it was added earlier
        self.assertEqual('en', search_record_list[1].original_language)
示例#4
0
文件: views.py 项目: brettle/mirosubs
def _add_lang_to_video(video, props, translated_from=None):

    sub_lang = SubtitleLanguage(
        video=video,
        is_original=props.get('is_original', False),
        is_complete=props.get('is_complete', False),
        language=props.get('code'),
        has_version=True,
        had_version=True,
        is_forked=True,
    )
    sub_lang.save()
    num_subs = props.get("num_subs", 0)

    if not translated_from:
        _add_subtitles(sub_lang, num_subs)

    if translated_from:
        sub_lang.is_original = False
        sub_lang.is_forked = False
        sub_lang.standard_language = translated_from
        sub_lang.save()
        _copy_subtitles(translated_from, sub_lang, num_subs)

    for translation_prop in props.get("translations", []):
        _add_lang_to_video(video, translation_prop, translated_from=sub_lang)

    sub_lang.update_percent_done()
    sub_lang.save()
    return sub_lang
示例#5
0
def _add_lang_to_video(video, props, translated_from=None):

    if props.get("is_original", False):
        video.subtitle_language().delete()
    sub_lang = SubtitleLanguage(
        video=video,
        is_original=props.get("is_original", False),
        is_complete=props.get("is_complete", False),
        language=props.get("code"),
        has_version=True,
        had_version=True,
        is_forked=True,
    )
    sub_lang.save()
    num_subs = props.get("num_subs", 0)

    if not translated_from:
        _add_subtitles(sub_lang, num_subs)

    if translated_from:
        sub_lang.is_original = False
        sub_lang.is_forked = False
        sub_lang.standard_language = translated_from
        sub_lang.save()
        _copy_subtitles(translated_from, sub_lang, num_subs)

    for translation_prop in props.get("translations", []):
        _add_lang_to_video(video, translation_prop, translated_from=sub_lang)

    sub_lang.is_complete = props.get("is_complete", False)
    sub_lang.save()
    from videos.tasks import video_changed_tasks

    video_changed_tasks.delay(sub_lang.video.id)
    return sub_lang
示例#6
0
def _create_trans(video, latest_version=None, lang_code=None, forked=False):
    translation = SubtitleLanguage()
    translation.video = video
    translation.language = lang_code
    translation.is_original = False
    translation.is_forked = forked
    if not forked:
        translation.standard_language = video.subtitle_language()
    translation.save()
    v = SubtitleVersion()
    v.language = translation
    if latest_version:
        v.version_no = latest_version.version_no + 1
    else:
        v.version_no = 1
    v.datetime_started = datetime.now()
    v.save()

    if latest_version is not None:
        for s in latest_version.subtitle_set.all():
            s.duplicate_for(v).save()
    return translation