26 lines
759 B
Python
26 lines
759 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, self.region)
|
|
)
|