Spaces:
Running
Running
Upload addon.py
Browse files
addon.py
CHANGED
|
@@ -27,6 +27,19 @@ def get_addon_url(request: Request = None) -> str:
|
|
| 27 |
return str(request.base_url).rstrip("/")
|
| 28 |
return f"http://localhost:{getattr(Config, 'PORT', 7860)}"
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
from config import Config
|
| 31 |
from tg_client import tg_client_manager
|
| 32 |
from utils import (
|
|
@@ -897,6 +910,8 @@ async def meta_handler(type: str, meta_id: str, request: Request, api_key: str =
|
|
| 897 |
|
| 898 |
first_msg = messages[0]
|
| 899 |
media = first_msg.video or first_msg.document or first_msg.audio
|
|
|
|
|
|
|
| 900 |
first_fn = getattr(media, "file_name", "video.mp4") or "video.mp4"
|
| 901 |
|
| 902 |
if is_zip_entry and zip_entry_filename:
|
|
@@ -1528,12 +1543,8 @@ async def tg_subtitle_proxy(
|
|
| 1528 |
elif filename_lower.endswith(".ass"):
|
| 1529 |
content_type = "text/plain"
|
| 1530 |
|
| 1531 |
-
safe_filename = filename.replace("\r", " ").replace("\n", " ").replace('"', '').replace("'", '').strip()
|
| 1532 |
-
if len(safe_filename) > 100:
|
| 1533 |
-
safe_filename = safe_filename[:97] + "..."
|
| 1534 |
-
|
| 1535 |
headers = {
|
| 1536 |
-
"Content-Disposition":
|
| 1537 |
"Access-Control-Allow-Origin": "*",
|
| 1538 |
"Content-Length": str(media.file_size),
|
| 1539 |
}
|
|
@@ -1617,14 +1628,10 @@ async def tg_stream_proxy(
|
|
| 1617 |
|
| 1618 |
status_code = 206 if range_header else 200
|
| 1619 |
|
| 1620 |
-
safe_filename = filename.replace("\r", " ").replace("\n", " ").replace('"', '').replace("'", '').strip()
|
| 1621 |
-
if len(safe_filename) > 100:
|
| 1622 |
-
safe_filename = safe_filename[:97] + "..."
|
| 1623 |
-
|
| 1624 |
headers = {
|
| 1625 |
"Accept-Ranges": "bytes",
|
| 1626 |
"Content-Length": str(content_length),
|
| 1627 |
-
"Content-Disposition":
|
| 1628 |
"Connection": "keep-alive",
|
| 1629 |
"Cache-Control": "no-cache",
|
| 1630 |
"X-Accel-Buffering": "no",
|
|
@@ -1779,14 +1786,10 @@ async def tg_split_stream_proxy(
|
|
| 1779 |
|
| 1780 |
status_code = 206 if range_header else 200
|
| 1781 |
|
| 1782 |
-
safe_filename = filename.replace("\r", " ").replace("\n", " ").replace('"', '').replace("'", '').strip()
|
| 1783 |
-
if len(safe_filename) > 100:
|
| 1784 |
-
safe_filename = safe_filename[:97] + "..."
|
| 1785 |
-
|
| 1786 |
headers = {
|
| 1787 |
"Accept-Ranges": "bytes",
|
| 1788 |
"Content-Length": str(content_length),
|
| 1789 |
-
"Content-Disposition":
|
| 1790 |
"Connection": "keep-alive",
|
| 1791 |
"Cache-Control": "no-cache",
|
| 1792 |
"X-Accel-Buffering": "no",
|
|
@@ -1934,14 +1937,10 @@ async def tg_zip_stream_proxy(
|
|
| 1934 |
|
| 1935 |
status_code = 206 if range_header else 200
|
| 1936 |
|
| 1937 |
-
safe_filename = filename.replace("\r", " ").replace("\n", " ").replace('"', '').replace("'", '').strip()
|
| 1938 |
-
if len(safe_filename) > 100:
|
| 1939 |
-
safe_filename = safe_filename[:97] + "..."
|
| 1940 |
-
|
| 1941 |
headers = {
|
| 1942 |
"Accept-Ranges": "bytes",
|
| 1943 |
"Content-Length": str(content_length),
|
| 1944 |
-
"Content-Disposition":
|
| 1945 |
"Connection": "keep-alive",
|
| 1946 |
"Cache-Control": "no-cache",
|
| 1947 |
"X-Accel-Buffering": "no",
|
|
|
|
| 27 |
return str(request.base_url).rstrip("/")
|
| 28 |
return f"http://localhost:{getattr(Config, 'PORT', 7860)}"
|
| 29 |
|
| 30 |
+
import os
|
| 31 |
+
|
| 32 |
+
def format_content_disposition(filename: str, disposition: str = "inline") -> str:
|
| 33 |
+
safe = filename.replace("\r", " ").replace("\n", " ").replace('"', '').replace("'", '').strip()
|
| 34 |
+
if len(safe) > 100:
|
| 35 |
+
safe = safe[:97] + "..."
|
| 36 |
+
ascii_name = safe.encode("ascii", "ignore").decode("ascii").strip()
|
| 37 |
+
ext = os.path.splitext(safe)[1]
|
| 38 |
+
if not ascii_name or ascii_name == ext:
|
| 39 |
+
ascii_name = f"media{ext if ext else '.mp4'}"
|
| 40 |
+
utf8_name = urllib.parse.quote(safe)
|
| 41 |
+
return f'{disposition}; filename="{ascii_name}"; filename*=UTF-8\'\'{utf8_name}'
|
| 42 |
+
|
| 43 |
from config import Config
|
| 44 |
from tg_client import tg_client_manager
|
| 45 |
from utils import (
|
|
|
|
| 910 |
|
| 911 |
first_msg = messages[0]
|
| 912 |
media = first_msg.video or first_msg.document or first_msg.audio
|
| 913 |
+
if not media:
|
| 914 |
+
return {"meta": {}}
|
| 915 |
first_fn = getattr(media, "file_name", "video.mp4") or "video.mp4"
|
| 916 |
|
| 917 |
if is_zip_entry and zip_entry_filename:
|
|
|
|
| 1543 |
elif filename_lower.endswith(".ass"):
|
| 1544 |
content_type = "text/plain"
|
| 1545 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1546 |
headers = {
|
| 1547 |
+
"Content-Disposition": format_content_disposition(filename),
|
| 1548 |
"Access-Control-Allow-Origin": "*",
|
| 1549 |
"Content-Length": str(media.file_size),
|
| 1550 |
}
|
|
|
|
| 1628 |
|
| 1629 |
status_code = 206 if range_header else 200
|
| 1630 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1631 |
headers = {
|
| 1632 |
"Accept-Ranges": "bytes",
|
| 1633 |
"Content-Length": str(content_length),
|
| 1634 |
+
"Content-Disposition": format_content_disposition(filename),
|
| 1635 |
"Connection": "keep-alive",
|
| 1636 |
"Cache-Control": "no-cache",
|
| 1637 |
"X-Accel-Buffering": "no",
|
|
|
|
| 1786 |
|
| 1787 |
status_code = 206 if range_header else 200
|
| 1788 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1789 |
headers = {
|
| 1790 |
"Accept-Ranges": "bytes",
|
| 1791 |
"Content-Length": str(content_length),
|
| 1792 |
+
"Content-Disposition": format_content_disposition(filename),
|
| 1793 |
"Connection": "keep-alive",
|
| 1794 |
"Cache-Control": "no-cache",
|
| 1795 |
"X-Accel-Buffering": "no",
|
|
|
|
| 1937 |
|
| 1938 |
status_code = 206 if range_header else 200
|
| 1939 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1940 |
headers = {
|
| 1941 |
"Accept-Ranges": "bytes",
|
| 1942 |
"Content-Length": str(content_length),
|
| 1943 |
+
"Content-Disposition": format_content_disposition(filename),
|
| 1944 |
"Connection": "keep-alive",
|
| 1945 |
"Cache-Control": "no-cache",
|
| 1946 |
"X-Accel-Buffering": "no",
|