Created
October 25, 2019 17:37
-
-
Save lxfly2000/ccabfcc4f3b6f2de681bcea50f3d46bf to your computer and use it in GitHub Desktop.
将哔哩哔哩的CC字幕转换成SRT格式
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#python 3.7.3 | |
#encoding=utf-8 | |
import json | |
import sys | |
def srtftime(s): | |
m=int(s/60) | |
s-=m*60 | |
h=int(m/60) | |
m-=h*60 | |
ms=s-int(s) | |
return '%02d:%02d:%02d,%03d'%(h,m,s,ms*1000) | |
subs=json.loads(open(sys.argv[1],encoding='utf-8').read()) | |
f=open(sys.argv[1]+'.srt',mode='w') | |
n=0 | |
for d in subs['body']: | |
n+=1 | |
f.write(str(n)+'\n'+srtftime(d['from'])+' --> '+srtftime(d['to'])+'\n'+d['content']+'\n\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment