Spaces:
Running
Running
Fix YouTube video length restriction
Browse files- app.py +7 -7
- download.py +1 -1
app.py
CHANGED
@@ -59,13 +59,6 @@ class UI:
|
|
59 |
selectedLanguage = languageName.lower() if len(languageName) > 0 else None
|
60 |
selectedModel = modelName if modelName is not None else "base"
|
61 |
|
62 |
-
if self.inputAudioMaxDuration > 0:
|
63 |
-
# Calculate audio length
|
64 |
-
audioDuration = ffmpeg.probe(source)["format"]["duration"]
|
65 |
-
|
66 |
-
if float(audioDuration) > self.inputAudioMaxDuration:
|
67 |
-
return [], ("[ERROR]: Maximum audio file length is " + str(self.inputAudioMaxDuration) + "s, file was " + str(audioDuration) + "s"), "[ERROR]"
|
68 |
-
|
69 |
model = model_cache.get(selectedModel, None)
|
70 |
|
71 |
if not model:
|
@@ -112,6 +105,13 @@ class UI:
|
|
112 |
# File input
|
113 |
source = uploadFile if uploadFile is not None else microphoneData
|
114 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
file_path = pathlib.Path(source)
|
116 |
sourceName = file_path.stem[:MAX_FILE_PREFIX_LENGTH] + file_path.suffix
|
117 |
|
|
|
59 |
selectedLanguage = languageName.lower() if len(languageName) > 0 else None
|
60 |
selectedModel = modelName if modelName is not None else "base"
|
61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
model = model_cache.get(selectedModel, None)
|
63 |
|
64 |
if not model:
|
|
|
105 |
# File input
|
106 |
source = uploadFile if uploadFile is not None else microphoneData
|
107 |
|
108 |
+
if self.inputAudioMaxDuration > 0:
|
109 |
+
# Calculate audio length
|
110 |
+
audioDuration = ffmpeg.probe(source)["format"]["duration"]
|
111 |
+
|
112 |
+
if float(audioDuration) > self.inputAudioMaxDuration:
|
113 |
+
raise ExceededMaximumDuration(videoDuration=audioDuration, maxDuration=self.inputAudioMaxDuration, message="Video is too long")
|
114 |
+
|
115 |
file_path = pathlib.Path(source)
|
116 |
sourceName = file_path.stem[:MAX_FILE_PREFIX_LENGTH] + file_path.suffix
|
117 |
|
download.py
CHANGED
@@ -26,7 +26,7 @@ def downloadUrl(url: str, maxDuration: int = None):
|
|
26 |
filename_collector = FilenameCollectorPP()
|
27 |
|
28 |
with YoutubeDL(ydl_opts) as ydl:
|
29 |
-
if maxDuration:
|
30 |
info = ydl.extract_info(url, download=False)
|
31 |
duration = info['duration']
|
32 |
|
|
|
26 |
filename_collector = FilenameCollectorPP()
|
27 |
|
28 |
with YoutubeDL(ydl_opts) as ydl:
|
29 |
+
if maxDuration and maxDuration > 0:
|
30 |
info = ydl.extract_info(url, download=False)
|
31 |
duration = info['duration']
|
32 |
|