Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
anasty17
GitHub Repository: anasty17/mirror-leech-telegram-bot
Path: blob/master/bot/helper/ext_utils/links_utils.py
1631 views
1
from re import match as re_match
2
3
4
def is_magnet(url: str):
5
return bool(re_match(r"^magnet:\?.*xt=urn:(btih|btmh):([a-zA-Z0-9]{32,40}|[a-z2-7]{32}).*", url))
6
7
8
def is_url(url: str):
9
return bool(
10
re_match(
11
r"^(?!\/)(rtmps?:\/\/|mms:\/\/|rtsp:\/\/|https?:\/\/|ftp:\/\/)?([^\/:]+:[^\/@]+@)?(www\.)?(?=[^\/:\s]+\.[^\/:\s]+)([^\/:\s]+\.[^\/:\s]+)(:\d+)?(\/[^#\s]*[\s\S]*)?(\?[^#\s]*)?(#.*)?$",
12
url,
13
)
14
)
15
16
17
def is_gdrive_link(url: str):
18
return "drive.google.com" in url or "drive.usercontent.google.com" in url
19
20
21
def is_telegram_link(url: str):
22
return url.startswith(("https://t.me/", "tg://openmessage?user_id="))
23
24
25
def is_share_link(url: str):
26
return bool(
27
re_match(
28
r"https?:\/\/.+\.gdtot\.\S+|https?:\/\/(filepress|filebee|appdrive|gdflix)\.\S+",
29
url,
30
)
31
)
32
33
34
def is_rclone_path(path: str):
35
return bool(
36
re_match(
37
r"^(mrcc:)?(?!(magnet:|mtp:|sa:|tp:))(?![- ])[a-zA-Z0-9_\. -]+(?<! ):(?!.*\/\/).*$|^rcl$",
38
path,
39
)
40
)
41
42
43
def is_gdrive_id(id_: str):
44
return bool(
45
re_match(
46
r"^(tp:|sa:|mtp:)?(?:[a-zA-Z0-9-_]{33}|[a-zA-Z0-9_-]{19})$|^gdl$|^(tp:|mtp:)?root$",
47
id_,
48
)
49
)
50
51