out = []
for url in result[:10]:
+ if "https://youtu" in url:
+ # does not work, another plugins does the job.
+ continue
if any([re.match(b, url) for b in url_blacklist]):
logger.info('url blacklist match for ' + url)
break
+import logging
import re
import requests
from distbot.bot.worker import Worker
from distbot.common.action import Action
+log = logging.getLogger(__name__)
+
class Youtube(Worker):
- """
- # approach 1: https://www.googleapis.com/youtube/v3/videos?part=snippet&id={YOUTUBE_VIDEO_ID}&fields=items(id,snippet)&key={YOUR_API_KEY}
- # approach 2 (without key): https://www.youtube.com/oembed?url=http://youtube.com/watch?v={YOUTUBE_VIDEO_ID}&format=json
- """
- binding_keys = [
- "#.youtube.#", "#.youtu.#",
- "#.youtube.#.nospoiler.#", "#.youtu.#.nospoiler.#",
- ]
+ binding_keys = Worker.CATCH_ALL
description = "resolves titles of posted youtube URLs"
URL_TEMPLATE = "https://www.youtube.com/oembed?url=http://youtube.com/watch?v={YOUTUBE_VIDEO_ID}&format=json"
regex = re.compile(regex)
result = regex.search(body)
if not result:
+ log.warning("Could not extract youtube video ID from: %s", body)
return None
else:
return result.groupdict().get("youtubeid", None)
return response.json().get("title")
def parse_body(self, msg):
+
+ result = re.findall(r'(https?://youtu[^\s>]+)', msg["body"])
+ if not result or "(nospoiler)" in msg["body"]:
+ return
+
try:
youtube_id = self.get_youtube_id_from_url(msg["body"])
if not youtube_id: