Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import moviepy.editor as mp
|
| 3 |
+
from pytube import YouTube
|
| 4 |
+
import gradio as gr
|
| 5 |
+
|
| 6 |
+
def download_video(url, quality, crop_start, crop_end):
|
| 7 |
+
yt = YouTube(url)
|
| 8 |
+
stream = yt.streams.filter(only_audio=False).first()
|
| 9 |
+
stream.download(output_path="downloads")
|
| 10 |
+
|
| 11 |
+
video_path = os.path.join("downloads", yt.title + ".mp4")
|
| 12 |
+
clip = mp.VideoFileClip(video_path)
|
| 13 |
+
|
| 14 |
+
if crop_start and crop_end:
|
| 15 |
+
clip = clip.subclip(crop_start, crop_end)
|
| 16 |
+
|
| 17 |
+
audio_path = os.path.join("downloads", yt.title + ".mp3")
|
| 18 |
+
clip.audio.write_audiofile(audio_path)
|
| 19 |
+
|
| 20 |
+
return {"video": video_path, "audio": audio_path}
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
iface = gr.Interface(
|
| 24 |
+
fn=download_video,
|
| 25 |
+
inputs=[
|
| 26 |
+
gr.Textbox(label="YouTube URL"),
|
| 27 |
+
gr.Radio(label="Quality", choices=["144p", "240p", "360p", "480p", "720p", "1080p"]),
|
| 28 |
+
gr.Number(label="Crop start (seconds)"),
|
| 29 |
+
gr.Number(label="Crop end (seconds)"),
|
| 30 |
+
],
|
| 31 |
+
outputs=[
|
| 32 |
+
gr.File(label="Video"),
|
| 33 |
+
gr.File(label="Audio"),
|
| 34 |
+
],
|
| 35 |
+
title="YouTube Audio and Video Downloader with Cropping",
|
| 36 |
+
description="Enter a YouTube URL, select a quality, and optionally enter crop start and end times to download the video and audio with cropping.",
|
| 37 |
+
)
|
| 38 |
+
iface.launch()
|