New module youtube-title: that retrieve title from a youtube link
This commit is contained in:
parent
fc500bc853
commit
b3274c0dc7
1 changed files with 27 additions and 0 deletions
27
modules/youtube-title.py
Normal file
27
modules/youtube-title.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
import urllib.request
|
||||
from bs4 import BeautifulSoup
|
||||
from nemubot.exception import IRCException
|
||||
from nemubot.hooks import hook
|
||||
from nemubot.tools.web import getURLContent
|
||||
from more import Response
|
||||
|
||||
nemubotversion = 3.4
|
||||
|
||||
def help_tiny():
|
||||
return "Return the video title from a youtube link"
|
||||
|
||||
def help_full():
|
||||
return "No help "
|
||||
|
||||
@hook("cmd_hook", "yt")
|
||||
def get_info_yt(msg):
|
||||
if len(msg.args) <= 0:
|
||||
raise IRCException("Please provide an URL from youtube.com")
|
||||
|
||||
res = list()
|
||||
for url in msg.args:
|
||||
req = getURLContent(url)
|
||||
soup = BeautifulSoup(req)
|
||||
desc = soup.body.find(id='eow-title')
|
||||
res.append(desc.text.strip())
|
||||
return Response(res, channel=msg.channel, nomore="No more description")
|
Loading…
Add table
Add a link
Reference in a new issue