mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-11-12 12: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:
@@ -213,7 +213,11 @@ class Config:
|
||||
warnings.warn(f"Unknown template variable '{var}' in {template_type} template")
|
||||
|
||||
test_template = re.sub(r"\{[^}]+\}", "TEST", template_str)
|
||||
if re.search(unsafe_chars, test_template):
|
||||
if template_type.startswith("folder"):
|
||||
unsafe_segment = any(re.search(unsafe_chars, seg) for seg in re.split(r"[\\/]", test_template))
|
||||
else:
|
||||
unsafe_segment = bool(re.search(unsafe_chars, test_template))
|
||||
if unsafe_segment:
|
||||
warnings.warn(f"Template '{template_type}' may contain filesystem-unsafe characters")
|
||||
|
||||
if not template_str.strip():
|
||||
|
||||
@@ -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