Skip to content

Commit a69002d

Browse files
committed
Battle-testing yt captions
1 parent eb3f796 commit a69002d

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

minet/cli/youtube/captions.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#
77
from minet.youtube import YouTubeScraper
88
from minet.youtube.types import YouTubeCaptionTrack, YouTubeCaptionLine
9+
from minet.youtube.exceptions import YouTubeInvalidVideoTargetError
910

1011
from minet.cli.utils import with_enricher_and_loading_bar
1112
from minet.cli.loading_bar import LoadingBar
@@ -21,11 +22,23 @@
2122
def action(cli_args, enricher, loading_bar: LoadingBar):
2223
scraper = YouTubeScraper()
2324

24-
with loading_bar.step():
25-
for row, video in enricher.cells(cli_args.column, with_rows=True):
26-
result = scraper.get_video_captions(video, langs=cli_args.lang)
25+
lang_warning_printed = False
26+
27+
for row, video in enricher.cells(cli_args.column, with_rows=True):
28+
with loading_bar.step():
29+
try:
30+
result = scraper.get_video_captions(video, langs=cli_args.lang)
31+
except YouTubeInvalidVideoTargetError:
32+
loading_bar.inc_stat("not-a-video", style="error")
33+
continue
2734

2835
if result is None:
36+
if not lang_warning_printed:
37+
lang_warning_printed = True
38+
loading_bar.warning(
39+
"Did you forget to pass the correct value to [dim]--lang[/dim]?"
40+
)
41+
2942
loading_bar.inc_stat("not-found", style="error")
3043
continue
3144

0 commit comments

Comments
 (0)