Skip to content

Commit

Permalink
Remove Non-Valid Metadata (#119)
Browse files Browse the repository at this point in the history
* Add option remove metadata if non-valid
  • Loading branch information
bpepple authored May 6, 2024
1 parent ebd6517 commit 1da3f9b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Help
-s, --sort Sort files that contain metadata tags. (default: False)
-z, --export-to-cbz Export a CBR (rar) archive to a CBZ (zip) archive. (default: False)
--validate Verify that comic archive has a valid ComicInfo.xml. (default: False)
--remove-non-valid Remove ComicInfo.xml from comic if not valid. Used with --validate option (default: False)
--delete-original Delete the original archive after successful export to another format. (default: False)
--duplicates Identify and give the option to delete duplicate pages in a directory of comics. (Experimental) (default: False)
--version Show the version number and exit
Expand Down
3 changes: 3 additions & 0 deletions metrontagger/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ def get_configs(opts: Namespace) -> MetronTaggerSettings: # noqa: PLR0912, C901
if opts.validate:
config.validate = opts.validate

if opts.remove_non_valid:
config.remove_non_valid = opts.remove_non_valid

if opts.duplicates:
config.duplicates = opts.duplicates

Expand Down
6 changes: 6 additions & 0 deletions metrontagger/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ def make_parser() -> argparse.ArgumentParser:
action="store_true",
default=False,
)
parser.add_argument(
"--remove-non-valid",
help="Remove ComicInfo.xml from comic if not valid. Used with --validate option",
action="store_true",
default=False,
)
parser.add_argument(
"--delete-original",
help="Delete the original archive after successful export to another format.",
Expand Down
9 changes: 7 additions & 2 deletions metrontagger/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def _export_to_zip(self: "Runner", file_list: list[Path]) -> None:
)

@staticmethod
def _validate_comic_info(file_list: list[Path]) -> None:
def _validate_comic_info(file_list: list[Path], remove_ci: bool = False) -> None:
questionary.print("\nValidating ComicInfo:\n---------------------", style=Styles.TITLE)
for comic in file_list:
ca = Comic(str(comic))
Expand All @@ -115,6 +115,11 @@ def _validate_comic_info(file_list: list[Path]) -> None:
)
else:
questionary.print(f"'{ca.path.name}' is not valid", style=Styles.ERROR)
if remove_ci and ca.remove_metadata():
questionary.print(
f"Removed non-valid metadata from '{ca.path.name}'.",
style=Styles.WARNING,
)

def _sort_comic_list(self: "Runner", file_list: list[Path]) -> None:
if not self.config.sort_dir:
Expand Down Expand Up @@ -331,4 +336,4 @@ def run(self: "Runner") -> None: # noqa: C901, PLR0912
self._sort_comic_list(file_list)

if self.config.validate:
self._validate_comic_info(file_list)
self._validate_comic_info(file_list, self.config.remove_non_valid)
1 change: 1 addition & 0 deletions metrontagger/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def __init__(self: "MetronTaggerSettings", config_dir: str | None = None) -> Non
self.export_to_cbz: bool = False
self.delete_original: bool = False
self.validate: bool = False
self.remove_non_valid: bool = False
self.duplicates: bool = False

# Rename settings
Expand Down

0 comments on commit 1da3f9b

Please sign in to comment.