用于操作和创建字幕(subrip、.srt等)的小程序包和cli
pyzub的Python项目详细描述
pyzub:操纵字幕
pyzub是一个用于操作字幕的小程序包和cli
支持的格式:
- subrip[.srt]。
计划支持:
- 阿尔法变电站[.ssa]
- 子查看器[.sub]
- 通用字幕格式[.usf]
安装:
运行pip install pyzub
命令行界面:
目前只有slide命令可用(可以说是最重要的功能)。 使用pyzub的slide命令可以移动字幕,以便手动同步它们。
$ pyzub slide -h
Usage: pyzub slide [OPTIONS] FILEPATH
Options:
--hours FLOAT
--minutes FLOAT
--seconds FLOAT
--milliseconds FLOAT
--microseconds FLOAT
--overwrite Modifies the subtitle file in place.
--verbose Displays a progress bar and a message when finished.
--help, -h Show this message and exit.
示例:
这将使您的字幕移动2.5秒(您也可以给出负值):
$ pyzub slide Game_of_Thrones_s03ep09.srt --seconds 2 --milliseconds 500
默认情况下,pyzub将生成名为game_of懔thrones懔s03ep09懔modified.srt的输出文件,除非使用--overwrite
。输出文件将始终采用utf-8编码,并使用系统新行字符。
这也可以:
$ pyzub slide Game_of_Thrones_s03ep09.srt --seconds -70.5 --milliseconds 5000
这将使您的字幕在时间上向后移动65.5秒。
套餐:
您可以阅读字幕文件:
frompyzub.subfilesimportSRTFilefilepath='/home/user/mysubtitle.srt'subfile=SRTFile(filepath)
遍历文件:
for subtitle in subfile:
print(subtitle)
打印srtfile:
print(subfile)
Relative Path: /home/user/mysubtitle.srt
Codec: ISO-8859-1
No. of Subtitles: 451
获取字幕:
# idx could be a number from 1 to 451 in this casesubtitle=subfile.get_subtitle(idx)
打印副标题:
print(subtitle)
Index: 1
Start Time: 00:00:04,605
End Time: 00:00:06,105
Text: En un día cualquiera,
当然,您可以直接修改任何内容:
# modify the textsubtile.text='modified subtitle'# times use timedelta from the datetime packagesubtitle.start_time=timedelta(minutes=10)# also, you can assign directly a stringsubtitle.end_time='01:25:59,650'# write the changes to disksubfile.dump('/home/user/mysubtitle_modified.srt')
最后:
print(len(subfile))
# output: 451 (i.e, the number of subtitles in the file)
print(len(subtitle))
# output: 21 (i.e, the number of chars in the subtitle's text attribute)
计划功能:
- 插入、删除字幕等。
- 自动语法和语法更正
许可证
麻省理工学院