2
《冰雪奇缘》之缘——A站弹幕 JSON 转 crt
source link: https://blog.lilydjwg.me/2014/3/3/frozen-danmaku-cmt-json-to-crt-subtitles.43226.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
《冰雪奇缘》之缘——A站弹幕 JSON 转 crt
本文来自依云's Blog,转载请注明。
都是《冰雪奇缘》惹的祸,不仅画面美仑美奂,音乐激荡人心,而且还玩多语言版本的主题曲。
而 you-get 竟助纣为虐,把歌词给下回来了!只叹 soimort 没有好人做到底,留一个语义不详的 JSON 让我情何以堪。
好在 muzuiget 才识不凡,有码略释其义,遂如我光影、声音、文字三位一体之愿!
编成代码数十行,只为女王歌一曲:
cmtjson2crt
#!/usr/bin/env python3
import
json
import
sys
def
cmtjson_reader(f):
data
=
json.load(f)
for
o
in
data:
c
=
o[
'c'
].split(
','
)
m
=
o[
'm'
]
# see
start
=
float
(c[
0
])
yield
start, m
def
format_time(t):
s, ms
=
divmod
(t,
1
)
s
=
int
(s)
ms
=
int
(ms
*
1000
)
m, s
=
divmod
(s,
60
)
h, m
=
divmod
(m,
60
)
return
'%d:%02d:%02d,%03d'
%
(h, m, s, ms)
def
crt_writer(f):
i
=
0
fmt
=
'%d\n%s --> %s\n%s\n\n'
try
:
while
True
:
t, m
=
yield
ts
=
format_time(t)
if
i !
=
0
:
f.write(fmt
%
(i, format_time(old_t), ts, old_m))
i
+
=
1
old_t
=
t
old_m
=
m
except
GeneratorExit:
f.write(fmt
%
(
i
+
1
, format_time(t), format_time(t
+
2
), m))
def
main():
w
=
crt_writer(sys.stdout)
w.send(
None
)
old_d0
=
0
for
d
in
cmtjson_reader(sys.stdin):
if
d[
0
] < old_d0:
break
w.send(d)
old_d0
=
d[
0
]
if
__name__
=
=
'__main__'
:
main()
mplayer 君虽识得 UTF-8 之码,却不通 fontconfig 之术,部分文字沦为了下划线。又及。
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK