fulvia/modules/youtube.py

25 lines
523 B
Python
Raw Normal View History

2020-07-03 17:09:21 -04:00
#!/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/")
2020-07-07 07:13:11 -04:00
@url_callback("youtu.be/")
2020-07-03 17:09:21 -04:00
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}")