aboutsummaryrefslogtreecommitdiff
path: root/modules/youtube.py
diff options
context:
space:
mode:
authorGravatar dngfx2018-09-23 00:55:36 +0100
committerGravatar dngfx2018-09-23 00:55:36 +0100
commite5283ed2e20e95df58c7a162fe76f88ebf3694e1 (patch)
tree59d34c61499cf85bad37179cb59a853e479ff60e /modules/youtube.py
parentclear channel.games properly. (diff)
signature
Update last.fm to include a youtube link. Also change the module name to last.fm
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..20dc072b 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.youtubefromlastfm").hook(self.get_yt_from_lastfm)
+
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 get_yt_from_lastfm(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