#!/usr/bin/env python3 # -*- coding: utf-8 -*- from telethon import TelegramClient from telethon.tl.types import DocumentAttributeAudio import mimetypes entity = 'AudioTube_bot' # - api_id = 1959 api_hash = '88b68d6da53fe68c1c3541bbefc' phone = '+79620181488' client = TelegramClient(entity, api_id, api_hash, update_workers=None, spawn_read_thread=False) client.connect() if not client.is_user_authorized(): # client.send_code_request(phone) # - , FloodWait client.sign_in(phone, input('Enter code: ')) client.start() def main(argv): file_path = argv[1] file_name = argv[2] chat_id = argv[3] object_id = argv[4] bot_name = argv[5] duration = argv[6] mimetypes.add_type('audio/aac','.aac') mimetypes.add_type('audio/ogg','.ogg') msg = client.send_file( str(bot_name), file_path, caption=str(chat_id + ':' + object_id + ':' + duration), file_name=str(file_name), use_cache=False, part_size_kb=512, attributes=[DocumentAttributeAudio( int(duration), voice=None, title=file_name[:-4], performer='')] ) client.disconnect() return 0 if __name__ == '__main__': import sys main(sys.argv[0:])
status = subprocess.check_call( "python3.6 audiotubeagent36/main.py " + path_file_mp3 + ' ' + audio_title + '.'+ us_audio_codec + ' ' + str(chat_id) + ' ' + str(pool_object['_id']) + ' ' + config.BOT_NAME + ' ' + str(duration),shell=True)
if message.content_type in ['document','audio']: user_id = message.from_user.id bot_settings = SafeConfigParser() bot_settings.read(config.PATH_SETTINGS_FILE) c_type = message.content_type if functions.check_is_admin(bot_settings, user_id): if c_type == 'audio': file_id = message.audio.file_id audio_title = message.audio.title else: file_id = message.document.file_id audio_title = message.document.file_name[:-4] client_chat_id = message.caption if client_chat_id.find(u':') != -1: client_chat_id, q_pool_obj_id, duration_s = re.split(r':',client_chat_id) # file_id q_pool.update_request_file_id(str(q_pool_obj_id), str(file_id)) # bot.send_audio(int(client_chat_id), file_id,caption='', duration=int(duration_s), title=audio_title, performer='') return
Source: https://habr.com/ru/post/348234/
All Articles