This commit is contained in:
17
garfmain.py
17
garfmain.py
@@ -42,18 +42,19 @@ weather = WeatherAPI()
|
||||
|
||||
|
||||
URL_PATTERNS = [
|
||||
r'https?://(?:www\.)?youtube\.com/watch\?[^\s]*',
|
||||
r'https?://youtu\.be/[^\s]*',
|
||||
r'https?://(?:open\.)?spotify\.com/[^\s]*',
|
||||
r"https?://(?:www\.)?youtube\.com/watch\?[^\s]*",
|
||||
r"https?://youtu\.be/[^\s]*",
|
||||
r"https?://(?:open\.)?spotify\.com/[^\s]*",
|
||||
]
|
||||
|
||||
|
||||
def clean_url(url):
|
||||
try:
|
||||
parsed = urlparse(url)
|
||||
|
||||
if 'youtube.com' in parsed.hostname:
|
||||
if "youtube.com" in parsed.hostname:
|
||||
params = parse_qs(parsed.query)
|
||||
video_id = params.get('v', [None])[0]
|
||||
video_id = params.get("v", [None])[0]
|
||||
if not video_id:
|
||||
return None
|
||||
# timestamp = params.get('t', [None])[0]
|
||||
@@ -61,15 +62,15 @@ def clean_url(url):
|
||||
# return f"https://www.youtube.com/watch?v={video_id}&t={timestamp}"
|
||||
return f"https://www.youtube.com/watch?v={video_id}"
|
||||
|
||||
if 'youtu.be' in parsed.hostname:
|
||||
if "youtu.be" in parsed.hostname:
|
||||
return f"https://youtu.be{parsed.path}"
|
||||
|
||||
if 'spotify.com' in parsed.hostname:
|
||||
if "spotify.com" in parsed.hostname:
|
||||
return f"https://open.spotify.com{parsed.path}"
|
||||
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
|
||||
|
||||
@garfbot.event
|
||||
async def on_ready():
|
||||
|
||||
Reference in New Issue
Block a user