diff --git a/README.md b/README.md index 8c8cd2b..87d2cef 100644 --- a/README.md +++ b/README.md @@ -91,6 +91,13 @@ Unlike fully automated tagging tools, Perdoo takes a manual approach when metada +
+perdoo pipeline + +![perdoo pipeline help](docs/img/perdoo_pipeline.svg) + +
+
perdoo rename diff --git a/docs/generate-docs.sh b/docs/generate-docs.sh index 0530d41..a05c9cb 100755 --- a/docs/generate-docs.sh +++ b/docs/generate-docs.sh @@ -8,6 +8,7 @@ COLUMNS=120 pdm run perdoo archive remove --generate-help-preview COLUMNS=120 pdm run perdoo archive tree --generate-help-preview COLUMNS=120 pdm run perdoo clean --generate-help-preview COLUMNS=120 pdm run perdoo convert --generate-help-preview +COLUMNS=120 pdm run perdoo pipeline --generate-help-preview COLUMNS=120 pdm run perdoo rename --generate-help-preview COLUMNS=120 pdm run perdoo settings --generate-help-preview COLUMNS=120 pdm run perdoo sync --generate-help-preview diff --git a/docs/img/perdoo.svg b/docs/img/perdoo.svg index 9a7b062..9fdf25b 100644 --- a/docs/img/perdoo.svg +++ b/docs/img/perdoo.svg @@ -1,4 +1,4 @@ - + - - + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + + + + - + - + - - Usage:perdoo [-h] [--version] {archive,clean,convert,rename,settings,sync}... - -Organize comic collections using metadata stored in comic archives. - -Positional Arguments: -{archive,clean,convert,rename,settings,sync} -archiveInspect the contents and metadata of comic archives. -cleanRemove configured unwanted files from comic archives. -convertConvert comic archives to the configured output format. -renameRename and organize comic archives using their metadata. -settingsDisplay current settings and default values. -syncFetch metadata for comic archives from configured services. - -Options: --h, --helpshow this help message and exit ---versionShow the installed version and exit. - + + Usage:perdoo [-h] [--version] {archive,clean,convert,pipeline,rename,settings,sync}... + +Organize comic collections using metadata stored in comic archives. + +Positional Arguments: +{archive,clean,convert,pipeline,rename,settings,sync} +archiveInspect the contents and metadata of comic archives. +cleanRemove configured unwanted files from comic archives. +convertConvert comic archives to the configured output format. +pipelineRuns convert, clean, sync and rename one after another +renameRename and organize comic archives using their metadata. +settingsDisplay current settings and default values. +syncFetch metadata for comic archives from configured services. + +Options: +-h, --helpshow this help message and exit +--versionShow the installed version and exit. + diff --git a/docs/img/perdoo_pipeline.svg b/docs/img/perdoo_pipeline.svg new file mode 100644 index 0000000..f01d8ad --- /dev/null +++ b/docs/img/perdoo_pipeline.svg @@ -0,0 +1,119 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Usage:perdoo pipeline [-h] [-iEXT] [-f] [-o] [-c] target + +Runs convert, clean, sync and rename one after another + +Positional Arguments: +targetComic archive or directory of comic archives to synchronize. + +Options: +-h, --helpshow this help message and exit +-i, --ignoreEXTSkip archives with this extension. Repeat to ignore multiple extensions. [cb7|cbr|cbt|cbz|pdf] +-f, --forceSynchronize even if the stored metadata was updated within the configured interval. +-o, --override-cv-format +Override the format provided by Comicvine +-c, --clean-emptyRemove any empty folders after processing inside the target, including the target + + + + + diff --git a/docs/img/perdoo_sync.svg b/docs/img/perdoo_sync.svg index 5eaf52e..722f0dc 100644 --- a/docs/img/perdoo_sync.svg +++ b/docs/img/perdoo_sync.svg @@ -1,4 +1,4 @@ - + - - + + - + - + - + - + - + - + - + - + - + - + - + + + + + + + - + - + - - Usage:perdoo sync [-h] [-iEXT] [-f] target - -Fetch metadata from configured services and store it in comic archives. - -Positional Arguments: -targetComic archive or directory of comic archives to synchronize. - -Options: --h, --helpshow this help message and exit --i, --ignoreEXTSkip archives with this extension. Repeat to ignore multiple extensions. [cb7|cbr|cbt|cbz|pdf] --f, --forceSynchronize even if the stored metadata was updated within the configured interval. - + + Usage:perdoo sync [-h] [-iEXT] [-f] [-o] target + +Fetch metadata from configured services and store it in comic archives. + +Positional Arguments: +targetComic archive or directory of comic archives to synchronize. + +Options: +-h, --helpshow this help message and exit +-i, --ignoreEXTSkip archives with this extension. Repeat to ignore multiple extensions. [cb7|cbr|cbt|cbz|pdf] +-f, --forceSynchronize even if the stored metadata was updated within the configured interval. +-o, --override-cv-format +Override the format provided by Comicvine + diff --git a/perdoo/cli/pipeline.py b/perdoo/cli/pipeline.py index ed3f25d..932cf3e 100644 --- a/perdoo/cli/pipeline.py +++ b/perdoo/cli/pipeline.py @@ -15,7 +15,10 @@ def register(subparsers: _SubParsersAction) -> None: parser = subparsers.add_parser( - "pipeline", help="", description="", formatter_class=RichHelpFormatter + "pipeline", + help="Runs convert, clean, sync and rename one after another", + description="Runs convert, clean, sync and rename one after another", + formatter_class=RichHelpFormatter, ) parser.add_argument( "target", @@ -37,6 +40,12 @@ def register(subparsers: _SubParsersAction) -> None: action="store_true", help="Synchronize even if the stored metadata was updated within the configured interval.", ) + parser.add_argument( + "-o", + "--override-cv-format", + action="store_true", + help="Override the format provided by Comicvine", + ) parser.add_argument( "-c", "--clean-empty", diff --git a/perdoo/cli/sync.py b/perdoo/cli/sync.py index 419f317..c593b5e 100644 --- a/perdoo/cli/sync.py +++ b/perdoo/cli/sync.py @@ -44,6 +44,12 @@ def register(subparsers: _SubParsersAction) -> None: action="store_true", help="Synchronize even if the stored metadata was updated within the configured interval.", ) + parser.add_argument( + "-o", + "--override-cv-format", + action="store_true", + help="Override the format provided by Comicvine", + ) parser.add_argument( "--generate-help-preview", action=HelpPreviewAction, path="docs/img/perdoo_sync.svg" ) @@ -72,7 +78,13 @@ def should_sync(metron_info: MetronInfo | None, comic_info: ComicInfo | None, da return True -def sync_comic(comic: Comic, services: Sequence[Service], days: int, force: bool = False) -> None: +def sync_comic( + comic: Comic, + services: Sequence[Service], + days: int, + force: bool = False, + override_cv_format: bool = False, +) -> None: try: metron_info = comic.get_metadata(MetronInfo) except MetadataValidationError as err: @@ -85,7 +97,7 @@ def sync_comic(comic: Comic, services: Sequence[Service], days: int, force: bool comic_info = None if not should_sync(metron_info=metron_info, comic_info=comic_info, days=days) and not force: return - query = Search.build(comic=comic) + query = Search.build(comic=comic, override_cv_format=override_cv_format) try: for svc in services: if result := svc.fetch(search=query): @@ -118,7 +130,11 @@ def run(args: Namespace) -> None: try: with Comic.open(file=entry) as comic: sync_comic( - comic=comic, services=services, days=settings.sync.days, force=args.force + comic=comic, + services=services, + days=settings.sync.days, + force=args.force, + override_cv_format=args.override_cv_format, ) except UnsupportedArchiveError: pass diff --git a/perdoo/services/_models.py b/perdoo/services/_models.py index 96818bd..5160ef6 100644 --- a/perdoo/services/_models.py +++ b/perdoo/services/_models.py @@ -60,9 +60,10 @@ class Search: issue: IssueSearch filename: str cover_hash: str | None = None + override_cv_format: bool = False @staticmethod - def build(comic: Comic) -> "Search": + def build(comic: Comic, override_cv_format: bool) -> "Search": search: Search if ( (metron_info := comic.get_metadata(MetronInfo)) @@ -75,6 +76,7 @@ def build(comic: Comic) -> "Search": else: search = search_from_filename(filename=comic.file.stem) search.cover_hash = _get_cover_hash(comic=comic) + search.override_cv_format = override_cv_format return search diff --git a/perdoo/services/comicvine.py b/perdoo/services/comicvine.py index 8be7fb1..c5d14c5 100644 --- a/perdoo/services/comicvine.py +++ b/perdoo/services/comicvine.py @@ -6,7 +6,7 @@ from natsort import humansorted, ns from questionary import Choice, confirm, text from shortbox.metadata import ComicInfo, MetronInfo -from shortbox.metadata.metron_info import InformationSource +from shortbox.metadata.metron_info import Format, InformationSource from simyan.comicvine import Comicvine as Simyan from simyan.errors import ServiceError from simyan.schemas.issue import Issue @@ -166,7 +166,9 @@ def _fetch_issue(self, series_id: int, search: IssueSearch, filename: str) -> Is return self._fetch_issue(series_id=series_id, search=search, filename=filename) return None - def _build_metron_info(self, series: Volume, issue: Issue) -> MetronInfo: + def _build_metron_info( + self, series: Volume, issue: Issue, format_: Format | None = None + ) -> MetronInfo: from shortbox.metadata.metron_info import ( # noqa: PLC0415 Arc, Credit, @@ -185,30 +187,12 @@ def load_role(value: str) -> Role: return Role.OTHER return MetronInfo( - ids=[Id(primary=True, source=InformationSource.COMIC_VINE, value=str(issue.id))], - publisher=Publisher(id=str(series.publisher.id), name=series.publisher.name) - if series.publisher and series.publisher.name - else None, - series=Series( - id=str(series.id), - name=series.name, - start_year=series.start_year, - alternative_names=[], - ), - collection_title=issue.name, - number=issue.number, - summary=issue.summary, - cover_date=issue.cover_date, - store_date=issue.store_date, arcs=[Arc(id=str(x.id), name=x.name) for x in issue.story_arcs if x.name], characters=[ Resource[str](id=str(x.id), value=x.name) for x in issue.characters if x.name ], - teams=[Resource[str](id=str(x.id), value=x.name) for x in issue.teams if x.name], - locations=[ - Resource[str](id=str(x.id), value=x.name) for x in issue.locations if x.name - ], - urls=[Url(primary=True, value=str(issue.site_url))], + collection_title=issue.name, + cover_date=issue.cover_date, credits=[ Credit( creator=Resource[str](id=str(x.id), value=x.name), @@ -221,24 +205,46 @@ def load_role(value: str) -> Role: for x in issue.creators if x.name ], - last_modified=datetime.now().astimezone(), genres=[], + ids=[Id(primary=True, source=InformationSource.COMIC_VINE, value=str(issue.id))], + last_modified=datetime.now().astimezone(), + locations=[ + Resource[str](id=str(x.id), value=x.name) for x in issue.locations if x.name + ], + number=issue.number, prices=[], + publisher=Publisher(id=str(series.publisher.id), name=series.publisher.name) + if series.publisher and series.publisher.name + else None, reprints=[], + series=Series( + alternative_names=[], + format=format_, + id=str(series.id), + name=series.name, + start_year=series.start_year, + ), + store_date=issue.store_date, stories=[], + summary=issue.summary, tags=[], + teams=[Resource[str](id=str(x.id), value=x.name) for x in issue.teams if x.name], universes=[], + urls=[Url(primary=True, value=str(issue.site_url))], ) - def _build_comic_info(self, series: Volume, issue: Issue) -> ComicInfo: + def _build_comic_info( + self, series: Volume, issue: Issue, format_: Format | None = None + ) -> ComicInfo: comic_info = ComicInfo( - title=issue.name, - series=series.name, + format=str(format_) if format_ else None, number=issue.number, - summary=issue.summary, + pages=[], publisher=series.publisher.name if series.publisher else None, + series=series.name, + summary=issue.summary, + title=issue.name, web=str(issue.site_url), - pages=[], ) comic_info.cover_date = issue.cover_date @@ -272,8 +278,12 @@ def fetch(self, search: Search) -> MetadataResult | None: ) if not issue: return None + if search.override_cv_format: + format_ = prompt_select( + message="Select a format", choices=[Choice(title=str(x), value=x) for x in Format] + ) return MetadataResult( - comic_info=self._build_comic_info(series=series, issue=issue), - metron_info=self._build_metron_info(series=series, issue=issue), + comic_info=self._build_comic_info(series=series, issue=issue, format_=format_), + metron_info=self._build_metron_info(series=series, issue=issue, format_=format_), )