-
Notifications
You must be signed in to change notification settings - Fork 1
/
aux_methods.py
78 lines (62 loc) · 3.27 KB
/
aux_methods.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from bot_globals import curr_mode, curr_privacy
from internal.functions import *
from internal.features import *
from constants import *
async def handle_media(data, data_size, data_res, update, file_type, context):
global curr_privacy
global curr_mode
if (data_res):
# video note , voice recording, video
file_name = ''
if (file_type in ['voice recording', 'video file', 'video chat']):
ext = ".oga" if file_type == 'voice recording' else ".mp4"
file_name = "media" + data.file_unique_id + ext
else:
file_name = data.file_name
file = await data.get_file()
file_path = file.file_path
await download_file(file_path=file_path, file_name=file_name)
await context.bot.send_message(chat_id=update.effective_chat.id, text=f"Received: {file_type}!")
if curr_mode == 'both':
lang = trans_both(f'media/{file_name}', curr_privacy)
elif curr_mode == 'english_only':
lang = trans_eng(audio=f'media/{file_name}')
elif curr_mode == 'sea_only':
lang = trans_sea(audio=f'media/{file_name}')
else:
lang = False
if (lang==False):
await delete_file(file_name=file_name)
await context.bot.send_message(chat_id=update.effective_chat.id, text=content_region_msg)
else:
json_name = file_name.split('.')[0] + '.json'
json_file = f'media/{json_name}'
await context.bot.send_document(chat_id=update.effective_chat.id, document=json_file)
await context.bot.send_message(chat_id=update.effective_chat.id, text=confirmation_msg)
await delete_file(file_name=file_name)
await delete_file(file_name=json_name)
else:
await context.bot.send_message(chat_id=update.effective_chat.id, text=f"Your file occupies {data_size} MB. EchoBot currently doesn't support files exceeding 25 MB :(")
async def handle_link(data_size, data_res, update, file_name, context):
if (data_res):
await context.bot.send_message(chat_id=update.effective_chat.id, text="Parsing Media...")
if curr_mode == 'both':
lang = trans_both(f'media/{file_name}', curr_privacy)
elif curr_mode == 'english_only':
lang = trans_eng(audio=f'media/{file_name}')
elif curr_mode == 'sea_only':
lang = trans_sea(audio=f'media/{file_name}')
else:
lang = False
if (lang==False):
await delete_file(file_name=file_name)
await context.bot.send_message(chat_id=update.effective_chat.id, text=content_region_msg)
else:
json_name = file_name.split('.')[0] + '.json'
json_file = f'media/{json_name}'
await context.bot.send_document(chat_id=update.effective_chat.id, document=json_file)
await context.bot.send_message(chat_id=update.effective_chat.id, text=confirmation_msg)
await delete_file(file_name=file_name)
await delete_file(file_name=json_name)
else:
await context.bot.send_message(chat_id=update.effective_chat.id, text=f"Your file occupies {data_size} MB. EchoBot currently doesn't support files exceeding 25 MB :(")