Skip to content

Commit

Permalink
v2.5.12
Browse files Browse the repository at this point in the history
  • Loading branch information
zachstultz authored May 17, 2024
1 parent 33ce03b commit 088d9bb
Showing 1 changed file with 30 additions and 10 deletions.
40 changes: 30 additions & 10 deletions komga_cover_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
import settings as settings_file

# Version of the script
script_version = (2, 5, 11)
script_version = (2, 5, 12)
script_version_text = "v{}.{}.{}".format(*script_version)

# Paths = existing library
Expand Down Expand Up @@ -3033,6 +3033,11 @@ def get_release_year(name, metadata=None):
# Pre-compile release group regex
release_groups_joined_regex = ""

# Pre-compiled regex for the release group at the end of the file name
release_group_end_regex = re.compile(
r"-(?! )([^\(\)\[\]\{\}]+)(?:%s)$" % file_extensions_regex, re.IGNORECASE
)


# Retrieves the release_group on the file name
def get_extra_from_group(name, groups, publisher_m=False, release_group_m=False):
Expand All @@ -3045,12 +3050,23 @@ def get_extra_from_group(name, groups, publisher_m=False, release_group_m=False)

search = ""

if publisher_m and publishers_joined_regex:
if publisher_m and publishers_joined_regex and contains_brackets(name):
search = publishers_joined_regex.search(name)
elif release_group_m and release_groups_joined_regex:
search = release_groups_joined_regex.search(name)
if search:
search = search.group()

return search.group() if search else ""
elif release_group_m:
search = release_group_end_regex.search(name) if "-" in name else ""

if search:
search = search.group(1)

if not search and release_groups_joined_regex and contains_brackets(name):
search = release_groups_joined_regex.findall(name)
if search:
search = search[-1] # use the last element

return search if search else ""


# Precompile the regular expressions
Expand Down Expand Up @@ -4385,15 +4401,16 @@ def reorganize_and_rename(files, dir):
if extras_to_add:
rename += " " + " ".join(extras_to_add)

# remove * from the replacement
rename = rename.replace("*", "")

if move_release_group_to_end_of_file_name and file.release_group:
release_group_escaped = re.escape(file.release_group)
if not re.search(
rf"\b{release_group_escaped}\b", rename, re.IGNORECASE
):
rename += f" {modifiers[file.extension] % file.release_group}"

# remove * from the replacement
rename = rename.replace("*", "")
rename += file.extension
rename = rename.strip()

Expand All @@ -4414,6 +4431,7 @@ def reorganize_and_rename(files, dir):

if watchdog_toggle:
transferred_files.append(rename_path)

try:
send_message(f"\n\t\tBEFORE: {file.name}", discord=False)
send_message(f"\t\tAFTER: {rename}", discord=False)
Expand Down Expand Up @@ -7098,9 +7116,10 @@ def remove_matching(text, pattern):

# Helper function to extract unique patterns from text
def extract_unique_patterns(text):
results = re.findall(r"(\{|\(|\[)(.*?)(\]|\)|\})", text, flags=re.IGNORECASE)
results = ["".join(result) for result in results]
return list(dict.fromkeys(results))
results = re.findall(
r"((?:\{|\(|\[).*?(?:\]|\)|\}))", text, flags=re.IGNORECASE
)
return results

# Helper function to remove specific patterns from a list
def remove_patterns(items, patterns):
Expand Down Expand Up @@ -10553,6 +10572,7 @@ def generate_rename_lists():
re.IGNORECASE,
)
),
None,
)
if found:
print(f'\t\tFound: "{found}", skipping file.')
Expand Down

0 comments on commit 088d9bb

Please sign in to comment.