2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-29 05:18:10 +00:00

Update media thumbs parsing for L93

This commit is contained in:
Dan 2019-01-21 18:45:52 +01:00
parent cb0b8ebeae
commit e99f86b69f
8 changed files with 30 additions and 27 deletions

View File

@ -97,7 +97,7 @@ class Animation(PyrogramType):
width=getattr(video_attributes, "w", 0), width=getattr(video_attributes, "w", 0),
height=getattr(video_attributes, "h", 0), height=getattr(video_attributes, "h", 0),
duration=getattr(video_attributes, "duration", 0), duration=getattr(video_attributes, "duration", 0),
thumb=PhotoSize._parse(client, animation.thumb), thumb=PhotoSize._parse(client, animation.thumbs),
mime_type=animation.mime_type, mime_type=animation.mime_type,
file_size=animation.size, file_size=animation.size,
file_name=file_name, file_name=file_name,

View File

@ -99,7 +99,7 @@ class Audio(PyrogramType):
title=audio_attributes.title, title=audio_attributes.title,
mime_type=audio.mime_type, mime_type=audio.mime_type,
file_size=audio.size, file_size=audio.size,
thumb=PhotoSize._parse(client, audio.thumb), thumb=PhotoSize._parse(client, audio.thumbs),
file_name=file_name, file_name=file_name,
date=audio.date, date=audio.date,
client=client client=client

View File

@ -78,7 +78,7 @@ class Document(PyrogramType):
document.access_hash document.access_hash
) )
), ),
thumb=PhotoSize._parse(client, document.thumb), thumb=PhotoSize._parse(client, document.thumbs),
file_name=file_name, file_name=file_name,
mime_type=document.mime_type, mime_type=document.mime_type,
file_size=document.size, file_size=document.size,

View File

@ -61,7 +61,6 @@ class Photo(PyrogramType):
for raw_size in raw_sizes: for raw_size in raw_sizes:
if isinstance(raw_size, (types.PhotoSize, types.PhotoCachedSize)): if isinstance(raw_size, (types.PhotoSize, types.PhotoCachedSize)):
if isinstance(raw_size, types.PhotoSize): if isinstance(raw_size, types.PhotoSize):
file_size = raw_size.size file_size = raw_size.size
elif isinstance(raw_size, types.PhotoCachedSize): elif isinstance(raw_size, types.PhotoCachedSize):

View File

@ -17,6 +17,7 @@
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from struct import pack from struct import pack
from typing import List, Union
import pyrogram import pyrogram
from pyrogram.api import types from pyrogram.api import types
@ -56,27 +57,30 @@ class PhotoSize(PyrogramType):
self.file_size = file_size self.file_size = file_size
@staticmethod @staticmethod
def _parse(client, photo_size: types.PhotoSize or types.PhotoCachedSize): def _parse(client, thumbs: List) -> Union["PhotoSize", None]:
if isinstance(photo_size, (types.PhotoSize, types.PhotoCachedSize)): if not thumbs:
return None
if isinstance(photo_size, types.PhotoSize): photo_size = thumbs[-1]
file_size = photo_size.size
elif isinstance(photo_size, types.PhotoCachedSize):
file_size = len(photo_size.bytes)
else:
file_size = 0
loc = photo_size.location if not isinstance(photo_size, (types.PhotoSize, types.PhotoCachedSize, types.PhotoStrippedSize)):
return None
if isinstance(loc, types.FileLocation): loc = photo_size.location
return PhotoSize(
file_id=encode( if not isinstance(loc, types.FileLocation):
pack( return None
"<iiqqqqi",
0, loc.dc_id, 0, 0, return PhotoSize(
loc.volume_id, loc.secret, loc.local_id)), file_id=encode(
width=photo_size.w, pack(
height=photo_size.h, "<iiqqqqi",
file_size=file_size, 0, loc.dc_id, 0, 0,
client=client loc.volume_id, loc.secret, loc.local_id
) )
),
width=getattr(photo_size, "w", 0),
height=getattr(photo_size, "h", 0),
file_size=getattr(photo_size, "size", len(photo_size.bytes)),
client=client
)

View File

@ -126,7 +126,7 @@ class Sticker(PyrogramType):
), ),
width=image_size_attributes.w if image_size_attributes else 0, width=image_size_attributes.w if image_size_attributes else 0,
height=image_size_attributes.h if image_size_attributes else 0, height=image_size_attributes.h if image_size_attributes else 0,
thumb=PhotoSize._parse(client, sticker.thumb), thumb=PhotoSize._parse(client, sticker.thumbs),
# TODO: mask_position # TODO: mask_position
set_name=set_name, set_name=set_name,
emoji=sticker_attributes.alt or None, emoji=sticker_attributes.alt or None,

View File

@ -97,7 +97,7 @@ class Video(PyrogramType):
width=video_attributes.w, width=video_attributes.w,
height=video_attributes.h, height=video_attributes.h,
duration=video_attributes.duration, duration=video_attributes.duration,
thumb=PhotoSize._parse(client, video.thumb), thumb=PhotoSize._parse(client, video.thumbs),
mime_type=video.mime_type, mime_type=video.mime_type,
file_size=video.size, file_size=video.size,
file_name=file_name, file_name=file_name,

View File

@ -85,7 +85,7 @@ class VideoNote(PyrogramType):
), ),
length=video_attributes.w, length=video_attributes.w,
duration=video_attributes.duration, duration=video_attributes.duration,
thumb=PhotoSize._parse(client, video_note.thumb), thumb=PhotoSize._parse(client, video_note.thumbs),
file_size=video_note.size, file_size=video_note.size,
mime_type=video_note.mime_type, mime_type=video_note.mime_type,
date=video_note.date, date=video_note.date,