From 97e2cc712e2b217833c1ac75e3fef10cff650537 Mon Sep 17 00:00:00 2001 From: iou1name Date: Fri, 3 Jul 2020 17:09:21 -0400 Subject: [PATCH] add youtube module --- modules/youtube.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 modules/youtube.py diff --git a/modules/youtube.py b/modules/youtube.py new file mode 100644 index 0000000..7fd1f1e --- /dev/null +++ b/modules/youtube.py @@ -0,0 +1,23 @@ +#!/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/") +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}")