fix(templates): use one separator style across a whole folder path

Detect the dot/space style from the full folder template instead of per segment, so `{artist}/{album} ({year})` no longer yields `Some.Artist/Some Album (2025)`. Also drops empty `[]` groups like the existing `()` handling and removes redundant cleanup passes.
This commit is contained in:
imSp4rky
2026-07-26 09:48:58 -06:00
parent 4c54c9ec1b
commit b74b64825e
7 changed files with 339 additions and 34 deletions
+5 -2
View File
@@ -12,7 +12,7 @@ from sortedcontainers import SortedKeyList
from unshackle.core.config import config
from unshackle.core.titles.title import Title
from unshackle.core.utilities import sanitize_filename
from unshackle.core.utils.template_formatter import TemplateFormatter
from unshackle.core.utils.template_formatter import TemplateFormatter, detect_spacer
class Episode(Title):
@@ -146,8 +146,11 @@ class Episode(Title):
context = self._build_template_context(media_info, show_service)
context["season"] = self._folder_season()
context["year"] = self.year or "" # folders keep the year
spacer = detect_spacer(template) # one style for the whole path
segments = [
TemplateFormatter(seg).format(context) for seg in re.split(r"[\\/]", template) if seg.strip()
TemplateFormatter(seg, spacer).format(context)
for seg in re.split(r"[\\/]", template)
if seg.strip()
]
return "/".join(s for s in segments if s)
+5 -2
View File
@@ -10,7 +10,7 @@ from sortedcontainers import SortedKeyList
from unshackle.core.config import config
from unshackle.core.titles.title import Title
from unshackle.core.utilities import sanitize_filename
from unshackle.core.utils.template_formatter import TemplateFormatter
from unshackle.core.utils.template_formatter import TemplateFormatter, detect_spacer
class Movie(Title):
@@ -63,8 +63,11 @@ class Movie(Title):
template = config.get_folder_template("movies")
if template:
context = self._build_template_context(media_info, show_service)
spacer = detect_spacer(template) # one style for the whole path
segments = [
TemplateFormatter(seg).format(context) for seg in re.split(r"[\\/]", template) if seg.strip()
TemplateFormatter(seg, spacer).format(context)
for seg in re.split(r"[\\/]", template)
if seg.strip()
]
return "/".join(s for s in segments if s)
name = f"{self.name}"
+5 -2
View File
@@ -9,7 +9,7 @@ from sortedcontainers import SortedKeyList
from unshackle.core.config import config
from unshackle.core.titles.title import Title
from unshackle.core.utilities import sanitize_filename
from unshackle.core.utils.template_formatter import TemplateFormatter
from unshackle.core.utils.template_formatter import TemplateFormatter, detect_spacer
class Song(Title):
@@ -171,8 +171,11 @@ class Song(Title):
template = config.get_folder_template("albums") or config.get_folder_template("songs")
if template:
context = self._build_template_context(media_info, show_service)
spacer = detect_spacer(template) # one style for the whole path
segments = [
TemplateFormatter(seg).format(context) for seg in re.split(r"[\\/]", template) if seg.strip()
TemplateFormatter(seg, spacer).format(context)
for seg in re.split(r"[\\/]", template)
if seg.strip()
]
return "/".join(s for s in segments if s)
name = f"{self.artist} - {self.album}"
+5 -2
View File
@@ -10,7 +10,7 @@ from sortedcontainers import SortedKeyList
from unshackle.core.config import config
from unshackle.core.titles.title import Title
from unshackle.core.utilities import sanitize_filename
from unshackle.core.utils.template_formatter import TemplateFormatter
from unshackle.core.utils.template_formatter import TemplateFormatter, detect_spacer
class Song(Title):
@@ -98,8 +98,11 @@ class Song(Title):
template = config.get_folder_template("songs")
if template:
context = self._build_template_context(media_info, show_service)
spacer = detect_spacer(template) # one style for the whole path
segments = [
TemplateFormatter(seg).format(context) for seg in re.split(r"[\\/]", template) if seg.strip()
TemplateFormatter(seg, spacer).format(context)
for seg in re.split(r"[\\/]", template)
if seg.strip()
]
return "/".join(s for s in segments if s)
name = f"{self.artist} - {self.album}"