Merge branch 'master' into feature/ISSUE-23
This commit is contained in:
commit
3781907943
10
README.md
10
README.md
|
@ -1,9 +1,9 @@
|
||||||
|
|
||||||
# YouTube Transcript/Subtitle API (including automatically generated subtitles and subtitle translations)
|
# YouTube Transcript/Subtitle API (including automatically generated subtitles and subtitle translations)
|
||||||
|
|
||||||
[](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=BAENLEW8VUJ6G&source=url) [](https://travis-ci.org/jdepoix/youtube-transcript-api) [](https://coveralls.io/github/jdepoix/youtube-transcript-api?branch=master) [](http://opensource.org/licenses/MIT) [](https://pypi.org/project/youtube-transcript-api/) [](https://pypi.org/project/youtube-transcript-api/)
|
[](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=BAENLEW8VUJ6G&source=url) [](https://travis-ci.com/jdepoix/youtube-transcript-api) [](https://coveralls.io/github/jdepoix/youtube-transcript-api?branch=master) [](http://opensource.org/licenses/MIT) [](https://pypi.org/project/youtube-transcript-api/) [](https://pypi.org/project/youtube-transcript-api/)
|
||||||
|
|
||||||
This is an python API which allows you to get the transcripts/subtitles for a given YouTube video. It also works for automatically generated subtitles, supports translating subtitles and it does not require a headless browser, like other selenium based solutions do!
|
This is a python API which allows you to get the transcript/subtitles for a given YouTube video. It also works for automatically generated subtitles, supports translating subtitles and it does not require a headless browser, like other selenium based solutions do!
|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
|
|
||||||
|
@ -271,6 +271,12 @@ If you are not sure which languages are available for a given video you can call
|
||||||
youtube_transcript_api --list-transcripts <first_video_id>
|
youtube_transcript_api --list-transcripts <first_video_id>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
If a video's ID starts with a hyphen you'll have to mask the hyphen using `\` to prevent the CLI from mistaking it for a argument name. For example to get the transcript for the video with the ID `-abc123` run:
|
||||||
|
|
||||||
|
```
|
||||||
|
youtube_transcript_api "\-abc123"
|
||||||
|
```
|
||||||
|
|
||||||
## Proxy
|
## Proxy
|
||||||
|
|
||||||
You can specify a https/http proxy, which will be used during the requests to YouTube:
|
You can specify a https/http proxy, which will be used during the requests to YouTube:
|
||||||
|
|
|
@ -128,4 +128,8 @@ class YouTubeTranscriptCli(object):
|
||||||
help='The cookie file that will be used for authorization with youtube.'
|
help='The cookie file that will be used for authorization with youtube.'
|
||||||
)
|
)
|
||||||
|
|
||||||
return parser.parse_args(self._args)
|
return self._sanitize_video_ids(parser.parse_args(self._args))
|
||||||
|
|
||||||
|
def _sanitize_video_ids(self, args):
|
||||||
|
args.video_ids = [video_id.replace('\\', '') for video_id in args.video_ids]
|
||||||
|
return args
|
||||||
|
|
|
@ -81,6 +81,12 @@ class TestYouTubeTranscriptCli(TestCase):
|
||||||
self.assertEqual(parsed_args.format, 'pretty')
|
self.assertEqual(parsed_args.format, 'pretty')
|
||||||
self.assertEqual(parsed_args.languages, ['en'])
|
self.assertEqual(parsed_args.languages, ['en'])
|
||||||
|
|
||||||
|
def test_argument_parsing__video_ids_starting_with_dash(self):
|
||||||
|
parsed_args = YouTubeTranscriptCli('\-v1 \-\-v2 \--v3'.split())._parse_args()
|
||||||
|
self.assertEqual(parsed_args.video_ids, ['-v1', '--v2', '--v3'])
|
||||||
|
self.assertEqual(parsed_args.json, False)
|
||||||
|
self.assertEqual(parsed_args.languages, ['en'])
|
||||||
|
|
||||||
def test_argument_parsing__fail_without_video_ids(self):
|
def test_argument_parsing__fail_without_video_ids(self):
|
||||||
with self.assertRaises(SystemExit):
|
with self.assertRaises(SystemExit):
|
||||||
YouTubeTranscriptCli('--format json'.split())._parse_args()
|
YouTubeTranscriptCli('--format json'.split())._parse_args()
|
||||||
|
|
Loading…
Reference in New Issue