From cb5b321539974d6b36a83567aa0f3832d40c6a2b Mon Sep 17 00:00:00 2001 From: Timmy Welch Date: Sun, 26 Jun 2022 01:53:40 -0700 Subject: [PATCH] Update filerenamer Remove space separated right partition of previous literal text --- comictaggerlib/filerenamer.py | 4 +++- testing/filenames.py | 44 +++++++++++++++++++++++++++++------ 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/comictaggerlib/filerenamer.py b/comictaggerlib/filerenamer.py index a98bb93..37b8eaf 100644 --- a/comictaggerlib/filerenamer.py +++ b/comictaggerlib/filerenamer.py @@ -107,9 +107,11 @@ class MetadataFormatter(string.Formatter): # format the object and append to the result fmt_obj = self.format_field(obj, format_spec) - if fmt_obj == "" and len(result) > 0 and self.smart_cleanup: + if fmt_obj == "" and len(result) > 0 and self.smart_cleanup and literal_text: lstrip = True if result: + if " " in result[-1]: + result[-1], _, _ = result[-1].rpartition(" ") result[-1] = result[-1].rstrip("-_({[#") if self.smart_cleanup: fmt_obj = " ".join(fmt_obj.split()) diff --git a/testing/filenames.py b/testing/filenames.py index ca0c31c..1e4c3ee 100644 --- a/testing/filenames.py +++ b/testing/filenames.py @@ -732,6 +732,18 @@ rnames = [ "universal", "Cory Doctorow's Futuristic Tales of the Here and Now #001 - Anda's Game (2007).cbz", ), + ( + "{series} #{issue} - {title} ({year})({price})", # price should be none, test no space between ')(' + False, + "universal", + "Cory Doctorow's Futuristic Tales of the Here and Now #001 - Anda's Game (2007).cbz", + ), + ( + "{series} #{issue} - {title} ({year}) ({price})", # price should be none, test double space ') (' + False, + "universal", + "Cory Doctorow's Futuristic Tales of the Here and Now #001 - Anda's Game (2007).cbz", + ), ( "{series} #{issue} - {title} ({year})", False, @@ -739,37 +751,37 @@ rnames = [ "Cory Doctorow's Futuristic Tales of the Here and Now #001 - Anda's Game (2007).cbz", ), ( - "{series}: {title} #{issue} ({year})", + "{series}: {title} #{issue} ({year})", # on windows the ':' is replaced False, "universal", "Cory Doctorow's Futuristic Tales of the Here and Now - Anda's Game #001 (2007).cbz", ), ( - "{series}: {title} #{issue} ({year})", + "{series}: {title} #{issue} ({year})", # on linux the ':' is preserved False, "Linux", "Cory Doctorow's Futuristic Tales of the Here and Now: Anda's Game #001 (2007).cbz", ), ( - "{publisher}/ {series} #{issue} - {title} ({year})", + "{publisher}/ {series} #{issue} - {title} ({year})", # leading whitespace is removed when moving True, "universal", "IDW Publishing/Cory Doctorow's Futuristic Tales of the Here and Now #001 - Anda's Game (2007).cbz", ), ( - "{publisher}/ {series} #{issue} - {title} ({year})", + "{publisher}/ {series} #{issue} - {title} ({year})", # leading whitespace is removed when only renaming False, "universal", "Cory Doctorow's Futuristic Tales of the Here and Now #001 - Anda's Game (2007).cbz", ), ( - r"{publisher}\ {series} #{issue} - {title} ({year})", + r"{publisher}\ {series} #{issue} - {title} ({year})", # backslashes separate directories False, "universal", "Cory Doctorow's Futuristic Tales of the Here and Now #001 - Anda's Game (2007).cbz", ), ( - "{series} # {issue} - {title} ({year})", + "{series} # {issue} - {title} ({year})", # double spaces are reduced to one False, "universal", "Cory Doctorow's Futuristic Tales of the Here and Now # 001 - Anda's Game (2007).cbz", @@ -781,9 +793,27 @@ rnames = [ "Cory Doctorow's Futuristic Tales of the Here and Now # 001 - lonely cottage (2007).cbz", ), ( - "{series} #{issue} - {title} - {WriteR}, {EDITOR} ({year})", + "{series} #{issue} - {title} - {WriteR}, {EDITOR} ({year})", # fields are case in-sensitive False, "universal", "Cory Doctorow's Futuristic Tales of the Here and Now #001 - Anda's Game - Dara Naraghi, Ted Adams (2007).cbz", ), + ( + "{series} v{price} #{issue} ({year})", # Remove previous text if value is "" + False, + "universal", + "Cory Doctorow's Futuristic Tales of the Here and Now #001 (2007).cbz", + ), + ( + "{series} {price} #{issue} ({year})", # Ensure that a single space remains + False, + "universal", + "Cory Doctorow's Futuristic Tales of the Here and Now #001 (2007).cbz", + ), + ( + "{series} - {title}{price} #{issue} ({year})", # Ensure removal before None values only impacts literal text + False, + "universal", + "Cory Doctorow's Futuristic Tales of the Here and Now - Anda's Game #001 (2007).cbz", + ), ]