mimbres commited on
Commit
66ad9cf
·
verified ·
1 Parent(s): ade398a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -13
app.py CHANGED
@@ -14,6 +14,7 @@ import torch
14
  import torchaudio
15
  import glob
16
  import gradio as gr
 
17
 
18
 
19
 
@@ -73,19 +74,28 @@ def prepare_media(source_path_or_url: os.PathLike,
73
  os.remove(mp4_file)
74
  except Exception as e:
75
  try:
76
- # Try alternative
77
- print(f"Failed with PyTube, error: {e}. Trying yt-dlp...")
78
- audio_file = './downloaded/yt_audio'
79
- # subprocess.run(['yt-dlp', '-x', source_path_or_url, '-f', 'bestaudio',
80
- # '-o', audio_file, '--audio-format', 'mp3', '--restrict-filenames',
81
- # '--force-overwrites', '--cookies', 'amt/src/extras/c.txt'])
82
- # subprocess.run(['yt-dlp', '-x', source_path_or_url, '-f', 'bestaudio',
83
- # '-o', audio_file, '--audio-format', 'mp3', '--restrict-filenames',
84
- # '--force-overwrites', '--cookies', 'amt/src/extras/c.txt'])
85
- subprocess.run(['yt-dlp', '-x', source_path_or_url, '-f', 'bestaudio',
86
- '-o', audio_file, '--audio-format', 'mp3', '--restrict-filenames',
87
- '--force-overwrites', '--username', 'oauth2', '--password', '',
88
- '--cache-dir', 'amt/src/extras/cache', '-v'])
 
 
 
 
 
 
 
 
 
89
  audio_file += '.mp3'
90
  except Exception as e:
91
  print(f"Alternative downloader failed, error: {e}. Please try again later!")
@@ -166,6 +176,8 @@ css = """
166
 
167
  with gr.Blocks(theme=theme, css=css) as demo:
168
 
 
 
169
  with gr.Row():
170
  with gr.Column(scale=10):
171
  gr.Markdown(
 
14
  import torchaudio
15
  import glob
16
  import gradio as gr
17
+ from gradio_log import Log
18
 
19
 
20
 
 
74
  os.remove(mp4_file)
75
  except Exception as e:
76
  try:
77
+ with open('amt/log.txt', 'w') as log_file:
78
+ # Try alternative
79
+ print(f"Failed with PyTube, error: {e}. Trying yt-dlp...")
80
+ audio_file = './downloaded/yt_audio'
81
+ # subprocess.run(['yt-dlp', '-x', source_path_or_url, '-f', 'bestaudio',
82
+ # '-o', audio_file, '--audio-format', 'mp3', '--restrict-filenames',
83
+ # '--force-overwrites', '--cookies', 'amt/src/extras/c.txt'])
84
+ # subprocess.run(['yt-dlp', '-x', source_path_or_url, '-f', 'bestaudio',
85
+ # '-o', audio_file, '--audio-format', 'mp3', '--restrict-filenames',
86
+ # '--force-overwrites', '--cookies', 'amt/src/extras/c.txt'])
87
+ process = subprocess.Popen(['yt-dlp', '-x', source_path_or_url, '-f', 'bestaudio',
88
+ '-o', audio_file, '--audio-format', 'mp3', '--restrict-filenames',
89
+ '--force-overwrites', '--username', 'oauth2', '--password', '',
90
+ '-v'],
91
+ stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
92
+
93
+ for line in iter(process.stdout.readline, ''):
94
+ log_file.write(line)
95
+ log_file.flush() # 파일에 내용을 즉시 쓰기
96
+
97
+ process.stdout.close()
98
+ process.wait()
99
  audio_file += '.mp3'
100
  except Exception as e:
101
  print(f"Alternative downloader failed, error: {e}. Please try again later!")
 
176
 
177
  with gr.Blocks(theme=theme, css=css) as demo:
178
 
179
+ Log(log_file, dark=True, xterm_font_size=12)
180
+
181
  with gr.Row():
182
  with gr.Column(scale=10):
183
  gr.Markdown(