aboutsummaryrefslogtreecommitdiff
path: root/modules/youtube.py
diff options
context:
space:
mode:
authorGravatar jesopo2018-09-24 12:28:33 +0100
committerGravatar GitHub2018-09-24 12:28:33 +0100
commit7522b0fae22c41c8e57d5494a239c97736e2c2b6 (patch)
tree0da6d00ce4bb86ddc88acff85ef6e3ef3f7fba4b /modules/youtube.py
parentAsk for alias of first server in start.py (diff)
parentMerge pull request #1 from jesopo/master (diff)
Merge pull request #23 from dngfx/master
Make tweets say Twitter instead of tweets, and update ducks
Diffstat (limited to 'modules/youtube.py')
-rw-r--r--modules/youtube.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/modules/youtube.py b/modules/youtube.py
index 3d075f64..c70e9ef8 100644
--- a/modules/youtube.py
+++ b/modules/youtube.py
@@ -24,6 +24,8 @@ class Module(object):
help="Find a video on youtube", usage="[query]")
events.on("received.message.channel").hook(self.channel_message)
+ events.on("get.searchyoutube").hook(self.search_video)
+
exports.add("channelset", {"setting": "auto-youtube",
"help": "Disable/Enable automatically getting info from "
"youtube URLs", "validate": Utils.bool_or_none})
@@ -63,6 +65,22 @@ class Module(object):
video_title, video_duration, video_uploader, "{:,}".format(
int(video_views)), video_opinions, URL_YOUTUBESHORT % video_id)
+ def search_video(self, event):
+ search = event["query"]
+ video_id = ""
+
+ search_page = Utils.get_url(URL_YOUTUBESEARCH,
+ get_params={"q": search, "part": "snippet",
+ "maxResults": "1", "type": "video",
+ "key": self.bot.config["google-api-key"]},
+ json=True)
+
+ if search_page:
+ if search_page["pageInfo"]["totalResults"] > 0:
+ video_id = search_page["items"][0]["id"]["videoId"]
+ return "https://youtu.be/%s" % video_id
+
+
def yt(self, event):
video_id = None
search = None