一个符合人体工程学的python库opensubtitles.org网站美国石油学会
subwinder的Python项目详细描述
分卷机
一个用于opensubtitles.orgAPI的符合人体工程学的python库。在
快速启动
我们的任务由三个简单的步骤组成
- 在
/path/to/movie.mkv
搜索电影的英文字幕,在/path/to/episode.avi
搜索电视节目集的法语字幕。在 - 把人们在字幕上留下的评论打印出来。在
- 下载原始媒体文件旁边的字幕,命名格式为
{media name}.{3 letter lang code}.{extension}
(类似于/path/to/movie.eng.ssa
和{})
注意:这需要一个免费的opensubtitles帐户。在
注意:用户代理特定于使用API的程序。您可以在“How to request a new user agent”下查看here,了解可以为开发设置什么用户代理,或者如何为您的程序获得正式的用户代理。在
fromsubwinderimportAuthSubwinder,MediafromdatetimeimportdatetimeasdtfrompathlibimportPath# Step 1. Getting our `Media` objects created and searching# You can create the `Media` by passing in the filepathmovie=Media("/path/to/movie.mkv")# Or if you are already using `Path`s then you can pass in a path too (or you# can build it from the individual pieces if you don't have local files)episode=Media(Path("/path/to/episode.avi"))withAuthSubwinder("<username>","<password>","<useragent>")asasw:results=asw.search_subtitles([(movie,"en"),(episode,"fr")])# We're assuming both `Media` returned a `SearchResult` for this exampleassertNonenotinresults# Step 2. Print any comments for both of our `SearchResult`sTIME_FORMAT="%Y-%m-%d %H:%M:%S"results_comments=asw.get_comments(results)forresult,result_commentsinzip(results,results_comments):print(f"{result.media.get_filename()} Comments:")forcommentinresult_comments:date=dt.strftime(comment.date,TIME_FORMAT)print(f"{date}{comment.author.name}: {comment.text}")print()# Step 3. Download both of the subtitles next to the original files# We're assuming we have enough remaining downloads for these, if not then# a `SubDownloadError` will be raised by `.download_subtitles(...)`assertasw.daily_download_info().remaining>=len(results)download_paths=asw.download_subtitles(results,name_format="{media_name}.{lang_3}.{ext}")
就这样,有了~20个sloc,你可以搜索,获取评论,下载几个字幕!在
安装
注意:最低要求的Python版本是3.7
,如果您不确定当前版本,可以使用python -V
或{
使用标准Python包管理器安装subwinder库,例如
^{pr2}$一如既往,建议您安装到虚拟环境中。在
可选依赖项
其中一个目标是保持较小的占地面积,以便安装时不需要任何依赖关系。为了实现这一点,一些功能被选在下面列出的可选依赖项后面。在
Dependency | Functionality |
---|---|
atomic_downloads | Attempts to download subtitles atomically to prevent partial downloads due to interruptions. Without this feature the library falls back to writing the file using normal ^{ |
安装包时可以指定可选的依赖项。如果不确定如何指定可选依赖项(也称为extras),请参阅文档。E、 g.有了皮普,就可以了
$ pip install subwinder[atomic_downloads]
文档
docs directory中有相当详尽的文档,涵盖了库当前公开的所有功能。如果文档中有任何不正确或令人困惑的地方,请raise an issue来解决这个问题。在
除此之外,examples directory中还有一些例子,如果你想看一些更实际的风格文档。在
使用subwinder
- 易于开发
- 使用库定义的对象,并按逻辑顺序获取和返回对象,以提供一个干净的接口
- 为了提供一致的体验,我们努力防止在稍有不同的键名下或在不同的类型下再次暴露相同的信息
- 值在有意义时被解析为内置的Python类型
- 批处理的端点将自动执行此操作,直至达到最大批处理大小
- 强大,但如果失败了,那就很快失败
- 自定义
Exception
被定义并用于提供失败时的上下文 - 如果某个东西将失败,请尝试检测它并尽早发出一个
Exception
- 自动重试请求使用指数后退来处理速率限制
- 自定义
- 占地面积小
- 没有必需的依赖项
- 可选依赖项列在安装标题下
使用subwinder
- Python3.7+是必需的(此时3.7已经有好几年的历史了)
- 并不是API中的所有值都公开了:但是,我在这方面很灵活,所以如果您有一个缺少的值的用法,请在an issue中使用它!在
- 目前内部API只支持英语。您仍然可以搜索其他语言的字幕,但媒体名称和长语言名称都将是英语。这将在API处于更稳定的状态后进行
许可证
subwinder
是在agplv3下授权的,它应该包含在库中。如果没有,你可以找到一个在线副本here。在
- 项目
标签: