import gradio as gr from pytube import YouTube import os def download_video(url, output_path="downloads"): try: yt = YouTube(url) video = yt.streams.filter(progressive=True, file_extension="mp4").order_by("resolution").desc().first() if not os.path.exists(output_path): os.makedirs(output_path) out_file = video.download(output_path) return f"Video downloaded successfully: {out_file}" except Exception as e: return f"An error occurred: {str(e)}" def video_info(url): try: yt = YouTube(url) return f"Title: {yt.title}\nViews: {yt.views}\nLength: {yt.length} seconds" except Exception as e: return f"An error occurred: {str(e)}" gradio_app = gr.Interface( fn=download_video, inputs=gr.Textbox(label="YouTube URL"), outputs=gr.Textbox(label="Download Status"), title="YouTube Video Downloader", description="Enter a YouTube URL to download the video.", examples=[["https://www.youtube.com/watch?v=dQw4w9WgXcQ"]], article="Note: Please ensure you have the right to download and use the video content." ) if __name__ == "__main__": gradio_app.launch()