diff options
Diffstat (limited to 'plugin.py')
| -rw-r--r-- | plugin.py | 42 |
1 files changed, 42 insertions, 0 deletions
@@ -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 |
