File size: 1,214 Bytes
66bc5dd ece84d0 4645510 66bc5dd ece84d0 4645510 f6030b8 4645510 66bc5dd 4645510 3226e53 4645510 3226e53 4645510 ece84d0 4645510 3226e53 ece84d0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | 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) # Display video information
download_video(url, resolution)
st.success('Download completed!')
else:
st.error('Please enter a valid URL.') |