parity with old code base
This commit is contained in:
parent
a04d10e8fe
commit
a72c46ea64
@ -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:
|
||||
|
42
plugin.py
42
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
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user