Skip to content

Commit

Permalink
Added Lrclib lyrics support
Browse files Browse the repository at this point in the history
  • Loading branch information
ChocoMeow committed Dec 16, 2024
1 parent 2648e76 commit 19cb196
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
21 changes: 20 additions & 1 deletion addons/lyrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
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/"
LRCLIB_ENDPOINT = "https://lrclib.net/api/"

class LyricsPlatform(ABC):
@abstractmethod
Expand Down Expand Up @@ -196,8 +197,26 @@ async def get_lyrics(self, title: str, artist: str) -> Optional[dict[str, str]]:
except:
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)
lyrics = result[0].get("plainLyrics", "") if result else ""
return {"default": lyrics}

lyricsPlatform: dict[str, LyricsPlatform] = {
"a_zlyrics": A_ZLyrics,
"genius": Genius,
"lyrist": Lyrist
"lyrist": Lyrist,
"lrclib": Lrclib
}
2 changes: 1 addition & 1 deletion voicelink/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
__version__ = "1.4"
__author__ = 'Vocard Development, Choco'
__license__ = "MIT"
__copyright__ = "Copyright 2023 (c) Vocard Development, Choco"
__copyright__ = "Copyright 2023 - present (c) Vocard Development, Choco"

from .enums import SearchType, LoopType
from .events import *
Expand Down

0 comments on commit 19cb196

Please sign in to comment.