Files
Mak5er 635e50b407 feat(settings): add media quality & file options, ZIP multi-photo archives, and categorized /settings UI
- Add video_quality, as_document, audio_format, and file_button to user settings schema and Alembic migrations.
- Categorize /settings into Media & Quality, Appearance & Buttons, and Chat & Clean-up with dynamic back navigation.
- Implement strict document delivery with disable_content_type_detection=True to prevent Telegram video player fallback when as_document is ON.
- Add multi-photo ZIP archive packaging for photo carousels in as_document mode.
- Differentiate DB media file cache entries between video and document types (url#document vs url#video) to eliminate cache collisions.
- Hide redundant Download File inline button when as_document setting is active.
- Remove obsolete referral system (/ref command and links).
2026-07-22 13:18:09 +03:00

65 lines
2.4 KiB
Python

import random
from typing import Mapping
_USER_AGENTS = (
# Chrome Desktop (Windows)
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36",
# Chrome Desktop (Mac)
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36",
# Safari Desktop (Mac)
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.4 Safari/605.1.15",
# Chrome Android
"Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Mobile Safari/537.36",
# Safari iOS
"Mozilla/5.0 (iPhone; CPU iPhone OS 17_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Mobile/15E148 Safari/605.1.15",
)
_CLIENT_HINTS = (
{
"sec-ch-ua": '"Not/A)Brand";v="8", "Chromium";v="126", "Google Chrome";v="126"',
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": '"Windows"',
},
{
"sec-ch-ua": '"Not/A)Brand";v="8", "Chromium";v="126", "Google Chrome";v="126"',
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": '"macOS"',
},
{
"sec-ch-ua": '"Not/A)Brand";v="8", "Chromium";v="126", "Google Chrome";v="126"',
"sec-ch-ua-mobile": "?1",
"sec-ch-ua-platform": '"Android"',
},
)
def get_random_user_agent() -> str:
"""Return a random modern browser User-Agent string."""
return random.choice(_USER_AGENTS)
def get_browser_headers() -> dict[str, str]:
"""Return a full set of realistic browser request headers."""
ua = get_random_user_agent()
hints = random.choice(_CLIENT_HINTS)
headers = {
"User-Agent": ua,
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webkit,video/mp4,video/*;q=0.8,*/*;q=0.5",
"Accept-Language": "en-US,en;q=0.9,uk;q=0.8",
"Accept-Encoding": "gzip, deflate, br",
"Sec-Fetch-Dest": "document",
"Sec-Fetch-Mode": "navigate",
"Sec-Fetch-Site": "same-origin",
"Sec-Fetch-User": "?1",
}
headers.update(hints)
return headers
def merge_browser_headers(custom_headers: Mapping[str, str] | None = None) -> dict[str, str]:
"""Merge custom headers with default browser headers, preserving custom overrides."""
base = get_browser_headers()
if custom_headers:
base.update(dict(custom_headers))
return base