Merge pull request #44 from ChocoMeow/Lrclib-Lyrics
Feature: Lrclib lyrics
This commit is contained in:
@@ -49,6 +49,7 @@ Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_6; en-US) AppleWebKit/530.6 (KHTM
|
|||||||
Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_6; en-US) AppleWebKit/530.5 (KHTML, like Gecko) Chrome/ Safari/530.5'''
|
Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_6; en-US) AppleWebKit/530.5 (KHTML, like Gecko) Chrome/ Safari/530.5'''
|
||||||
|
|
||||||
LYRIST_ENDPOINT = "https://lyrist.vercel.app/api/"
|
LYRIST_ENDPOINT = "https://lyrist.vercel.app/api/"
|
||||||
|
LRCLIB_ENDPOINT = "https://lrclib.net/api/"
|
||||||
|
|
||||||
class LyricsPlatform(ABC):
|
class LyricsPlatform(ABC):
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
@@ -196,8 +197,26 @@ class Lyrist(LyricsPlatform):
|
|||||||
except:
|
except:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
class Lrclib(LyricsPlatform):
|
||||||
|
async def get(self, url, params: dict = None) -> list[dict]:
|
||||||
|
try:
|
||||||
|
async with aiohttp.ClientSession() as session:
|
||||||
|
resp = await session.get(url=url, headers={'User-Agent': random.choice(userAgents)}, params=params)
|
||||||
|
if resp.status != 200:
|
||||||
|
return None
|
||||||
|
return await resp.json()
|
||||||
|
except:
|
||||||
|
return []
|
||||||
|
|
||||||
|
async def get_lyrics(self, title, artist):
|
||||||
|
params = {"q": f"{title} - {artist}"}
|
||||||
|
result = await self.get(LRCLIB_ENDPOINT + "search", params)
|
||||||
|
if result:
|
||||||
|
return {"default": result[0].get("plainLyrics", "")}
|
||||||
|
|
||||||
lyricsPlatform: dict[str, LyricsPlatform] = {
|
lyricsPlatform: dict[str, LyricsPlatform] = {
|
||||||
"a_zlyrics": A_ZLyrics,
|
"a_zlyrics": A_ZLyrics,
|
||||||
"genius": Genius,
|
"genius": Genius,
|
||||||
"lyrist": Lyrist
|
"lyrist": Lyrist,
|
||||||
|
"lrclib": Lrclib
|
||||||
}
|
}
|
||||||
@@ -24,7 +24,7 @@ SOFTWARE.
|
|||||||
__version__ = "1.4"
|
__version__ = "1.4"
|
||||||
__author__ = 'Vocard Development, Choco'
|
__author__ = 'Vocard Development, Choco'
|
||||||
__license__ = "MIT"
|
__license__ = "MIT"
|
||||||
__copyright__ = "Copyright 2023 (c) Vocard Development, Choco"
|
__copyright__ = "Copyright 2023 - present (c) Vocard Development, Choco"
|
||||||
|
|
||||||
from .enums import SearchType, LoopType
|
from .enums import SearchType, LoopType
|
||||||
from .events import *
|
from .events import *
|
||||||
|
|||||||
Reference in New Issue
Block a user