Merge pull request #86 from jonasasx/fix/download-media-extension-detection

fix: strip extension in download_media to auto-detect real file type
This commit is contained in:
Eugene Evstafev 2026-04-01 12:12:10 +01:00 committed by GitHub
commit a050889fc8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2157,7 +2157,12 @@ async def download_media(
if path_error:
return path_error
downloaded = await client.download_media(msg, file=str(out_path))
# Strip user-supplied extension so Telethon auto-detects the real media type.
# If a path with extension is passed (e.g. ticket.jpg), Telethon writes to that
# exact path even if the file is actually a PDF. Stripping the suffix lets
# Telethon append the correct extension based on the actual file content.
out_path_for_dl = out_path.with_suffix("")
downloaded = await client.download_media(msg, file=str(out_path_for_dl))
if not downloaded:
return f"Download failed for message {message_id}."