From e242f2a55584634f9a45c0d1ff8397d2183167a4 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 27 Dec 2017 20:59:37 +0100 Subject: [PATCH] Add support for downloading files in different DCs --- pyrogram/client/client.py | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index e872c846..750aed7f 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -817,6 +817,7 @@ class Client: return r def get_file(self, + dc_id: int, id: int = None, access_hash: int = None, volume_id: int = None, @@ -827,6 +828,38 @@ class Client: # TODO: Use proper file name and extension # TODO: Remove redundant code + if dc_id != self.dc_id: + exported_auth = self.send( + functions.auth.ExportAuthorization( + dc_id=dc_id + ) + ) + + session = Session( + dc_id, + self.test_mode, + Auth(dc_id, self.test_mode).create(), + self.config.api_id + ) + + session.start() + + session.send( + functions.auth.ImportAuthorization( + id=exported_auth.id, + bytes=exported_auth.bytes + ) + ) + else: + session = Session( + dc_id, + self.test_mode, + self.auth_key, + self.config.api_id + ) + + session.start() + if volume_id: # Photos are accessed by volume_id, local_id, secret location = types.InputFileLocation( volume_id=volume_id, @@ -843,9 +876,6 @@ class Client: limit = 512 * 1024 offset = 0 - session = Session(self.dc_id, self.test_mode, self.auth_key, self.config.api_id) - session.start() - try: r = session.send( functions.upload.GetFile(