Update to layer 98

This commit is contained in:
Lonami Exo
2019-04-22 16:51:05 +02:00
parent a151d24951
commit 8868ce14e8
4 changed files with 59 additions and 36 deletions
+18 -3
View File
@@ -76,7 +76,14 @@ class DownloadMethods(UserMethods):
photo = entity.photo
if isinstance(photo, (types.UserProfilePhoto, types.ChatPhoto)):
loc = photo.photo_big if download_big else photo.photo_small
dc_id = photo.dc_id
which = photo.photo_big if download_big else photo.photo_small
loc = types.InputPeerPhotoFileLocation(
peer=await self.get_input_entity(entity),
local_id=which.local_id,
volume_id=which.volume_id,
big=download_big
)
else:
# It doesn't make any sense to check if `photo` can be used
# as input location, because then this method would be able
@@ -90,7 +97,7 @@ class DownloadMethods(UserMethods):
)
try:
result = await self.download_file(loc, file)
result = await self.download_file(loc, file, dc_id=dc_id)
return result if file is bytes else file
except errors.LocationInvalidError:
# See issue #500, Android app fails as of v4.6.0 (1155).
@@ -168,7 +175,7 @@ class DownloadMethods(UserMethods):
async def download_file(
self, input_location, file=None, *, part_size_kb=None,
file_size=None, progress_callback=None):
file_size=None, progress_callback=None, dc_id=None):
"""
Downloads the given input location to a file.
@@ -197,6 +204,10 @@ class DownloadMethods(UserMethods):
A callback function accepting two parameters:
``(downloaded bytes, total)``. Note that the
``total`` is the provided ``file_size``.
dc_id (`int`, optional):
The data center the library should connect to in order
to download the file. You shouldn't worry about this.
"""
if not part_size_kb:
if not file_size:
@@ -225,7 +236,11 @@ class DownloadMethods(UserMethods):
else:
f = file
old_dc = dc_id
dc_id, input_location = utils.get_input_location(input_location)
if dc_id is None:
dc_id = old_dc
exported = dc_id and self.session.dc_id != dc_id
if exported:
try:
+1 -1
View File
@@ -159,7 +159,7 @@ class AdminLogEvent:
"""
Whether the channel's photo was changed in this event or not.
If ``True``, `old` and `new` will be present as :tl:`ChatPhoto`.
If ``True``, `old` and `new` will be present as :tl:`Photo`.
"""
return isinstance(self.original.action,
types.ChannelAdminLogEventActionChangePhoto)
+16 -13
View File
@@ -630,22 +630,25 @@ def get_input_location(location):
if isinstance(location, types.Document):
return (location.dc_id, types.InputDocumentFileLocation(
location.id, location.access_hash,
file_reference=location.file_reference
id=location.id,
access_hash=location.access_hash,
file_reference=location.file_reference,
thumb_size='' # Presumably to download one of its thumbnails
))
elif isinstance(location, types.Photo):
try:
location = next(
x for x in reversed(location.sizes)
if not isinstance(x, types.PhotoSizeEmpty)
).location
except StopIteration:
pass
return (location.dc_id, types.InputPhotoFileLocation(
id=location.id,
access_hash=location.access_hash,
file_reference=location.file_reference,
thumb_size='' # Presumably to download one of its thumbnails
))
if isinstance(location, types.FileLocation):
return (location.dc_id, types.InputFileLocation(
location.volume_id, location.local_id, location.secret,
file_reference=location.file_reference
if isinstance(location, types.FileLocationToBeDeprecated):
return (None, types.InputFileLocation(
volume_id=location.volume_id,
local_id=location.local_id,
secret=0,
file_reference=b''
))
elif isinstance(location, types.FileLocationUnavailable):
raise TypeError('Unavailable location cannot be used as input')