mirror of
				https://github.com/devine-dl/devine.git
				synced 2025-11-04 03:44:49 +00:00 
			
		
		
		
	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:
		
							parent
							
								
									f0b589c8a5
								
							
						
					
					
						commit
						c77d521a42
					
				@ -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]:
 | 
			
		||||
        """
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user