chore: Add support for fetching raw cover images

This commit is contained in:
Rafael Moraes 2024-06-02 21:15:03 -03:00
parent 57ee6e1db8
commit b8bd406d74
3 changed files with 21 additions and 1 deletions

View File

@ -197,3 +197,5 @@ The following synced lyrics formats are available:
The following cover formats are available:
* `jpg`
* `png`
* `raw`
* Gets the raw cover without any processing in JPEG format.

View File

@ -353,8 +353,25 @@ class Downloader:
return self.output_path.joinpath(*final_path_folder).joinpath(*final_path_file)
def get_cover_url(self, metadata: dict) -> str:
if self.cover_format == CoverFormat.RAW:
return self._get_raw_cover_url(metadata["attributes"]["artwork"]["url"])
return self._get_cover_url(metadata["attributes"]["artwork"]["url"])
def _get_raw_cover_url(self, cover_url_template: str) -> str:
return re.sub(
r"image/thumb/",
"",
re.sub(
r"is1-ssl",
"a1",
re.sub(
r"/\{w\}x\{h\}([a-z]{2})\.jpg",
"",
cover_url_template,
),
),
)
def _get_cover_url(self, cover_url_template: str) -> str:
return re.sub(
r"\{w\}x\{h\}([a-z]{2})\.jpg",
@ -409,7 +426,7 @@ class Downloader:
self.get_url_response_bytes(cover_url),
imageformat=(
MP4Cover.FORMAT_JPEG
if self.cover_format == CoverFormat.JPG
if self.cover_format in (CoverFormat.JPG, CoverFormat.RAW)
else MP4Cover.FORMAT_PNG
),
)

View File

@ -46,3 +46,4 @@ class PostQuality(Enum):
class CoverFormat(Enum):
JPG = "jpg"
PNG = "png"
RAW = "raw"