Update app.py
Browse files
app.py
CHANGED
|
@@ -137,26 +137,34 @@ def split_wav_or_mp3_file(audiofileuploader, mindur2, maxdur2, name_for_split_fi
|
|
| 137 |
|
| 138 |
def download_video_as_audio_only(yt_video, audio_output_format):
|
| 139 |
try:
|
| 140 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
except pytube.exceptions.RegexMatchError:
|
| 142 |
raise gr.Error("URL not valid or is empty! Please fix the link or enter one!")
|
| 143 |
except urllib.error.HTTPError as not_ok:
|
| 144 |
raise gr.Error(f"Recieved {not_ok}")
|
| 145 |
except pytube.exceptions.AgeRestrictedError:
|
| 146 |
raise gr.Error("The video you inputted is age-restricted! Please try another link.")
|
| 147 |
-
video = yt.streams.
|
| 148 |
-
video.download()
|
| 149 |
-
video_path = f"{video.default_filename}"
|
| 150 |
-
video_clip = VideoFileClip(video_path)
|
| 151 |
-
audio_clip = video_clip.audio
|
| 152 |
-
if audio_output_format == "wav":
|
| 153 |
-
|
| 154 |
-
elif audio_output_format == "mp3":
|
| 155 |
-
|
| 156 |
-
audio_clip.close()
|
| 157 |
-
video_clip.close()
|
| 158 |
-
for mp4remove in glob.glob("*.mp4"):
|
| 159 |
-
|
| 160 |
single_zip_name = "only_audio.zip"
|
| 161 |
audio_files = glob.glob("*.wav") if audio_output_format == "wav" else glob.glob("*.mp3")
|
| 162 |
with zipfile.ZipFile(single_zip_name, 'w') as zip_file:
|
|
@@ -168,7 +176,7 @@ def download_video_as_audio_only(yt_video, audio_output_format):
|
|
| 168 |
for outputmp3removal in glob.glob("*.mp3"):
|
| 169 |
if os.path.exists(outputmp3removal):
|
| 170 |
os.remove(outputmp3removal)
|
| 171 |
-
return f"Done! Download the zip file below! This only contains the audio file.\n\nYou have downloaded
|
| 172 |
|
| 173 |
def mp4_to_wav_or_mp3(mp4fileuploader, file_format):
|
| 174 |
if mp4fileuploader == None:
|
|
@@ -230,7 +238,7 @@ def mvsep_check_request(hash_textbox):
|
|
| 230 |
rjson = r.json()
|
| 231 |
success = rjson['success']
|
| 232 |
status = rjson['status']
|
| 233 |
-
return f"Was successful? {str(success)}.\
|
| 234 |
except requests.exceptions.JSONDecodeError:
|
| 235 |
return gr.Info("Status not available or request not sent.")
|
| 236 |
|
|
@@ -253,21 +261,32 @@ def mvsep_download_separated_audio(hash_textbox):
|
|
| 253 |
|
| 254 |
def mvsep_yt_link_request(mvsep_key2, sep_dropdown2, yt_link):
|
| 255 |
try:
|
| 256 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 257 |
except pytube.exceptions.RegexMatchError:
|
| 258 |
raise gr.Error("URL not valid or is empty! Please fix the link or enter one!")
|
| 259 |
except urllib.error.HTTPError as not_ok:
|
| 260 |
raise gr.Error(f"Recieved {not_ok}")
|
| 261 |
except pytube.exceptions.AgeRestrictedError:
|
| 262 |
raise gr.Error("The video you inputted is age-restricted! Please try another link.")
|
| 263 |
-
video = yt.streams.get_highest_resolution()
|
| 264 |
-
video.download()
|
| 265 |
-
video_path = f"{video.default_filename}"
|
| 266 |
-
video_clip = VideoFileClip(video_path)
|
| 267 |
-
audio_clip = video_clip.audio
|
| 268 |
-
audio_clip.write_audiofile("output.mp3")
|
| 269 |
-
audio_clip.close()
|
| 270 |
-
video_clip.close()
|
|
|
|
|
|
|
|
|
|
| 271 |
for removalmp4 in glob.glob("*.mp4"):
|
| 272 |
os.remove(removalmp4)
|
| 273 |
|
|
@@ -285,7 +304,6 @@ def mvsep_yt_link_request(mvsep_key2, sep_dropdown2, yt_link):
|
|
| 285 |
return f"Request sent successfully! Your hash is: {hash_val}\n\nUse the next tab to check the status of your request."
|
| 286 |
|
| 287 |
|
| 288 |
-
|
| 289 |
with gr.Blocks(theme='sudeepshouche/minimalist', title="Global Dataset Maker") as app:
|
| 290 |
gr.HTML(
|
| 291 |
"<h1> Welcome to the Cafeteria (formally GDMGS)!</h1>"
|
|
@@ -523,6 +541,7 @@ with gr.Blocks(theme='sudeepshouche/minimalist', title="Global Dataset Maker") a
|
|
| 523 |
)
|
| 524 |
|
| 525 |
with gr.TabItem("Changelog"):
|
|
|
|
| 526 |
gr.Markdown("v0.99.6 - Added a yt link request method for MVSEP.")
|
| 527 |
gr.Markdown("v0.99.5 - Added bug fixes and Dropdown instead of button for MVSEP.")
|
| 528 |
gr.Markdown("v0.99.4 - Added a button to display the available models for MVSEP.")
|
|
|
|
| 137 |
|
| 138 |
def download_video_as_audio_only(yt_video, audio_output_format):
|
| 139 |
try:
|
| 140 |
+
ydl_opts = {
|
| 141 |
+
'format': f"{audio_output_format}/bestaudio/best",
|
| 142 |
+
'postprocessors': [{
|
| 143 |
+
'key': 'FFmpegExtractAudio',
|
| 144 |
+
'preferredcodec': "mp3"
|
| 145 |
+
}]
|
| 146 |
+
}
|
| 147 |
+
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
| 148 |
+
ydl.download(yt_video)
|
| 149 |
except pytube.exceptions.RegexMatchError:
|
| 150 |
raise gr.Error("URL not valid or is empty! Please fix the link or enter one!")
|
| 151 |
except urllib.error.HTTPError as not_ok:
|
| 152 |
raise gr.Error(f"Recieved {not_ok}")
|
| 153 |
except pytube.exceptions.AgeRestrictedError:
|
| 154 |
raise gr.Error("The video you inputted is age-restricted! Please try another link.")
|
| 155 |
+
#video = yt.streams.get_audio_only()
|
| 156 |
+
#video.download()
|
| 157 |
+
#video_path = f"{video.default_filename}"
|
| 158 |
+
#video_clip = VideoFileClip(video_path)
|
| 159 |
+
#audio_clip = video_clip.audio
|
| 160 |
+
#if audio_output_format == "wav":
|
| 161 |
+
# audio_clip.write_audiofile("output.wav")
|
| 162 |
+
#elif audio_output_format == "mp3":
|
| 163 |
+
# audio_clip.write_audiofile("output.mp3")
|
| 164 |
+
#audio_clip.close()
|
| 165 |
+
#video_clip.close()
|
| 166 |
+
#for mp4remove in glob.glob("*.mp4"):
|
| 167 |
+
# os.remove(mp4remove)
|
| 168 |
single_zip_name = "only_audio.zip"
|
| 169 |
audio_files = glob.glob("*.wav") if audio_output_format == "wav" else glob.glob("*.mp3")
|
| 170 |
with zipfile.ZipFile(single_zip_name, 'w') as zip_file:
|
|
|
|
| 176 |
for outputmp3removal in glob.glob("*.mp3"):
|
| 177 |
if os.path.exists(outputmp3removal):
|
| 178 |
os.remove(outputmp3removal)
|
| 179 |
+
return f"Done! Download the zip file below! This only contains the audio file.\n\nYou have downloaded a video.", single_zip_name
|
| 180 |
|
| 181 |
def mp4_to_wav_or_mp3(mp4fileuploader, file_format):
|
| 182 |
if mp4fileuploader == None:
|
|
|
|
| 238 |
rjson = r.json()
|
| 239 |
success = rjson['success']
|
| 240 |
status = rjson['status']
|
| 241 |
+
return f"Was successful? {str(success)}.\nStatus: {status}."
|
| 242 |
except requests.exceptions.JSONDecodeError:
|
| 243 |
return gr.Info("Status not available or request not sent.")
|
| 244 |
|
|
|
|
| 261 |
|
| 262 |
def mvsep_yt_link_request(mvsep_key2, sep_dropdown2, yt_link):
|
| 263 |
try:
|
| 264 |
+
ydl_opts = {
|
| 265 |
+
'format': "mp3/bestaudio/best",
|
| 266 |
+
'postprocessors': [{
|
| 267 |
+
'key': 'FFmpegExtractAudio',
|
| 268 |
+
'preferredcodec': "mp3"
|
| 269 |
+
}]
|
| 270 |
+
}
|
| 271 |
+
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
| 272 |
+
ydl.download(yt_link)
|
| 273 |
except pytube.exceptions.RegexMatchError:
|
| 274 |
raise gr.Error("URL not valid or is empty! Please fix the link or enter one!")
|
| 275 |
except urllib.error.HTTPError as not_ok:
|
| 276 |
raise gr.Error(f"Recieved {not_ok}")
|
| 277 |
except pytube.exceptions.AgeRestrictedError:
|
| 278 |
raise gr.Error("The video you inputted is age-restricted! Please try another link.")
|
| 279 |
+
#video = yt.streams.get_highest_resolution()
|
| 280 |
+
#video.download()
|
| 281 |
+
#video_path = f"{video.default_filename}"
|
| 282 |
+
#video_clip = VideoFileClip(video_path)
|
| 283 |
+
#audio_clip = video_clip.audio
|
| 284 |
+
#audio_clip.write_audiofile("output.mp3")
|
| 285 |
+
#audio_clip.close()
|
| 286 |
+
#video_clip.close()
|
| 287 |
+
for rename in glob.glob("*.mp3"):
|
| 288 |
+
if os.path.exists(rename):
|
| 289 |
+
os.rename(rename, "output.mp3")
|
| 290 |
for removalmp4 in glob.glob("*.mp4"):
|
| 291 |
os.remove(removalmp4)
|
| 292 |
|
|
|
|
| 304 |
return f"Request sent successfully! Your hash is: {hash_val}\n\nUse the next tab to check the status of your request."
|
| 305 |
|
| 306 |
|
|
|
|
| 307 |
with gr.Blocks(theme='sudeepshouche/minimalist', title="Global Dataset Maker") as app:
|
| 308 |
gr.HTML(
|
| 309 |
"<h1> Welcome to the Cafeteria (formally GDMGS)!</h1>"
|
|
|
|
| 541 |
)
|
| 542 |
|
| 543 |
with gr.TabItem("Changelog"):
|
| 544 |
+
gr.Markdown("v0.99.7 - Temporarily fixed an issue causing a 400 error to happen whenever a youtube url was placed.")
|
| 545 |
gr.Markdown("v0.99.6 - Added a yt link request method for MVSEP.")
|
| 546 |
gr.Markdown("v0.99.5 - Added bug fixes and Dropdown instead of button for MVSEP.")
|
| 547 |
gr.Markdown("v0.99.4 - Added a button to display the available models for MVSEP.")
|