fix(template): detect folder spacer from template separators, not raw string

The previous heuristic checked the raw template string for dots, which could match dots inside variable names or title content, causing
Plex-friendly folder names to incorrectly use dots as spacers. Now strips template variables first and checks only the separators between them to determine user intent.
This commit is contained in:
imSp4rky
2026-03-31 09:13:44 -06:00
parent 5e801580a3
commit 8a714d6455
3 changed files with 16 additions and 16 deletions

View File

@@ -107,10 +107,9 @@ class Episode(Title):
folder_name = formatter.format(context) folder_name = formatter.format(context)
if '.' in config.folder_template and ' ' not in config.folder_template: separators = re.sub(r'\{[^}]*\}', '', config.folder_template)
return sanitize_filename(folder_name, ".") spacer = "." if "." in separators and " " not in separators else " "
else: return sanitize_filename(folder_name, spacer)
return sanitize_filename(folder_name, " ")
series_template = config.output_template.get("series") series_template = config.output_template.get("series")
if series_template: if series_template:
@@ -130,10 +129,9 @@ class Episode(Title):
folder_name = formatter.format(context) folder_name = formatter.format(context)
if '.' in series_template and ' ' not in series_template: separators = re.sub(r'\{[^}]*\}', '', derived_template)
return sanitize_filename(folder_name, ".") spacer = "." if "." in separators and " " not in separators else " "
else: return sanitize_filename(folder_name, spacer)
return sanitize_filename(folder_name, " ")
else: else:
name = f"{self.title}" name = f"{self.title}"
if self.year: if self.year:

View File

@@ -1,3 +1,4 @@
import re
from abc import ABC from abc import ABC
from typing import Any, Iterable, Optional, Union from typing import Any, Iterable, Optional, Union
@@ -63,10 +64,10 @@ class Movie(Title):
formatter = TemplateFormatter(config.folder_template) formatter = TemplateFormatter(config.folder_template)
context = self._build_template_context(media_info, show_service) context = self._build_template_context(media_info, show_service)
folder_name = formatter.format(context) folder_name = formatter.format(context)
if '.' in config.folder_template and ' ' not in config.folder_template:
return sanitize_filename(folder_name, ".") separators = re.sub(r'\{[^}]*\}', '', config.folder_template)
else: spacer = "." if "." in separators and " " not in separators else " "
return sanitize_filename(folder_name, " ") return sanitize_filename(folder_name, spacer)
name = f"{self.name}" name = f"{self.name}"
if self.year: if self.year:
name += f" ({self.year})" name += f" ({self.year})"

View File

@@ -1,3 +1,4 @@
import re
from abc import ABC from abc import ABC
from typing import Any, Iterable, Optional, Union from typing import Any, Iterable, Optional, Union
@@ -98,10 +99,10 @@ class Song(Title):
formatter = TemplateFormatter(config.folder_template) formatter = TemplateFormatter(config.folder_template)
context = self._build_template_context(media_info, show_service) context = self._build_template_context(media_info, show_service)
folder_name = formatter.format(context) folder_name = formatter.format(context)
if '.' in config.folder_template and ' ' not in config.folder_template:
return sanitize_filename(folder_name, ".") separators = re.sub(r'\{[^}]*\}', '', config.folder_template)
else: spacer = "." if "." in separators and " " not in separators else " "
return sanitize_filename(folder_name, " ") return sanitize_filename(folder_name, spacer)
name = f"{self.artist} - {self.album}" name = f"{self.artist} - {self.album}"
if self.year: if self.year:
name += f" ({self.year})" name += f" ({self.year})"