Skip to content

Commit 19cb196

Browse files
committed
Added Lrclib lyrics support
1 parent 2648e76 commit 19cb196

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

addons/lyrics.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_6; en-US) AppleWebKit/530.5 (KHTML, like Gecko) Chrome/ Safari/530.5'''
5050

5151
LYRIST_ENDPOINT = "https://lyrist.vercel.app/api/"
52+
LRCLIB_ENDPOINT = "https://lrclib.net/api/"
5253

5354
class LyricsPlatform(ABC):
5455
@abstractmethod
@@ -196,8 +197,26 @@ async def get_lyrics(self, title: str, artist: str) -> Optional[dict[str, str]]:
196197
except:
197198
return None
198199

200+
class Lrclib(LyricsPlatform):
201+
async def get(self, url, params: dict = None) -> list[dict]:
202+
try:
203+
async with aiohttp.ClientSession() as session:
204+
resp = await session.get(url=url, headers={'User-Agent': random.choice(userAgents)}, params=params)
205+
if resp.status != 200:
206+
return None
207+
return await resp.json()
208+
except:
209+
return []
210+
211+
async def get_lyrics(self, title, artist):
212+
params = {"q": f"{title} - {artist}"}
213+
result = await self.get(LRCLIB_ENDPOINT + "search", params)
214+
lyrics = result[0].get("plainLyrics", "") if result else ""
215+
return {"default": lyrics}
216+
199217
lyricsPlatform: dict[str, LyricsPlatform] = {
200218
"a_zlyrics": A_ZLyrics,
201219
"genius": Genius,
202-
"lyrist": Lyrist
220+
"lyrist": Lyrist,
221+
"lrclib": Lrclib
203222
}

voicelink/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
__version__ = "1.4"
2525
__author__ = 'Vocard Development, Choco'
2626
__license__ = "MIT"
27-
__copyright__ = "Copyright 2023 (c) Vocard Development, Choco"
27+
__copyright__ = "Copyright 2023 - present (c) Vocard Development, Choco"
2828

2929
from .enums import SearchType, LoopType
3030
from .events import *

0 commit comments

Comments
 (0)