Use global validation util

This commit is contained in:
Alex Camilleri 2024-01-19 12:30:40 +01:00
parent 6f90750eb7
commit f8e6bd78e8
1 changed files with 4 additions and 12 deletions

View File

@ -7,6 +7,7 @@ from typing import Optional
from .covers import Covers
from .util import get_quality_id, safe_get, typed
from ..filepath_utils import clean_filename
PHON_COPYRIGHT = "\u2117"
COPYRIGHT = "\u00a9"
@ -67,27 +68,18 @@ class AlbumMetadata:
none_str = "Unknown"
info: dict[str, str | int | float] = {
"albumartist": self.validate_str(self.albumartist),
"albumcomposer": self.validate_str(self.albumcomposer) or none_str,
"albumartist": clean_filename(self.albumartist),
"albumcomposer": clean_filename(self.albumcomposer) or none_str,
"bit_depth": self.info.bit_depth or none_str,
"id": self.info.id,
"sampling_rate": self.info.sampling_rate or none_str,
"title": self.validate_str(self.album),
"title": clean_filename(self.album),
"year": self.year,
"container": self.info.container,
}
return formatter.format(**info)
def validate_str(self, string) -> str:
# The OS will not correctly process the folders if special characters
# or trailing spaces are present
bad_chars = ['/', '\\', ':', '*', '?', '\"', '<', '>', '|']
valid_string = ''.join(i for i in string if not i in bad_chars).rstrip()
return valid_string
@classmethod
def from_qobuz(cls, resp: dict) -> AlbumMetadata:
album = resp.get("title", "Unknown Album")