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:
commit
a050889fc8
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