當前位置: 首頁>>代碼示例>>Python>>正文


Python pyrogram.Client方法代碼示例

本文整理匯總了Python中pyrogram.Client方法的典型用法代碼示例。如果您正苦於以下問題:Python pyrogram.Client方法的具體用法?Python pyrogram.Client怎麽用?Python pyrogram.Client使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pyrogram的用法示例。


在下文中一共展示了pyrogram.Client方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: begin_import

# 需要導入模塊: import pyrogram [as 別名]
# 或者: from pyrogram import Client [as 別名]
def begin_import(config: dict):
    """Skeleton fucntion that creates client and import, write config"""
    client = pyrogram.Client(
        "media_downloader",
        api_id=config["api_id"],
        api_hash=config["api_hash"],
    )
    await client.start()
    last_read_message_id = await process_messages(
        client,
        config["chat_id"],
        config["last_read_message_id"],
        config["media_types"],
        config["file_formats"],
    )
    await client.stop()
    config["last_read_message_id"] = last_read_message_id + 1
    return config 
開發者ID:Dineshkarthik,項目名稱:telegram_media_downloader,代碼行數:20,代碼來源:media_downloader.py

示例2: __init__

# 需要導入模塊: import pyrogram [as 別名]
# 或者: from pyrogram import Client [as 別名]
def __init__(self, listener):
        super().__init__()
        self.__listener = listener
        self.__resource_lock = threading.RLock()
        self.__name = ""
        self.__gid = ''
        self.__start_time = time.time()
        self.__user_bot = Client(api_id=TELEGRAM_API,
                                 api_hash=TELEGRAM_HASH,
                                 session_name=USER_SESSION_STRING)
        self.__user_bot.start()
        self.__is_cancelled = False 
開發者ID:lzzy12,項目名稱:python-aria-mirror-bot,代碼行數:14,代碼來源:telegram_downloader.py

示例3: __init__

# 需要導入模塊: import pyrogram [as 別名]
# 或者: from pyrogram import Client [as 別名]
def __init__(self, config: Config):
        self._config = config
        self._client = pyrogram.Client(config.session_name, config.api_id, config.api_hash,
                                       bot_token=config.token, sleep_threshold=0) 
開發者ID:andrew-ld,項目名稱:smart-tv-telegram,代碼行數:6,代碼來源:mtproto.py

示例4: _play

# 需要導入模塊: import pyrogram [as 別名]
# 或者: from pyrogram import Client [as 別名]
def _play(self, client: Client, message: Message):
        state, args = self._get_state(message)

        if state != "select":
            return

        self._set_state(message, False)

        if message.text == "Cancel":
            await message.reply("Cancelled", reply_markup=_remove)
            return

        # noinspection PyTupleAssignmentBalance
        msg_id, filename, devices = args

        try:
            device = next(
                device
                for device in devices
                if repr(device) == message.text
            )
        except StopIteration:
            await message.reply("Wrong device", reply_markup=_remove)
            return

        await device.stop()
        await device.play(f"http://{self._config.listen_host}:{self._config.listen_port}/stream/{msg_id}", filename)
        await message.reply(f"Playing ID: {msg_id}", reply_markup=_remove)

    # noinspection PyUnusedLocal 
開發者ID:andrew-ld,項目名稱:smart-tv-telegram,代碼行數:32,代碼來源:bot.py

示例5: _new_document

# 需要導入模塊: import pyrogram [as 別名]
# 或者: from pyrogram import Client [as 別名]
def _new_document(self, client: Client, message: Message):
        devices = []

        if self._config.upnp_enabled:
            devices.extend(await UpnpDeviceFinder.find(self._config))

        if self._config.chromecast_enabled:
            # noinspection PyUnresolvedReferences
            devices.extend(await ChromecastDeviceFinder.find(self._config))

        if self._config.xbmc_enabled:
            devices.extend(await XbmcDeviceFinder.find(self._config))

        if self._config.vlc_enabled:
            devices.extend(await VlcDeviceFinder.find(self._config))

        if devices:
            file_name = ""

            for typ in named_media_types:
                obj = getattr(message, typ)

                if obj is not None:
                    file_name = obj.file_name
                    break

            self._set_state(message, "select", message.message_id, file_name, devices.copy())

            buttons = [[KeyboardButton(repr(device))] for device in devices]
            buttons.append([KeyboardButton("Cancel")])
            markup = ReplyKeyboardMarkup(buttons, one_time_keyboard=True)

            await message.reply("Select a device", reply_markup=markup)

        else:
            await message.reply("Supported devices not found in the network", reply_markup=_remove) 
