Update app.py
Browse files
app.py
CHANGED
|
@@ -1,65 +1,66 @@
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import yt_dlp
|
| 3 |
import os
|
| 4 |
from glob import glob
|
| 5 |
|
| 6 |
-
|
| 7 |
-
return
|
| 8 |
-
|
| 9 |
-
def
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
'
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
'
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
iface.launch()
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
import gradio as gr
|
| 4 |
import yt_dlp
|
| 5 |
import os
|
| 6 |
from glob import glob
|
| 7 |
|
| 8 |
+
hours, minutes, seconds = map(int, time_str.split(':'))
|
| 9 |
+
return hours * 3600 + minutes * 60 + seconds
|
| 10 |
+
|
| 11 |
+
def download_videos(data):
|
| 12 |
+
output_files = []
|
| 13 |
+
for item in data:
|
| 14 |
+
video_url = item['video_url']
|
| 15 |
+
start_time = item['start_time']
|
| 16 |
+
end_time = item['end_time']
|
| 17 |
+
|
| 18 |
+
start_seconds = convert_time_to_seconds(start_time)
|
| 19 |
+
end_seconds = convert_time_to_seconds(end_time)
|
| 20 |
+
|
| 21 |
+
options = {
|
| 22 |
+
'format': 'bestaudio/best',
|
| 23 |
+
'postprocessors': [{
|
| 24 |
+
'key': 'FFmpegExtractAudio',
|
| 25 |
+
'preferredcodec': 'mp3',
|
| 26 |
+
'preferredquality': '128',
|
| 27 |
+
}],
|
| 28 |
+
'outtmpl': '%(title)s.%(ext)s',
|
| 29 |
+
'postprocessor_args': [
|
| 30 |
+
'-ss', str(start_seconds),
|
| 31 |
+
'-to', str(end_seconds)
|
| 32 |
+
]
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
with yt_dlp.YoutubeDL(options) as ydl:
|
| 36 |
+
ydl.download([video_url])
|
| 37 |
+
|
| 38 |
+
download_files = glob('*.mp3')
|
| 39 |
+
for file in download_files:
|
| 40 |
+
os.rename(file, os.path.join('downloaded', file))
|
| 41 |
+
output_files.append(os.path.join('downloaded', file))
|
| 42 |
+
|
| 43 |
+
return output_files
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
interface = gr.Interface(
|
| 50 |
+
fn=download_videos,
|
| 51 |
+
inputs=gr.inputs.DynamicList([
|
| 52 |
+
gr.inputs.Textbox(label="YouTube Video URL", placeholder="Enter YouTube video URL here..."),
|
| 53 |
+
gr.inputs.Textbox(label="Start Time (HH:MM:SS)", placeholder="00:00:00"),
|
| 54 |
+
gr.inputs.Textbox(label="End Time (HH:MM:SS)", placeholder="00:05:00")
|
| 55 |
+
]),
|
| 56 |
+
outputs=gr.outputs.File(label="Downloaded MP3 Files"),
|
| 57 |
+
title="Batch YouTube Video Downloader",
|
| 58 |
+
description="Add multiple entries to download specific clips from YouTube videos as MP3."
|
| 59 |
+
)
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
interface.launch()
|
|
|