-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
102 lines (82 loc) · 3.2 KB
/
main.py
File metadata and controls
102 lines (82 loc) · 3.2 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
from telethon import TelegramClient, events
import asyncio
import edit_video
import requests
download_path = "downloaded_video/"
upload_path = "edited_video/"
api_id = 24259180
api_hash = "63cf9778009838a7d48f75866a5b6fc9"
download_chat_id = -1002126759941
upload_chat_id = -1001996807858
client = TelegramClient('ha', api_id, api_hash)
newest_msg_id_source = 0
# -------------------------------------------------------------
async def SendMsg():
chat = await client.get_entity(upload_chat_id)
# Get the chat history
messages = await client.get_messages(chat, limit=1)
# Check if there is at least one message
if messages:
msg = messages[0]
# url = f'https://alpha-one-cph1808.000webhostapp.com/index.php?msg_id={msg.id}'
url = f'http://localhost:3000/index.php?msg_id={msg.id}'
response = requests.get(url)
# Check the response status code
if response.status_code == 200:
# Request was successful
print('GET request was successful')
# You can access the response content (e.g., HTML) using response.text
else:
print('GET request failed with status code:', response.status_code)
else:
print("No messages in the chat")
async def get_newest_message_id():
global newest_msg_id_source
# Replace 'chat_username' with the username or chat ID of the group
chat = await client.get_entity(download_chat_id)
# Get the chat history
messages = await client.get_messages(chat, limit=1)
# Check if there is at least one message
if messages:
# Get the ID of the newest message
message = messages[0]
# Check the type of the message using the message's type
if CheckMsgMedia(message) == 1 and newest_msg_id_source < message.id:
newest_msg_id_source = message.id
print("msg video found")
print(f"vid size: {message.video.size}")
await DownLoadVid(message.video, newest_msg_id_source)
await UpLoadVid(newest_msg_id_source)
else:
print("No messages in the chat")
def CheckMsgMedia(msg):
if msg.video:
return 1
else:
return 0
async def DownLoadVid(vid, vid_name):
file_path = download_path + str(vid_name) + ".mp4"
await client.download_media(vid, file=file_path)
print("download file successfully")
print("editing vid")
edit_video.EditVid(vid_name)
async def UpLoadVid(vid_name):
file_path = upload_path + str(vid_name) + "_edited.mp4"
channel = await client.get_entity(upload_chat_id)
print("uploading")
await client.send_file(channel, file_path)
print("upload successfully")
# --------------------------------------------------------------------------------
@client.on(events.NewMessage)
async def my_event_handler(event):
# download and edit new video
if download_chat_id == event.chat_id:
asyncio.gather(get_newest_message_id())
# await event.reply('hi!')
print("replied")
# send msg when edit complete
if upload_chat_id == event.chat_id:
await SendMsg()
client.start()
client.run_until_disconnected()
# -----------------------------------------------------------------------------------