当前位置: 首页>>代码示例>>Python>>正文


Python SubRipFile.append方法代码示例

本文整理汇总了Python中pysrt.SubRipFile.append方法的典型用法代码示例。如果您正苦于以下问题:Python SubRipFile.append方法的具体用法?Python SubRipFile.append怎么用?Python SubRipFile.append使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pysrt.SubRipFile的用法示例。


在下文中一共展示了SubRipFile.append方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: to_srt

# 需要导入模块: from pysrt import SubRipFile [as 别名]
# 或者: from pysrt.SubRipFile import append [as 别名]
def to_srt(df, filename):
    out = SubRipFile(encoding='utf-8')
    for i, r in df.iterrows():
        begin = convert_time(r['begin'])
        end = convert_time(r['end'])
        out.append(SubRipItem(0, begin, end, r['text']))
    out.save(filename)
开发者ID:kshmelkov,项目名称:forrestgump,代码行数:9,代码来源:split_subtitles.py

示例2: get_captions

# 需要导入模块: from pysrt import SubRipFile [as 别名]
# 或者: from pysrt.SubRipFile import append [as 别名]
def get_captions(client_name, clip_id):
    h = httplib2.Http()
    g_url = 'http://%s/JSON.php?clip_id=%s' % ( client_name, clip_id)
    print "Fetching URL: %s" % g_url

    try:
        response, j = h.request(g_url)
    except httplib.BadStatusLine as exception:
        return None

    dirname = os.getcwd() + "/data/granicus/srt/%s/" % client_name
    filename = dirname + "%s.srt" % clip_id
    subs = SubRipFile()

    if response.get('status') == '200':
        captions = []
        try:
            j = json.loads(j, strict=False)[0]
        except ValueError:
            ts = re.sub('([{,]\s+)([a-z]+)(: ")', lambda s: '%s"%s"%s' % (s.groups()[0], s.groups()[1], s.groups()[2]), j).replace("\\", "")
            try:
                j = json.loads(ts, strict=False)[0]
            except UnicodeDecodeError:
                ts = unicode(ts, errors='ignore')
                j = json.loads(ts, strict=False)[0]
        except:
            j = False

        sub_count = 0
        for item in j:
            if item["type"] == "text":
                cap = item["text"]
                offset = round(float(item["time"]), 3)
                captions.append({'time': offset, 'text': cap})
                end = get_cap_end(j, sub_count)
                if end:
                    subtitle = SubRipItem(index=sub_count, start=SubRipTime(seconds=offset), end=SubRipTime(seconds=end), text=cap)
                    subs.append(subtitle)

            sub_count = sub_count + 1

        try:
            subs.save(path=filename, encoding="utf-8")
        except IOError:
            p = subprocess.Popen('mkdir -p %s' % dirname, shell=True, stdout=subprocess.PIPE)
            t = p.wait()

            subs.save(path=filename, encoding="utf-8")

        s3_url = push_to_s3(filename, '%s/%s.srt' % (client_name, clip_id))
        return (captions, s3_url)
    else:
        return ([], '')
开发者ID:eres805,项目名称:congress,代码行数:55,代码来源:videos.py

示例3: save

# 需要导入模块: from pysrt import SubRipFile [as 别名]
# 或者: from pysrt.SubRipFile import append [as 别名]
    def save(self, path):
        if path.endswith('srt'):
            verify_dependencies(['pysrt'])
            from pysrt import SubRipFile, SubRipItem
            from datetime import time

            out = SubRipFile()
            for elem in self._elements:
                start = time(*self._to_tup(elem.onset))
                end = time(*self._to_tup(elem.onset + elem.duration))
                out.append(SubRipItem(0, start, end, elem.text))
            out.save(path)
        else:
            with open(path, 'w') as f:
                f.write('onset\ttext\tduration\n')
                for elem in self._elements:
                    f.write('{}\t{}\t{}\n'.format(elem.onset,
                                                  elem.text,
                                                  elem.duration))
开发者ID:tyarkoni,项目名称:featureX,代码行数:21,代码来源:text.py

示例4: merge_subtitle

# 需要导入模块: from pysrt import SubRipFile [as 别名]
# 或者: from pysrt.SubRipFile import append [as 别名]
def merge_subtitle(sub_a, sub_b, delta, encoding='utf-8'):
    """
    合并两种不同言语的srt字幕

    因为两个字幕文件的时间轴不一样,所以合并后的字幕会在某一字幕文件转换时生成新的一条字幕,
    导致双语字幕并不是同时变化,不过这也是没有办法的事,无法避免

    参考https://github.com/byroot/pysrt/issues/17

    https://github.com/byroot/pysrt/issues/15

    :param sub_a: 使用sub_a = SubRipFile.open(sub_a_path, encoding=encoding)
    :param sub_b:
    :param delta:
    :return:
    """
    out = SubRipFile()
    intervals = [item.start.ordinal for item in sub_a]
    intervals.extend([item.end.ordinal for item in sub_a])
    intervals.extend([item.start.ordinal for item in sub_b])
    intervals.extend([item.end.ordinal for item in sub_b])
    intervals.sort()

    j = k = 0
    for i in xrange(1, len(intervals)):
        start = SubRipTime.from_ordinal(intervals[i - 1])
        end = SubRipTime.from_ordinal(intervals[i])

        if (end - start) > delta:
            text_a, j = find_subtitle(sub_a, start, end, j)
            text_b, k = find_subtitle(sub_b, start, end, k)

            text = join_lines(text_a, text_b)
            if len(text) > 0:
                item = SubRipItem(0, start, end, text)
                out.append(item)

    out.clean_indexes()
    return out
