https://pypi.org/project/srt/ …… 我看我还是做抽象一点 🤔不就是个 subtitle 时间轴嘛
PyPI
srt
A tiny library for parsing, modifying, and composing SRT files.
🤔 #Python #code 之前我看 SCP-079 群里那个翻译的实现(用的不是 Qt 封的 translate 什么的),他们是这个格式
{
}
第一次看到的时候,我觉得好高大上啊,而且以为他们肯定重载了 and / or operator 的语义,甚至在脑内自动意淫出了一个递归结构:
(后来发现递归的其实是一个链表)
然后我编写了一个查表算法(后来被证实不过是链表查找,开始我还以为是高大上的递归结构呢):
再后来,我发现这整个其实都是谎话—— 使用这种方式意味着 SCP-079 用 zh_cn: bool 作为参数,然后利用 truthy/falsey value 的动态类型特性,去 "Hack" 一个 EDSL(embedded domain specific lang.)……
如果要缓存,结果是一个关于
{
"admin": (zh_cn and "管理员") or "Administrator" }
第一次看到的时候,我觉得好高大上啊,而且以为他们肯定重载了 and / or operator 的语义,甚至在脑内自动意淫出了一个递归结构:
(后来发现递归的其实是一个链表)
class Translation:
def __init__(self, lang, text):
self.lang, self.text = lang, text
class Link:
def __init__(self, head, tail):
self.head, self.tail = head, tail
def _and(lang, text): return Translation(lang, text)
def _or(translation, tail): return Link(translation, tail) 然后我编写了一个查表算法(后来被证实不过是链表查找,开始我还以为是高大上的递归结构呢):
def getTranslation(key, lang):
current = translations[key]
while current != None:
if current.head.lang == lang: return current.head.text
raise KeyError(f"undefined {key} for {lang}") 再后来,我发现这整个其实都是谎话—— 使用这种方式意味着 SCP-079 用 zh_cn: bool 作为参数,然后利用 truthy/falsey value 的动态类型特性,去 "Hack" 一个 EDSL(embedded domain specific lang.)……
如果要缓存,结果是一个关于
zh_cn 之类的 bool 的 Map<LangID, Map<TextID, Text>>
我看还不如这样吧:{
"admin": i18n(zh_cn="管理员", en_us="Administrator")
} def i18n(**kwargs):
require(all(map(languages.__contains__, map(dict.key, kwargs) )), "unsupported language")
return kwargs (草,这么直白太过分……)
duangsuse::Echo
突然觉得自己好傻逼,这个 merge 到底是做什么操作…… 我知道它在 reduce 更新一个变量,但第一次写错了(消耗-重赋值顺序错误),而且现在我也不知道这种代码风格也没有办法优化
突然想起来,好像是
sequence { takeWhile }
duangsuse::Echo
158 How can something be so nice? 178 Yet so shocking, yet so nice. 321 How can something be so new? 403 Yet so known but yet so new? 466 Ohh, one two, three, the time has gone. 494 Problematic things undone. 585 How an something be so cruel? 640 Yet so warm…
122-163 "How can something be so nice?"
178-250 "Yet so shocking, yet so nice."
283-321 "How can something be so new?"
358-387 "Yet so known but yet so new?"
430-466 "Ohh, one two, three, the time has gone."
494-506 "Problematic things undone."
537-587 "How can something be so cruel?"
610-657 "Yet so warm but yet so cruel?"
684-966 ""
990-996 "Try to find from a different sight,"
1039-1077 "Get to choose where to look back,"
1096-1235 "Resolve what others can't do for now..."
1279-1366 "What a beautiful way to fix all wrong things."
1383-1486 "Evolve future generations of work teams."
1516-1612 "But tell me why's that fear of yours,"
1646-1738 " 'Cause you know it is going to work... (keep it up)"
1757-1833 "Let's start from now, stay tuned, you're half way through!"
1868-1903 "Break it, crash it, take it farther"
1950-1978 "Making something even smarter.”"
1993-2030 "Do it, start it, make it happen,"
2048-2096 "Stab in statements screaming louder."
2119-2187 "How can something be so nice?"
2207-2239 "Yet so shocking, yet so nice."
2261-2281 "How can something be so new?"
2334-2399 "Yet so known but yet..."
2424-2699 "IT'S SOMETHING NEW"
178-250 "Yet so shocking, yet so nice."
283-321 "How can something be so new?"
358-387 "Yet so known but yet so new?"
430-466 "Ohh, one two, three, the time has gone."
494-506 "Problematic things undone."
537-587 "How can something be so cruel?"
610-657 "Yet so warm but yet so cruel?"
684-966 ""
990-996 "Try to find from a different sight,"
1039-1077 "Get to choose where to look back,"
1096-1235 "Resolve what others can't do for now..."
1279-1366 "What a beautiful way to fix all wrong things."
1383-1486 "Evolve future generations of work teams."
1516-1612 "But tell me why's that fear of yours,"
1646-1738 " 'Cause you know it is going to work... (keep it up)"
1757-1833 "Let's start from now, stay tuned, you're half way through!"
1868-1903 "Break it, crash it, take it farther"
1950-1978 "Making something even smarter.”"
1993-2030 "Do it, start it, make it happen,"
2048-2096 "Stab in statements screaming louder."
2119-2187 "How can something be so nice?"
2207-2239 "Yet so shocking, yet so nice."
2261-2281 "How can something be so new?"
2334-2399 "Yet so known but yet..."
2424-2699 "IT'S SOMETHING NEW"
直接作为可以从视频里拖出 subtitle 的工具了,虽然我不打算进一步包装好
现在已经可以从字幕视频制作歌词,考虑一下加个 SRT 转化的功能
现在已经可以从字幕视频制作歌词,考虑一下加个 SRT 转化的功能