MySafeCode commited on
Commit
882426e
·
verified ·
1 Parent(s): 6f7e9cf

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import yt_dlp
3
+ import tempfile
4
+ import os
5
+
6
+ def get_snippet(url):
7
+ # Create a temporary file
8
+ temp_file = tempfile.NamedTemporaryFile(suffix=".mp3", delete=False)
9
+ temp_file.close()
10
+
11
+ ydl_opts = {
12
+ 'format': 'bestaudio/best',
13
+ 'outtmpl': temp_file.name,
14
+ 'postprocessor_args': ['-t', '30'], # first 30 seconds
15
+ 'quiet': True,
16
+ }
17
+
18
+ try:
19
+ with yt_dlp.YoutubeDL(ydl_opts) as ydl:
20
+ ydl.download([url])
21
+ return temp_file.name
22
+ except Exception as e:
23
+ return f"Error: {str(e)}"
24
+
25
+ # Gradio UI
26
+ with gr.Blocks() as demo:
27
+ gr.Markdown("### Minimal SoundCloud 30s Stream")
28
+ url_input = gr.Textbox(label="SoundCloud URL", value="https://soundcloud.com/antonio-antetomaso/mutiny-on-the-bounty-closing-titles-cover")
29
+ audio_out = gr.Audio(label="Audio Snippet")
30
+ btn = gr.Button("Get 30s Snippet")
31
+
32
+ btn.click(get_snippet, inputs=url_input, outputs=audio_out)
33
+
34
+ demo.launch()