From 69d58eede2e9bf83aa1ed1d8fcf956efde494726 Mon Sep 17 00:00:00 2001 From: jesopo Date: Wed, 3 Oct 2018 13:22:37 +0100 Subject: Move src/Utils.py in to src/utils/, splitting functionality out in to modules of related functionality --- modules/youtube.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'modules/youtube.py') diff --git a/modules/youtube.py b/modules/youtube.py index c44ac7fa..0e976aec 100644 --- a/modules/youtube.py +++ b/modules/youtube.py @@ -1,7 +1,7 @@ #--require-config google-api-key import re -from src import ModuleManager, Utils +from src import ModuleManager, utils REGEX_YOUTUBE = re.compile( "https?://(?:www.)?(?:youtu.be/|youtube.com/watch\?[\S]*v=)([\w\-]{11})", @@ -16,12 +16,12 @@ URL_YOUTUBESHORT = "https://youtu.be/%s" ARROW_UP = "▲" ARROW_DOWN = "▼" -@Utils.export("channelset", {"setting": "auto-youtube", +@utils.export("channelset", {"setting": "auto-youtube", "help": "Disable/Enable automatically getting info from youtube URLs", - "validate": Utils.bool_or_none}) + "validate": utils.bool_or_none}) class Module(ModuleManager.BaseModule): def get_video_page(self, video_id, part): - return Utils.get_url(URL_YOUTUBEVIDEO, get_params={"part": part, + return utils.http.get_url(URL_YOUTUBEVIDEO, get_params={"part": part, "id": video_id, "key": self.bot.config["google-api-key"]}, json=True) def video_details(self, video_id): @@ -55,12 +55,12 @@ class Module(ModuleManager.BaseModule): video_title, video_duration, video_uploader, "{:,}".format( int(video_views)), video_opinions, URL_YOUTUBESHORT % video_id) - @Utils.hook("get.searchyoutube") + @utils.hook("get.searchyoutube") def search_video(self, event): search = event["query"] video_id = "" - search_page = Utils.get_url(URL_YOUTUBESEARCH, + search_page = utils.http.get_url(URL_YOUTUBESEARCH, get_params={"q": search, "part": "snippet", "maxResults": "1", "type": "video", "key": self.bot.config["google-api-key"]}, @@ -71,7 +71,7 @@ class Module(ModuleManager.BaseModule): video_id = search_page["items"][0]["id"]["videoId"] return "https://youtu.be/%s" % video_id - @Utils.hook("received.command.yt|youtube") + @utils.hook("received.command.yt|youtube") def yt(self, event): """ :help: Find a video on youtube @@ -87,7 +87,7 @@ class Module(ModuleManager.BaseModule): video_id = re.search(REGEX_YOUTUBE, last_youtube.message).group(1) if search or video_id: if not video_id: - search_page = Utils.get_url(URL_YOUTUBESEARCH, + search_page = utils.http.get_url(URL_YOUTUBESEARCH, get_params={"q": search, "part": "snippet", "maxResults": "1", "type": "video", "key": self.bot.config["google-api-key"]}, @@ -106,7 +106,7 @@ class Module(ModuleManager.BaseModule): else: event["stderr"].write("No search phrase provided") - @Utils.hook("received.message.channel") + @utils.hook("received.message.channel") def channel_message(self, event): match = re.search(REGEX_YOUTUBE, event["message"]) if match and event["channel"].get_setting("auto-youtube", False): -- cgit v1.3.1-10-gc9f91