Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assume 01 if no episode # in filename #10

Merged
merged 2 commits into from
Sep 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions modules/local_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from modules.onepacenet import get_arcs, get_image, extract_title

REGEX = re.compile(
r"\[(One Pace)\]\[(?P<Chapters>.+?)\]\s?(?P<Arc>.+?)\s(?P<Episode>\d{1,2})\s?\[(?P<Quality>\d{3,4}p)\]\[(?P<Hash>.+?)\]\.mkv"
r"\[(One Pace)\]\[(?P<Chapters>.+?)\]\s(?P<Arc>.+?)(?P<Episode>\d{1,2})?\s\[(?P<Quality>\d{3,4}p)\]\[(?P<Hash>.+?)\]\.mkv"
)


Expand Down Expand Up @@ -81,10 +81,12 @@ def copy_cover_to_destination(self):
print(f"Copied cover for {self.title} from onepace.net to target directory")


def __extract_group_value_from_match(match, group_name) -> str:
def __extract_group_value_from_match(match, group_name, optional: bool = False) -> str:
"""Extract a group from a match"""
group = match.group(group_name)
if match is None:
if optional:
return None
print(
(
f"Could not extract '{group_name}' from file name '{match}'\n",
Expand Down Expand Up @@ -124,14 +126,19 @@ def get_episode(target_dir: str, arcs, file: FileInfo) -> Episode:
file_arc.replace(
"Whiskey", "Whisky"
) # Fix spelling difference in file name from onepace.net data :)
file_episode = __extract_group_value_from_match(data, "Episode")

file_episode = __extract_group_value_from_match(data, "Episode", optional=True)
if file_episode is None or file_episode == "None":
file_episode = "01"

file_quality = __extract_group_value_from_match(data, "Quality")

matching_arc = next((a for a in arcs if extract_title(a) == file_arc), None)
if matching_arc is None:
print(f"Could not find matching arc for {file_arc} on onepace.net")
return None
print(f"Found matching arc for {file_arc}")

matching_episode = next(
(e for e in matching_arc["episodes"] if e["part"] == int(file_episode)),
None,
Expand All @@ -142,15 +149,15 @@ def get_episode(target_dir: str, arcs, file: FileInfo) -> Episode:
)
return None
print(f"Found matching episode for {file_arc}/{file_episode} on onepace.net")
episode = Episode(

return Episode(
title=matching_episode["invariant_title"],
episode_number=matching_episode["part"],
resolution=file_quality,
arc_title=extract_title(matching_arc),
source_file=file,
target_directory=os.path.join(target_dir, f"Season {matching_arc['part']:02d}"),
)
return episode


def copy_arc_cover_to_destination(target_directory: str, arc):
Expand Down