Naman0001's picture
Update app.py
210ef49 verified
import gradio as gr
import yt_dlp
import os
import random
import string
text="""Unleash The Power of GhostByte's YOutube Video Downloader!
Directly Download Original Quality Videos from server! No quality Loss!
Click on download button in output box to download video
Video format is webm and there is no problem with it!
NOTE: GOOGLE BLOCKS IP IF TOO MANY REQUESTS SENT. SO THE VIDEO WILL NOT DOWNLOAD THEN. I WILL RESOLVE IT AS SOON AS POSSIBLE!"""
gr.Markdown(text)
# Function to generate a random alphabet name for the video file
def generate_random_name(length=10):
letters = string.ascii_lowercase
return ''.join(random.choice(letters) for _ in range(length))
# Function to download YouTube video using yt-dlp
def download_youtube_video(url):
# Set yt-dlp options
ydl_opts = {
'outtmpl': f'{generate_random_name()}'# Save video with a random name
}
# Download video
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
info_dict = ydl.extract_info(url, download=True)
filename = ydl.prepare_filename(info_dict) + ".webm"
print(filename)
return filename
# Interface for Gradio app
interface = gr.Interface(
fn=download_youtube_video,
inputs=gr.Textbox(label="Enter YouTube link"),
outputs=gr.Video(label = "video_path")
).launch()