mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-16 12:51:18 +00:00
Update media thumbs parsing for L93
This commit is contained in:
parent
cb0b8ebeae
commit
e99f86b69f
@ -97,7 +97,7 @@ class Animation(PyrogramType):
|
||||
width=getattr(video_attributes, "w", 0),
|
||||
height=getattr(video_attributes, "h", 0),
|
||||
duration=getattr(video_attributes, "duration", 0),
|
||||
thumb=PhotoSize._parse(client, animation.thumb),
|
||||
thumb=PhotoSize._parse(client, animation.thumbs),
|
||||
mime_type=animation.mime_type,
|
||||
file_size=animation.size,
|
||||
file_name=file_name,
|
||||
|
@ -99,7 +99,7 @@ class Audio(PyrogramType):
|
||||
title=audio_attributes.title,
|
||||
mime_type=audio.mime_type,
|
||||
file_size=audio.size,
|
||||
thumb=PhotoSize._parse(client, audio.thumb),
|
||||
thumb=PhotoSize._parse(client, audio.thumbs),
|
||||
file_name=file_name,
|
||||
date=audio.date,
|
||||
client=client
|
||||
|
@ -78,7 +78,7 @@ class Document(PyrogramType):
|
||||
document.access_hash
|
||||
)
|
||||
),
|
||||
thumb=PhotoSize._parse(client, document.thumb),
|
||||
thumb=PhotoSize._parse(client, document.thumbs),
|
||||
file_name=file_name,
|
||||
mime_type=document.mime_type,
|
||||
file_size=document.size,
|
||||
|
@ -61,7 +61,6 @@ class Photo(PyrogramType):
|
||||
|
||||
for raw_size in raw_sizes:
|
||||
if isinstance(raw_size, (types.PhotoSize, types.PhotoCachedSize)):
|
||||
|
||||
if isinstance(raw_size, types.PhotoSize):
|
||||
file_size = raw_size.size
|
||||
elif isinstance(raw_size, types.PhotoCachedSize):
|
||||
|
@ -17,6 +17,7 @@
|
||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from struct import pack
|
||||
from typing import List, Union
|
||||
|
||||
import pyrogram
|
||||
from pyrogram.api import types
|
||||
@ -56,27 +57,30 @@ class PhotoSize(PyrogramType):
|
||||
self.file_size = file_size
|
||||
|
||||
@staticmethod
|
||||
def _parse(client, photo_size: types.PhotoSize or types.PhotoCachedSize):
|
||||
if isinstance(photo_size, (types.PhotoSize, types.PhotoCachedSize)):
|
||||
def _parse(client, thumbs: List) -> Union["PhotoSize", None]:
|
||||
if not thumbs:
|
||||
return None
|
||||
|
||||
if isinstance(photo_size, types.PhotoSize):
|
||||
file_size = photo_size.size
|
||||
elif isinstance(photo_size, types.PhotoCachedSize):
|
||||
file_size = len(photo_size.bytes)
|
||||
else:
|
||||
file_size = 0
|
||||
photo_size = thumbs[-1]
|
||||
|
||||
loc = photo_size.location
|
||||
if not isinstance(photo_size, (types.PhotoSize, types.PhotoCachedSize, types.PhotoStrippedSize)):
|
||||
return None
|
||||
|
||||
if isinstance(loc, types.FileLocation):
|
||||
return PhotoSize(
|
||||
file_id=encode(
|
||||
pack(
|
||||
"<iiqqqqi",
|
||||
0, loc.dc_id, 0, 0,
|
||||
loc.volume_id, loc.secret, loc.local_id)),
|
||||
width=photo_size.w,
|
||||
height=photo_size.h,
|
||||
file_size=file_size,
|
||||
client=client
|
||||
loc = photo_size.location
|
||||
|
||||
if not isinstance(loc, types.FileLocation):
|
||||
return None
|
||||
|
||||
return PhotoSize(
|
||||
file_id=encode(
|
||||
pack(
|
||||
"<iiqqqqi",
|
||||
0, loc.dc_id, 0, 0,
|
||||
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
|
||||
)
|
||||
|
@ -126,7 +126,7 @@ class Sticker(PyrogramType):
|
||||
),
|
||||
width=image_size_attributes.w 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
|
||||
set_name=set_name,
|
||||
emoji=sticker_attributes.alt or None,
|
||||
|
@ -97,7 +97,7 @@ class Video(PyrogramType):
|
||||
width=video_attributes.w,
|
||||
height=video_attributes.h,
|
||||
duration=video_attributes.duration,
|
||||
thumb=PhotoSize._parse(client, video.thumb),
|
||||
thumb=PhotoSize._parse(client, video.thumbs),
|
||||
mime_type=video.mime_type,
|
||||
file_size=video.size,
|
||||
file_name=file_name,
|
||||
|
@ -85,7 +85,7 @@ class VideoNote(PyrogramType):
|
||||
),
|
||||
length=video_attributes.w,
|
||||
duration=video_attributes.duration,
|
||||
thumb=PhotoSize._parse(client, video_note.thumb),
|
||||
thumb=PhotoSize._parse(client, video_note.thumbs),
|
||||
file_size=video_note.size,
|
||||
mime_type=video_note.mime_type,
|
||||
date=video_note.date,
|
||||
|
Loading…
Reference in New Issue
Block a user