Provide lyrics service through D-Bus.
Project description
LyriK
A lyrics provider running on D-Bus.
Installation
Use pip
$ 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.
e.g.
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()
)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
lyrik-0.1.0.tar.gz
(19.9 kB
view details)
Built Distribution
lyrik-0.1.0-py3-none-any.whl
(22.8 kB
view details)
File details
Details for the file lyrik-0.1.0.tar.gz
.
File metadata
- Download URL: lyrik-0.1.0.tar.gz
- Upload date:
- Size: 19.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.11.3 Linux/6.4.6-zen1-1-zen
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 66ff87eb80a533f792bf1f30c12ecae319a535162f66dcc9a361162cf5f026d3 |
|
MD5 | e7a76898edbf1ddbd70524c4f38dd471 |
|
BLAKE2b-256 | bc9fc93c2bf525f1f0e690f05ab248e4b3c5921cf848ef7794a7d629e3736183 |
File details
Details for the file lyrik-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: lyrik-0.1.0-py3-none-any.whl
- Upload date:
- Size: 22.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.11.3 Linux/6.4.6-zen1-1-zen
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 014776e36730ba6099321ac05b8f24d0633ad310afe3033151c70b0813807567 |
|
MD5 | 4db68e5b731f4da88d69167f4eaac531 |
|
BLAKE2b-256 | fce183972ddd79a83eedddfb7fb5b4d47d1e5c05040d8739ae108483f682795b |