Skip to content

Commit

Permalink
Merge branch 'main' into duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
bpepple committed Oct 3, 2023
2 parents 61d8bd1 + ff3ce58 commit 9e5ac33
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 3 deletions.
5 changes: 4 additions & 1 deletion metrontagger/filerenamer.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,10 @@ def determine_name(self: "FileRenamer", filename: Path) -> Optional[str]:
)
new_name = self.replace_token(new_name, meta_data.alternate_count, "%alternatecount%")
new_name = self.replace_token(new_name, meta_data.imprint, "%imprint%")
new_name = self.replace_token(new_name, meta_data.series.format, "%format%")
if meta_data.series.format == "Hard Cover":
new_name = self.replace_token(new_name, "HC", "%format%")
elif meta_data.series.format == "Trade Paperback":
new_name = self.replace_token(new_name, "TPB", "%format%")
new_name = self.replace_token(new_name, meta_data.age_rating, "%maturityrating%")
new_name = self.replace_token(new_name, meta_data.stories, "%storyarc%")
new_name = self.replace_token(new_name, meta_data.series_group, "%seriesgroup%")
Expand Down
5 changes: 4 additions & 1 deletion metrontagger/filesorter.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ def _overwrite_existing(new_path: Path, old_comic: Path) -> None:

def sort_comics(self: "FileSorter", comic: Path) -> bool:
"""Method to move the comic file based on it's metadata tag"""
comic_archive = Comic(comic)
try:
comic_archive = Comic(comic)
except FileNotFoundError:
return False
if comic_archive.has_metadata():
meta_data = comic_archive.read_metadata()
else:
Expand Down
2 changes: 1 addition & 1 deletion metrontagger/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def _sort_comic_list(self: "Runner", file_list: list[Path]) -> None:
for comic in file_list:
result = file_sorter.sort_comics(comic)
if not result:
questionary.print(f"unable to move {comic.name}.", style=Styles.ERROR)
questionary.print(f"Unable to move '{comic.name}'.", style=Styles.ERROR)

@staticmethod
def _comics_with_no_metadata(file_list: list[Path]) -> None:
Expand Down
14 changes: 14 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,17 @@ def fake_comic(tmp_path_factory: Path) -> zipfile.ZipFile:
zf.writestr("cover.jpg", image_data)

return z_file


@pytest.fixture()
def fake_tpb(tmp_path_factory: Path) -> zipfile.ZipFile:
z_file = (
tmp_path_factory.mktemp("comic")
/ "Batman - The Adventures Continue Season One (2021) "
"(digital) (Son of Ultron-Empire).cbz"
)
image_data = create_cover_page()
with zipfile.ZipFile(z_file, mode="w") as zf:
zf.writestr("cover.jpg", image_data)

return z_file
22 changes: 22 additions & 0 deletions tests/test_filerenamer.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,28 @@ def test_rename_file(fake_comic: ZipFile) -> None:
assert expected_result == renamed_file.name


def test_rename_tpb(fake_tpb: ZipFile, fake_tpb_metadata: Metadata) -> None:
fn = (
"Batman - The Adventures Continue Season One (2021) "
"(digital) (Son of Ultron-Empire).cbz"
)
assert fake_tpb.name == fn
renamer = FileRenamer(fake_tpb_metadata)
renamer.set_template("%series% %format% v%volume% #%issue% (%year%)")
renamer.set_issue_zero_padding(3)
renamer.set_smart_cleanup(True)
renamed_file = renamer.rename_file(fake_tpb)
assert renamed_file is not None
expected_result = (
f"{fake_tpb_metadata.series.name} "
"TPB "
f"v{fake_tpb_metadata.series.volume} "
f"#00{fake_tpb_metadata.issue} "
f"({fake_tpb_metadata.cover_date.year}).cbz"
)
assert expected_result == renamed_file.name


def test_half_issues_rename(fake_comic: ZipFile) -> None:
md = Metadata()
md.series = Series("Batman", volume=2)
Expand Down

0 comments on commit 9e5ac33

Please sign in to comment.