add youtube module
This commit is contained in:
parent
ae045c6082
commit
97e2cc712e
23
modules/youtube.py
Normal file
23
modules/youtube.py
Normal file
|
@ -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}")
|
Loading…
Reference in New Issue
Block a user