mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-11-24 18:05:07 +00:00
fix(output): treat / and \ as folder separators on any OS
Split folder templates on both separators and format each segment separately so sanitize_filename never rewrites the divider; validate folder.* templates per-segment.
This commit is contained in:
@@ -102,15 +102,12 @@ class Episode(Title):
|
||||
if folder:
|
||||
template = config.get_folder_template("series")
|
||||
if template:
|
||||
formatter = TemplateFormatter(template)
|
||||
context = self._build_template_context(media_info, show_service)
|
||||
context["season"] = f"S{self.season:02}"
|
||||
|
||||
folder_name = formatter.format(context)
|
||||
|
||||
separators = re.sub(r"\{[^}]*\}", "", template)
|
||||
spacer = "." if "." in separators and " " not in separators else " "
|
||||
return "/".join(sanitize_filename(p, spacer) for p in folder_name.split("/") if p)
|
||||
segments = [
|
||||
TemplateFormatter(seg).format(context) for seg in re.split(r"[\\/]", template) if seg.strip()
|
||||
]
|
||||
return "/".join(s for s in segments if s)
|
||||
|
||||
series_template = config.output_template.get("series")
|
||||
if series_template:
|
||||
|
||||
@@ -62,13 +62,11 @@ class Movie(Title):
|
||||
if folder:
|
||||
template = config.get_folder_template("movies")
|
||||
if template:
|
||||
formatter = TemplateFormatter(template)
|
||||
context = self._build_template_context(media_info, show_service)
|
||||
folder_name = formatter.format(context)
|
||||
|
||||
separators = re.sub(r"\{[^}]*\}", "", template)
|
||||
spacer = "." if "." in separators and " " not in separators else " "
|
||||
return "/".join(sanitize_filename(p, spacer) for p in folder_name.split("/") if p)
|
||||
segments = [
|
||||
TemplateFormatter(seg).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}"
|
||||
if self.year:
|
||||
name += f" ({self.year})"
|
||||
|
||||
@@ -170,13 +170,11 @@ class Song(Title):
|
||||
# legacy "songs" folder template, then to "{artist} - {album} ({year})".
|
||||
template = config.get_folder_template("albums") or config.get_folder_template("songs")
|
||||
if template:
|
||||
formatter = TemplateFormatter(template)
|
||||
context = self._build_template_context(media_info, show_service)
|
||||
folder_name = formatter.format(context)
|
||||
|
||||
separators = re.sub(r"\{[^}]*\}", "", template)
|
||||
spacer = "." if "." in separators and " " not in separators else " "
|
||||
return sanitize_filename(folder_name, spacer)
|
||||
segments = [
|
||||
TemplateFormatter(seg).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}"
|
||||
if self.year:
|
||||
name += f" ({self.year})"
|
||||
|
||||
@@ -97,13 +97,11 @@ class Song(Title):
|
||||
if folder:
|
||||
template = config.get_folder_template("songs")
|
||||
if template:
|
||||
formatter = TemplateFormatter(template)
|
||||
context = self._build_template_context(media_info, show_service)
|
||||
folder_name = formatter.format(context)
|
||||
|
||||
separators = re.sub(r"\{[^}]*\}", "", template)
|
||||
spacer = "." if "." in separators and " " not in separators else " "
|
||||
return "/".join(sanitize_filename(p, spacer) for p in folder_name.split("/") if p)
|
||||
segments = [
|
||||
TemplateFormatter(seg).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}"
|
||||
if self.year:
|
||||
name += f" ({self.year})"
|
||||
|
||||
Reference in New Issue
Block a user