adjusted CLI to be able to handle masked hyphens

This commit is contained in:
Jonas Depoix 2021-03-15 10:34:05 +01:00
parent cf0647f91f
commit 72f035fa6d
3 changed files with 18 additions and 2 deletions

View File

@ -195,7 +195,13 @@ If you are not sure which languages are available for a given video you can call
```
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

View File

@ -131,4 +131,8 @@ class YouTubeTranscriptCli():
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

View File

@ -79,6 +79,12 @@ class TestYouTubeTranscriptCli(TestCase):
self.assertEqual(parsed_args.json, False)
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):
with self.assertRaises(SystemExit):
YouTubeTranscriptCli('--json'.split())._parse_args()