summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPratyush Desai2021-08-03 03:41:47 +0530
committerPratyush Desai2021-08-03 03:41:47 +0530
commita72c46ea64fc83478831cbf27ce16885c87f813d (patch)
treee5c6d93dbbf704a3966121cf53b901ba12dd9072
parenta04d10e8fe285d443439ae81c305a92250e28176 (diff)
downloadspotify-a72c46ea64fc83478831cbf27ce16885c87f813d.tar.gz
spotify-a72c46ea64fc83478831cbf27ce16885c87f813d.tar.bz2
spotify-a72c46ea64fc83478831cbf27ce16885c87f813d.zip
parity with old code base
-rw-r--r--config.py5
-rw-r--r--plugin.py42
2 files changed, 47 insertions, 0 deletions
diff --git a/config.py b/config.py
index 9849129..c170fb9 100644
--- a/config.py
+++ b/config.py
@@ -52,5 +52,10 @@ Spotify = conf.registerPlugin('Spotify')
# conf.registerGlobalValue(Spotify, 'someConfigVariableName',
# registry.Boolean(False, _("""Help for someConfigVariableName.""")))
+conf.registerGlobalValue(Spotify, 'clientID',
+ registry.string('', """ Sets the ClientID obtainable from https://developer.spotify.com/""", private=True))
+
+conf.registerGlobalValue(Spotify, 'clientSECRET',
+ registry.string('', """ Sets the ClientSECRET obtainable from https://developer.spotify.com/""", private=True))
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
diff --git a/plugin.py b/plugin.py
index c117a0d..adbe893 100644
--- a/plugin.py
+++ b/plugin.py
@@ -28,6 +28,12 @@
###
+# My Libs
+import spotipy
+import os
+from spotipy.oauth2 import SpotifyClientCredentials
+
+# Limnoria Libs
from supybot import utils, plugins, ircutils, callbacks
from supybot.commands import *
try:
@@ -43,7 +49,43 @@ class Spotify(callbacks.Plugin):
"""Limnoria Spotify"""
threaded = True
+ def sp(self, irc, msg, args, song):
+ """<artist> <song>
+ The track details for which the URL/trackID is desired.
+ """
+ clientID = self.registryValue('clientID')
+ if not clientID:
+ irc.error("The clientID is not set. Please set it via "
+ "'config plugins.spotify.clientID' and reload the plugin. "
+ "You can sign up for it from "
+ "https://developer.spotify.com/", Raise=True)
+
+ clientSECRET = self.registryValue('clientSECRET')
+ if not clientSECRET:
+ irc.error("The clientSECRET is not set. Please set it via "
+ "'config plugins.spotify.clientSECRET' and reload the plugin. "
+ "You can sign up for it from "
+ "https://developer.spotify.com/", Raise=True)
+
+ os.getenv('SPOTIPY_CLIENT_ID') = clientID
+ os.getenv('SPOTIPY_CLIENT_SECRET') = clientSECRET
+
+ spotified = spotipy.Spotify(client_credentials_manager=SpotifyClientCredentials())
+ results = spotified.search(song)
+ items = results['tracks']['items']
+ if len(items) > 0:
+ track = items[0]
+ track_uri = track['uri']
+ track_artist = track['artists'][0]['name']
+ track_album = track['album']['name']
+ track_name =track['name']
+ track_url = track['external_urls']['spotify']
+ re = utils.str.format(' 🎶️ \x02\x0301,03SPOTIFY\x0f 🎶️ %s by %s from %s at %s and uri %s', track_name, track_artist, track_album, track_url, track_uri)
+ irc.reply(re)
+ else:
+ irc.error('No Results')
+ sp = wrap(sp, ['text'])
Class = Spotify