本文整理匯總了Python中babelsubs.storage.SubtitleSet.find方法的典型用法代碼示例。如果您正苦於以下問題:Python SubtitleSet.find方法的具體用法?Python SubtitleSet.find怎麽用?Python SubtitleSet.find使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類babelsubs.storage.SubtitleSet
的用法示例。
在下文中一共展示了SubtitleSet.find方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: merge_subtitles
# 需要導入模塊: from babelsubs.storage import SubtitleSet [as 別名]
# 或者: from babelsubs.storage.SubtitleSet import find [as 別名]
def merge_subtitles(cls, subtitle_sets, initial_ttml=None):
"""Combine multiple subtitles sets into a single XML string.
"""
if len(subtitle_sets) == 0:
raise TypeError("DFXPGenerator.merge_subtitles: No subtitles given")
if initial_ttml is None:
tt = SubtitleSet('').as_etree_node()
body = tt.find(TTML + 'body')
body.remove(body.find(TTML + 'div'))
else:
tt = initial_ttml
body = tt.find(TTML + 'body')
if body is None:
raise ValueError("no body tag")
# set the default language to blank. We will create a div for each
# subtitle set and set xml:lang on that.
tt.set(XML + 'lang', '')
# for each subtitle set we will append the body of tt
for i, subtitle_set in enumerate(subtitle_sets):
root_elt = subtitle_set.as_etree_node()
language_code = root_elt.get(XML + 'lang')
lang_div = etree.SubElement(body, TTML + 'div')
lang_div.set(XML + 'lang', language_code)
lang_div.extend(root_elt.find(TTML + 'body').findall(TTML + 'div'))
utils.indent_ttml(tt)
return etree.tostring(tt)