Download app.py from FASHHaha/Yt2: direct link, hf CLI and curl.
- Browser
- Download file 1.21 kB
-
https://huggingface.co/spaces/FASHHaha/Yt2/resolve/main/app.py
- Command line
-
hf download hf://spaces/FASHHaha/Yt2/app.py
-
curl -L -o app.py https://huggingface.co/spaces/FASHHaha/Yt2/resolve/main/app.py
1.21 kB
| 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.') |