test-rtechs commited on
Commit
3d6bc22
·
verified ·
1 Parent(s): 8be02cd

Update app_rvc.py

Browse files

download and fix updated!

Files changed (1) hide show
  1. app_rvc.py +56 -1
app_rvc.py CHANGED
@@ -105,6 +105,9 @@ import argparse
105
  import time
106
  import hashlib
107
  import sys
 
 
 
108
 
109
  directories = [
110
  "downloads",
@@ -276,6 +279,42 @@ def check_openai_api_key():
276
  "translation process in Advanced settings."
277
  )
278
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
279
 
280
  class SoniTranslate(SoniTrCache):
281
  def __init__(self, cpu_mode=False):
@@ -2111,6 +2150,22 @@ def create_gui(theme, logs_in_gui=False):
2111
  outputs=[video_output],
2112
  cache_examples=False,
2113
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2114
 
2115
  with gr.Tab(lg_conf["tab_docs"]):
2116
  with gr.Column():
@@ -2921,4 +2976,4 @@ if __name__ == "__main__":
2921
  show_error=True,
2922
  quiet=False,
2923
  debug=(True if logger.isEnabledFor(logging.DEBUG) else False),
2924
- )
 
105
  import time
106
  import hashlib
107
  import sys
108
+ import yt_dlp
109
+ from moviepy.editor import VideoFileClip
110
+
111
 
112
  directories = [
113
  "downloads",
 
279
  "translation process in Advanced settings."
280
  )
281
 
282
+ def download_and_adjust_youtube_video(url, speed_factor, start_time=None, end_time=None):
283
+ # Create the 'downloaded' folder if it doesn't exist
284
+ os.makedirs("downloaded", exist_ok=True)
285
+
286
+ # Configure yt-dlp options
287
+ ydl_opts = {
288
+ 'format': 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best',
289
+ 'outtmpl': 'downloaded/%(title)s.%(ext)s',
290
+ }
291
+
292
+ # Download the video
293
+ with yt_dlp.YoutubeDL(ydl_opts) as ydl:
294
+ info = ydl.extract_info(url, download=True)
295
+ filename = ydl.prepare_filename(info)
296
+
297
+ # Load the video and adjust speed
298
+ video = VideoFileClip(filename)
299
+
300
+ # Trim the video if start_time and end_time are provided
301
+ if start_time is not None and end_time is not None:
302
+ video = video.subclip(start_time, end_time)
303
+
304
+ # Adjust speed
305
+ adjusted_video = video.speedx(speed_factor)
306
+
307
+ # Generate output filename
308
+ output_filename = f"downloaded/{os.path.splitext(os.path.basename(filename))[0]}_speed{speed_factor}.mp4"
309
+
310
+ # Write the adjusted video
311
+ adjusted_video.write_videofile(output_filename)
312
+
313
+ # Close the video objects
314
+ video.close()
315
+ adjusted_video.close()
316
+
317
+ return output_filename
318
 
319
  class SoniTranslate(SoniTrCache):
320
  def __init__(self, cpu_mode=False):
 
2150
  outputs=[video_output],
2151
  cache_examples=False,
2152
  )
2153
+
2154
+
2155
+ with gr.Tab("YouTube Download"):
2156
+ with gr.Column():
2157
+ youtube_url = gr.Textbox(label="YouTube URL")
2158
+ speed_factor = gr.Slider(minimum=0.5, maximum=2.0, value=1.0, step=0.1, label="Speed Factor")
2159
+ start_time = gr.Number(label="Start Time (seconds)", value=None)
2160
+ end_time = gr.Number(label="End Time (seconds)", value=None)
2161
+ download_button = gr.Button("Download and Adjust")
2162
+ download_output = gr.File(label="Downloaded Video")
2163
+
2164
+ download_button.click(
2165
+ download_and_adjust_youtube_video,
2166
+ inputs=[youtube_url, speed_factor, start_time, end_time],
2167
+ outputs=download_output
2168
+ )
2169
 
2170
  with gr.Tab(lg_conf["tab_docs"]):
2171
  with gr.Column():
 
2976
  show_error=True,
2977
  quiet=False,
2978
  debug=(True if logger.isEnabledFor(logging.DEBUG) else False),
2979
+ )