Path: blob/master/bot/helper/ext_utils/links_utils.py
1631 views
from re import match as re_match123def is_magnet(url: str):4return bool(re_match(r"^magnet:\?.*xt=urn:(btih|btmh):([a-zA-Z0-9]{32,40}|[a-z2-7]{32}).*", url))567def is_url(url: str):8return bool(9re_match(10r"^(?!\/)(rtmps?:\/\/|mms:\/\/|rtsp:\/\/|https?:\/\/|ftp:\/\/)?([^\/:]+:[^\/@]+@)?(www\.)?(?=[^\/:\s]+\.[^\/:\s]+)([^\/:\s]+\.[^\/:\s]+)(:\d+)?(\/[^#\s]*[\s\S]*)?(\?[^#\s]*)?(#.*)?$",11url,12)13)141516def is_gdrive_link(url: str):17return "drive.google.com" in url or "drive.usercontent.google.com" in url181920def is_telegram_link(url: str):21return url.startswith(("https://t.me/", "tg://openmessage?user_id="))222324def is_share_link(url: str):25return bool(26re_match(27r"https?:\/\/.+\.gdtot\.\S+|https?:\/\/(filepress|filebee|appdrive|gdflix)\.\S+",28url,29)30)313233def is_rclone_path(path: str):34return bool(35re_match(36r"^(mrcc:)?(?!(magnet:|mtp:|sa:|tp:))(?![- ])[a-zA-Z0-9_\. -]+(?<! ):(?!.*\/\/).*$|^rcl$",37path,38)39)404142def is_gdrive_id(id_: str):43return bool(44re_match(45r"^(tp:|sa:|mtp:)?(?:[a-zA-Z0-9-_]{33}|[a-zA-Z0-9_-]{19})$|^gdl$|^(tp:|mtp:)?root$",46id_,47)48)495051