From a72c46ea64fc83478831cbf27ce16885c87f813d Mon Sep 17 00:00:00 2001 From: Pratyush Desai Date: Tue, 3 Aug 2021 03:41:47 +0530 Subject: [PATCH] parity with old code base --- config.py | 5 +++++ plugin.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) 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): + """ + 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