test-rtechs commited on
Commit
42f33fc
1 Parent(s): 16fd6bc

Update app_rvc.py

Browse files
Files changed (1) hide show
  1. app_rvc.py +6 -11
app_rvc.py CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
2
  import os
3
  import subprocess
4
  import logging
 
5
  os.system("pip install -q piper-tts==1.2.0")
6
  os.system("pip install -q -r requirements_xtts.txt")
7
  os.system("pip install -q TTS==0.21.1 --no-deps")
@@ -285,12 +286,6 @@ def check_openai_api_key():
285
  "translation process in Advanced settings."
286
  )
287
 
288
- import os
289
- import subprocess
290
- import yt_dlp
291
- import logging
292
-
293
- logger = logging.getLogger(__name__)
294
 
295
  def download_and_adjust_youtube_video(url, speed_factor, start_time=None, end_time=None):
296
  # Create the 'downloaded' folder if it doesn't exist
@@ -309,14 +304,15 @@ def download_and_adjust_youtube_video(url, speed_factor, start_time=None, end_ti
309
 
310
  logger.info(f"Downloaded video: {filename}")
311
 
312
- # Generate output filename
313
- output_filename = f"downloaded/{os.path.splitext(os.path.basename(filename))[0]}_speed{speed_factor}.mp4"
 
314
 
315
  # Prepare FFmpeg command
316
  ffmpeg_cmd = ['ffmpeg', '-i', filename]
317
 
318
- # Add trim options if start_time and end_time are provided
319
- if start_time is not None and end_time is not None:
320
  ffmpeg_cmd.extend(['-ss', str(start_time), '-to', str(end_time)])
321
 
322
  # Add speed adjustment
@@ -335,7 +331,6 @@ def download_and_adjust_youtube_video(url, speed_factor, start_time=None, end_ti
335
  except subprocess.CalledProcessError as e:
336
  logger.error(f"Error processing video: {e}")
337
  logger.error(f"FFmpeg stderr: {e.stderr}")
338
- logger.error(f"FFmpeg stdout: {e.stdout}")
339
  raise
340
 
341
  return output_filename
 
2
  import os
3
  import subprocess
4
  import logging
5
+ import re
6
  os.system("pip install -q piper-tts==1.2.0")
7
  os.system("pip install -q -r requirements_xtts.txt")
8
  os.system("pip install -q TTS==0.21.1 --no-deps")
 
286
  "translation process in Advanced settings."
287
  )
288
 
 
 
 
 
 
 
289
 
290
  def download_and_adjust_youtube_video(url, speed_factor, start_time=None, end_time=None):
291
  # Create the 'downloaded' folder if it doesn't exist
 
304
 
305
  logger.info(f"Downloaded video: {filename}")
306
 
307
+ # Sanitize filename
308
+ safe_filename = re.sub(r'[^\w\-_\. ]', '_', os.path.splitext(os.path.basename(filename))[0])
309
+ output_filename = f"downloaded/{safe_filename}_speed{speed_factor}.mp4"
310
 
311
  # Prepare FFmpeg command
312
  ffmpeg_cmd = ['ffmpeg', '-i', filename]
313
 
314
+ # Add trim options if start_time and end_time are provided and valid
315
+ if start_time is not None and end_time is not None and start_time < end_time:
316
  ffmpeg_cmd.extend(['-ss', str(start_time), '-to', str(end_time)])
317
 
318
  # Add speed adjustment
 
331
  except subprocess.CalledProcessError as e:
332
  logger.error(f"Error processing video: {e}")
333
  logger.error(f"FFmpeg stderr: {e.stderr}")
 
334
  raise
335
 
336
  return output_filename