fix: strip extension in download_media to auto-detect real file type
When a caller passes a file_path with an explicit extension (e.g. ticket.jpg), Telethon honours that extension verbatim even if the actual media is a PDF. Stripping the suffix before calling client.download_media() lets Telethon append the correct extension based on the real file content. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
0b1e2b48fd
commit
130631f4ae
1 changed files with 6 additions and 1 deletions
7
main.py
7
main.py
|
|
@ -2157,7 +2157,12 @@ async def download_media(
|
||||||
if path_error:
|
if path_error:
|
||||||
return 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:
|
if not downloaded:
|
||||||
return f"Download failed for message {message_id}."
|
return f"Download failed for message {message_id}."
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue