Update app.py
Browse files
app.py
CHANGED
@@ -9,29 +9,34 @@ from tempfile import TemporaryDirectory
|
|
9 |
cachedir = ".cache"
|
10 |
|
11 |
|
12 |
-
def clip(yt_url, start_timestamp, end_timestamp):
|
13 |
start_timestamp = int(start_timestamp)
|
14 |
duration = int(end_timestamp) - int(start_timestamp)
|
15 |
|
16 |
with TemporaryDirectory() as tmpdir:
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
35 |
clip_path = f"{uuid4()}.mp3"
|
36 |
print(f'ffmpeg -ss {start_timestamp} -t {duration} -i "{video_output_path}" "{clip_path}"')
|
37 |
subprocess.run(f'ffmpeg -ss {start_timestamp} -t {duration} -i "{video_output_path}" "{clip_path}"', shell=True)
|
@@ -39,10 +44,11 @@ def clip(yt_url, start_timestamp, end_timestamp):
|
|
39 |
|
40 |
|
41 |
url_link = gr.Textbox(label="YouTube URL")
|
|
|
42 |
start_timestamp = gr.Textbox(label="Clip start timestamp (in seconds)")
|
43 |
end_timestamp = gr.Textbox(label="Clip end timestamp (in seconds)")
|
44 |
|
45 |
-
interface = gr.Interface(clip, [url_link, start_timestamp, end_timestamp], "audio", title="YouTube Clipper", description="After downloading the clips, please go to https://demo.deepsync.co/11-voice-cloning to clone the voice.")
|
46 |
|
47 |
if __name__=="__main__":
|
48 |
interface.queue().launch(auth=(os.environ.get("GRADIO_USERNAME"), os.environ.get("GRADIO_PASSWORD")))
|
|
|
9 |
cachedir = ".cache"
|
10 |
|
11 |
|
12 |
+
def clip(yt_url, video_file_path, start_timestamp, end_timestamp):
|
13 |
start_timestamp = int(start_timestamp)
|
14 |
duration = int(end_timestamp) - int(start_timestamp)
|
15 |
|
16 |
with TemporaryDirectory() as tmpdir:
|
17 |
+
if yt_url is not None:
|
18 |
+
video_output_path = os.path.join(tmpdir, "video.mp4")
|
19 |
+
ydl_opts = {
|
20 |
+
"quiet": True,
|
21 |
+
"outtmpl": video_output_path,
|
22 |
+
"postprocessors": [{"key": "FFmpegVideoConvertor", "preferedformat": "mp4"}],
|
23 |
+
"cachedir": cachedir
|
24 |
+
}
|
25 |
+
if not os.path.exists(video_output_path):
|
26 |
+
try:
|
27 |
+
ydl_opts["format"] = "22"
|
28 |
+
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
29 |
+
ydl.download([yt_url])
|
30 |
+
except Exception as e:
|
31 |
+
print(e)
|
32 |
+
ydl_opts["format"] = "bestvideo[height<=480][ext=mp4]+bestaudio[ext=m4a]/best[height<=480][ext=mp4]/best"
|
33 |
+
sleep(5)
|
34 |
+
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
35 |
+
ydl.download([yt_url])
|
36 |
+
elif os.path.exists(video_file_path):
|
37 |
+
video_output_path = video_file_path
|
38 |
+
else:
|
39 |
+
raise Exception("Select valid input.")
|
40 |
clip_path = f"{uuid4()}.mp3"
|
41 |
print(f'ffmpeg -ss {start_timestamp} -t {duration} -i "{video_output_path}" "{clip_path}"')
|
42 |
subprocess.run(f'ffmpeg -ss {start_timestamp} -t {duration} -i "{video_output_path}" "{clip_path}"', shell=True)
|
|
|
44 |
|
45 |
|
46 |
url_link = gr.Textbox(label="YouTube URL")
|
47 |
+
video_file = gr.Video(label="Upload Video")
|
48 |
start_timestamp = gr.Textbox(label="Clip start timestamp (in seconds)")
|
49 |
end_timestamp = gr.Textbox(label="Clip end timestamp (in seconds)")
|
50 |
|
51 |
+
interface = gr.Interface(clip, [url_link, video_file, start_timestamp, end_timestamp], "audio", title="YouTube / Video Clipper", description="After downloading the clips, please go to https://demo.deepsync.co/11-voice-cloning to clone the voice.")
|
52 |
|
53 |
if __name__=="__main__":
|
54 |
interface.queue().launch(auth=(os.environ.get("GRADIO_USERNAME"), os.environ.get("GRADIO_PASSWORD")))
|