下载youtube字幕(闭路字幕,cc)为txt或json格式

download-youtube-subtitle的Python项目详细描述


下载Youtube字幕Build Status

下载youtube字幕(闭路字幕,cc)或srt为txt或json。在

特点

  1. 同时支持翻译输出,对语言学习有帮助。在
  2. 支持youtube代理,请按照Using Anaconda behind a company proxy by setting environment-variables中的步骤操作。在
  3. 用travis Build Status进行全面测试,以确保一切正常。在

algolia/youtube-captions-scraper: Fetch youtube user submitted or fallback to auto-generated captions的python版本

示例

dl-youtube-cc 5tKOV0KqPlg --translation zh-Hans

或者

dl-youtube-cc https://www.youtube.com/watch?v=5tKOV0KqPlg --translation zh-Hans

将另存为HowSouthAfricaCouldPreparetheU.S.forPresidentTrumpTheDailyShow.txt

https://youtube.com/get_video_info?video_id=5tKOV0KqPlg
---------00:01----------
All right, well, uh,
let's get back to real life
好吧,恩,让我们回到现实生活中

---------00:04----------
or whatever we're calling
this thing now.
或我们现在所说的这个东西。 
// continue

dl-youtube-cc 5tKOV0KqPlg --translation zh-Hans --to_json=True将另存为HowSouthAfricaCouldPreparetheU.S.forPresidentTrumpTheDailyShow.json

^{pr2}$

安装并运行

通过download-youtube-subtitle · PyPI

安装
  1. pip install download-youtube-subtitle或{}
  2. dl-youtube-cc -h

或卸载以重新安装新版本

pip uninstall download-youtube-subtitle -y

在cli中运行

dl-youtube-cc -h将显示以下内容。在


NAME
    dl-youtube-cc - download youtube closed caption(subtitles) by videoID

SYNOPSIS
    dl-youtube-cc VIDEOID <flags>

DESCRIPTION
    Examples:
    dl-youtube-cc -h # to see this helpful infomation
    dl-youtube-cc 5tKOV0KqPlg --save_to_file=False # print stuff in console
    dl-youtube-cc 5tKOV0KqPlg --output_file='test.txt' # print stuff in named file
    dl-youtube-cc 5tKOV0KqPlg --to_json=True # print stuff in json
    dl-youtube-cc 5tKOV0KqPlg --translation 'ja' # use japanese translation, see ./lang_code for full list
    dl-youtube-cc 5tKOV0KqPlg --translation False # without translation
    dl-youtube-cc 5tKOV0KqPlg --caption_num=1 # choose the caption num

POSITIONAL ARGUMENTS
    VIDEOID
        string, the video link or the id of youtube video, the string after 'v=' in a youtube video link

FLAGS
    --output_file=OUTPUT_FILE
        string, default to video title
    --save_to_file=SAVE_TO_FILE
        bool, default to True, True or False
    --translation=TRANSLATION
        bool or string, which will be displayed as original transcript, default to 'zh-Hans' for simplified Chinese, False or lang code, see ./lang_code.json for full list
    --to_json=TO_JSON
        bool, default to False, export caption to json
    --caption_num=CAPTION_NUM
        number, default to 0, choose the caption which will be displayed as original transcript
    --remove_font_tag=REMOVE_FONT_TAG
        bool, default to True, remove font tag in txt transcript, but not in json's merged

NOTES
    You can also use flags syntax for POSITIONAL ARGUMENTS
	

在代码

中使用
importdownload_youtube_subtitle.commonascommonimportdownload_youtube_subtitle.mainasdownload_youtube_subtitle# ...

发展

环境设置

for conda

pip install 'fire''requests''IPython'

用法

python main.py -h
python main.py VIDEOID

测试

cd tests
./run.sh
./test_cli.sh

参考

deployment - How can I use setuptools to generate a console_scripts entry point which calls ^{}? - Stack Overflow

Packaging Python Projects — Python Packaging User Guide

./nb/notebook2script.py来自course-v3/nbs/dl2 at master · fastai/course-v3

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

推荐PyPI第三方库


热门话题
来自偏移量的java JavaPairInputStream流   gzip Java TarInputStream读取tar的文件名。包含另一个tar的gz文件。gz文件   如何在Linux shell脚本中确定和使用实际的java路径   java请求太多FirebaseError   java错误json解析   java在localserver上发送安卓应用程序的输出   JavaSpring:启动和停止webapplication时更新DBtable条目   java如何使用JavaFX在矩形处设置文本?   java SQL查询在Hibernate中出现异常   java我无法使用javamail代码通过outlook(hotmail帐户)配置发送邮件,但在gmail中工作正常   java是不同的持久性。测试运行/JPA装置的xml属性   无头Eclipse的java导出战   使用ContentVersionStrategy的java Spring引导缓存禁止使用gzip进行资源压缩   java如何获取计算机的设备令牌?   图像文件的java ImageInfo不包含有效值   继承强制在Java中使用基类方法