開發者ID:andrew-ld,項目名稱:smart-tv-telegram,代碼行數:38,代碼來源:bot.py

示例6: main

# 需要導入模塊: import pyrogram [as 別名]
# 或者: from pyrogram import Client [as 別名]
def main(api_id, api_hash):
    """ generate StringSession for the current MemorySession"""
    async with Client(
            ":memory:",
            api_id=api_id,
            api_hash=api_hash
    ) as app:
        print(app.export_session_string()) 
開發者ID:athphane,項目名稱:userbot,代碼行數:10,代碼來源:genStrSession.py

示例7: download_media

# 需要導入模塊: import pyrogram [as 別名]
# 或者: from pyrogram import Client [as 別名]
def download_media(
    client: pyrogram.client.client.Client,
    message: pyrogram.Message,
    media_types: List[str],
    file_formats: dict,
):
    """Download media from Telegram.

    Parameters
    ----------
    client: pyrogram.client.client.Client
        Client to interact with Telegram APIs.
    message: pyrogram.Message
        Message object retrived from telegram.
    media_types: list
        List of strings of media types to be downloaded.
        Ex : `["audio", "photo"]`
        Supported formats:
            * audio
            * document
            * photo
            * video
            * voice
    file_formats: dict
        Dictionary containing the list of file_formats
        to be downloaded for `audio`, `document` & `video`
        media types

    Returns
    -------
    integer
        message_id
    """

    def _can_download(_type, file_formats, file_format):
        if _type in ["audio", "document", "video"]:
            allowed_formats: list = file_formats[_type]
            if (
                not file_format in allowed_formats
                and allowed_formats[0] != "all"
            ):
                return False
        return True

    if message.media:
        for _type in media_types:
            _media = getattr(message, _type, None)
            if _media:
                file_ref, file_name, file_format = await _get_media_meta(
                    _media, _type
                )
                if _can_download(_type, file_formats, file_format):
                    download_path = await client.download_media(
                        message, file_ref=file_ref, file_name=file_name
                    )
                    logger.info("Media downloaded - %s", download_path)
    return message.message_id 
開發者ID:Dineshkarthik,項目名稱:telegram_media_downloader,代碼行數:59,代碼來源:media_downloader.py

示例8: process_messages

# 需要導入模塊: import pyrogram [as 別名]
# 或者: from pyrogram import Client [as 別名]
def process_messages(
    client: pyrogram.client.client.Client,
    chat_id: str,
    last_read_message_id: int,
    media_types: List[str],
    file_formats: dict,
) -> int:
    """Download media from Telegram.

    Parameters
    ----------
    client: pyrogram.client.client.Client
        Client to interact with Telegram APIs.
    chat_id: string
        Id of the chat to download media from.
    last_read_message_id: integer
        Id of last message read from the conversational thread.
    media_types: list
        List of strings of media types to be downloaded.
        Ex : `["audio", "photo"]`
        Supported formats:
            * audio
            * document
            * photo
            * video
            * voice
    file_formats: dict
        Dictionary containing the list of file_formats
        to be downloaded for `audio`, `document` & `video`
        media types
    Returns
    -------
    integer
        last_message_id
    """
    message_ids = await asyncio.gather(
        *[
            download_media(client, message, media_types, file_formats)
            async for message in client.iter_history(
                chat_id, offset_id=last_read_message_id, reverse=True
            )
        ]
    )

    last_message_id = max(message_ids, default=last_read_message_id)
    return last_message_id 
開發者ID:Dineshkarthik,項目名稱:telegram_media_downloader,代碼行數:48,代碼來源:media_downloader.py


注:本文中的pyrogram.Client方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。