Python telethon.utils.get_input_location() Examples
The following are 5
code examples of telethon.utils.get_input_location().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
telethon.utils
, or try the search function
.
Example #1
Source File: FastTelethon.py From TG-UserBot with GNU General Public License v3.0 | 6 votes |
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
Example #2
Source File: FastTelethon.py From BotHub with Apache License 2.0 | 6 votes |
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
Example #3
Source File: parallel_file_transfer.py From mautrix-telegram with GNU Affero General Public License v3.0 | 5 votes |
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)
Example #4
Source File: paralleltransfer.py From tgfilestream with GNU Affero General Public License v3.0 | 5 votes |
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)
Example #5
Source File: wh.py From BotHub with Apache License 2.0 | 4 votes |
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