| import streamlit as st |
| from googleapiclient.discovery import build |
| from pytube import YouTube |
|
|
| API_KEY = 'YOUR_API_KEY' |
| YOUTUBE_API_SERVICE_NAME = 'youtube' |
| YOUTUBE_API_VERSION = 'v3' |
|
|
| def get_video_info(url): |
| video_id = url.split('v=')[1] |
| youtube = build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION, developerKey=API_KEY) |
| request = youtube.videos().list(part="snippet,contentDetails,statistics", id=video_id) |
| response = request.execute() |
| return response |
|
|
| def download_video(url, resolution): |
| yt = YouTube(url) |
| if resolution == 'audio': |
| stream = yt.streams.filter(only_audio=True).first() |
| else: |
| stream = yt.streams.filter(res=resolution).first() |
| return stream.download() |
|
|
| st.title('All-in-One YouTube Downloader') |
|
|
| url = st.text_input('Enter the URL of the YouTube video') |
| resolution = st.selectbox('Select Resolution', ['360p', '720p', '1080p', 'audio']) |
|
|
| if st.button('Download'): |
| if url: |
| st.write('Starting download...') |
| info = get_video_info(url) |
| st.write(info) |
| download_video(url, resolution) |
| st.success('Download completed!') |
| else: |
| st.error('Please enter a valid URL.') |