This commit refactors the entire backend application into a more structured and maintainable Flask project. It introduces an application factory pattern, consolidates routes into a blueprint, and implements a robust authentication and database layer. - Introduces a Flask application factory (`create_app` in `main.py`) for better organization and testability. - Consolidates all API routes into a single blueprint (`routes/api.py`) for modularity. - Implements a new basic authentication system using a decorator (`@requires_basic_auth`) to secure all endpoints. - Refactors the database access layer with standardized query execution and connection handling. - Adds new modules for core logic, including an account checker (`checker.py`) and user retrieval (`get_users.py`). - Updates the VSCode launch configuration to support the new Flask application structure. BREAKING CHANGE: The application has been completely restructured. The old `server.py` entry point is removed. The application should now be run via the app factory in `main.py`. All API endpoints now require basic authentication.
31 lines
1.1 KiB
Python
31 lines
1.1 KiB
Python
import requests
|
|
from requests_tor import RequestsTor
|
|
|
|
def build_url(stream_url, username, password):
|
|
return f"{stream_url}/player_api.php?username={username}&password={password}"
|
|
|
|
def check_url(url):
|
|
try:
|
|
tr = RequestsTor()
|
|
response = tr.get(url, timeout=5)
|
|
response.raise_for_status()
|
|
if response.json().get("user_info", {}).get("auth"):
|
|
return response.json()
|
|
except requests.exceptions.RequestException as e:
|
|
if e.response and e.response.status_code == 403:
|
|
try:
|
|
response = requests.get(url, timeout=5)
|
|
response.raise_for_status()
|
|
if response.json().get("user_info", {}).get("auth"):
|
|
return response.json()
|
|
except requests.exceptions.RequestException:
|
|
return None
|
|
return None
|
|
|
|
def single_account_check(account_data, stream_urls):
|
|
for stream_url in stream_urls:
|
|
url = build_url(stream_url, account_data['username'], account_data['password'])
|
|
result = check_url(url)
|
|
if result:
|
|
return {"url": stream_url, "data": result}
|
|
return None |