-
Notifications
You must be signed in to change notification settings - Fork 3k
Expand file tree
/
Copy pathhelpers.py
More file actions
75 lines (65 loc) · 2.45 KB
/
helpers.py
File metadata and controls
75 lines (65 loc) · 2.45 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
#Github.com/Vasusen-code
from main.utils import logger
from pyrogram.errors import FloodWait, InviteHashInvalid, InviteHashExpired, UserAlreadyParticipant
from telethon import errors, events
import asyncio, subprocess, re, os, time
from pathlib import Path
from datetime import datetime as dt
#Join private chat-------------------------------------------------------------------------------------------------------------
async def join(client, invite_link):
try:
await client.join_chat(invite_link)
return "Successfully joined the Channel"
except UserAlreadyParticipant:
return "User is already a participant."
except (InviteHashInvalid, InviteHashExpired):
return "Could not join. Maybe your link is expired or Invalid."
except FloodWait:
return "Too many requests, try again later."
except Exception as e:
logger.error(e)
return "Could not join, try joining manually."
#Regex---------------------------------------------------------------------------------------------------------------
#to get the url from event
def get_link(string):
regex = r"(?i)\b((?:https?://|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'\".,<>?«»“”‘’]))"
url = re.findall(regex,string)
try:
link = [x[0] for x in url][0]
if link:
return link
else:
return False
except Exception:
return False
#Screenshot---------------------------------------------------------------------------------------------------------------
def hhmmss(seconds):
x = time.strftime('%H:%M:%S',time.gmtime(seconds))
return x
async def screenshot(video, duration, sender):
if os.path.exists(f'{sender}.jpg'):
return f'{sender}.jpg'
time_stamp = hhmmss(int(duration)/2)
out = dt.now().isoformat("_", "seconds") + ".jpg"
cmd = ["ffmpeg",
"-ss",
f"{time_stamp}",
"-i",
f"{video}",
"-frames:v",
"1",
f"{out}",
"-y"
]
process = await asyncio.create_subprocess_exec(
*cmd,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE
)
stdout, stderr = await process.communicate()
x = stderr.decode().strip()
y = stdout.decode().strip()
if os.path.isfile(out):
return out
else:
None