Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import json
|
| 3 |
+
import asyncio
|
| 4 |
+
import streamlit as st
|
| 5 |
+
import logging
|
| 6 |
+
|
| 7 |
+
# Configure logging
|
| 8 |
+
logging.basicConfig(
|
| 9 |
+
level=logging.INFO,
|
| 10 |
+
format='%(asctime)s - %(levelname)s - %(message)s',
|
| 11 |
+
handlers=[
|
| 12 |
+
logging.FileHandler('app.log'),
|
| 13 |
+
logging.StreamHandler()
|
| 14 |
+
]
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
# Load Google OAuth config from environment variables
|
| 18 |
+
GOOGLE_OAUTH_CONFIG = {
|
| 19 |
+
"web": {
|
| 20 |
+
"client_id": os.environ.get("GOOGLE_CLIENT_ID"),
|
| 21 |
+
"project_id": os.environ.get("GOOGLE_PROJECT_ID"),
|
| 22 |
+
"auth_uri": os.environ.get("GOOGLE_AUTH_URI", "https://accounts.google.com/o/oauth2/auth"),
|
| 23 |
+
"token_uri": os.environ.get("GOOGLE_TOKEN_URI", "https://oauth2.googleapis.com/token"),
|
| 24 |
+
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
| 25 |
+
"client_secret": os.environ.get("GOOGLE_CLIENT_SECRET"),
|
| 26 |
+
"redirect_uris": [os.environ.get("GOOGLE_REDIRECT_URI")]
|
| 27 |
+
}
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
# Setup the UI
|
| 31 |
+
st.set_page_config(page_title="Advanced File Downloader", layout="wide", page_icon="📁")
|
| 32 |
+
|
| 33 |
+
# Import the core components (still keeping modular organization)
|
| 34 |
+
from utils import USER_AGENTS, STEALTH_SETTINGS, PROXY_ROTATION_CONFIG
|
| 35 |
+
from utils import (
|
| 36 |
+
get_random_user_agent, sizeof_fmt, create_zip_file, humanize_file_size, get_domain,
|
| 37 |
+
is_download_link, normalize_download_url, detect_captcha, show_user_friendly_error
|
| 38 |
+
)
|
| 39 |
+
from google_drive import (
|
| 40 |
+
get_google_auth_url, exchange_code_for_credentials, google_drive_upload, create_drive_folder
|
| 41 |
+
)
|
| 42 |
+
from download_manager import DownloadManager
|
| 43 |
+
from rag_search import EnhancedRAGSearch
|
| 44 |
+
|
| 45 |
+
# Initialize session state variables
|
| 46 |
+
def initialize_session_state():
|
| 47 |
+
if 'files' not in st.session_state:
|
| 48 |
+
st.session_state.files = []
|
| 49 |
+
if 'downloaded_paths' not in st.session_state:
|
| 50 |
+
st.session_state.downloaded_paths = []
|
| 51 |
+
if 'download_complete' not in st.session_state:
|
| 52 |
+
st.session_state.download_complete = False
|
| 53 |
+
if 'selected_tab' not in st.session_state:
|
| 54 |
+
st.session_state.selected_tab = 0
|
| 55 |
+
if 'rag_search' not in st.session_state:
|
| 56 |
+
st.session_state.rag_search = EnhancedRAGSearch()
|
| 57 |
+
if 'keep_progress' not in st.session_state:
|
| 58 |
+
st.session_state.keep_progress = False
|
| 59 |
+
if 'google_credentials' not in st.session_state:
|
| 60 |
+
st.session_state.google_credentials = None
|
| 61 |
+
if 'mode' not in st.session_state:
|
| 62 |
+
st.session_state.mode = "Standard"
|
| 63 |
+
if 'use_proxy' not in st.session_state:
|
| 64 |
+
st.session_state.use_proxy = False
|
| 65 |
+
if 'proxy_string' not in st.session_state:
|
| 66 |
+
st.session_state.proxy_string = None
|
| 67 |
+
if 'stealth_mode' not in st.session_state:
|
| 68 |
+
st.session_state.stealth_mode = True
|
| 69 |
+
|
| 70 |
+
# Import the UI code while keeping the modular structure
|
| 71 |
+
from ui import setup_ui, create_sidebar, display_file_results, handle_downloads, handle_google_drive_upload
|
| 72 |
+
from main import main as app_main
|
| 73 |
+
|
| 74 |
+
# Set up and run the application
|
| 75 |
+
def main():
|
| 76 |
+
initialize_session_state()
|
| 77 |
+
app_main()
|
| 78 |
+
|
| 79 |
+
if __name__ == "__main__":
|
| 80 |
+
main()
|