Fix group, channel and supergroup ChatPhoto downloads (#327)

Closes #326
This commit is contained in:
Dan 2019-10-19 16:40:13 +02:00 committed by GitHub
parent cedb87ef41
commit 945bc61262
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 8 deletions

View File

@ -1221,6 +1221,7 @@ class Client(Methods, BaseClient):
access_hash=data.access_hash,
thumb_size=data.thumb_size,
peer_id=data.peer_id,
peer_type=data.peer_type,
peer_access_hash=data.peer_access_hash,
volume_id=data.volume_id,
local_id=data.local_id,
@ -1866,6 +1867,7 @@ class Client(Methods, BaseClient):
access_hash: int,
thumb_size: str,
peer_id: int,
peer_type: str,
peer_access_hash: int,
volume_id: int,
local_id: int,
@ -1913,11 +1915,23 @@ class Client(Methods, BaseClient):
file_ref = utils.decode_file_ref(file_ref)
if media_type == 1:
location = types.InputPeerPhotoFileLocation(
peer=types.InputPeerUser(
if peer_type == "user":
peer = types.InputPeerUser(
user_id=peer_id,
access_hash=peer_access_hash
),
)
elif peer_type == "chat":
peer = types.InputPeerChat(
chat_id=peer_id
)
else:
peer = types.InputPeerChannel(
channel_id=peer_id,
access_hash=peer_access_hash
)
location = types.InputPeerPhotoFileLocation(
peer=peer,
volume_id=volume_id,
local_id=local_id,
big=is_big or None

View File

@ -20,9 +20,9 @@
class FileData:
def __init__(
self, *, media_type: int = None, dc_id: int = None, document_id: int = None, access_hash: int = None,
thumb_size: str = None, peer_id: int = None, peer_access_hash: int = None, volume_id: int = None,
local_id: int = None, is_big: bool = None, file_size: int = None, mime_type: str = None, file_name: str = None,
date: int = None, file_ref: str = None
thumb_size: str = None, peer_id: int = None, peer_type: str = None, peer_access_hash: int = None,
volume_id: int = None, local_id: int = None, is_big: bool = None, file_size: int = None, mime_type: str = None,
file_name: str = None, date: int = None, file_ref: str = None
):
self.media_type = media_type
self.dc_id = dc_id
@ -30,6 +30,7 @@ class FileData:
self.access_hash = access_hash
self.thumb_size = thumb_size
self.peer_id = peer_id
self.peer_type = peer_type
self.peer_access_hash = peer_access_hash
self.volume_id = volume_id
self.local_id = local_id

View File

@ -146,13 +146,23 @@ class DownloadMedia(BaseClient):
if media_type == 1:
unpacked = struct.unpack("<iiqqqiiiqi", decoded)
dc_id, photo_id, _, volume_id, size_type, peer_id, _, peer_access_hash, local_id = unpacked[1:]
dc_id, photo_id, _, volume_id, size_type, peer_id, x, peer_access_hash, local_id = unpacked[1:]
if x == 0:
peer_type = "user"
elif x == -1:
peer_id = -peer_id
peer_type = "chat"
else:
peer_id = utils.get_channel_id(peer_id - 1000727379968)
peer_type = "channel"
data = FileData(
**get_existing_attributes(),
media_type=media_type,
dc_id=dc_id,
peer_id=peer_id,
peer_type=peer_type,
peer_access_hash=peer_access_hash,
volume_id=volume_id,
local_id=local_id,

View File

@ -55,7 +55,7 @@ class ChatPhoto(Object):
if not isinstance(chat_photo, (types.UserProfilePhoto, types.ChatPhoto)):
return None
if not peer_access_hash:
if peer_access_hash is None:
return None
photo_id = getattr(chat_photo, "photo_id", 0)