pygbot/youtube.py

18 lines
549 B
Python

import re
import requests
from bs4 import BeautifulSoup
def gettitle(bot, channel, message):
try:
link = ' '.join(message.split()[1:])
iflinkok = re.search("^http", link)
if iflinkok != None:
page = requests.get(link)
soup = BeautifulSoup(page.text, 'html.parser')
title = soup.find("meta", itemprop="name")["content"]
bot.send(channel, title)
else:
bot.send(channel, "Failed to get title")
except:
bot.send(channel, "Failed to get title")