diff options
| author | Pratyush Desai | 2021-08-03 03:41:47 +0530 |
|---|---|---|
| committer | Pratyush Desai | 2021-08-03 03:41:47 +0530 |
| commit | a72c46ea64fc83478831cbf27ce16885c87f813d (patch) | |
| tree | e5c6d93dbbf704a3966121cf53b901ba12dd9072 | |
| parent | a04d10e8fe285d443439ae81c305a92250e28176 (diff) | |
| download | spotify-a72c46ea64fc83478831cbf27ce16885c87f813d.tar.gz spotify-a72c46ea64fc83478831cbf27ce16885c87f813d.tar.bz2 spotify-a72c46ea64fc83478831cbf27ce16885c87f813d.zip | |
parity with old code base
| -rw-r--r-- | config.py | 5 | ||||
| -rw-r--r-- | plugin.py | 42 |
2 files changed, 47 insertions, 0 deletions
@@ -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: @@ -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 |
