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