Update filerenaming for web_links

Ensure the j specifier in MetadataFormatter converts to str before joining
Add a web_link variable to the filerenamer
This commit is contained in:
Timmy Welch 2024-02-17 17:40:21 -08:00
parent 44e9a47a8b
commit b2d3869488
2 changed files with 12 additions and 1 deletions

View File

@ -69,7 +69,7 @@ class MetadataFormatter(string.Formatter):
if conversion == "t":
return str(value).title()
if conversion == "j":
return ", ".join(list(value))
return ", ".join(list(str(v) for v in value))
return cast(str, super().convert_field(value, conversion))
def handle_replacements(self, string: str, replacements: list[Replacement]) -> str:
@ -218,6 +218,10 @@ class FileRenamer:
fmt = MetadataFormatter(self.smart_cleanup, platform=self.platform, replacements=self.replacements)
md_dict = vars(md)
md_dict["web_link"] = ""
if md.web_links:
md_dict["web_link"] = md.web_links[0]
md_dict["issue"] = IssueString(md.issue).as_string(pad=self.issue_zero_padding)
for role in ["writer", "penciller", "inker", "colorist", "letterer", "cover artist", "editor"]:
md_dict[role] = md.get_primary_credit(role)

View File

@ -1152,6 +1152,13 @@ rnames = [
"Anda's Game https:--comicvine.gamespot.com-cory-doctorows-futuristic-tales-of-the-here-and-no-4000-140529-.cbz",
does_not_raise(),
),
(
"{title} {web_links!j}", # Test that join forces str conversion
False,
"Linux",
"Anda's Game https:--comicvine.gamespot.com-cory-doctorows-futuristic-tales-of-the-here-and-no-4000-140529-.cbz",
does_not_raise(),
),
(
"{series}:{title} #{issue} ({year})", # on windows the ':' is replaced
False,