mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-11-29 04:15:09 +00:00
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:
@@ -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)
|
||||
|
||||
|
||||
@@ -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}"
|
||||
|
||||
@@ -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}"
|
||||
|
||||
@@ -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}"
|
||||
|
||||
Reference in New Issue
Block a user