File size: 2,995 Bytes
c5e23a5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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()