Spaces:
Paused
Paused
Update app.py
Browse files123456 unmodified lines121314151617181920213 unmodified lines252627282930313233343536373839404142import streamlit as stimport yt_dlpdef get_youtube_formats(url):ydl_opts = {6 unmodified linesdef download_video(url, format_id=None):ydl_opts = {'format': format_id if format_id else 'best'}with yt_dlp.YoutubeDL(ydl_opts) as ydl:ydl.download([url])st.title("Video Downloader")3 unmodified linesif "youtube.com" in url or "youtu.be" in url:st.write("Fetching available formats from YouTube...")formats = get_youtube_formats(url)format_options = [f"{f['format_id']} - {f.get('format_note', 'No note')} - {f['ext']}" for f in formats]format_choice = st.selectbox("Select video quality:", format_options)selected_format_id = format_choice.split(' ')[0]if st.button("Download"):st.write("Downloading...")download_video(url, format_id=selected_format_id)st.success("Download complete!")else:st.write("Downloading in best available quality...")if st.button("Download"):st.write("Downloading...")download_video(url)st.success("Download complete!")1234566 unmodified lines1314151617181920212223243 unmodified lines28293031323334353637383940414243444546474849505152535455565758596061import streamlit as stimport yt_dlpimport osdef get_youtube_formats(url):ydl_opts = {6 unmodified linesdef download_video(url, format_id=None):ydl_opts = {'format': format_id if format_id else 'best','outtmpl': 'downloaded_video.%(ext)s'}with yt_dlp.YoutubeDL(ydl_opts) as ydl:ydl.download([url])return 'downloaded_video.mp4' # Assuming MP4 format for simplicityst.title("Video Downloader")3 unmodified linesif "youtube.com" in url or "youtu.be" in url:st.write("Fetching available formats from YouTube...")formats = get_youtube_formats(url)format_options = [f"{f['format_id']} - {f.get('format_note', 'No note')} - {f['ext']} - {f['filesize'] or 'Unknown size'}" for f in formats]format_choice = st.selectbox("Select video quality:", format_options)selected_format_id = format_choice.split(' ')[0]if st.button("Download"):st.write("Downloading...")downloaded_file = download_video(url, format_id=selected_format_id)st.success("Download complete!")with open(downloaded_file, 'rb') as file:btn = st.download_button(label="Download Video",data=file,file_name=downloaded_file,mime='video/mp4')else:st.write("Downloading in best available quality...")if st.button("Download"):st.write("Downloading...")downloaded_file = download_video(url)st.success("Download complete!")with open(downloaded_file, 'rb') as file:btn = st.download_button(label="Download Video",data=file,file_name=downloaded_file,mime='video/mp4')
app.py+23-4