下载youtube字幕(闭路字幕,cc)为txt或json格式
download-youtube-subtitle的Python项目详细描述
下载Youtube字幕
下载youtube字幕(闭路字幕,cc)或srt为txt或json。在
特点
- 同时支持翻译输出,对语言学习有帮助。在
- 支持youtube代理,请按照Using Anaconda behind a company proxy by setting environment-variables中的步骤操作。在
- 用travis 进行全面测试,以确保一切正常。在
示例
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
安装并运行
通过download-youtube-subtitle · PyPI
安装pip install download-youtube-subtitle
或{} 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# ...
发展
环境设置
pip install 'fire''requests''IPython'
用法
python main.py -h python main.py VIDEOID
测试
cd tests
./run.sh
./test_cli.sh
参考
Packaging Python Projects — Python Packaging User Guide
./nb/notebook2script.py
来自course-v3/nbs/dl2 at master · fastai/course-v3
- 项目
标签: