lucas-ventura commited on
Commit
a92d566
·
verified ·
1 Parent(s): 9aa1697

Update tools/download/video.py

Browse files
Files changed (1) hide show
  1. tools/download/video.py +23 -9
tools/download/video.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import io
2
  from contextlib import redirect_stderr
3
  from tempfile import mkdtemp
@@ -24,9 +25,9 @@ def download_url(
24
  destinationDirectory: str = None,
25
  playlistItems: str = "1",
26
  cookies_from_browser: str = None,
27
- ) -> List[str]:
28
  try:
29
- return _perform_download(
30
  url,
31
  maxDuration=maxDuration,
32
  outputTemplate=None,
@@ -34,16 +35,29 @@ def download_url(
34
  playlistItems=playlistItems,
35
  cookies_from_browser=cookies_from_browser,
36
  )
 
37
  except yt_dlp.utils.DownloadError as e:
38
  # In case of an OS error, try again with a different output template
39
  if e.msg and e.msg.find("[Errno 36] File name too long") >= 0:
40
- return _perform_download(
41
- url,
42
- maxDuration=maxDuration,
43
- outputTemplate="%(title).10s %(id)s.%(ext)s",
44
- cookies_from_browser=cookies_from_browser,
45
- )
46
- raise
 
 
 
 
 
 
 
 
 
 
 
 
47
 
48
 
49
  def _perform_download(
 
1
+ # Code based on cutechicken/whisper-webui-translate
2
  import io
3
  from contextlib import redirect_stderr
4
  from tempfile import mkdtemp
 
25
  destinationDirectory: str = None,
26
  playlistItems: str = "1",
27
  cookies_from_browser: str = None,
28
+ ) -> tuple[bool, str, List[str]]:
29
  try:
30
+ video_paths = _perform_download(
31
  url,
32
  maxDuration=maxDuration,
33
  outputTemplate=None,
 
35
  playlistItems=playlistItems,
36
  cookies_from_browser=cookies_from_browser,
37
  )
38
+ return True, None, video_paths
39
  except yt_dlp.utils.DownloadError as e:
40
  # In case of an OS error, try again with a different output template
41
  if e.msg and e.msg.find("[Errno 36] File name too long") >= 0:
42
+ try:
43
+ video_paths = _perform_download(
44
+ url,
45
+ maxDuration=maxDuration,
46
+ outputTemplate="%(title).10s %(id)s.%(ext)s",
47
+ cookies_from_browser=cookies_from_browser,
48
+ )
49
+ return True, None, video_paths
50
+ except Exception as retry_error:
51
+ return False, str(retry_error), []
52
+ return False, str(e), []
53
+ except ExceededMaximumDuration as e:
54
+ return (
55
+ False,
56
+ f"Video exceeds maximum duration: {e.videoDuration}s > {e.maxDuration}s",
57
+ [],
58
+ )
59
+ except Exception as e:
60
+ return False, str(e), []
61
 
62
 
63
  def _perform_download(