merge youtube module into url module, add twitter/nitter support
This commit is contained in:
parent
044c508112
commit
989d1ab726
|
@ -30,6 +30,22 @@ def get_puush_fname(bot, url):
|
|||
bot.msg(f"[ \x0310puu.sh \x03] - \x0304{fname}")
|
||||
|
||||
|
||||
@url_callback("youtube.com/")
|
||||
@url_callback("youtu.be/")
|
||||
def youtube_title(bot, url):
|
||||
"""
|
||||
Retrieve the title of the YouTube video and display it.
|
||||
"""
|
||||
url = "https://www.youtube.com/oembed?url=" + url
|
||||
res = requests.get(url)
|
||||
res.raise_for_status()
|
||||
|
||||
title = res.json()['title']
|
||||
hostname = urlparse(url).hostname
|
||||
|
||||
bot.msg(f"[ \x0310{title} \x03] - \x0304{hostname}")
|
||||
|
||||
|
||||
@hook(True)
|
||||
def title_auto(bot, trigger):
|
||||
"""
|
||||
|
@ -45,6 +61,7 @@ def title_auto(bot, trigger):
|
|||
return
|
||||
|
||||
for url in urls:
|
||||
url = url.replace('twitter.com', 'nitter.net')
|
||||
broken = False
|
||||
for key in bot.url_callbacks:
|
||||
if key in url:
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
"""
|
||||
Display the YouTube video titles.
|
||||
"""
|
||||
from urllib.parse import urlparse
|
||||
|
||||
import requests
|
||||
|
||||
from module import url_callback
|
||||
|
||||
@url_callback("youtube.com/")
|
||||
@url_callback("youtu.be/")
|
||||
def youtube_title(bot, url):
|
||||
"""
|
||||
Retrieve the title of the YouTube video and display it.
|
||||
"""
|
||||
url = "https://www.youtube.com/oembed?url=" + url
|
||||
res = requests.get(url)
|
||||
res.raise_for_status()
|
||||
|
||||
title = res.json()['title']
|
||||
hostname = urlparse(url).hostname
|
||||
|
||||
bot.msg(f"[ \x0310{title} \x03] - \x0304{hostname}")
|
Loading…
Reference in New Issue
Block a user