Merge pull request #103 from jdepoix/bugfix/ISSUE-80
adjusted CLI to be able to handle masked hyphens
This commit is contained in:
commit
c3f0cfca45
|
@ -197,6 +197,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:
|
||||||
|
|
|
@ -131,4 +131,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
|
||||||
|
|
|
@ -79,6 +79,12 @@ class TestYouTubeTranscriptCli(TestCase):
|
||||||
self.assertEqual(parsed_args.json, False)
|
self.assertEqual(parsed_args.json, False)
|
||||||
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('--json'.split())._parse_args()
|
YouTubeTranscriptCli('--json'.split())._parse_args()
|
||||||
|
|
Loading…
Reference in New Issue