From b933c6ac1418309a392a608e5af75472acc6f320 Mon Sep 17 00:00:00 2001 From: Lars Noack Date: Fri, 19 Apr 2024 12:17:08 +0200 Subject: [PATCH] feat: improved the lyrics support for bandcamp --- development/actual_donwload.py | 3 ++- music_kraken/objects/formatted_text.py | 10 +++++++++- music_kraken/pages/bandcamp.py | 9 ++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/development/actual_donwload.py b/development/actual_donwload.py index abc5fe6..ff96706 100644 --- a/development/actual_donwload.py +++ b/development/actual_donwload.py @@ -7,7 +7,8 @@ logging.getLogger().setLevel(logging.DEBUG) if __name__ == "__main__": commands = [ "s: #a Ghost Bath", - "d: 0", + "0", + "1", ] diff --git a/music_kraken/objects/formatted_text.py b/music_kraken/objects/formatted_text.py index c7ee042..6d95389 100644 --- a/music_kraken/objects/formatted_text.py +++ b/music_kraken/objects/formatted_text.py @@ -1,18 +1,26 @@ import mistune import html2markdown + +def plain_to_markdown(plain: str) -> str: + return plain.replace("\n", " \n") + + class FormattedText: html = "" def __init__( self, markdown: str = None, - html: str = None + html: str = None, + plain: str = None, ) -> None: if html is not None: self.html = html elif markdown is not None: self.html = mistune.markdown(markdown) + elif plain is not None: + self.html = mistune.markdown(plain_to_markdown(plain)) @property def is_empty(self) -> bool: diff --git a/music_kraken/pages/bandcamp.py b/music_kraken/pages/bandcamp.py index a583cd9..f63e30e 100644 --- a/music_kraken/pages/bandcamp.py +++ b/music_kraken/pages/bandcamp.py @@ -18,7 +18,8 @@ from ..objects import ( Contact, ID3Timestamp, Lyrics, - FormattedText + FormattedText, + Artwork, ) from ..connection import Connection from ..utils.support_classes.download_result import DownloadResult @@ -254,6 +255,12 @@ class Bandcamp(Page): return artist 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( title=clean_song_title(track["item"]["name"]), source_list=[Source(self.SOURCE_TYPE, track["item"]["mainEntityOfPage"])],