feat: improved the lyrics support for bandcamp
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Hazel 2024-04-19 12:17:08 +02:00
parent 3c5bbc19af
commit b933c6ac14
3 changed files with 19 additions and 3 deletions

View File

@ -7,7 +7,8 @@ logging.getLogger().setLevel(logging.DEBUG)
if __name__ == "__main__": if __name__ == "__main__":
commands = [ commands = [
"s: #a Ghost Bath", "s: #a Ghost Bath",
"d: 0", "0",
"1",
] ]

View File

@ -1,18 +1,26 @@
import mistune import mistune
import html2markdown import html2markdown
def plain_to_markdown(plain: str) -> str:
return plain.replace("\n", " \n")
class FormattedText: class FormattedText:
html = "" html = ""
def __init__( def __init__(
self, self,
markdown: str = None, markdown: str = None,
html: str = None html: str = None,
plain: str = None,
) -> None: ) -> None:
if html is not None: if html is not None:
self.html = html self.html = html
elif markdown is not None: elif markdown is not None:
self.html = mistune.markdown(markdown) self.html = mistune.markdown(markdown)
elif plain is not None:
self.html = mistune.markdown(plain_to_markdown(plain))
@property @property
def is_empty(self) -> bool: def is_empty(self) -> bool:

View File

@ -18,7 +18,8 @@ from ..objects import (
Contact, Contact,
ID3Timestamp, ID3Timestamp,
Lyrics, Lyrics,
FormattedText FormattedText,
Artwork,
) )
from ..connection import Connection from ..connection import Connection
from ..utils.support_classes.download_result import DownloadResult from ..utils.support_classes.download_result import DownloadResult
@ -254,6 +255,12 @@ class Bandcamp(Page):
return artist return artist
def _parse_track_element(self, track: dict) -> Optional[Song]: def _parse_track_element(self, track: dict) -> Optional[Song]:
lyrics_list: List[Lyrics] = []
_lyrics: Optional[str] = track.get("item", {}).get("recordingOf", {}).get("lyrics", {}).get("text")
if _lyrics is not None:
lyrics_list.append(Lyrics(text=FormattedText(plain=_lyrics)))
return Song( return Song(
title=clean_song_title(track["item"]["name"]), title=clean_song_title(track["item"]["name"]),
source_list=[Source(self.SOURCE_TYPE, track["item"]["mainEntityOfPage"])], source_list=[Source(self.SOURCE_TYPE, track["item"]["mainEntityOfPage"])],