# LyriK
A lyrics provider running on D-Bus.
## Installation
Use `pip`
```shell
$ pip install lyrik
```
But at present, you cannot do it because it is still on development.
## Extension
### Interface
`Interface` can be written to provide lyrics from other resources.<br>
e.g.
```py
from pycloudmusic.object.music163 import Music
from netwrok_interface import (
AbstractNetworkInterface,
LyricsResponse,
NoFoundError,
InternetError,
)
from pycloudmusic import Music163Api
from pycloudmusic.error import Music163BadCode, CannotConnectApi, Music163BadData
from typing import Generator, Tuple, Dict, Any
import asyncio
class NeteaseMusicInterface(AbstractNetworkInterface):
def __init__(self) -> None:
self.__api = Music163Api()
@classmethod
def name(cls) -> str:
return "NeteaseMusicInterface"
async def get_lyrics(
self, title: str, album: str, artist: str, hazy_search=True
) -> LyricsResponse:
result: tuple[
int, Generator[Music, None, None]
] = await self.__api.search_music(
"{0} {1} {2}".format(title, album, " ".join(artist)), 0
)
(count, generator) = result
music_list: list[tuple[int, Music]] = []
for page in range(count // 30 if count % 30 == 0 else count // 30 + 1):
try:
result: tuple[
int, Generator[Music, None, None]
] = await self.__api.search_music(
"{0} {1} {2}".format(title, album, " ".join(artist)), page
)
for music in generator:
if not music.name[0] == title:
continue
if music.album_data["name"] == album and set(
a["name"] for a in music.artist
) == set(artist):
lyrics = await music.lyric()
return LyricsResponse(
False,
lyrics["lrc"]["lyric"],
None
if lyrics["tlyric"]["lyric"] == ""
else {"zh_CN": lyrics["tlyric"]["lyric"]},
self.name()
)
elif hazy_search:
weight = 0
if music.album_data["name"] == album:
weight += 1
if set(a["name"] for a in music.artist) == set(artist):
weight += 1
music_list.append((weight, music))
except KeyError as exception:
raise NoFoundError(self, title, artist, album) from exception
except (Music163BadData, Music163BadCode, CannotConnectApi) as exception:
raise InternetError(self) from exception
if len(music_list) == 0:
raise NoFoundError(self, title, artist, album)
lyrics = await max(music_list, key=lambda x: x[0])[1].lyric()
return LyricsResponse(
True,
lyrics["lrc"]["lyric"],
None
if lyrics["tlyric"]["lyric"] == ""
else {"zh_CN": lyrics["tlyric"]["lyric"]},
self.name()
)
```
Raw data
{
"_id": null,
"home_page": "https://github.com/LiYulin-s/LyriK",
"name": "lyrik",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.10,<4.0",
"maintainer_email": "",
"keywords": "lyrics,dbus",
"author": "Lee_Yurin",
"author_email": "liyulin.self@foxmail.com",
"download_url": "https://files.pythonhosted.org/packages/bc/9f/c93c2bf525f1f0e690f05ab248e4b3c5921cf848ef7794a7d629e3736183/lyrik-0.1.0.tar.gz",
"platform": null,
"description": "# LyriK\nA lyrics provider running on D-Bus.\n## Installation\nUse `pip`\n```shell\n$ pip install lyrik\n```\nBut at present, you cannot do it because it is still on development.\n\n## Extension\n### Interface\n`Interface` can be written to provide lyrics from other resources.<br>\ne.g.\n```py\nfrom pycloudmusic.object.music163 import Music\n\nfrom netwrok_interface import (\n AbstractNetworkInterface,\n LyricsResponse,\n NoFoundError,\n InternetError,\n)\n\nfrom pycloudmusic import Music163Api\n\nfrom pycloudmusic.error import Music163BadCode, CannotConnectApi, Music163BadData\n\nfrom typing import Generator, Tuple, Dict, Any\n\nimport asyncio\n\n\nclass NeteaseMusicInterface(AbstractNetworkInterface):\n def __init__(self) -> None:\n self.__api = Music163Api()\n\n @classmethod\n def name(cls) -> str:\n return \"NeteaseMusicInterface\"\n\n async def get_lyrics(\n self, title: str, album: str, artist: str, hazy_search=True\n ) -> LyricsResponse:\n result: tuple[\n int, Generator[Music, None, None]\n ] = await self.__api.search_music(\n \"{0} {1} {2}\".format(title, album, \" \".join(artist)), 0\n )\n (count, generator) = result\n music_list: list[tuple[int, Music]] = []\n for page in range(count // 30 if count % 30 == 0 else count // 30 + 1):\n try:\n result: tuple[\n int, Generator[Music, None, None]\n ] = await self.__api.search_music(\n \"{0} {1} {2}\".format(title, album, \" \".join(artist)), page\n )\n for music in generator:\n if not music.name[0] == title:\n continue\n if music.album_data[\"name\"] == album and set(\n a[\"name\"] for a in music.artist\n ) == set(artist):\n lyrics = await music.lyric()\n return LyricsResponse(\n False,\n lyrics[\"lrc\"][\"lyric\"],\n None\n if lyrics[\"tlyric\"][\"lyric\"] == \"\"\n else {\"zh_CN\": lyrics[\"tlyric\"][\"lyric\"]},\n self.name()\n )\n elif hazy_search:\n weight = 0\n if music.album_data[\"name\"] == album:\n weight += 1\n if set(a[\"name\"] for a in music.artist) == set(artist):\n weight += 1\n music_list.append((weight, music))\n except KeyError as exception:\n raise NoFoundError(self, title, artist, album) from exception\n except (Music163BadData, Music163BadCode, CannotConnectApi) as exception:\n raise InternetError(self) from exception\n if len(music_list) == 0:\n raise NoFoundError(self, title, artist, album)\n lyrics = await max(music_list, key=lambda x: x[0])[1].lyric()\n return LyricsResponse(\n True,\n lyrics[\"lrc\"][\"lyric\"],\n None\n if lyrics[\"tlyric\"][\"lyric\"] == \"\"\n else {\"zh_CN\": lyrics[\"tlyric\"][\"lyric\"]},\n self.name()\n )\n```\n",
"bugtrack_url": null,
"license": "GPLv3",
"summary": "Provide lyrics service through D-Bus.",
"version": "0.1.0",
"project_urls": {
"Homepage": "https://github.com/LiYulin-s/LyriK"
},
"split_keywords": [
"lyrics",
"dbus"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "fce183972ddd79a83eedddfb7fb5b4d47d1e5c05040d8739ae108483f682795b",
"md5": "4db68e5b731f4da88d69167f4eaac531",
"sha256": "014776e36730ba6099321ac05b8f24d0633ad310afe3033151c70b0813807567"
},
"downloads": -1,
"filename": "lyrik-0.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "4db68e5b731f4da88d69167f4eaac531",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10,<4.0",
"size": 22765,
"upload_time": "2023-08-06T03:56:01",
"upload_time_iso_8601": "2023-08-06T03:56:01.460711Z",
"url": "https://files.pythonhosted.org/packages/fc/e1/83972ddd79a83eedddfb7fb5b4d47d1e5c05040d8739ae108483f682795b/lyrik-0.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "bc9fc93c2bf525f1f0e690f05ab248e4b3c5921cf848ef7794a7d629e3736183",
"md5": "e7a76898edbf1ddbd70524c4f38dd471",
"sha256": "66ff87eb80a533f792bf1f30c12ecae319a535162f66dcc9a361162cf5f026d3"
},
"downloads": -1,
"filename": "lyrik-0.1.0.tar.gz",
"has_sig": false,
"md5_digest": "e7a76898edbf1ddbd70524c4f38dd471",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10,<4.0",
"size": 19939,
"upload_time": "2023-08-06T03:56:03",
"upload_time_iso_8601": "2023-08-06T03:56:03.748192Z",
"url": "https://files.pythonhosted.org/packages/bc/9f/c93c2bf525f1f0e690f05ab248e4b3c5921cf848ef7794a7d629e3736183/lyrik-0.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-08-06 03:56:03",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "LiYulin-s",
"github_project": "LyriK",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "lyrik"
}