merge youtube module into url module, add twitter/nitter support

This commit is contained in:
iou1name 2020-07-07 07:57:42 -04:00
parent 044c508112
commit 989d1ab726
2 changed files with 17 additions and 24 deletions

View File

@ -30,6 +30,22 @@ def get_puush_fname(bot, url):
bot.msg(f"[ \x0310puu.sh \x03] - \x0304{fname}") 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) @hook(True)
def title_auto(bot, trigger): def title_auto(bot, trigger):
""" """
@ -45,6 +61,7 @@ def title_auto(bot, trigger):
return return
for url in urls: for url in urls:
url = url.replace('twitter.com', 'nitter.net')
broken = False broken = False
for key in bot.url_callbacks: for key in bot.url_callbacks:
if key in url: if key in url:

View File

@ -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}")