mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-29 13:27:47 +00:00
Rename encode/decode to encode/decode_file_id
This commit is contained in:
parent
92c1b48132
commit
91d3508c13
@ -27,7 +27,7 @@ from . import BaseClient
|
|||||||
from ...api import types
|
from ...api import types
|
||||||
|
|
||||||
|
|
||||||
def decode(s: str) -> bytes:
|
def decode_file_id(s: str) -> bytes:
|
||||||
s = base64.urlsafe_b64decode(s + "=" * (-len(s) % 4))
|
s = base64.urlsafe_b64decode(s + "=" * (-len(s) % 4))
|
||||||
r = b""
|
r = b""
|
||||||
|
|
||||||
@ -53,7 +53,7 @@ def decode(s: str) -> bytes:
|
|||||||
return r
|
return r
|
||||||
|
|
||||||
|
|
||||||
def encode(s: bytes) -> str:
|
def encode_file_id(s: bytes) -> str:
|
||||||
r = b""
|
r = b""
|
||||||
n = 0
|
n = 0
|
||||||
|
|
||||||
@ -97,7 +97,7 @@ def get_input_media_from_file_id(
|
|||||||
expected_media_type: int = None
|
expected_media_type: int = None
|
||||||
) -> Union[types.InputMediaPhoto, types.InputMediaDocument]:
|
) -> Union[types.InputMediaPhoto, types.InputMediaDocument]:
|
||||||
try:
|
try:
|
||||||
decoded = decode(file_id_str)
|
decoded = decode_file_id(file_id_str)
|
||||||
except Exception:
|
except Exception:
|
||||||
raise ValueError("Failed to decode file_id: {}".format(file_id_str))
|
raise ValueError("Failed to decode file_id: {}".format(file_id_str))
|
||||||
else:
|
else:
|
||||||
|
@ -141,7 +141,7 @@ class DownloadMedia(BaseClient):
|
|||||||
return dict(filter(lambda x: x[1] is not None, data.__dict__.items()))
|
return dict(filter(lambda x: x[1] is not None, data.__dict__.items()))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
decoded = utils.decode(file_id_str)
|
decoded = utils.decode_file_id(file_id_str)
|
||||||
media_type = decoded[0]
|
media_type = decoded[0]
|
||||||
|
|
||||||
if media_type == 1:
|
if media_type == 1:
|
||||||
|
@ -55,7 +55,7 @@ class DeleteProfilePhotos(BaseClient):
|
|||||||
input_photos = []
|
input_photos = []
|
||||||
|
|
||||||
for photo_id in photo_ids:
|
for photo_id in photo_ids:
|
||||||
unpacked = unpack("<iiqqc", utils.decode(photo_id))
|
unpacked = unpack("<iiqqc", utils.decode_file_id(photo_id))
|
||||||
|
|
||||||
input_photos.append(
|
input_photos.append(
|
||||||
types.InputPhoto(
|
types.InputPhoto(
|
||||||
|
@ -23,7 +23,7 @@ import pyrogram
|
|||||||
from pyrogram.api import types
|
from pyrogram.api import types
|
||||||
from .thumbnail import Thumbnail
|
from .thumbnail import Thumbnail
|
||||||
from ..object import Object
|
from ..object import Object
|
||||||
from ...ext.utils import encode, encode_file_ref
|
from ...ext.utils import encode_file_id, encode_file_ref
|
||||||
|
|
||||||
|
|
||||||
class Animation(Object):
|
class Animation(Object):
|
||||||
@ -97,7 +97,7 @@ class Animation(Object):
|
|||||||
file_name: str
|
file_name: str
|
||||||
) -> "Animation":
|
) -> "Animation":
|
||||||
return Animation(
|
return Animation(
|
||||||
file_id=encode(
|
file_id=encode_file_id(
|
||||||
pack(
|
pack(
|
||||||
"<iiqq",
|
"<iiqq",
|
||||||
10,
|
10,
|
||||||
|
@ -23,7 +23,7 @@ import pyrogram
|
|||||||
from pyrogram.api import types
|
from pyrogram.api import types
|
||||||
from .thumbnail import Thumbnail
|
from .thumbnail import Thumbnail
|
||||||
from ..object import Object
|
from ..object import Object
|
||||||
from ...ext.utils import encode, encode_file_ref
|
from ...ext.utils import encode_file_id, encode_file_ref
|
||||||
|
|
||||||
|
|
||||||
class Audio(Object):
|
class Audio(Object):
|
||||||
@ -97,7 +97,7 @@ class Audio(Object):
|
|||||||
file_name: str
|
file_name: str
|
||||||
) -> "Audio":
|
) -> "Audio":
|
||||||
return Audio(
|
return Audio(
|
||||||
file_id=encode(
|
file_id=encode_file_id(
|
||||||
pack(
|
pack(
|
||||||
"<iiqq",
|
"<iiqq",
|
||||||
9,
|
9,
|
||||||
|
@ -23,7 +23,7 @@ import pyrogram
|
|||||||
from pyrogram.api import types
|
from pyrogram.api import types
|
||||||
from .thumbnail import Thumbnail
|
from .thumbnail import Thumbnail
|
||||||
from ..object import Object
|
from ..object import Object
|
||||||
from ...ext.utils import encode, encode_file_ref
|
from ...ext.utils import encode_file_id, encode_file_ref
|
||||||
|
|
||||||
|
|
||||||
class Document(Object):
|
class Document(Object):
|
||||||
@ -77,7 +77,7 @@ class Document(Object):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def _parse(client, document: types.Document, file_name: str) -> "Document":
|
def _parse(client, document: types.Document, file_name: str) -> "Document":
|
||||||
return Document(
|
return Document(
|
||||||
file_id=encode(
|
file_id=encode_file_id(
|
||||||
pack(
|
pack(
|
||||||
"<iiqq",
|
"<iiqq",
|
||||||
5,
|
5,
|
||||||
|
@ -23,7 +23,7 @@ import pyrogram
|
|||||||
from pyrogram.api import types
|
from pyrogram.api import types
|
||||||
from .thumbnail import Thumbnail
|
from .thumbnail import Thumbnail
|
||||||
from ..object import Object
|
from ..object import Object
|
||||||
from ...ext.utils import encode, encode_file_ref
|
from ...ext.utils import encode_file_id, encode_file_ref
|
||||||
|
|
||||||
|
|
||||||
class Photo(Object):
|
class Photo(Object):
|
||||||
@ -80,7 +80,7 @@ class Photo(Object):
|
|||||||
big = photo.sizes[-1]
|
big = photo.sizes[-1]
|
||||||
|
|
||||||
return Photo(
|
return Photo(
|
||||||
file_id=encode(
|
file_id=encode_file_id(
|
||||||
pack(
|
pack(
|
||||||
"<iiqqqiiii",
|
"<iiqqqiiii",
|
||||||
2, photo.dc_id, photo.id, photo.access_hash,
|
2, photo.dc_id, photo.id, photo.access_hash,
|
||||||
|
@ -25,7 +25,7 @@ from pyrogram.api import types, functions
|
|||||||
from pyrogram.errors import StickersetInvalid
|
from pyrogram.errors import StickersetInvalid
|
||||||
from .thumbnail import Thumbnail
|
from .thumbnail import Thumbnail
|
||||||
from ..object import Object
|
from ..object import Object
|
||||||
from ...ext.utils import encode, encode_file_ref
|
from ...ext.utils import encode_file_id, encode_file_ref
|
||||||
|
|
||||||
|
|
||||||
class Sticker(Object):
|
class Sticker(Object):
|
||||||
@ -131,7 +131,7 @@ class Sticker(Object):
|
|||||||
set_name = None
|
set_name = None
|
||||||
|
|
||||||
return Sticker(
|
return Sticker(
|
||||||
file_id=encode(
|
file_id=encode_file_id(
|
||||||
pack(
|
pack(
|
||||||
"<iiqq",
|
"<iiqq",
|
||||||
8,
|
8,
|
||||||
|
@ -21,7 +21,7 @@ from typing import Union, List
|
|||||||
|
|
||||||
import pyrogram
|
import pyrogram
|
||||||
from pyrogram.api import types
|
from pyrogram.api import types
|
||||||
from pyrogram.client.ext.utils import encode
|
from pyrogram.client.ext.utils import encode_file_id
|
||||||
from .stripped_thumbnail import StrippedThumbnail
|
from .stripped_thumbnail import StrippedThumbnail
|
||||||
from ..object import Object
|
from ..object import Object
|
||||||
|
|
||||||
@ -85,7 +85,7 @@ class Thumbnail(Object):
|
|||||||
if isinstance(thumbnail, types.PhotoSize):
|
if isinstance(thumbnail, types.PhotoSize):
|
||||||
thumbnails.append(
|
thumbnails.append(
|
||||||
Thumbnail(
|
Thumbnail(
|
||||||
file_id=encode(
|
file_id=encode_file_id(
|
||||||
pack(
|
pack(
|
||||||
"<iiqqqiiii",
|
"<iiqqqiiii",
|
||||||
media_type, media.dc_id, media.id, media.access_hash,
|
media_type, media.dc_id, media.id, media.access_hash,
|
||||||
|
@ -23,7 +23,7 @@ import pyrogram
|
|||||||
from pyrogram.api import types
|
from pyrogram.api import types
|
||||||
from .thumbnail import Thumbnail
|
from .thumbnail import Thumbnail
|
||||||
from ..object import Object
|
from ..object import Object
|
||||||
from ...ext.utils import encode, encode_file_ref
|
from ...ext.utils import encode_file_id, encode_file_ref
|
||||||
|
|
||||||
|
|
||||||
class Video(Object):
|
class Video(Object):
|
||||||
@ -102,7 +102,7 @@ class Video(Object):
|
|||||||
file_name: str
|
file_name: str
|
||||||
) -> "Video":
|
) -> "Video":
|
||||||
return Video(
|
return Video(
|
||||||
file_id=encode(
|
file_id=encode_file_id(
|
||||||
pack(
|
pack(
|
||||||
"<iiqq",
|
"<iiqq",
|
||||||
4,
|
4,
|
||||||
|
@ -23,7 +23,7 @@ import pyrogram
|
|||||||
from pyrogram.api import types
|
from pyrogram.api import types
|
||||||
from .thumbnail import Thumbnail
|
from .thumbnail import Thumbnail
|
||||||
from ..object import Object
|
from ..object import Object
|
||||||
from ...ext.utils import encode, encode_file_ref
|
from ...ext.utils import encode_file_id, encode_file_ref
|
||||||
|
|
||||||
|
|
||||||
class VideoNote(Object):
|
class VideoNote(Object):
|
||||||
@ -82,7 +82,7 @@ class VideoNote(Object):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def _parse(client, video_note: types.Document, video_attributes: types.DocumentAttributeVideo) -> "VideoNote":
|
def _parse(client, video_note: types.Document, video_attributes: types.DocumentAttributeVideo) -> "VideoNote":
|
||||||
return VideoNote(
|
return VideoNote(
|
||||||
file_id=encode(
|
file_id=encode_file_id(
|
||||||
pack(
|
pack(
|
||||||
"<iiqq",
|
"<iiqq",
|
||||||
13,
|
13,
|
||||||
|
@ -21,7 +21,7 @@ from struct import pack
|
|||||||
import pyrogram
|
import pyrogram
|
||||||
from pyrogram.api import types
|
from pyrogram.api import types
|
||||||
from ..object import Object
|
from ..object import Object
|
||||||
from ...ext.utils import encode, encode_file_ref
|
from ...ext.utils import encode_file_id, encode_file_ref
|
||||||
|
|
||||||
|
|
||||||
class Voice(Object):
|
class Voice(Object):
|
||||||
@ -75,7 +75,7 @@ class Voice(Object):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def _parse(client, voice: types.Document, attributes: types.DocumentAttributeAudio) -> "Voice":
|
def _parse(client, voice: types.Document, attributes: types.DocumentAttributeAudio) -> "Voice":
|
||||||
return Voice(
|
return Voice(
|
||||||
file_id=encode(
|
file_id=encode_file_id(
|
||||||
pack(
|
pack(
|
||||||
"<iiqq",
|
"<iiqq",
|
||||||
3,
|
3,
|
||||||
|
@ -22,7 +22,7 @@ import pyrogram
|
|||||||
from pyrogram.api import types
|
from pyrogram.api import types
|
||||||
from pyrogram.client.ext import utils
|
from pyrogram.client.ext import utils
|
||||||
from ..object import Object
|
from ..object import Object
|
||||||
from ...ext.utils import encode
|
from ...ext.utils import encode_file_id
|
||||||
|
|
||||||
|
|
||||||
class ChatPhoto(Object):
|
class ChatPhoto(Object):
|
||||||
@ -73,7 +73,7 @@ class ChatPhoto(Object):
|
|||||||
x = -234
|
x = -234
|
||||||
|
|
||||||
return ChatPhoto(
|
return ChatPhoto(
|
||||||
small_file_id=encode(
|
small_file_id=encode_file_id(
|
||||||
pack(
|
pack(
|
||||||
"<iiqqqiiiqi",
|
"<iiqqqiiiqi",
|
||||||
1, chat_photo.dc_id, photo_id,
|
1, chat_photo.dc_id, photo_id,
|
||||||
@ -81,7 +81,7 @@ class ChatPhoto(Object):
|
|||||||
2, peer_id, x, peer_access_hash, loc_small.local_id
|
2, peer_id, x, peer_access_hash, loc_small.local_id
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
big_file_id=encode(
|
big_file_id=encode_file_id(
|
||||||
pack(
|
pack(
|
||||||
"<iiqqqiiiqi",
|
"<iiqqqiiiqi",
|
||||||
1, chat_photo.dc_id, photo_id,
|
1, chat_photo.dc_id, photo_id,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user