Merge pull request #43 from jdepoix/bugfix/cli-language-default
fixed bug in cli where no transcript could be retrieved if no language was specified
This commit is contained in:
commit
bfecd64b85
55
README.md
55
README.md
|
@ -1,12 +1,7 @@
|
||||||
|
|
||||||
# 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://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://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/)
|
|
||||||
|
|
||||||
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 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!
|
||||||
|
|
||||||
|
@ -44,12 +39,12 @@ This will return a list of dictionaries looking somewhat like this:
|
||||||
'text': 'Hey there',
|
'text': 'Hey there',
|
||||||
'start': 7.58,
|
'start': 7.58,
|
||||||
'duration': 6.13
|
'duration': 6.13
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'text': 'how are you',
|
'text': 'how are you',
|
||||||
'start': 14.08,
|
'start': 14.08,
|
||||||
'duration': 7.58
|
'duration': 7.58
|
||||||
},
|
},
|
||||||
# ...
|
# ...
|
||||||
]
|
]
|
||||||
```
|
```
|
||||||
|
@ -98,15 +93,15 @@ The methods `find_generated_transcript`, `find_manually_created_transcript`, `fi
|
||||||
|
|
||||||
```python
|
```python
|
||||||
print(
|
print(
|
||||||
transcript.video_id,
|
transcript.video_id,
|
||||||
transcript.language,
|
transcript.language,
|
||||||
transcript.language_code,
|
transcript.language_code,
|
||||||
# whether it has been manually created or generated by YouTube
|
# whether it has been manually created or generated by YouTube
|
||||||
transcript.is_generated,
|
transcript.is_generated,
|
||||||
# whether this transcript can be translated or not
|
# whether this transcript can be translated or not
|
||||||
transcript.is_translatable,
|
transcript.is_translatable,
|
||||||
# a list of languages the transcript can be translated to
|
# a list of languages the transcript can be translated to
|
||||||
transcript.translation_languages,
|
transcript.translation_languages,
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -135,23 +130,23 @@ transcript_list = YouTubeTranscriptApi.get('video_id')
|
||||||
for transcript in transcript_list:
|
for transcript in transcript_list:
|
||||||
|
|
||||||
# the Transcript object provides metadata properties
|
# the Transcript object provides metadata properties
|
||||||
print(
|
print(
|
||||||
transcript.video_id,
|
transcript.video_id,
|
||||||
transcript.language,
|
transcript.language,
|
||||||
transcript.language_code,
|
transcript.language_code,
|
||||||
# whether it has been manually created or generated by YouTube
|
# whether it has been manually created or generated by YouTube
|
||||||
transcript.is_generated,
|
transcript.is_generated,
|
||||||
# whether this transcript can be translated or not
|
# whether this transcript can be translated or not
|
||||||
transcript.is_translatable,
|
transcript.is_translatable,
|
||||||
# a list of languages the transcript can be translated to
|
# a list of languages the transcript can be translated to
|
||||||
transcript.translation_languages,
|
transcript.translation_languages,
|
||||||
)
|
)
|
||||||
|
|
||||||
# fetch the actual transcript data
|
# fetch the actual transcript data
|
||||||
print(transcript.fetch())
|
print(transcript.fetch())
|
||||||
|
|
||||||
# translating the transcript will return another transcript object
|
# translating the transcript will return another transcript object
|
||||||
print(transcript.translate('en').fetch())
|
print(transcript.translate('en').fetch())
|
||||||
|
|
||||||
# you can also directly filter for the language you are looking for, using the transcript list
|
# you can also directly filter for the language you are looking for, using the transcript list
|
||||||
transcript = transcript_list.find_transcript(['de', 'en'])
|
transcript = transcript_list.find_transcript(['de', 'en'])
|
||||||
|
|
|
@ -72,7 +72,7 @@ class YouTubeTranscriptCli():
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--languages',
|
'--languages',
|
||||||
nargs='*',
|
nargs='*',
|
||||||
default=[],
|
default=['en',],
|
||||||
type=str,
|
type=str,
|
||||||
help=(
|
help=(
|
||||||
'A list of language codes in a descending priority. For example, if this is set to "de en" it will '
|
'A list of language codes in a descending priority. For example, if this is set to "de en" it will '
|
||||||
|
|
|
@ -77,7 +77,7 @@ class TestYouTubeTranscriptCli(TestCase):
|
||||||
parsed_args = YouTubeTranscriptCli('v1 v2'.split())._parse_args()
|
parsed_args = YouTubeTranscriptCli('v1 v2'.split())._parse_args()
|
||||||
self.assertEqual(parsed_args.video_ids, ['v1', 'v2'])
|
self.assertEqual(parsed_args.video_ids, ['v1', 'v2'])
|
||||||
self.assertEqual(parsed_args.json, False)
|
self.assertEqual(parsed_args.json, False)
|
||||||
self.assertEqual(parsed_args.languages, [])
|
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):
|
||||||
|
@ -87,12 +87,12 @@ class TestYouTubeTranscriptCli(TestCase):
|
||||||
parsed_args = YouTubeTranscriptCli('v1 v2 --json'.split())._parse_args()
|
parsed_args = YouTubeTranscriptCli('v1 v2 --json'.split())._parse_args()
|
||||||
self.assertEqual(parsed_args.video_ids, ['v1', 'v2'])
|
self.assertEqual(parsed_args.video_ids, ['v1', 'v2'])
|
||||||
self.assertEqual(parsed_args.json, True)
|
self.assertEqual(parsed_args.json, True)
|
||||||
self.assertEqual(parsed_args.languages, [])
|
self.assertEqual(parsed_args.languages, ['en'])
|
||||||
|
|
||||||
parsed_args = YouTubeTranscriptCli('--json v1 v2'.split())._parse_args()
|
parsed_args = YouTubeTranscriptCli('--json v1 v2'.split())._parse_args()
|
||||||
self.assertEqual(parsed_args.video_ids, ['v1', 'v2'])
|
self.assertEqual(parsed_args.video_ids, ['v1', 'v2'])
|
||||||
self.assertEqual(parsed_args.json, True)
|
self.assertEqual(parsed_args.json, True)
|
||||||
self.assertEqual(parsed_args.languages, [])
|
self.assertEqual(parsed_args.languages, ['en'])
|
||||||
|
|
||||||
def test_argument_parsing__languages(self):
|
def test_argument_parsing__languages(self):
|
||||||
parsed_args = YouTubeTranscriptCli('v1 v2 --languages de en'.split())._parse_args()
|
parsed_args = YouTubeTranscriptCli('v1 v2 --languages de en'.split())._parse_args()
|
||||||
|
|
Loading…
Reference in New Issue