dj-embe/framework/spotify.py

31 lines
940 B
Python

from asyncio import AbstractEventLoop
import spotipy
from spotipy import MemoryCacheHandler
from spotipy.oauth2 import SpotifyClientCredentials
from config import SpotifyConfig
class Spotify:
def __init__(self, loop: AbstractEventLoop, config: SpotifyConfig) -> None:
self.loop = loop
self.client = spotipy.Spotify(
auth_manager=SpotifyClientCredentials(
client_id=config.clientId,
client_secret=config.clientSecret,
cache_handler=MemoryCacheHandler(),
),
)
self.region = config.region
async def getTrack(self, url: str):
return await self.loop.run_in_executor(
None, lambda: self.client.track(url, market=self.region)
)
async def getPlaylist(self, url: str):
return await self.loop.run_in_executor(
None, lambda: self.client.playlist(url, market=self.region)
)