Added some docs to jewtube plugin

This commit is contained in:
mrhanky 2017-06-01 14:50:35 +02:00
parent 1ab4162d4f
commit d0f38ca532
No known key found for this signature in database
GPG Key ID: 67D772C481CB41B8

View File

@ -5,12 +5,11 @@ import re
import requests
from docopt import Dict as DocOptDict
from irc3 import event, IrcBot
from irc3.plugins.command import command
from irc3.utils import IrcString
from . import Plugin
from ..utils import date_from_iso, pp
from ..utils import date_from_iso
# TODO: write better code lol
@ -23,6 +22,7 @@ class YouTube(Plugin):
SEARCH = '{}/search?part=id'.format(URL)
def get_video_data(self, video_id: str):
"""Requests the infos for a video id and formats them."""
data = self._api(self.API, id=video_id)
if not data['items']:
@ -53,8 +53,8 @@ class YouTube(Plugin):
views=views,
date=date.strftime('%Y.%m.%d'))
@event(r'(?i)^:.* PRIVMSG (?P<target>.*) :.*(?:youtube.*?(?:v=|/v/)'
r'|youtu\.be/)(?P<video_id>[-_a-zA-Z0-9]+).*')
@irc3.event(r'(?i)^:.* PRIVMSG (?P<target>.*) :.*(?:youtube.*?(?:v=|/v/)'
r'|youtu\.be/)(?P<video_id>[-_a-zA-Z0-9]+).*')
def youtube_parser(self, target: str, video_id: str):
data = self.get_video_data(video_id)
if data:
@ -81,5 +81,6 @@ class YouTube(Plugin):
@staticmethod
def _api(url: str, **kwargs):
"""Wrapper around requests.get which adds the Google API key."""
kwargs['key'] = os.environ['GOOGLE_API_KEY']
return requests.get(url, params=kwargs).json()