import os import json import asyncio import streamlit as st import logging # Configure logging logging.basicConfig( level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s', handlers=[ logging.FileHandler('app.log'), logging.StreamHandler() ] ) # Load Google OAuth config from environment variables GOOGLE_OAUTH_CONFIG = { "web": { "client_id": os.environ.get("GOOGLE_CLIENT_ID"), "project_id": os.environ.get("GOOGLE_PROJECT_ID"), "auth_uri": os.environ.get("GOOGLE_AUTH_URI", "https://accounts.google.com/o/oauth2/auth"), "token_uri": os.environ.get("GOOGLE_TOKEN_URI", "https://oauth2.googleapis.com/token"), "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", "client_secret": os.environ.get("GOOGLE_CLIENT_SECRET"), "redirect_uris": [os.environ.get("GOOGLE_REDIRECT_URI")] } } # Setup the UI st.set_page_config(page_title="Advanced File Downloader", layout="wide", page_icon="📁") # Import the core components (still keeping modular organization) from utils import USER_AGENTS, STEALTH_SETTINGS, PROXY_ROTATION_CONFIG from utils import ( get_random_user_agent, sizeof_fmt, create_zip_file, humanize_file_size, get_domain, is_download_link, normalize_download_url, detect_captcha, show_user_friendly_error ) from google_drive import ( get_google_auth_url, exchange_code_for_credentials, google_drive_upload, create_drive_folder ) from download_manager import DownloadManager from rag_search import EnhancedRAGSearch # Initialize session state variables def initialize_session_state(): if 'files' not in st.session_state: st.session_state.files = [] if 'downloaded_paths' not in st.session_state: st.session_state.downloaded_paths = [] if 'download_complete' not in st.session_state: st.session_state.download_complete = False if 'selected_tab' not in st.session_state: st.session_state.selected_tab = 0 if 'rag_search' not in st.session_state: st.session_state.rag_search = EnhancedRAGSearch() if 'keep_progress' not in st.session_state: st.session_state.keep_progress = False if 'google_credentials' not in st.session_state: st.session_state.google_credentials = None if 'mode' not in st.session_state: st.session_state.mode = "Standard" if 'use_proxy' not in st.session_state: st.session_state.use_proxy = False if 'proxy_string' not in st.session_state: st.session_state.proxy_string = None if 'stealth_mode' not in st.session_state: st.session_state.stealth_mode = True # Import the UI code while keeping the modular structure from ui import setup_ui, create_sidebar, display_file_results, handle_downloads, handle_google_drive_upload from main import main as app_main # Set up and run the application def main(): initialize_session_state() app_main() if __name__ == "__main__": main()