async def func(filepath: str, client: Client, message: Message, delete=False): if not os_path.exists(filepath): LOGGER.error(f'File not found : {filepath}') await message.edit_text( LOCAL.UPLOAD_FAILED_FILE_MISSING.format( name=os_path.basename(filepath))) return if os_path.isdir(filepath): ls = os_lisdir(filepath) async for filepath in ls: await message.edit( LOCAL.UPLOADING_FILE.format(name=os_path.basename(filepath))) await func(filepath, message, delete) if delete: os_rmdir(filepath) return video = ['.mp4', '.mkv', '.avi', '.webm', '.wmv', '.mov'] photo = ['.jpg', '.jpeg', '.png'] file_ext = os_path.splitext(filepath)[1].lower() LOGGER.debug(f'Uploading : {filepath}') if STATUS.UPLOAD_AS_DOC: upload_fn = client.send_document elif file_ext in photo: upload_fn = client.send_photo elif file_ext in video: async def upload_fn(chat_id, file, **kwargs): probe = await ffprobe.func(file.path) duration = int(float(probe["format"]["duration"])) video_stream = next((stream for stream in probe['streams'] if stream['codec_type'] == 'video'), None) width = int(video_stream['width'] if 'width' in video_stream else 0) height = int(video_stream['height'] if 'height' in video_stream else 0) await message.edit(LOCAL.GENERATE_THUMBNAIL.format(name=file.name)) thumbnail = os_path.join(CONFIG.ROOT, CONFIG.WORKDIR, CONFIG.THUMBNAIL_NAME) use_default_thumbnail = os_path.exists(thumbnail) if not use_default_thumbnail: thumbnail = await thumbnail_video.func(file.path) await client.send_video(chat_id, file, supports_streaming=True, thumb=str(thumbnail), height=height, width=width, duration=duration, **kwargs) if not use_default_thumbnail: os_remove(str(thumbnail)) else: upload_fn = client.send_document if os_path.getsize(filepath) > int(CONFIG.UPLOAD_MAX_SIZE): LOGGER.debug(f'File too large : {filepath}') await message.edit_text( LOCAL.SPLIT_FILE.format(name=os_path.basename(filepath))) async for file in split.func(filepath, int(CONFIG.UPLOAD_MAX_SIZE)): await message.edit(LOCAL.UPLOADING_FILE.format(name=file.name)) info = { "time": time(), "name": file.name, "last_update": 0, "prev_text": "" } await upload_fn(message.chat.id, file, disable_notification=True, progress=progress_upload_tg, progress_args=(message, info), caption=f'<code>{file.name}</code>') LOGGER.debug(f'Uploaded : {file.name}') if delete: os_remove(filepath)
async def func(filepath: str, client: Client, message: Message, delete=False): if not os_path.exists(filepath): LOGGER.error(f'File not found : {filepath}') await message.edit_text( LOCAL.UPLOAD_FAILED_FILE_MISSING.format( name=os_path.basename(filepath))) return if os_path.isdir(filepath): ls = os_lisdir(filepath) async for filepath in ls: await message.edit( LOCAL.UPLOADING_FILE.format(name=os_path.basename(filepath))) await func(filepath, message, delete) if delete: os_rmdir(filepath) return video = ['.mp4', '.mkv', '.avi', '.webm', '.wmv', '.mov'] photo = ['.jpg', '.jpeg', '.png'] file_ext = os_path.splitext(filepath)[1].lower() LOGGER.debug(f'Uploading : {filepath}') if STATUS.UPLOAD_AS_DOC: upload_fn = client.send_document elif file_ext in photo: upload_fn = client.send_photo elif file_ext in video: async def upload_fn(chat_id, file, **kwargs): probe = await ffprobe.func(file.path) duration = int(float(probe["format"]["duration"])) video_stream = next((stream for stream in probe['streams'] if stream['codec_type'] == 'video'), None) width = int(video_stream['width'] if 'width' in video_stream else 0) height = int(video_stream['height'] if 'height' in video_stream else 0) await message.edit(LOCAL.GENERATE_THUMBNAIL.format(name=file.name)) thumb_image_path = CONFIG.DOWNLOAD_LOCATION + "/" + str( update.from_user.id) + ".jpg" if not os.path.exists(thumb_image_path): mes = await thumb(update.from_user.id) if mes != None: m = await bot.get_messages(update.chat.id, mes.msg_id) await m.download(file_name=thumb_image_path) thumb_image_path = thumb_image_path else: if "thumbnail" in response_json: if response_json["thumbnail"] is not None: thumbnail = response_json["thumbnail"] thumbnail_image = response_json["thumbnail"] thumb_image_path = DownLoadFile( thumbnail_image, CONFIG.DOWNLOAD_LOCATION + "/" + str(update.from_user.id) + ".jpg", CONFIG.CHUNK_SIZE, None, # bot, LOCAL.DOWNLOAD_START, update.message_id, update.chat.id) await client.send_video(chat_id, file, supports_streaming=True, thumb=thumb_image_path, height=height, width=width, duration=duration, **kwargs) if not use_default_thumbnail: os_remove(str(thumbnail)) else: upload_fn = client.send_document if os_path.getsize(filepath) > int(CONFIG.UPLOAD_MAX_SIZE): LOGGER.debug(f'File too large : {filepath}') await message.edit_text( LOCAL.SPLIT_FILE.format(name=os_path.basename(filepath))) async for file in split.func(filepath, int(CONFIG.UPLOAD_MAX_SIZE)): await message.edit(LOCAL.UPLOADING_FILE.format(name=file.name)) info = { "time": time(), "name": file.name, "last_update": 0, "prev_text": "" } await upload_fn(message.chat.id, file, disable_notification=True, progress=progress_upload_tg, progress_args=(message, info), caption=f'<code>{file.name}</code>') LOGGER.debug(f'Uploaded : {file.name}') if delete: os_remove(filepath)