Rebase onto upstream (a4d95fd) #12

Closed
wylab wants to merge 144 commits from rebase-onto-upstream into main
Showing only changes of commit 8c25385c39 - Show all commits
+13 -7
View File
@@ -246,7 +246,7 @@ class TelegramChannel(BaseChannel):
)
# Process each media item
processed_media: list[tuple[str, MediaKind, bytes]] = []
processed_media: list[tuple[str, MediaKind, bytes, str]] = []
for path in media_paths:
try:
@@ -254,6 +254,8 @@ class TelegramChannel(BaseChannel):
if path.startswith(("http://", "https://")):
content, mime = await fetch_media(path, max_bytes=100_000_000)
kind = classify_media(mime)
# Extract filename from URL
filename = Path(path).name
else:
# Local file
file_path = Path(path)
@@ -266,6 +268,8 @@ class TelegramChannel(BaseChannel):
mime = detect_mime(path, content)
kind = classify_media(mime)
# Extract filename from local path
filename = file_path.name
# Optimize images
if kind == MediaKind.IMAGE:
@@ -274,7 +278,7 @@ class TelegramChannel(BaseChannel):
except Exception as e:
logger.warning(f"Image optimization failed: {e}, sending original")
processed_media.append((path, kind, content))
processed_media.append((path, kind, content, filename))
except Exception as e:
logger.error(f"Failed to process media {path}: {e}")
@@ -290,7 +294,7 @@ class TelegramChannel(BaseChannel):
return
# Group media for album sending
media_items = [(path, kind) for path, kind, _ in processed_media]
media_items = [(path, kind) for path, kind, _, _ in processed_media]
grouping = group_media_for_album(media_items)
# Handle caption length (Telegram limit: 1024 chars)
@@ -307,7 +311,7 @@ class TelegramChannel(BaseChannel):
album_paths = grouping["album"]
album_media = []
for path, kind, content in processed_media:
for path, kind, content, filename in processed_media:
if path not in album_paths:
continue
@@ -335,7 +339,7 @@ class TelegramChannel(BaseChannel):
)
# Send separate media
for i, (path, kind, content) in enumerate(processed_media):
for i, (path, kind, content, filename) in enumerate(processed_media):
if path in grouping["album"]:
continue # Already sent in album
@@ -361,14 +365,16 @@ class TelegramChannel(BaseChannel):
chat_id=chat_id,
audio=content,
caption=item_caption,
parse_mode="HTML" if item_caption else None
parse_mode="HTML" if item_caption else None,
filename=filename
)
elif kind == MediaKind.DOCUMENT:
await self._app.bot.send_document(
chat_id=chat_id,
document=content,
caption=item_caption,
parse_mode="HTML" if item_caption else None
parse_mode="HTML" if item_caption else None,
filename=filename
)
# Send follow-up text if caption was too long