forked from dmotts/yt-to-cloud-uploader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
53 lines (41 loc) · 1.96 KB
/
main.py
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import streamlit as st
from core.gcloud import GoogleAuth, GoogleDriveService
from core.youtube import YouTubeDownloader, YouTubeDriveUploader
from core import base
CLIENT_SECRETS_FILE = 'client_secrets.json' # Path to your OAuth2 client secrets file
def main():
auth: base.Auth = None
st.title("YouTube to Google Drive Uploader")
google_logo_url = "https://upload.wikimedia.org/wikipedia/commons/thumb/5/53/Google_%22G%22_Logo.svg/512px-Google_%22G%22_Logo.svg.png"
if st.button("Sign in with Google", key='google-signin'):
st.markdown(
f'<a href="#" class="btn btn-primary"><img src="{google_logo_url}" width="20" height="20" alt="Google Sign In" /> Sign in with Google</a>',
unsafe_allow_html=True
)
auth = GoogleAuth(CLIENT_SECRETS_FILE)
auth.sign_in()
st.success("Successfully signed in!")
if not auth:
st.warning("Please sign in to continue.")
return
creds = auth.get_credentials()
if creds:
drive_service = GoogleDriveService(creds)
youtube_downloader = YouTubeDownloader()
uploader = YouTubeDriveUploader(drive_service)
video_url = st.text_input("Enter YouTube Video or Playlist URL:")
if st.button("Download and Upload"):
if "playlist" in video_url:
st.write("Processing playlist...")
with st.spinner('Downloading playlist...'):
video_paths = youtube_downloader.download_playlist(video_url)
uploader.upload_playlist(video_paths, "Downloaded Playlist")
st.success("Playlist uploaded successfully!")
else:
st.write("Processing video...")
with st.spinner('Downloading video...'):
video_path = youtube_downloader.download_video(video_url)
uploader.upload_video(video_path)
st.success("Video uploaded successfully!")
if __name__ == "__main__":
main()