用于操作和创建字幕(subrip、.srt等)的小程序包和cli

pyzub的Python项目详细描述


pyzub:操纵字幕

pyzub是一个用于操作字幕的小程序包和cli

支持的格式:

  • subrip[.srt]。

计划支持:

  • 阿尔法变电站[.ssa]
  • 子查看器[.sub]
  • 通用字幕格式[.usf]

安装:

运行pip install pyzub

命令行界面:

目前只有slide命令可用(可以说是最重要的功能)。 使用pyzubslide命令可以移动字幕,以便手动同步它们。

$ 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)

计划功能:

  • 插入、删除字幕等。
  • 自动语法和语法更正

许可证

麻省理工学院

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
JavaBeanio如何将抽象类或接口映射为记录或段   java Jboss 4.2.2到Jboss 7.1.1的迁移问题   如果Java运行时高于给定版本,则强制Maven失败   java在部署时持久化实体   java如何使用jdatechooser从mysql数据库中保存和检索空日期   java Google Drive SDK如何获取文件所在的文件夹?   java使用spring mvc mybatis从oracle db获取失败用户登录结果的数量   数组如何在java中拆分数字文件?   创建对象期间出现安卓 Java空指针异常   java 安卓supportv4。jar在Eclipse中未正确导入   java如何在javafx中创建这种类型的按钮   关于Spring集成和原型范围的java之谜   java正则表达式:在2个标记之间提取DNA信息   使用getText()时出现java空指针异常。toString()。修剪();   java如何从spring控制器获取angularjs中的模型属性值