Fix get_profile_photos returning a list of None

This commit is contained in:
Dan 2020-12-25 15:22:37 +01:00
parent d4c07304d0
commit 449b065fe9

View File

@ -16,7 +16,7 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import List, Optional from typing import List
import pyrogram import pyrogram
from pyrogram import raw from pyrogram import raw
@ -80,20 +80,22 @@ class Photo(Object):
self.thumbs = thumbs self.thumbs = thumbs
@staticmethod @staticmethod
def _parse(client, photo: "raw.types.Photo", ttl_seconds: int = None) -> Optional["Photo"]: def _parse(client, photo: "raw.types.Photo", ttl_seconds: int = None) -> "Photo":
if isinstance(photo, raw.types.Photo): if isinstance(photo, raw.types.Photo):
big = photo.sizes[-1] try:
progressive = next(p for p in photo.sizes if isinstance(p, raw.types.PhotoSizeProgressive))
except StopIteration:
photo_size_objs = [p for p in photo.sizes if isinstance(p, raw.types.PhotoSize)]
photo_size_objs.sort(key=lambda p: p.size)
if isinstance(big, (raw.types.PhotoStrippedSize, raw.types.PhotoPathSize)): big = photo_size_objs[-1]
return None else:
if isinstance(big, raw.types.PhotoSizeProgressive):
big = raw.types.PhotoSize( big = raw.types.PhotoSize(
type=big.type, type=progressive.type,
location=big.location, location=progressive.location,
w=big.w, w=progressive.w,
h=big.h, h=progressive.h,
size=big.sizes[-1] size=sorted(progressive.sizes)[-1]
) )
return Photo( return Photo(