开发者ID:GoTop,项目名称:AutoSystem,代码行数:41,代码来源:subtitle.py

示例5: merge_subtitle

# 需要导入模块: from pysrt import SubRipFile [as 别名]
# 或者: from pysrt.SubRipFile import append [as 别名]
def merge_subtitle(sub_a, sub_b, delta):
    out = SubRipFile()
    intervals = [item.start.ordinal for item in sub_a]
    intervals.extend([item.end.ordinal for item in sub_a])
    intervals.extend([item.start.ordinal for item in sub_b])
    intervals.extend([item.end.ordinal for item in sub_b])
    intervals.sort()

    j = k = 0
    for i in xrange(1, len(intervals)):
        start = SubRipTime.from_ordinal(intervals[i-1])
        end = SubRipTime.from_ordinal(intervals[i])

        if (end-start) > delta:
            text_a, j = find_subtitle(sub_a, start, end, j)
            text_b, k = find_subtitle(sub_b, start, end, k)

            text = join_lines(text_a, text_b)
            if len(text) > 0:
                item = SubRipItem(0, start, end, text)
                out.append(item)

    out.clean_indexes()
    return out
开发者ID:EdwardBetts,项目名称:pysrt,代码行数:26,代码来源:mvyskoc_merge.py

示例6: SubRipFile

# 需要导入模块: from pysrt import SubRipFile [as 别名]
# 或者: from pysrt.SubRipFile import append [as 别名]
srt_log_path = current_directory + '/comment_log/' + chat_channel + '.srt'

bot = irc_bot.irc_bot(username, oauth, chat_channel, chat_server[0], chat_server[1], twitchclient_version = twitchclient_version)

outsrt = SubRipFile()

text = ''

while 1:
	raw_msg_list = bot.get_message()
	if len(raw_msg_list) > 0:
		if len(text) > 0:
			end = SubRipTime.from_time(datetime.now())
			item = SubRipItem(0, start, end, text)
			outsrt.append(item)
		start = SubRipTime.from_time(datetime.now())
		text = ''
		timestamp = get_timestamp(timestamp_format)
		for item in raw_msg_list:
			if record_raw:
				log_add(raw_log_path, timestamp + ' ' + item + '\n')
			username, message = irc_bot.parse_user(item)
			if username != '':
				safe_print(chat_channel + " " + username + ": " + message)
				log_add(log_path, timestamp + ' ' + username + ': ' + message + '\n')
				text += username + ": " + message + '\n'
				outsrt.clean_indexes()
				outsrt.save(srt_log_path, encoding='utf-8')

开发者ID:gamedeff,项目名称:Twitch_Batch_Logger,代码行数:30,代码来源:comment_logger_srt.py

示例7: SubRipFile

# 需要导入模块: from pysrt import SubRipFile [as 别名]
# 或者: from pysrt.SubRipFile import append [as 别名]
srt = SubRipFile(eol='\n', encoding='utf-8')
i = 1

for line in sublog:
    line = line.split(",", 1)
    if (line[0] and line[0][0] == '-'):
        if (START_TIME == None and line[0][:8] == '- start '):
            START_TIME = datetime.strptime(line[0], '- start ' + TIMEFORMAT +
            '\n')
        continue

    no = datetime.strptime(line[0], TIMEFORMAT) - START_TIME
    if (abs(no) > timedelta(1)):
        print("\nCan't go over a day in a subtitle! Delete non-used lines in" + \
                " log.\nLet there only be one '- start' line at the top of" + \
                " the log-file.")
        sys.exit(1)

    time = SubRipTime.from_ordinal(no.seconds*1000 + no.microseconds*0.001)

    item = SubRipItem(i, start=time, end=time + 30*1000,
            text=unicode(line[1], 'utf-8'))
    srt.append(item)
    i += 1

srt.clean_indexes()
#srt.save(path=sys.stdout)

for line in srt:
    sys.stdout.write(unicode(line).encode('utf-8'))
开发者ID:WNRI,项目名称:errantia,代码行数:32,代码来源:sublog_to_srt.py


注:本文中的pysrt.SubRipFile.append方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。