Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not download media #4327

Open
3 tasks done
binoTiger opened this issue Mar 14, 2024 · 4 comments
Open
3 tasks done

Can not download media #4327

binoTiger opened this issue Mar 14, 2024 · 4 comments

Comments

@binoTiger
Copy link

Code that causes the issue

async with TelegramClient(my telegram data of Russian account with proxy) as client:
    channel = await client.get_entity(PeerChannel(1103688715))

    messages = await client.get_messages(
        entity=channel,
        offset_id=0,
        offset_date=None,
        add_offset=0,
        limit=100,
    )

    for message in messages:
        if getattr(message, 'video'):
            if message.file.name:
                filename = message.file.name
            else:
            filename = message.id
        
            await message.download_media(file=f'./media/{filename}')

Expected behavior

client gets a bunch of messages, and downloads the videos, if there are any.

Actual behavior

client receives a stack of messages, but when I try to download them, I get an error

Traceback

File [~/Documents/programming/.venv/lib/python3.11/site-packages/telethon/client/downloads.py:66](https://file+.vscode-resource.vscode-cdn.net/Users/user/Documents/programming/wspace/~/Documents/programming/.venv/lib/python3.11/site-packages/telethon/client/downloads.py:66), in _DirectDownloadIter._load_next_chunk(self)
     [65](https://file+.vscode-resource.vscode-cdn.net/Users/user/Documents/programming/wspace/~/Documents/programming/.venv/lib/python3.11/site-packages/telethon/client/downloads.py:65) async def _load_next_chunk(self):
---> [66](https://file+.vscode-resource.vscode-cdn.net/Users/user/Documents/programming/wspace/~/Documents/programming/.venv/lib/python3.11/site-packages/telethon/client/downloads.py:66)     cur = await self._request()
     [67](https://file+.vscode-resource.vscode-cdn.net/Users/user/Documents/programming/wspace/~/Documents/programming/.venv/lib/python3.11/site-packages/telethon/client/downloads.py:67)     self.buffer.append(cur)
     [68](https://file+.vscode-resource.vscode-cdn.net/Users/user/Documents/programming/wspace/~/Documents/programming/.venv/lib/python3.11/site-packages/telethon/client/downloads.py:68)     if len(cur) < self.request.limit:

File [~/Documents/programming/.venv/lib/python3.11/site-packages/telethon/client/downloads.py:79](https://file+.vscode-resource.vscode-cdn.net/Users/user/Documents/programming/wspace/~/Documents/programming/.venv/lib/python3.11/site-packages/telethon/client/downloads.py:79), in _DirectDownloadIter._request(self)
     [77](https://file+.vscode-resource.vscode-cdn.net/Users/user/Documents/programming/wspace/~/Documents/programming/.venv/lib/python3.11/site-packages/telethon/client/downloads.py:77) self._timed_out = False
     [78](https://file+.vscode-resource.vscode-cdn.net/Users/user/Documents/programming/wspace/~/Documents/programming/.venv/lib/python3.11/site-packages/telethon/client/downloads.py:78) if isinstance(result, types.upload.FileCdnRedirect):
---> [79](https://file+.vscode-resource.vscode-cdn.net/Users/user/Documents/programming/wspace/~/Documents/programming/.venv/lib/python3.11/site-packages/telethon/client/downloads.py:79)     raise NotImplementedError  # TODO Implement
     [80](https://file+.vscode-resource.vscode-cdn.net/Users/user/Documents/programming/wspace/~/Documents/programming/.venv/lib/python3.11/site-packages/telethon/client/downloads.py:80) else:
     [81](https://file+.vscode-resource.vscode-cdn.net/Users/user/Documents/programming/wspace/~/Documents/programming/.venv/lib/python3.11/site-packages/telethon/client/downloads.py:81)     return result.bytes

NotImplementedError:

Telethon version

1.34.0

Python version

3.11.6

Operating system (including distribution name and version)

macOS 14.1

Other details

No response

Checklist

  • The error is in the library's code, and not in my own.
  • I have searched for this issue before posting it and there isn't an open duplicate.
  • I ran pip install -U https://github.com/LonamiWebs/Telethon/archive/v1.zip and triggered the bug in the latest version.
@Lonami
Copy link
Member

Lonami commented Mar 14, 2024

I don't have plan to implement support for downloads CDNs, however, that shouldn't happen because the default is to not allow CDN redirects:

self.request = functions.upload.GetFileRequest(
file, offset=offset, limit=request_size)

https://tl.telethon.dev/methods/upload/get_file.html (where cdn_supported is a flag and the default is False).

@binoTiger
Copy link
Author

okay, well, then what should I do in this situation?

@Lonami
Copy link
Member

Lonami commented Mar 15, 2024

Someone needs to implement the feature. Whether that's you or someone else is up to you. As I said I'm not interested in doing so and don't really have the time to dig into it. However, there may be some old code in the Git commit history for this repository containing some clues on how CDN downloads work.

@TechyCSR
Copy link

@binoTiger that may be because of Your proxy .
because for me CDN don worked well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants