当前位置: 首页>>代码示例>>Python>>正文


Python utils.get_input_location方法代码示例

本文整理汇总了Python中telethon.utils.get_input_location方法的典型用法代码示例。如果您正苦于以下问题:Python utils.get_input_location方法的具体用法?Python utils.get_input_location怎么用?Python utils.get_input_location使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在telethon.utils的用法示例。


在下文中一共展示了utils.get_input_location方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: download_file

# 需要导入模块: from telethon import utils [as 别名]
# 或者: from telethon.utils import get_input_location [as 别名]
def download_file(
    self: TelegramClient, location: TypeLocation,
    out: BinaryIO, progress_callback: callable = None
) -> BinaryIO:
    size = location.size
    dc_id, location = utils.get_input_location(location)
    # We lock the transfers because telegram has connection count limits
    downloader = ParallelTransferrer(self, dc_id)
    downloaded = downloader.download(location, size)
    async for x in downloaded:
        out.write(x)
        if progress_callback:
            r = progress_callback(out.tell(), size)
            if inspect.isawaitable(r):
                await r

    return out 
开发者ID:TG-UserBot,项目名称:TG-UserBot,代码行数:19,代码来源:FastTelethon.py

示例2: download_file

# 需要导入模块: from telethon import utils [as 别名]
# 或者: from telethon.utils import get_input_location [as 别名]
def download_file(self: TelegramClient,
                        location: TypeLocation,
                        out: BinaryIO,
                        progress_callback: callable = None) -> BinaryIO:
    size = location.size
    dc_id, location = utils.get_input_location(location)
    # We lock the transfers because telegram has connection count limits
    downloader = ParallelTransferrer(self, dc_id)
    downloaded = downloader.download(location, size)
    async for x in downloaded:
        out.write(x)
        if progress_callback:
            r = progress_callback(out.tell(), size)
            if inspect.isawaitable(r):
                await r

    return out 
开发者ID:mkaraniya,项目名称:BotHub,代码行数:19,代码来源:FastTelethon.py

示例3: parallel_transfer_to_matrix

# 需要导入模块: from telethon import utils [as 别名]
# 或者: from telethon.utils import get_input_location [as 别名]
def parallel_transfer_to_matrix(client: MautrixTelegramClient, intent: IntentAPI,
                                      loc_id: str, location: TypeLocation, filename: str,
                                      encrypt: bool, parallel_id: int) -> DBTelegramFile:
    size = location.size
    mime_type = location.mime_type
    dc_id, location = utils.get_input_location(location)
    # We lock the transfers because telegram has connection count limits
    async with parallel_transfer_locks[parallel_id]:
        downloader = ParallelTransferrer(client, dc_id)
        data = downloader.download(location, size)
        decryption_info = None
        up_mime_type = mime_type
        if encrypt and async_encrypt_attachment:
            async def encrypted(stream):
                nonlocal decryption_info
                async for chunk in async_encrypt_attachment(stream):
                    if isinstance(chunk, dict):
                        decryption_info = EncryptedFile.deserialize(chunk)
                    else:
                        yield chunk

            data = encrypted(data)
            up_mime_type = "application/octet-stream"
        content_uri = await intent.upload_media(data, mime_type=up_mime_type, filename=filename,
                                                size=size if not encrypt else None)
        if decryption_info:
            decryption_info.url = content_uri
    return DBTelegramFile(id=loc_id, mxc=content_uri, mime_type=mime_type,
                          was_converted=False, timestamp=int(time.time()), size=size,
                          width=None, height=None, decryption_info=decryption_info) 
开发者ID:tulir,项目名称:mautrix-telegram,代码行数:32,代码来源:parallel_file_transfer.py

示例4: download

# 需要导入模块: from telethon import utils [as 别名]
# 或者: from telethon.utils import get_input_location [as 别名]
def download(self, file: TypeLocation, file_size: int, offset: int, limit: int
                 ) -> AsyncGenerator[bytes, None]:
        dc_id, location = utils.get_input_location(file)
        part_size = 512 * 1024
        first_part_cut = offset % part_size
        first_part = math.floor(offset / part_size)
        last_part_cut = part_size - (limit % part_size)
        last_part = math.ceil(limit / part_size)
        part_count = math.ceil(file_size / part_size)
        self.log.debug(f"Starting parallel download: chunks {first_part}-{last_part}"
                       f" of {part_count} {location!s}")
        request = GetFileRequest(location, offset=first_part * part_size, limit=part_size)

        return self._int_download(request, first_part, last_part, part_count, part_size, dc_id,
                                  first_part_cut, last_part_cut) 
开发者ID:tulir,项目名称:tgfilestream,代码行数:17,代码来源:paralleltransfer.py

示例5: fetch_info

# 需要导入模块: from telethon import utils [as 别名]
# 或者: from telethon.utils import get_input_location [as 别名]
def fetch_info(replied_user, event):
    """ Get details from the User object. """
    replied_user_profile_photos = await event.client(
        GetUserPhotosRequest(user_id=replied_user.user.id,
                             offset=42,
                             max_id=0,
                             limit=80))
    replied_user_profile_photos_count = "NaN."
    try:
        replied_user_profile_photos_count = replied_user_profile_photos.count
    except AttributeError as e:
        pass
    user_id = replied_user.user.id
    first_name = replied_user.user.first_name
    last_name = replied_user.user.last_name
    try:
        dc_id, location = get_input_location(replied_user.profile_photo)
    except Exception as e:
        dc_id = "Need a Profile Picture to check DC ID!"
        location = str(e)
    common_chat = replied_user.common_chats_count
    username = replied_user.user.username
    user_bio = replied_user.about
    is_bot = replied_user.user.bot
    restricted = replied_user.user.restricted
    verified = replied_user.user.verified
    photo = await event.client.download_profile_photo(user_id,
                                        TMP_DOWNLOAD_DIRECTORY +
                                                      str(user_id) + ".jpg",
                                                      download_big=True)
    first_name = first_name.replace(
        "\u2060", "") if first_name else ("")
    last_name = last_name.replace(
        "\u2060", "") if last_name else ("")
    username = "@{}".format(username) if username else (
        "This User has no Username")
    user_bio = "This User has no About" if not user_bio else user_bio
    if user_id != (await event.client.get_me()).id:
        common_chat = replied_user.common_chats_count
    else:
        common_chat = "I've seen them in... Wow. Are they stalking me? "
        common_chat += "They're in all the same places I am... oh. It's me."
        
    

    caption += f"<b>General Info OF {DEFAULTUSER}:</b> \n"
    caption += f"<a href=\"tg://user?id={user_id}\">{first_name}</a> \n"
    caption += f"<b>First Name</b>: {first_name} \n"
    caption += f"<b>ID</b>: <code>{user_id}</code> \n"
    caption += f"Last Name</b>: {last_name} \n"
    caption += f"<b>Username</b>: {username} \n"
    caption += f"DC ID: {dc_id}\n"
    caption += f"Number of PPs: {replied_user_profile_photos_count}\n"
    caption += f"Common Groups: {common_chat} \n \n"
    caption += f"<b>Bio</b>: \n<code>{user_bio}</code> \n"

    return caption 
开发者ID:mkaraniya,项目名称:BotHub,代码行数:59,代码来源:wh.py


注:本文中的telethon.utils.get_input_location方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。