Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,9 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import yt_dlp
|
| 3 |
import os
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
# Set up the Streamlit app title and description
|
| 6 |
st.title("YouTube Video Downloader")
|
|
@@ -27,13 +30,29 @@ quality_pref = st.sidebar.selectbox(
|
|
| 27 |
['Highest', '720p', '480p', '360p', '240p']
|
| 28 |
)
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
# Button to download video
|
| 31 |
if st.sidebar.button('Download'):
|
| 32 |
if not video_url:
|
| 33 |
st.error("Please provide a YouTube video URL.")
|
| 34 |
else:
|
| 35 |
try:
|
| 36 |
-
# Check if the video is accessible
|
| 37 |
ydl_opts_check = {
|
| 38 |
'quiet': True,
|
| 39 |
'noplaylist': True
|
|
@@ -96,3 +115,9 @@ body {
|
|
| 96 |
# Footer with copyright and year
|
| 97 |
st.markdown("---")
|
| 98 |
st.markdown('<div style="text-align: center;">© 2024 VidFlex by Engr. Sumayyea Salahuddin. All rights reserved.</div>', unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import yt_dlp
|
| 3 |
import os
|
| 4 |
+
from google_auth_oauthlib.flow import InstalledAppFlow
|
| 5 |
+
from googleapiclient.discovery import build
|
| 6 |
+
import google.auth.transport.requests
|
| 7 |
|
| 8 |
# Set up the Streamlit app title and description
|
| 9 |
st.title("YouTube Video Downloader")
|
|
|
|
| 30 |
['Highest', '720p', '480p', '360p', '240p']
|
| 31 |
)
|
| 32 |
|
| 33 |
+
# Button to connect to YouTube account
|
| 34 |
+
def authenticate_youtube():
|
| 35 |
+
flow = InstalledAppFlow.from_client_secrets_file(
|
| 36 |
+
'client_secrets.json',
|
| 37 |
+
scopes=["https://www.googleapis.com/auth/youtube.force-ssl"]
|
| 38 |
+
)
|
| 39 |
+
credentials = flow.run_local_server(port=0)
|
| 40 |
+
return build('youtube', 'v3', credentials=credentials)
|
| 41 |
+
|
| 42 |
+
if st.sidebar.button('Connect to YouTube Account'):
|
| 43 |
+
try:
|
| 44 |
+
youtube = authenticate_youtube()
|
| 45 |
+
st.sidebar.success("Successfully connected to YouTube.")
|
| 46 |
+
except Exception as e:
|
| 47 |
+
st.sidebar.error(f"Failed to connect to YouTube: {str(e)}")
|
| 48 |
+
|
| 49 |
# Button to download video
|
| 50 |
if st.sidebar.button('Download'):
|
| 51 |
if not video_url:
|
| 52 |
st.error("Please provide a YouTube video URL.")
|
| 53 |
else:
|
| 54 |
try:
|
| 55 |
+
# Check if the video is accessible with authentication
|
| 56 |
ydl_opts_check = {
|
| 57 |
'quiet': True,
|
| 58 |
'noplaylist': True
|
|
|
|
| 115 |
# Footer with copyright and year
|
| 116 |
st.markdown("---")
|
| 117 |
st.markdown('<div style="text-align: center;">© 2024 VidFlex by Engr. Sumayyea Salahuddin. All rights reserved.</div>', unsafe_allow_html=True)
|
| 118 |
+
|
| 119 |
+
# requirements.txt content:
|
| 120 |
+
# streamlit
|
| 121 |
+
# yt-dlp
|
| 122 |
+
# google-auth-oauthlib
|
| 123 |
+
# google-api-python-client
|