Skip to main content

download youtube subtitles(closed caption, cc) as txt or json

Project description

Download Youtube Subtitle Build Status

Download youtube subtitles(closed caption, cc) or srt as txt or json.

Features

  1. Support exportting translation at the same time which is useful for language study.
  2. Support proxy for youtube, follow the step at Using Anaconda behind a company proxy — Anaconda documentation.
  3. Full test with traivis Build Status to make sure things are on rail.

python version of algolia/youtube-captions-scraper: Fetch youtube user submitted or fallback to auto-generated captions

Example

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

or

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

will saved as 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 False --to_json=True will saved as HowSouthAfricaCouldPreparetheU.S.forPresidentTrumpTheDailyShow.json

{
    "original": [
        {
            "start": "1.367",
            "dur": "3.137",
            "text": "All right, well, uh,\nlet's get back to real life"
        },
	// continue
	]
	"translation": [
	{
		"start": "1.367",
		"dur": "3.137",
		"text": "好吧,恩,让我们回到现实生活中"
	},
		// continue
	]
	"merged": [
	{
		"start": "1.367",
		"dur": "3.137",
		"text": "All right, well, uh,\nlet's get back to real life",
		"translate_text": "好吧,恩,让我们回到现实生活中"
	},
		// continue
	]

Install and Run

Install via download-youtube-subtitle · PyPI

  1. pip install download-youtube-subtitle or pip install download-youtube-subtitle --user
  2. dl-youtube-cc -h

or uninstall to reinstall new version

pip uninstall download-youtube-subtitle -y

run in cli

dl-youtube-cc -h will show the following.


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
	

Use in Code

import download_youtube_subtitle.common as common
import download_youtube_subtitle.main as download_youtube_subtitle
# ...

Development

Environment Setup

for conda

pip install 'fire' 'requests' 'IPython'

Usage

python main.py -h
python main.py VIDEOID

Tests

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

Ref

deployment - How can I use setuptools to generate a console_scripts entry point which calls python -m mypackage? - Stack Overflow

Packaging Python Projects — Python Packaging User Guide

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

download-youtube-subtitle-1.0.1.tar.gz (7.4 kB view details)

Uploaded Source

File details

Details for the file download-youtube-subtitle-1.0.1.tar.gz.

File metadata

  • Download URL: download-youtube-subtitle-1.0.1.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.1.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.7.7

File hashes

Hashes for download-youtube-subtitle-1.0.1.tar.gz
Algorithm Hash digest
SHA256 c991ec2d0e543cc557411796994173cd2de62206f957ce37f3dcb01f1770acc0
MD5 bb200b0018d10edfec73155d3e8ee380
BLAKE2b-256 556db6765a521338cc55480a49eab611aa7d1d78ef37e683ec3ab5d42b08635c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page