refactor(Track): Default the track name to it's lang's script/territory

This allows you to override the whole track name instead of just prefixing before the script/territory. If you want no track name at all, you can set the track name to an empty string.

The script "Zzzz" (placeholder?) and territory "ZZ" (placeholder?) are not used. The script/territory values are only used if available and if necessary. I.e., fr-CA will use "Canada" but fr-FR will NOT use "France", it will be blank.
This commit is contained in:
rlaphoenix 2024-03-10 15:16:55 +00:00
parent f0b589c8a5
commit c77d521a42
1 changed files with 18 additions and 24 deletions

View File

@ -94,6 +94,23 @@ class Track:
self.downloader = downloader
self.data = data or {}
if self.name is None:
lang = Language.get(self.language)
if (lang.language or "").lower() == (lang.territory or "").lower():
lang.territory = None # e.g. en-en, de-DE
reduced = lang.simplify_script()
extra_parts = []
if reduced.script is not None:
script = reduced.script_name(max_distance=25)
if script and script != "Zzzz":
extra_parts.append(script)
if reduced.territory is not None:
territory = reduced.territory_name(max_distance=25)
if territory and territory != "ZZ":
territory = territory.removesuffix(" SAR China")
extra_parts.append(territory)
self.name = ", ".join(extra_parts) or None
if not id_:
this = copy(self)
this.url = self.url.rsplit("?", maxsplit=1)[0]
@ -323,30 +340,7 @@ class Track:
def get_track_name(self) -> Optional[str]:
"""Get the Track Name."""
simplified_language = self.language.simplify_script()
script = simplified_language.script_name(max_distance=25)
territory = simplified_language.territory_name(max_distance=25)
if territory and territory.endswith(" SAR China"):
territory = territory.split(" SAR China")[0]
if (script or "").lower() == (territory or "").lower():
script = None
territory = None
if script == "Zzzz":
script = None
if territory in ("ZZ", "US"):
territory = None
region = script
if region and territory:
region += f", {territory}"
if self.name:
track_name = self.name + (f" ({region})" if region else "")
else:
track_name = region or None
return track_name
return self.name
def get_key_id(self, init_data: Optional[bytes] = None, *args, **kwargs) -> Optional[UUID]:
"""