2015-02-21 18:30:32 -08:00
|
|
|
"""A class to represent a single comic, be it file or folder of images"""
|
2024-01-29 09:14:25 -08:00
|
|
|
|
2023-02-16 17:23:13 -08:00
|
|
|
# Copyright 2012-2014 ComicTagger Authors
|
2022-06-02 18:32:16 -07:00
|
|
|
#
|
2015-02-21 18:30:32 -08:00
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
2022-06-02 18:32:16 -07:00
|
|
|
#
|
2015-02-21 18:30:32 -08:00
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
2022-06-02 18:32:16 -07:00
|
|
|
#
|
2015-02-21 18:30:32 -08:00
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
2022-06-02 18:32:16 -07:00
|
|
|
from __future__ import annotations
|
2015-02-16 04:27:21 -08:00
|
|
|
|
2024-02-11 13:18:03 -08:00
|
|
|
import importlib.util
|
Code cleanup
Remove no longer used google scripts
Remove convenience files from comicataggerlib and import comicapi directly
Add type-hints to facilitate auto-complete tools
Make PyQt5 code more compatible with PyQt6
Implement automatic tooling
isort and black for code formatting
Line length has been set to 120
flake8 for code standards with exceptions:
E203 - Whitespace before ':' - format compatiblity with black
E501 - Line too long - flake8 line limit cannot be set
E722 - Do not use bare except - fixing bare except statements is a
lot of overhead and there are already
many in the codebase
These changes, along with some manual fixes creates much more readable code.
See examples below:
diff --git a/comicapi/comet.py b/comicapi/comet.py
index d1741c5..52dc195 100644
--- a/comicapi/comet.py
+++ b/comicapi/comet.py
@@ -166,7 +166,2 @@ class CoMet:
- if credit['role'].lower() in set(self.editor_synonyms):
- ET.SubElement(
- root,
- 'editor').text = "{0}".format(
- credit['person'])
@@ -174,2 +169,4 @@ class CoMet:
self.indent(root)
+ if credit["role"].lower() in set(self.editor_synonyms):
+ ET.SubElement(root, "editor").text = str(credit["person"])
diff --git a/comictaggerlib/autotagmatchwindow.py b/comictaggerlib/autotagmatchwindow.py
index 4338176..9219f01 100644
--- a/comictaggerlib/autotagmatchwindow.py
+++ b/comictaggerlib/autotagmatchwindow.py
@@ -63,4 +63,3 @@ class AutoTagMatchWindow(QtWidgets.QDialog):
self.skipButton, QtWidgets.QDialogButtonBox.ActionRole)
- self.buttonBox.button(QtWidgets.QDialogButtonBox.Ok).setText(
- "Accept and Write Tags")
+ self.buttonBox.button(QtWidgets.QDialogButtonBox.StandardButton.Ok).setText("Accept and Write Tags")
diff --git a/comictaggerlib/cli.py b/comictaggerlib/cli.py
index 688907d..dbd0c2e 100644
--- a/comictaggerlib/cli.py
+++ b/comictaggerlib/cli.py
@@ -293,7 +293,3 @@ def process_file_cli(filename, opts, settings, match_results):
if opts.raw:
- print((
- "{0}".format(
- str(
- ca.readRawCIX(),
- errors='ignore'))))
+ print(ca.read_raw_cix())
else:
2022-04-01 16:50:46 -07:00
|
|
|
import io
|
2024-02-10 21:00:24 -08:00
|
|
|
import itertools
|
Code cleanup
Remove no longer used google scripts
Remove convenience files from comicataggerlib and import comicapi directly
Add type-hints to facilitate auto-complete tools
Make PyQt5 code more compatible with PyQt6
Implement automatic tooling
isort and black for code formatting
Line length has been set to 120
flake8 for code standards with exceptions:
E203 - Whitespace before ':' - format compatiblity with black
E501 - Line too long - flake8 line limit cannot be set
E722 - Do not use bare except - fixing bare except statements is a
lot of overhead and there are already
many in the codebase
These changes, along with some manual fixes creates much more readable code.
See examples below:
diff --git a/comicapi/comet.py b/comicapi/comet.py
index d1741c5..52dc195 100644
--- a/comicapi/comet.py
+++ b/comicapi/comet.py
@@ -166,7 +166,2 @@ class CoMet:
- if credit['role'].lower() in set(self.editor_synonyms):
- ET.SubElement(
- root,
- 'editor').text = "{0}".format(
- credit['person'])
@@ -174,2 +169,4 @@ class CoMet:
self.indent(root)
+ if credit["role"].lower() in set(self.editor_synonyms):
+ ET.SubElement(root, "editor").text = str(credit["person"])
diff --git a/comictaggerlib/autotagmatchwindow.py b/comictaggerlib/autotagmatchwindow.py
index 4338176..9219f01 100644
--- a/comictaggerlib/autotagmatchwindow.py
+++ b/comictaggerlib/autotagmatchwindow.py
@@ -63,4 +63,3 @@ class AutoTagMatchWindow(QtWidgets.QDialog):
self.skipButton, QtWidgets.QDialogButtonBox.ActionRole)
- self.buttonBox.button(QtWidgets.QDialogButtonBox.Ok).setText(
- "Accept and Write Tags")
+ self.buttonBox.button(QtWidgets.QDialogButtonBox.StandardButton.Ok).setText("Accept and Write Tags")
diff --git a/comictaggerlib/cli.py b/comictaggerlib/cli.py
index 688907d..dbd0c2e 100644
--- a/comictaggerlib/cli.py
+++ b/comictaggerlib/cli.py
@@ -293,7 +293,3 @@ def process_file_cli(filename, opts, settings, match_results):
if opts.raw:
- print((
- "{0}".format(
- str(
- ca.readRawCIX(),
- errors='ignore'))))
+ print(ca.read_raw_cix())
else:
2022-04-01 16:50:46 -07:00
|
|
|
import logging
|
2015-02-16 04:27:21 -08:00
|
|
|
import os
|
2022-05-17 13:57:04 -07:00
|
|
|
import pathlib
|
2022-06-01 21:14:51 -07:00
|
|
|
import shutil
|
2022-08-17 15:53:19 -07:00
|
|
|
import sys
|
2024-04-27 15:44:54 -07:00
|
|
|
from collections.abc import Iterable
|
2024-02-10 21:00:24 -08:00
|
|
|
from typing import TYPE_CHECKING
|
2015-02-16 05:09:21 -08:00
|
|
|
|
2023-09-06 01:50:05 -07:00
|
|
|
from comicapi import utils
|
2022-08-17 15:53:19 -07:00
|
|
|
from comicapi.archivers import Archiver, UnknownArchiver, ZipArchiver
|
2023-12-17 21:47:43 -08:00
|
|
|
from comicapi.genericmetadata import GenericMetadata
|
2024-06-20 16:47:10 -07:00
|
|
|
from comicapi.tags import Tag
|
2023-12-17 21:47:43 -08:00
|
|
|
from comictaggerlib.ctversion import version
|
2022-06-02 18:32:16 -07:00
|
|
|
|
2024-02-10 21:00:24 -08:00
|
|
|
if TYPE_CHECKING:
|
|
|
|
from importlib.metadata import EntryPoint
|
|
|
|
|
Code cleanup
Remove no longer used google scripts
Remove convenience files from comicataggerlib and import comicapi directly
Add type-hints to facilitate auto-complete tools
Make PyQt5 code more compatible with PyQt6
Implement automatic tooling
isort and black for code formatting
Line length has been set to 120
flake8 for code standards with exceptions:
E203 - Whitespace before ':' - format compatiblity with black
E501 - Line too long - flake8 line limit cannot be set
E722 - Do not use bare except - fixing bare except statements is a
lot of overhead and there are already
many in the codebase
These changes, along with some manual fixes creates much more readable code.
See examples below:
diff --git a/comicapi/comet.py b/comicapi/comet.py
index d1741c5..52dc195 100644
--- a/comicapi/comet.py
+++ b/comicapi/comet.py
@@ -166,7 +166,2 @@ class CoMet:
- if credit['role'].lower() in set(self.editor_synonyms):
- ET.SubElement(
- root,
- 'editor').text = "{0}".format(
- credit['person'])
@@ -174,2 +169,4 @@ class CoMet:
self.indent(root)
+ if credit["role"].lower() in set(self.editor_synonyms):
+ ET.SubElement(root, "editor").text = str(credit["person"])
diff --git a/comictaggerlib/autotagmatchwindow.py b/comictaggerlib/autotagmatchwindow.py
index 4338176..9219f01 100644
--- a/comictaggerlib/autotagmatchwindow.py
+++ b/comictaggerlib/autotagmatchwindow.py
@@ -63,4 +63,3 @@ class AutoTagMatchWindow(QtWidgets.QDialog):
self.skipButton, QtWidgets.QDialogButtonBox.ActionRole)
- self.buttonBox.button(QtWidgets.QDialogButtonBox.Ok).setText(
- "Accept and Write Tags")
+ self.buttonBox.button(QtWidgets.QDialogButtonBox.StandardButton.Ok).setText("Accept and Write Tags")
diff --git a/comictaggerlib/cli.py b/comictaggerlib/cli.py
index 688907d..dbd0c2e 100644
--- a/comictaggerlib/cli.py
+++ b/comictaggerlib/cli.py
@@ -293,7 +293,3 @@ def process_file_cli(filename, opts, settings, match_results):
if opts.raw:
- print((
- "{0}".format(
- str(
- ca.readRawCIX(),
- errors='ignore'))))
+ print(ca.read_raw_cix())
else:
2022-04-01 16:50:46 -07:00
|
|
|
logger = logging.getLogger(__name__)
|
2023-01-11 16:19:44 -08:00
|
|
|
|
2022-08-17 15:53:19 -07:00
|
|
|
archivers: list[type[Archiver]] = []
|
2024-06-20 16:47:10 -07:00
|
|
|
tags: dict[str, Tag] = {}
|
2022-08-17 15:53:19 -07:00
|
|
|
|
|
|
|
|
2024-04-27 15:44:54 -07:00
|
|
|
def load_archive_plugins(local_plugins: Iterable[EntryPoint] = tuple()) -> None:
|
2024-06-20 16:47:10 -07:00
|
|
|
if archivers:
|
|
|
|
return
|
|
|
|
if sys.version_info < (3, 10):
|
|
|
|
from importlib_metadata import entry_points
|
|
|
|
else:
|
|
|
|
from importlib.metadata import entry_points
|
|
|
|
builtin: list[type[Archiver]] = []
|
|
|
|
archive_plugins: list[type[Archiver]] = []
|
|
|
|
# A list is used first matching plugin wins
|
|
|
|
|
|
|
|
for ep in itertools.chain(local_plugins, entry_points(group="comicapi.archiver")):
|
|
|
|
try:
|
|
|
|
spec = importlib.util.find_spec(ep.module)
|
|
|
|
except ValueError:
|
|
|
|
spec = None
|
|
|
|
try:
|
|
|
|
archiver: type[Archiver] = ep.load()
|
|
|
|
|
|
|
|
if ep.module.startswith("comicapi"):
|
|
|
|
builtin.append(archiver)
|
|
|
|
else:
|
|
|
|
archive_plugins.append(archiver)
|
|
|
|
except Exception:
|
2024-02-11 13:18:03 -08:00
|
|
|
if spec and spec.has_location:
|
2024-06-20 16:47:10 -07:00
|
|
|
logger.exception("Failed to load archive plugin: %s from %s", ep.name, spec.origin)
|
2024-02-11 13:18:03 -08:00
|
|
|
else:
|
2024-06-20 16:47:10 -07:00
|
|
|
logger.exception("Failed to load archive plugin: %s", ep.name)
|
|
|
|
archivers.clear()
|
|
|
|
archivers.extend(archive_plugins)
|
|
|
|
archivers.extend(builtin)
|
|
|
|
|
|
|
|
|
|
|
|
def load_tag_plugins(version: str = f"ComicAPI/{version}", local_plugins: Iterable[EntryPoint] = tuple()) -> None:
|
|
|
|
if tags:
|
|
|
|
return
|
|
|
|
if sys.version_info < (3, 10):
|
|
|
|
from importlib_metadata import entry_points
|
|
|
|
else:
|
|
|
|
from importlib.metadata import entry_points
|
|
|
|
builtin: dict[str, Tag] = {}
|
|
|
|
tag_plugins: dict[str, tuple[Tag, str]] = {}
|
|
|
|
# A dict is used, last plugin wins
|
|
|
|
for ep in itertools.chain(entry_points(group="comicapi.tags"), local_plugins):
|
|
|
|
location = "Unknown"
|
|
|
|
try:
|
|
|
|
_spec = importlib.util.find_spec(ep.module)
|
|
|
|
if _spec and _spec.has_location and _spec.origin:
|
|
|
|
location = _spec.origin
|
|
|
|
except ValueError:
|
|
|
|
location = "Unknown"
|
|
|
|
|
|
|
|
try:
|
|
|
|
tag: type[Tag] = ep.load()
|
|
|
|
|
|
|
|
if ep.module.startswith("comicapi"):
|
|
|
|
builtin[tag.id] = tag(version)
|
|
|
|
else:
|
|
|
|
if tag.id in tag_plugins:
|
|
|
|
logger.warning(
|
|
|
|
"Plugin %s from %s is overriding the existing plugin for %s tags",
|
|
|
|
ep.module,
|
|
|
|
location,
|
|
|
|
tag.id,
|
|
|
|
)
|
|
|
|
tag_plugins[tag.id] = (tag(version), location)
|
|
|
|
except Exception:
|
|
|
|
logger.exception("Failed to load tag plugin: %s from %s", ep.name, location)
|
|
|
|
|
|
|
|
for tag_id in set(builtin.keys()).intersection(tag_plugins):
|
|
|
|
location = tag_plugins[tag_id][1]
|
|
|
|
logger.warning("Builtin plugin for %s tags are being overridden by a plugin from %s", tag_id, location)
|
|
|
|
|
|
|
|
tags.clear()
|
|
|
|
tags.update(builtin)
|
|
|
|
tags.update({s[0]: s[1][0] for s in tag_plugins.items()})
|
Code cleanup
Remove no longer used google scripts
Remove convenience files from comicataggerlib and import comicapi directly
Add type-hints to facilitate auto-complete tools
Make PyQt5 code more compatible with PyQt6
Implement automatic tooling
isort and black for code formatting
Line length has been set to 120
flake8 for code standards with exceptions:
E203 - Whitespace before ':' - format compatiblity with black
E501 - Line too long - flake8 line limit cannot be set
E722 - Do not use bare except - fixing bare except statements is a
lot of overhead and there are already
many in the codebase
These changes, along with some manual fixes creates much more readable code.
See examples below:
diff --git a/comicapi/comet.py b/comicapi/comet.py
index d1741c5..52dc195 100644
--- a/comicapi/comet.py
+++ b/comicapi/comet.py
@@ -166,7 +166,2 @@ class CoMet:
- if credit['role'].lower() in set(self.editor_synonyms):
- ET.SubElement(
- root,
- 'editor').text = "{0}".format(
- credit['person'])
@@ -174,2 +169,4 @@ class CoMet:
self.indent(root)
+ if credit["role"].lower() in set(self.editor_synonyms):
+ ET.SubElement(root, "editor").text = str(credit["person"])
diff --git a/comictaggerlib/autotagmatchwindow.py b/comictaggerlib/autotagmatchwindow.py
index 4338176..9219f01 100644
--- a/comictaggerlib/autotagmatchwindow.py
+++ b/comictaggerlib/autotagmatchwindow.py
@@ -63,4 +63,3 @@ class AutoTagMatchWindow(QtWidgets.QDialog):
self.skipButton, QtWidgets.QDialogButtonBox.ActionRole)
- self.buttonBox.button(QtWidgets.QDialogButtonBox.Ok).setText(
- "Accept and Write Tags")
+ self.buttonBox.button(QtWidgets.QDialogButtonBox.StandardButton.Ok).setText("Accept and Write Tags")
diff --git a/comictaggerlib/cli.py b/comictaggerlib/cli.py
index 688907d..dbd0c2e 100644
--- a/comictaggerlib/cli.py
+++ b/comictaggerlib/cli.py
@@ -293,7 +293,3 @@ def process_file_cli(filename, opts, settings, match_results):
if opts.raw:
- print((
- "{0}".format(
- str(
- ca.readRawCIX(),
- errors='ignore'))))
+ print(ca.read_raw_cix())
else:
2022-04-01 16:50:46 -07:00
|
|
|
|
2015-02-21 18:30:32 -08:00
|
|
|
|
2015-02-16 04:27:21 -08:00
|
|
|
class ComicArchive:
|
2022-08-10 16:46:00 -07:00
|
|
|
logo_data = b""
|
2023-06-22 20:11:40 -07:00
|
|
|
pil_available = True
|
Code cleanup
Remove no longer used google scripts
Remove convenience files from comicataggerlib and import comicapi directly
Add type-hints to facilitate auto-complete tools
Make PyQt5 code more compatible with PyQt6
Implement automatic tooling
isort and black for code formatting
Line length has been set to 120
flake8 for code standards with exceptions:
E203 - Whitespace before ':' - format compatiblity with black
E501 - Line too long - flake8 line limit cannot be set
E722 - Do not use bare except - fixing bare except statements is a
lot of overhead and there are already
many in the codebase
These changes, along with some manual fixes creates much more readable code.
See examples below:
diff --git a/comicapi/comet.py b/comicapi/comet.py
index d1741c5..52dc195 100644
--- a/comicapi/comet.py
+++ b/comicapi/comet.py
@@ -166,7 +166,2 @@ class CoMet:
- if credit['role'].lower() in set(self.editor_synonyms):
- ET.SubElement(
- root,
- 'editor').text = "{0}".format(
- credit['person'])
@@ -174,2 +169,4 @@ class CoMet:
self.indent(root)
+ if credit["role"].lower() in set(self.editor_synonyms):
+ ET.SubElement(root, "editor").text = str(credit["person"])
diff --git a/comictaggerlib/autotagmatchwindow.py b/comictaggerlib/autotagmatchwindow.py
index 4338176..9219f01 100644
--- a/comictaggerlib/autotagmatchwindow.py
+++ b/comictaggerlib/autotagmatchwindow.py
@@ -63,4 +63,3 @@ class AutoTagMatchWindow(QtWidgets.QDialog):
self.skipButton, QtWidgets.QDialogButtonBox.ActionRole)
- self.buttonBox.button(QtWidgets.QDialogButtonBox.Ok).setText(
- "Accept and Write Tags")
+ self.buttonBox.button(QtWidgets.QDialogButtonBox.StandardButton.Ok).setText("Accept and Write Tags")
diff --git a/comictaggerlib/cli.py b/comictaggerlib/cli.py
index 688907d..dbd0c2e 100644
--- a/comictaggerlib/cli.py
+++ b/comictaggerlib/cli.py
@@ -293,7 +293,3 @@ def process_file_cli(filename, opts, settings, match_results):
if opts.raw:
- print((
- "{0}".format(
- str(
- ca.readRawCIX(),
- errors='ignore'))))
+ print(ca.read_raw_cix())
else:
2022-04-01 16:50:46 -07:00
|
|
|
|
2023-12-18 02:37:34 -08:00
|
|
|
def __init__(
|
|
|
|
self, path: pathlib.Path | str | Archiver, default_image_path: pathlib.Path | str | None = None
|
|
|
|
) -> None:
|
2023-12-17 21:47:43 -08:00
|
|
|
self.md: dict[str, GenericMetadata] = {}
|
2022-06-02 18:32:16 -07:00
|
|
|
self.page_count: int | None = None
|
2022-05-17 13:57:04 -07:00
|
|
|
self.page_list: list[str] = []
|
2015-02-16 05:09:21 -08:00
|
|
|
|
Code cleanup
Remove no longer used google scripts
Remove convenience files from comicataggerlib and import comicapi directly
Add type-hints to facilitate auto-complete tools
Make PyQt5 code more compatible with PyQt6
Implement automatic tooling
isort and black for code formatting
Line length has been set to 120
flake8 for code standards with exceptions:
E203 - Whitespace before ':' - format compatiblity with black
E501 - Line too long - flake8 line limit cannot be set
E722 - Do not use bare except - fixing bare except statements is a
lot of overhead and there are already
many in the codebase
These changes, along with some manual fixes creates much more readable code.
See examples below:
diff --git a/comicapi/comet.py b/comicapi/comet.py
index d1741c5..52dc195 100644
--- a/comicapi/comet.py
+++ b/comicapi/comet.py
@@ -166,7 +166,2 @@ class CoMet:
- if credit['role'].lower() in set(self.editor_synonyms):
- ET.SubElement(
- root,
- 'editor').text = "{0}".format(
- credit['person'])
@@ -174,2 +169,4 @@ class CoMet:
self.indent(root)
+ if credit["role"].lower() in set(self.editor_synonyms):
+ ET.SubElement(root, "editor").text = str(credit["person"])
diff --git a/comictaggerlib/autotagmatchwindow.py b/comictaggerlib/autotagmatchwindow.py
index 4338176..9219f01 100644
--- a/comictaggerlib/autotagmatchwindow.py
+++ b/comictaggerlib/autotagmatchwindow.py
@@ -63,4 +63,3 @@ class AutoTagMatchWindow(QtWidgets.QDialog):
self.skipButton, QtWidgets.QDialogButtonBox.ActionRole)
- self.buttonBox.button(QtWidgets.QDialogButtonBox.Ok).setText(
- "Accept and Write Tags")
+ self.buttonBox.button(QtWidgets.QDialogButtonBox.StandardButton.Ok).setText("Accept and Write Tags")
diff --git a/comictaggerlib/cli.py b/comictaggerlib/cli.py
index 688907d..dbd0c2e 100644
--- a/comictaggerlib/cli.py
+++ b/comictaggerlib/cli.py
@@ -293,7 +293,3 @@ def process_file_cli(filename, opts, settings, match_results):
if opts.raw:
- print((
- "{0}".format(
- str(
- ca.readRawCIX(),
- errors='ignore'))))
+ print(ca.read_raw_cix())
else:
2022-04-01 16:50:46 -07:00
|
|
|
self.reset_cache()
|
2015-02-16 05:09:21 -08:00
|
|
|
self.default_image_path = default_image_path
|
|
|
|
|
2023-12-18 02:37:34 -08:00
|
|
|
if isinstance(path, Archiver):
|
|
|
|
self.path = path.path
|
|
|
|
self.archiver: Archiver = path
|
|
|
|
else:
|
|
|
|
self.path = pathlib.Path(path).absolute()
|
|
|
|
self.archiver = UnknownArchiver.open(self.path)
|
2015-02-16 05:09:21 -08:00
|
|
|
|
2023-01-12 17:00:11 -08:00
|
|
|
load_archive_plugins()
|
2024-06-20 16:47:10 -07:00
|
|
|
load_tag_plugins()
|
2022-08-17 15:53:19 -07:00
|
|
|
for archiver in archivers:
|
2023-12-17 15:51:43 -08:00
|
|
|
if archiver.enabled and archiver.is_valid(self.path):
|
2022-08-17 15:53:19 -07:00
|
|
|
self.archiver = archiver.open(self.path)
|
|
|
|
break
|
2022-06-01 21:14:51 -07:00
|
|
|
|
|
|
|
if not ComicArchive.logo_data and self.default_image_path:
|
|
|
|
with open(self.default_image_path, mode="rb") as fd:
|
|
|
|
ComicArchive.logo_data = fd.read()
|
2015-02-16 05:09:21 -08:00
|
|
|
|
2022-05-17 13:57:04 -07:00
|
|
|
def reset_cache(self) -> None:
|
2015-02-21 18:30:32 -08:00
|
|
|
"""Clears the cached data"""
|
|
|
|
|
|
|
|
self.page_count = None
|
2023-12-17 21:47:43 -08:00
|
|
|
self.page_list.clear()
|
|
|
|
self.md.clear()
|
2015-02-16 05:09:21 -08:00
|
|
|
|
2024-06-20 16:47:10 -07:00
|
|
|
def load_cache(self, tag_ids: Iterable[str]) -> None:
|
|
|
|
for tag_id in tag_ids:
|
|
|
|
if tag_id not in tags:
|
|
|
|
continue
|
|
|
|
tag = tags[tag_id]
|
|
|
|
if not tag.enabled:
|
|
|
|
continue
|
|
|
|
md = tag.read_tags(self.archiver)
|
|
|
|
if not md.is_empty:
|
|
|
|
self.md[tag_id] = md
|
2023-12-17 21:47:43 -08:00
|
|
|
|
2024-06-20 16:47:10 -07:00
|
|
|
def get_supported_tags(self) -> list[str]:
|
|
|
|
return [tag_id for tag_id, tag in tags.items() if tag.enabled and tag.supports_tags(self.archiver)]
|
2015-02-16 05:09:21 -08:00
|
|
|
|
2022-06-02 18:32:16 -07:00
|
|
|
def rename(self, path: pathlib.Path | str) -> None:
|
2022-07-09 22:27:45 -07:00
|
|
|
new_path = pathlib.Path(path).absolute()
|
|
|
|
if new_path == self.path:
|
|
|
|
return
|
|
|
|
os.makedirs(new_path.parent, 0o777, True)
|
2022-07-29 22:05:03 -07:00
|
|
|
shutil.move(self.path, new_path)
|
2022-07-09 22:27:45 -07:00
|
|
|
self.path = new_path
|
2022-05-17 13:57:04 -07:00
|
|
|
self.archiver.path = pathlib.Path(path)
|
2015-02-16 05:09:21 -08:00
|
|
|
|
2022-08-17 15:53:19 -07:00
|
|
|
def is_writable(self, check_archive_status: bool = True) -> bool:
|
|
|
|
if isinstance(self.archiver, UnknownArchiver):
|
2015-02-16 05:09:21 -08:00
|
|
|
return False
|
|
|
|
|
2022-08-17 15:53:19 -07:00
|
|
|
if check_archive_status and not self.archiver.is_writable():
|
2015-02-16 05:09:21 -08:00
|
|
|
return False
|
|
|
|
|
2022-08-17 15:53:19 -07:00
|
|
|
if not (os.access(self.path, os.W_OK) or os.access(self.path.parent, os.W_OK)):
|
2015-02-16 05:09:21 -08:00
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
2022-08-17 15:53:19 -07:00
|
|
|
def is_zip(self) -> bool:
|
|
|
|
return self.archiver.name() == "ZIP"
|
2015-02-16 05:09:21 -08:00
|
|
|
|
2022-05-17 13:57:04 -07:00
|
|
|
def seems_to_be_a_comic_archive(self) -> bool:
|
2024-08-03 23:11:31 -07:00
|
|
|
if (
|
|
|
|
not (isinstance(self.archiver, UnknownArchiver))
|
|
|
|
and self.get_number_of_pages() > 0
|
|
|
|
and self.archiver.is_valid(self.path)
|
|
|
|
):
|
2015-02-16 05:09:21 -08:00
|
|
|
return True
|
|
|
|
|
Code cleanup
Remove no longer used google scripts
Remove convenience files from comicataggerlib and import comicapi directly
Add type-hints to facilitate auto-complete tools
Make PyQt5 code more compatible with PyQt6
Implement automatic tooling
isort and black for code formatting
Line length has been set to 120
flake8 for code standards with exceptions:
E203 - Whitespace before ':' - format compatiblity with black
E501 - Line too long - flake8 line limit cannot be set
E722 - Do not use bare except - fixing bare except statements is a
lot of overhead and there are already
many in the codebase
These changes, along with some manual fixes creates much more readable code.
See examples below:
diff --git a/comicapi/comet.py b/comicapi/comet.py
index d1741c5..52dc195 100644
--- a/comicapi/comet.py
+++ b/comicapi/comet.py
@@ -166,7 +166,2 @@ class CoMet:
- if credit['role'].lower() in set(self.editor_synonyms):
- ET.SubElement(
- root,
- 'editor').text = "{0}".format(
- credit['person'])
@@ -174,2 +169,4 @@ class CoMet:
self.indent(root)
+ if credit["role"].lower() in set(self.editor_synonyms):
+ ET.SubElement(root, "editor").text = str(credit["person"])
diff --git a/comictaggerlib/autotagmatchwindow.py b/comictaggerlib/autotagmatchwindow.py
index 4338176..9219f01 100644
--- a/comictaggerlib/autotagmatchwindow.py
+++ b/comictaggerlib/autotagmatchwindow.py
@@ -63,4 +63,3 @@ class AutoTagMatchWindow(QtWidgets.QDialog):
self.skipButton, QtWidgets.QDialogButtonBox.ActionRole)
- self.buttonBox.button(QtWidgets.QDialogButtonBox.Ok).setText(
- "Accept and Write Tags")
+ self.buttonBox.button(QtWidgets.QDialogButtonBox.StandardButton.Ok).setText("Accept and Write Tags")
diff --git a/comictaggerlib/cli.py b/comictaggerlib/cli.py
index 688907d..dbd0c2e 100644
--- a/comictaggerlib/cli.py
+++ b/comictaggerlib/cli.py
@@ -293,7 +293,3 @@ def process_file_cli(filename, opts, settings, match_results):
if opts.raw:
- print((
- "{0}".format(
- str(
- ca.readRawCIX(),
- errors='ignore'))))
+ print(ca.read_raw_cix())
else:
2022-04-01 16:50:46 -07:00
|
|
|
return False
|
2015-02-16 05:09:21 -08:00
|
|
|
|
2022-08-17 15:53:19 -07:00
|
|
|
def extension(self) -> str:
|
|
|
|
return self.archiver.extension()
|
|
|
|
|
2024-06-20 16:47:10 -07:00
|
|
|
def read_tags(self, tag_id: str) -> GenericMetadata:
|
|
|
|
if tag_id in self.md:
|
|
|
|
return self.md[tag_id]
|
2023-12-18 16:56:54 -08:00
|
|
|
md = GenericMetadata()
|
2024-06-20 16:47:10 -07:00
|
|
|
tag = tags[tag_id]
|
|
|
|
if tag.enabled and tag.has_tags(self.archiver):
|
|
|
|
md = tag.read_tags(self.archiver)
|
2023-12-18 16:56:54 -08:00
|
|
|
md.apply_default_page_list(self.get_page_name_list())
|
2023-12-18 02:37:34 -08:00
|
|
|
return md
|
2015-02-16 05:09:21 -08:00
|
|
|
|
2024-06-20 16:47:10 -07:00
|
|
|
def read_raw_tags(self, tag_id: str) -> str:
|
|
|
|
if not tags[tag_id].enabled:
|
|
|
|
return ""
|
|
|
|
return tags[tag_id].read_raw_tags(self.archiver)
|
2023-12-17 21:47:43 -08:00
|
|
|
|
2024-06-20 16:47:10 -07:00
|
|
|
def write_tags(self, metadata: GenericMetadata, tag_id: str) -> bool:
|
|
|
|
if tag_id in self.md:
|
|
|
|
del self.md[tag_id]
|
|
|
|
if not tags[tag_id].enabled:
|
|
|
|
return False
|
2024-07-27 15:50:15 -07:00
|
|
|
|
|
|
|
self.apply_archive_info_to_metadata(metadata, True, True)
|
2024-06-20 16:47:10 -07:00
|
|
|
return tags[tag_id].write_tags(metadata, self.archiver)
|
2023-12-17 21:47:43 -08:00
|
|
|
|
2024-06-20 16:47:10 -07:00
|
|
|
def has_tags(self, tag_id: str) -> bool:
|
|
|
|
if tag_id in self.md:
|
2023-12-17 21:47:43 -08:00
|
|
|
return True
|
2024-06-20 16:47:10 -07:00
|
|
|
if not tags[tag_id].enabled:
|
|
|
|
return False
|
|
|
|
return tags[tag_id].has_tags(self.archiver)
|
2023-12-17 21:47:43 -08:00
|
|
|
|
2024-06-20 16:47:10 -07:00
|
|
|
def remove_tags(self, tag_id: str) -> bool:
|
|
|
|
if tag_id in self.md:
|
|
|
|
del self.md[tag_id]
|
|
|
|
if not tags[tag_id].enabled:
|
|
|
|
return False
|
|
|
|
return tags[tag_id].remove_tags(self.archiver)
|
2015-02-16 05:09:21 -08:00
|
|
|
|
2022-05-17 13:57:04 -07:00
|
|
|
def get_page(self, index: int) -> bytes:
|
2022-08-10 16:46:00 -07:00
|
|
|
image_data = b""
|
2015-02-16 05:09:21 -08:00
|
|
|
|
Code cleanup
Remove no longer used google scripts
Remove convenience files from comicataggerlib and import comicapi directly
Add type-hints to facilitate auto-complete tools
Make PyQt5 code more compatible with PyQt6
Implement automatic tooling
isort and black for code formatting
Line length has been set to 120
flake8 for code standards with exceptions:
E203 - Whitespace before ':' - format compatiblity with black
E501 - Line too long - flake8 line limit cannot be set
E722 - Do not use bare except - fixing bare except statements is a
lot of overhead and there are already
many in the codebase
These changes, along with some manual fixes creates much more readable code.
See examples below:
diff --git a/comicapi/comet.py b/comicapi/comet.py
index d1741c5..52dc195 100644
--- a/comicapi/comet.py
+++ b/comicapi/comet.py
@@ -166,7 +166,2 @@ class CoMet:
- if credit['role'].lower() in set(self.editor_synonyms):
- ET.SubElement(
- root,
- 'editor').text = "{0}".format(
- credit['person'])
@@ -174,2 +169,4 @@ class CoMet:
self.indent(root)
+ if credit["role"].lower() in set(self.editor_synonyms):
+ ET.SubElement(root, "editor").text = str(credit["person"])
diff --git a/comictaggerlib/autotagmatchwindow.py b/comictaggerlib/autotagmatchwindow.py
index 4338176..9219f01 100644
--- a/comictaggerlib/autotagmatchwindow.py
+++ b/comictaggerlib/autotagmatchwindow.py
@@ -63,4 +63,3 @@ class AutoTagMatchWindow(QtWidgets.QDialog):
self.skipButton, QtWidgets.QDialogButtonBox.ActionRole)
- self.buttonBox.button(QtWidgets.QDialogButtonBox.Ok).setText(
- "Accept and Write Tags")
+ self.buttonBox.button(QtWidgets.QDialogButtonBox.StandardButton.Ok).setText("Accept and Write Tags")
diff --git a/comictaggerlib/cli.py b/comictaggerlib/cli.py
index 688907d..dbd0c2e 100644
--- a/comictaggerlib/cli.py
+++ b/comictaggerlib/cli.py
@@ -293,7 +293,3 @@ def process_file_cli(filename, opts, settings, match_results):
if opts.raw:
- print((
- "{0}".format(
- str(
- ca.readRawCIX(),
- errors='ignore'))))
+ print(ca.read_raw_cix())
else:
2022-04-01 16:50:46 -07:00
|
|
|
filename = self.get_page_name(index)
|
2015-02-16 05:09:21 -08:00
|
|
|
|
2022-05-17 13:57:04 -07:00
|
|
|
if filename:
|
2015-02-16 05:09:21 -08:00
|
|
|
try:
|
2022-08-10 16:46:00 -07:00
|
|
|
image_data = self.archiver.read_file(filename) or b""
|
2024-08-03 23:11:31 -07:00
|
|
|
except Exception:
|
|
|
|
logger.exception("Error reading in page %d. Substituting logo page.", index)
|
2015-02-16 05:09:21 -08:00
|
|
|
image_data = ComicArchive.logo_data
|
|
|
|
|
|
|
|
return image_data
|
|
|
|
|
2022-05-17 13:57:04 -07:00
|
|
|
def get_page_name(self, index: int) -> str:
|
2015-02-16 05:09:21 -08:00
|
|
|
if index is None:
|
2022-07-18 12:17:13 -07:00
|
|
|
return ""
|
2015-02-16 05:09:21 -08:00
|
|
|
|
Code cleanup
Remove no longer used google scripts
Remove convenience files from comicataggerlib and import comicapi directly
Add type-hints to facilitate auto-complete tools
Make PyQt5 code more compatible with PyQt6
Implement automatic tooling
isort and black for code formatting
Line length has been set to 120
flake8 for code standards with exceptions:
E203 - Whitespace before ':' - format compatiblity with black
E501 - Line too long - flake8 line limit cannot be set
E722 - Do not use bare except - fixing bare except statements is a
lot of overhead and there are already
many in the codebase
These changes, along with some manual fixes creates much more readable code.
See examples below:
diff --git a/comicapi/comet.py b/comicapi/comet.py
index d1741c5..52dc195 100644
--- a/comicapi/comet.py
+++ b/comicapi/comet.py
@@ -166,7 +166,2 @@ class CoMet:
- if credit['role'].lower() in set(self.editor_synonyms):
- ET.SubElement(
- root,
- 'editor').text = "{0}".format(
- credit['person'])
@@ -174,2 +169,4 @@ class CoMet:
self.indent(root)
+ if credit["role"].lower() in set(self.editor_synonyms):
+ ET.SubElement(root, "editor").text = str(credit["person"])
diff --git a/comictaggerlib/autotagmatchwindow.py b/comictaggerlib/autotagmatchwindow.py
index 4338176..9219f01 100644
--- a/comictaggerlib/autotagmatchwindow.py
+++ b/comictaggerlib/autotagmatchwindow.py
@@ -63,4 +63,3 @@ class AutoTagMatchWindow(QtWidgets.QDialog):
self.skipButton, QtWidgets.QDialogButtonBox.ActionRole)
- self.buttonBox.button(QtWidgets.QDialogButtonBox.Ok).setText(
- "Accept and Write Tags")
+ self.buttonBox.button(QtWidgets.QDialogButtonBox.StandardButton.Ok).setText("Accept and Write Tags")
diff --git a/comictaggerlib/cli.py b/comictaggerlib/cli.py
index 688907d..dbd0c2e 100644
--- a/comictaggerlib/cli.py
+++ b/comictaggerlib/cli.py
@@ -293,7 +293,3 @@ def process_file_cli(filename, opts, settings, match_results):
if opts.raw:
- print((
- "{0}".format(
- str(
- ca.readRawCIX(),
- errors='ignore'))))
+ print(ca.read_raw_cix())
else:
2022-04-01 16:50:46 -07:00
|
|
|
page_list = self.get_page_name_list()
|
2015-02-16 05:09:21 -08:00
|
|
|
|
2015-02-21 18:30:32 -08:00
|
|
|
num_pages = len(page_list)
|
2015-02-16 05:09:21 -08:00
|
|
|
if num_pages == 0 or index >= num_pages:
|
2022-05-17 13:57:04 -07:00
|
|
|
return ""
|
2015-02-16 05:09:21 -08:00
|
|
|
|
2015-02-21 18:30:32 -08:00
|
|
|
return page_list[index]
|
2015-02-16 05:09:21 -08:00
|
|
|
|
2022-06-02 18:32:16 -07:00
|
|
|
def get_scanner_page_index(self) -> int | None:
|
2015-02-16 05:09:21 -08:00
|
|
|
scanner_page_index = None
|
|
|
|
|
2015-02-21 18:30:32 -08:00
|
|
|
# make a guess at the scanner page
|
Code cleanup
Remove no longer used google scripts
Remove convenience files from comicataggerlib and import comicapi directly
Add type-hints to facilitate auto-complete tools
Make PyQt5 code more compatible with PyQt6
Implement automatic tooling
isort and black for code formatting
Line length has been set to 120
flake8 for code standards with exceptions:
E203 - Whitespace before ':' - format compatiblity with black
E501 - Line too long - flake8 line limit cannot be set
E722 - Do not use bare except - fixing bare except statements is a
lot of overhead and there are already
many in the codebase
These changes, along with some manual fixes creates much more readable code.
See examples below:
diff --git a/comicapi/comet.py b/comicapi/comet.py
index d1741c5..52dc195 100644
--- a/comicapi/comet.py
+++ b/comicapi/comet.py
@@ -166,7 +166,2 @@ class CoMet:
- if credit['role'].lower() in set(self.editor_synonyms):
- ET.SubElement(
- root,
- 'editor').text = "{0}".format(
- credit['person'])
@@ -174,2 +169,4 @@ class CoMet:
self.indent(root)
+ if credit["role"].lower() in set(self.editor_synonyms):
+ ET.SubElement(root, "editor").text = str(credit["person"])
diff --git a/comictaggerlib/autotagmatchwindow.py b/comictaggerlib/autotagmatchwindow.py
index 4338176..9219f01 100644
--- a/comictaggerlib/autotagmatchwindow.py
+++ b/comictaggerlib/autotagmatchwindow.py
@@ -63,4 +63,3 @@ class AutoTagMatchWindow(QtWidgets.QDialog):
self.skipButton, QtWidgets.QDialogButtonBox.ActionRole)
- self.buttonBox.button(QtWidgets.QDialogButtonBox.Ok).setText(
- "Accept and Write Tags")
+ self.buttonBox.button(QtWidgets.QDialogButtonBox.StandardButton.Ok).setText("Accept and Write Tags")
diff --git a/comictaggerlib/cli.py b/comictaggerlib/cli.py
index 688907d..dbd0c2e 100644
--- a/comictaggerlib/cli.py
+++ b/comictaggerlib/cli.py
@@ -293,7 +293,3 @@ def process_file_cli(filename, opts, settings, match_results):
if opts.raw:
- print((
- "{0}".format(
- str(
- ca.readRawCIX(),
- errors='ignore'))))
+ print(ca.read_raw_cix())
else:
2022-04-01 16:50:46 -07:00
|
|
|
name_list = self.get_page_name_list()
|
|
|
|
count = self.get_number_of_pages()
|
2015-02-16 05:09:21 -08:00
|
|
|
|
2015-02-21 18:30:32 -08:00
|
|
|
# too few pages to really know
|
2015-02-16 05:09:21 -08:00
|
|
|
if count < 5:
|
|
|
|
return None
|
|
|
|
|
2022-04-04 18:59:26 -07:00
|
|
|
# count the length of every filename, and count occurrences
|
2022-05-17 13:57:04 -07:00
|
|
|
length_buckets: dict[int, int] = {}
|
2015-02-16 05:09:21 -08:00
|
|
|
for name in name_list:
|
2015-02-21 18:30:32 -08:00
|
|
|
fname = os.path.split(name)[1]
|
2015-02-16 05:09:21 -08:00
|
|
|
length = len(fname)
|
2015-02-21 18:30:32 -08:00
|
|
|
if length in length_buckets:
|
|
|
|
length_buckets[length] += 1
|
2015-02-16 05:09:21 -08:00
|
|
|
else:
|
2015-02-21 18:30:32 -08:00
|
|
|
length_buckets[length] = 1
|
2015-02-16 05:09:21 -08:00
|
|
|
|
|
|
|
# sort by most common
|
2022-06-01 21:14:51 -07:00
|
|
|
sorted_buckets = sorted(length_buckets.items(), key=lambda tup: (tup[1], tup[0]), reverse=True)
|
2015-02-16 05:09:21 -08:00
|
|
|
|
2022-04-04 18:59:26 -07:00
|
|
|
# statistical mode occurrence is first
|
2015-02-16 05:09:21 -08:00
|
|
|
mode_length = sorted_buckets[0][0]
|
|
|
|
|
|
|
|
# we are only going to consider the final image file:
|
2015-02-21 18:30:32 -08:00
|
|
|
final_name = os.path.split(name_list[count - 1])[1]
|
2015-02-16 05:09:21 -08:00
|
|
|
|
Code cleanup
Remove no longer used google scripts
Remove convenience files from comicataggerlib and import comicapi directly
Add type-hints to facilitate auto-complete tools
Make PyQt5 code more compatible with PyQt6
Implement automatic tooling
isort and black for code formatting
Line length has been set to 120
flake8 for code standards with exceptions:
E203 - Whitespace before ':' - format compatiblity with black
E501 - Line too long - flake8 line limit cannot be set
E722 - Do not use bare except - fixing bare except statements is a
lot of overhead and there are already
many in the codebase
These changes, along with some manual fixes creates much more readable code.
See examples below:
diff --git a/comicapi/comet.py b/comicapi/comet.py
index d1741c5..52dc195 100644
--- a/comicapi/comet.py
+++ b/comicapi/comet.py
@@ -166,7 +166,2 @@ class CoMet:
- if credit['role'].lower() in set(self.editor_synonyms):
- ET.SubElement(
- root,
- 'editor').text = "{0}".format(
- credit['person'])
@@ -174,2 +169,4 @@ class CoMet:
self.indent(root)
+ if credit["role"].lower() in set(self.editor_synonyms):
+ ET.SubElement(root, "editor").text = str(credit["person"])
diff --git a/comictaggerlib/autotagmatchwindow.py b/comictaggerlib/autotagmatchwindow.py
index 4338176..9219f01 100644
--- a/comictaggerlib/autotagmatchwindow.py
+++ b/comictaggerlib/autotagmatchwindow.py
@@ -63,4 +63,3 @@ class AutoTagMatchWindow(QtWidgets.QDialog):
self.skipButton, QtWidgets.QDialogButtonBox.ActionRole)
- self.buttonBox.button(QtWidgets.QDialogButtonBox.Ok).setText(
- "Accept and Write Tags")
+ self.buttonBox.button(QtWidgets.QDialogButtonBox.StandardButton.Ok).setText("Accept and Write Tags")
diff --git a/comictaggerlib/cli.py b/comictaggerlib/cli.py
index 688907d..dbd0c2e 100644
--- a/comictaggerlib/cli.py
+++ b/comictaggerlib/cli.py
@@ -293,7 +293,3 @@ def process_file_cli(filename, opts, settings, match_results):
if opts.raw:
- print((
- "{0}".format(
- str(
- ca.readRawCIX(),
- errors='ignore'))))
+ print(ca.read_raw_cix())
else:
2022-04-01 16:50:46 -07:00
|
|
|
common_length_list = []
|
2015-02-16 05:09:21 -08:00
|
|
|
for name in name_list:
|
|
|
|
if len(os.path.split(name)[1]) == mode_length:
|
2015-02-21 18:30:32 -08:00
|
|
|
common_length_list.append(os.path.split(name)[1])
|
2015-02-16 05:09:21 -08:00
|
|
|
|
|
|
|
prefix = os.path.commonprefix(common_length_list)
|
|
|
|
|
|
|
|
if mode_length <= 7 and prefix == "":
|
2015-02-21 18:30:32 -08:00
|
|
|
# probably all numbers
|
2015-02-16 05:09:21 -08:00
|
|
|
if len(final_name) > mode_length:
|
2015-02-21 18:30:32 -08:00
|
|
|
scanner_page_index = count - 1
|
2015-02-16 05:09:21 -08:00
|
|
|
|
Code cleanup
Remove no longer used google scripts
Remove convenience files from comicataggerlib and import comicapi directly
Add type-hints to facilitate auto-complete tools
Make PyQt5 code more compatible with PyQt6
Implement automatic tooling
isort and black for code formatting
Line length has been set to 120
flake8 for code standards with exceptions:
E203 - Whitespace before ':' - format compatiblity with black
E501 - Line too long - flake8 line limit cannot be set
E722 - Do not use bare except - fixing bare except statements is a
lot of overhead and there are already
many in the codebase
These changes, along with some manual fixes creates much more readable code.
See examples below:
diff --git a/comicapi/comet.py b/comicapi/comet.py
index d1741c5..52dc195 100644
--- a/comicapi/comet.py
+++ b/comicapi/comet.py
@@ -166,7 +166,2 @@ class CoMet:
- if credit['role'].lower() in set(self.editor_synonyms):
- ET.SubElement(
- root,
- 'editor').text = "{0}".format(
- credit['person'])
@@ -174,2 +169,4 @@ class CoMet:
self.indent(root)
+ if credit["role"].lower() in set(self.editor_synonyms):
+ ET.SubElement(root, "editor").text = str(credit["person"])
diff --git a/comictaggerlib/autotagmatchwindow.py b/comictaggerlib/autotagmatchwindow.py
index 4338176..9219f01 100644
--- a/comictaggerlib/autotagmatchwindow.py
+++ b/comictaggerlib/autotagmatchwindow.py
@@ -63,4 +63,3 @@ class AutoTagMatchWindow(QtWidgets.QDialog):
self.skipButton, QtWidgets.QDialogButtonBox.ActionRole)
- self.buttonBox.button(QtWidgets.QDialogButtonBox.Ok).setText(
- "Accept and Write Tags")
+ self.buttonBox.button(QtWidgets.QDialogButtonBox.StandardButton.Ok).setText("Accept and Write Tags")
diff --git a/comictaggerlib/cli.py b/comictaggerlib/cli.py
index 688907d..dbd0c2e 100644
--- a/comictaggerlib/cli.py
+++ b/comictaggerlib/cli.py
@@ -293,7 +293,3 @@ def process_file_cli(filename, opts, settings, match_results):
if opts.raw:
- print((
- "{0}".format(
- str(
- ca.readRawCIX(),
- errors='ignore'))))
+ print(ca.read_raw_cix())
else:
2022-04-01 16:50:46 -07:00
|
|
|
# see if the last page doesn't start with the same prefix as most others
|
2015-02-16 05:09:21 -08:00
|
|
|
elif not final_name.startswith(prefix):
|
2015-02-21 18:30:32 -08:00
|
|
|
scanner_page_index = count - 1
|
2015-02-16 05:09:21 -08:00
|
|
|
|
|
|
|
return scanner_page_index
|
|
|
|
|
2023-12-18 02:37:34 -08:00
|
|
|
def get_page_name_list(self) -> list[str]:
|
2022-05-17 13:57:04 -07:00
|
|
|
if not self.page_list:
|
2023-12-20 21:24:12 -08:00
|
|
|
self.page_list = utils.get_page_name_list(self.archiver.get_filename_list())
|
2015-02-16 05:09:21 -08:00
|
|
|
|
|
|
|
return self.page_list
|
|
|
|
|
2022-05-17 13:57:04 -07:00
|
|
|
def get_number_of_pages(self) -> int:
|
2015-02-16 05:09:21 -08:00
|
|
|
if self.page_count is None:
|
Code cleanup
Remove no longer used google scripts
Remove convenience files from comicataggerlib and import comicapi directly
Add type-hints to facilitate auto-complete tools
Make PyQt5 code more compatible with PyQt6
Implement automatic tooling
isort and black for code formatting
Line length has been set to 120
flake8 for code standards with exceptions:
E203 - Whitespace before ':' - format compatiblity with black
E501 - Line too long - flake8 line limit cannot be set
E722 - Do not use bare except - fixing bare except statements is a
lot of overhead and there are already
many in the codebase
These changes, along with some manual fixes creates much more readable code.
See examples below:
diff --git a/comicapi/comet.py b/comicapi/comet.py
index d1741c5..52dc195 100644
--- a/comicapi/comet.py
+++ b/comicapi/comet.py
@@ -166,7 +166,2 @@ class CoMet:
- if credit['role'].lower() in set(self.editor_synonyms):
- ET.SubElement(
- root,
- 'editor').text = "{0}".format(
- credit['person'])
@@ -174,2 +169,4 @@ class CoMet:
self.indent(root)
+ if credit["role"].lower() in set(self.editor_synonyms):
+ ET.SubElement(root, "editor").text = str(credit["person"])
diff --git a/comictaggerlib/autotagmatchwindow.py b/comictaggerlib/autotagmatchwindow.py
index 4338176..9219f01 100644
--- a/comictaggerlib/autotagmatchwindow.py
+++ b/comictaggerlib/autotagmatchwindow.py
@@ -63,4 +63,3 @@ class AutoTagMatchWindow(QtWidgets.QDialog):
self.skipButton, QtWidgets.QDialogButtonBox.ActionRole)
- self.buttonBox.button(QtWidgets.QDialogButtonBox.Ok).setText(
- "Accept and Write Tags")
+ self.buttonBox.button(QtWidgets.QDialogButtonBox.StandardButton.Ok).setText("Accept and Write Tags")
diff --git a/comictaggerlib/cli.py b/comictaggerlib/cli.py
index 688907d..dbd0c2e 100644
--- a/comictaggerlib/cli.py
+++ b/comictaggerlib/cli.py
@@ -293,7 +293,3 @@ def process_file_cli(filename, opts, settings, match_results):
if opts.raw:
- print((
- "{0}".format(
- str(
- ca.readRawCIX(),
- errors='ignore'))))
+ print(ca.read_raw_cix())
else:
2022-04-01 16:50:46 -07:00
|
|
|
self.page_count = len(self.get_page_name_list())
|
2015-02-16 05:09:21 -08:00
|
|
|
return self.page_count
|
|
|
|
|
2024-07-27 15:57:11 -07:00
|
|
|
def apply_archive_info_to_metadata(
|
|
|
|
self, md: GenericMetadata, calc_page_sizes: bool = False, detect_double_page: bool = False
|
|
|
|
) -> None:
|
Code cleanup
Remove no longer used google scripts
Remove convenience files from comicataggerlib and import comicapi directly
Add type-hints to facilitate auto-complete tools
Make PyQt5 code more compatible with PyQt6
Implement automatic tooling
isort and black for code formatting
Line length has been set to 120
flake8 for code standards with exceptions:
E203 - Whitespace before ':' - format compatiblity with black
E501 - Line too long - flake8 line limit cannot be set
E722 - Do not use bare except - fixing bare except statements is a
lot of overhead and there are already
many in the codebase
These changes, along with some manual fixes creates much more readable code.
See examples below:
diff --git a/comicapi/comet.py b/comicapi/comet.py
index d1741c5..52dc195 100644
--- a/comicapi/comet.py
+++ b/comicapi/comet.py
@@ -166,7 +166,2 @@ class CoMet:
- if credit['role'].lower() in set(self.editor_synonyms):
- ET.SubElement(
- root,
- 'editor').text = "{0}".format(
- credit['person'])
@@ -174,2 +169,4 @@ class CoMet:
self.indent(root)
+ if credit["role"].lower() in set(self.editor_synonyms):
+ ET.SubElement(root, "editor").text = str(credit["person"])
diff --git a/comictaggerlib/autotagmatchwindow.py b/comictaggerlib/autotagmatchwindow.py
index 4338176..9219f01 100644
--- a/comictaggerlib/autotagmatchwindow.py
+++ b/comictaggerlib/autotagmatchwindow.py
@@ -63,4 +63,3 @@ class AutoTagMatchWindow(QtWidgets.QDialog):
self.skipButton, QtWidgets.QDialogButtonBox.ActionRole)
- self.buttonBox.button(QtWidgets.QDialogButtonBox.Ok).setText(
- "Accept and Write Tags")
+ self.buttonBox.button(QtWidgets.QDialogButtonBox.StandardButton.Ok).setText("Accept and Write Tags")
diff --git a/comictaggerlib/cli.py b/comictaggerlib/cli.py
index 688907d..dbd0c2e 100644
--- a/comictaggerlib/cli.py
+++ b/comictaggerlib/cli.py
@@ -293,7 +293,3 @@ def process_file_cli(filename, opts, settings, match_results):
if opts.raw:
- print((
- "{0}".format(
- str(
- ca.readRawCIX(),
- errors='ignore'))))
+ print(ca.read_raw_cix())
else:
2022-04-01 16:50:46 -07:00
|
|
|
md.page_count = self.get_number_of_pages()
|
2024-07-27 15:50:15 -07:00
|
|
|
md.apply_default_page_list(self.get_page_name_list())
|
2024-08-03 23:11:31 -07:00
|
|
|
if not calc_page_sizes or not self.seems_to_be_a_comic_archive():
|
|
|
|
return
|
|
|
|
for p in md.pages:
|
|
|
|
|
|
|
|
if not self.pil_available:
|
|
|
|
if p.byte_size is not None:
|
|
|
|
data = self.get_page(p.archive_index)
|
|
|
|
p.byte_size = len(data)
|
|
|
|
continue
|
|
|
|
try:
|
|
|
|
from PIL import Image
|
|
|
|
|
|
|
|
self.pil_available = True
|
|
|
|
except ImportError:
|
|
|
|
self.pil_available = False
|
|
|
|
if p.byte_size is not None:
|
|
|
|
data = self.get_page(p.archive_index)
|
|
|
|
p.byte_size = len(data)
|
|
|
|
continue
|
|
|
|
|
|
|
|
if p.byte_size is None or p.height is None or p.width is None or p.double_page is None:
|
|
|
|
try:
|
|
|
|
data = self.get_page(p.archive_index)
|
|
|
|
p.byte_size = len(data)
|
|
|
|
if not data:
|
|
|
|
continue
|
|
|
|
|
|
|
|
im = Image.open(io.BytesIO(data))
|
|
|
|
w, h = im.size
|
|
|
|
|
|
|
|
p.height = h
|
|
|
|
p.width = w
|
|
|
|
if detect_double_page:
|
|
|
|
p.double_page = p.is_double_page()
|
|
|
|
except Exception as e:
|
|
|
|
logger.exception("Error decoding image [%s] %s :: image %s", e, self.path, p.archive_index)
|
Code cleanup
Remove no longer used google scripts
Remove convenience files from comicataggerlib and import comicapi directly
Add type-hints to facilitate auto-complete tools
Make PyQt5 code more compatible with PyQt6
Implement automatic tooling
isort and black for code formatting
Line length has been set to 120
flake8 for code standards with exceptions:
E203 - Whitespace before ':' - format compatiblity with black
E501 - Line too long - flake8 line limit cannot be set
E722 - Do not use bare except - fixing bare except statements is a
lot of overhead and there are already
many in the codebase
These changes, along with some manual fixes creates much more readable code.
See examples below:
diff --git a/comicapi/comet.py b/comicapi/comet.py
index d1741c5..52dc195 100644
--- a/comicapi/comet.py
+++ b/comicapi/comet.py
@@ -166,7 +166,2 @@ class CoMet:
- if credit['role'].lower() in set(self.editor_synonyms):
- ET.SubElement(
- root,
- 'editor').text = "{0}".format(
- credit['person'])
@@ -174,2 +169,4 @@ class CoMet:
self.indent(root)
+ if credit["role"].lower() in set(self.editor_synonyms):
+ ET.SubElement(root, "editor").text = str(credit["person"])
diff --git a/comictaggerlib/autotagmatchwindow.py b/comictaggerlib/autotagmatchwindow.py
index 4338176..9219f01 100644
--- a/comictaggerlib/autotagmatchwindow.py
+++ b/comictaggerlib/autotagmatchwindow.py
@@ -63,4 +63,3 @@ class AutoTagMatchWindow(QtWidgets.QDialog):
self.skipButton, QtWidgets.QDialogButtonBox.ActionRole)
- self.buttonBox.button(QtWidgets.QDialogButtonBox.Ok).setText(
- "Accept and Write Tags")
+ self.buttonBox.button(QtWidgets.QDialogButtonBox.StandardButton.Ok).setText("Accept and Write Tags")
diff --git a/comictaggerlib/cli.py b/comictaggerlib/cli.py
index 688907d..dbd0c2e 100644
--- a/comictaggerlib/cli.py
+++ b/comictaggerlib/cli.py
@@ -293,7 +293,3 @@ def process_file_cli(filename, opts, settings, match_results):
if opts.raw:
- print((
- "{0}".format(
- str(
- ca.readRawCIX(),
- errors='ignore'))))
+ print(ca.read_raw_cix())
else:
2022-04-01 16:50:46 -07:00
|
|
|
|
2022-04-29 16:37:44 -07:00
|
|
|
def metadata_from_filename(
|
2022-05-17 13:57:04 -07:00
|
|
|
self,
|
2024-03-03 21:47:31 -08:00
|
|
|
parser: utils.Parser = utils.Parser.ORIGINAL,
|
2022-05-17 13:57:04 -07:00
|
|
|
remove_c2c: bool = False,
|
|
|
|
remove_fcbd: bool = False,
|
|
|
|
remove_publisher: bool = False,
|
2022-05-19 17:58:45 -07:00
|
|
|
split_words: bool = False,
|
2023-09-06 01:50:05 -07:00
|
|
|
allow_issue_start_with_letter: bool = False,
|
|
|
|
protofolius_issue_number_scheme: bool = False,
|
2022-05-17 13:57:04 -07:00
|
|
|
) -> GenericMetadata:
|
2015-02-16 05:09:21 -08:00
|
|
|
metadata = GenericMetadata()
|
|
|
|
|
2023-09-06 01:50:05 -07:00
|
|
|
filename_info = utils.parse_filename(
|
|
|
|
self.path.name,
|
2024-03-03 21:47:31 -08:00
|
|
|
parser=parser,
|
2023-09-06 01:50:05 -07:00
|
|
|
remove_c2c=remove_c2c,
|
|
|
|
remove_fcbd=remove_fcbd,
|
|
|
|
remove_publisher=remove_publisher,
|
|
|
|
split_words=split_words,
|
|
|
|
allow_issue_start_with_letter=allow_issue_start_with_letter,
|
|
|
|
protofolius_issue_number_scheme=protofolius_issue_number_scheme,
|
|
|
|
)
|
|
|
|
metadata.alternate_number = utils.xlate(filename_info.get("alternate", None))
|
|
|
|
metadata.issue = utils.xlate(filename_info.get("issue", None))
|
|
|
|
metadata.issue_count = utils.xlate_int(filename_info.get("issue_count", None))
|
|
|
|
metadata.publisher = utils.xlate(filename_info.get("publisher", None))
|
|
|
|
metadata.series = utils.xlate(filename_info.get("series", None))
|
|
|
|
metadata.title = utils.xlate(filename_info.get("title", None))
|
|
|
|
metadata.volume = utils.xlate_int(filename_info.get("volume", None))
|
|
|
|
metadata.volume_count = utils.xlate_int(filename_info.get("volume_count", None))
|
|
|
|
metadata.year = utils.xlate_int(filename_info.get("year", None))
|
|
|
|
|
|
|
|
metadata.scan_info = utils.xlate(filename_info.get("remainder", None))
|
2024-06-21 20:07:07 -07:00
|
|
|
|
|
|
|
if filename_info.get("fcbd", None):
|
|
|
|
metadata.format = "FCBD"
|
|
|
|
metadata.tags.add("FCBD")
|
|
|
|
|
|
|
|
if filename_info.get("c2c", None):
|
|
|
|
metadata.tags.add("c2c")
|
|
|
|
|
2023-09-06 01:50:05 -07:00
|
|
|
if filename_info.get("annual", None):
|
|
|
|
metadata.format = "Annual"
|
2024-06-21 20:07:07 -07:00
|
|
|
|
2023-09-06 01:50:05 -07:00
|
|
|
if filename_info.get("format", None):
|
|
|
|
metadata.format = filename_info["format"]
|
2015-02-16 05:09:21 -08:00
|
|
|
|
Code cleanup
Remove no longer used google scripts
Remove convenience files from comicataggerlib and import comicapi directly
Add type-hints to facilitate auto-complete tools
Make PyQt5 code more compatible with PyQt6
Implement automatic tooling
isort and black for code formatting
Line length has been set to 120
flake8 for code standards with exceptions:
E203 - Whitespace before ':' - format compatiblity with black
E501 - Line too long - flake8 line limit cannot be set
E722 - Do not use bare except - fixing bare except statements is a
lot of overhead and there are already
many in the codebase
These changes, along with some manual fixes creates much more readable code.
See examples below:
diff --git a/comicapi/comet.py b/comicapi/comet.py
index d1741c5..52dc195 100644
--- a/comicapi/comet.py
+++ b/comicapi/comet.py
@@ -166,7 +166,2 @@ class CoMet:
- if credit['role'].lower() in set(self.editor_synonyms):
- ET.SubElement(
- root,
- 'editor').text = "{0}".format(
- credit['person'])
@@ -174,2 +169,4 @@ class CoMet:
self.indent(root)
+ if credit["role"].lower() in set(self.editor_synonyms):
+ ET.SubElement(root, "editor").text = str(credit["person"])
diff --git a/comictaggerlib/autotagmatchwindow.py b/comictaggerlib/autotagmatchwindow.py
index 4338176..9219f01 100644
--- a/comictaggerlib/autotagmatchwindow.py
+++ b/comictaggerlib/autotagmatchwindow.py
@@ -63,4 +63,3 @@ class AutoTagMatchWindow(QtWidgets.QDialog):
self.skipButton, QtWidgets.QDialogButtonBox.ActionRole)
- self.buttonBox.button(QtWidgets.QDialogButtonBox.Ok).setText(
- "Accept and Write Tags")
+ self.buttonBox.button(QtWidgets.QDialogButtonBox.StandardButton.Ok).setText("Accept and Write Tags")
diff --git a/comictaggerlib/cli.py b/comictaggerlib/cli.py
index 688907d..dbd0c2e 100644
--- a/comictaggerlib/cli.py
+++ b/comictaggerlib/cli.py
@@ -293,7 +293,3 @@ def process_file_cli(filename, opts, settings, match_results):
if opts.raw:
- print((
- "{0}".format(
- str(
- ca.readRawCIX(),
- errors='ignore'))))
+ print(ca.read_raw_cix())
else:
2022-04-01 16:50:46 -07:00
|
|
|
metadata.is_empty = False
|
2015-02-16 05:09:21 -08:00
|
|
|
return metadata
|
|
|
|
|
2022-08-17 15:53:19 -07:00
|
|
|
def export_as_zip(self, zip_filename: pathlib.Path) -> bool:
|
|
|
|
if self.archiver.name() == "ZIP":
|
2015-02-16 05:09:21 -08:00
|
|
|
# nothing to do, we're already a zip
|
|
|
|
return True
|
|
|
|
|
2022-08-17 15:53:19 -07:00
|
|
|
zip_archiver = ZipArchiver.open(zip_filename)
|
Code cleanup
Remove no longer used google scripts
Remove convenience files from comicataggerlib and import comicapi directly
Add type-hints to facilitate auto-complete tools
Make PyQt5 code more compatible with PyQt6
Implement automatic tooling
isort and black for code formatting
Line length has been set to 120
flake8 for code standards with exceptions:
E203 - Whitespace before ':' - format compatiblity with black
E501 - Line too long - flake8 line limit cannot be set
E722 - Do not use bare except - fixing bare except statements is a
lot of overhead and there are already
many in the codebase
These changes, along with some manual fixes creates much more readable code.
See examples below:
diff --git a/comicapi/comet.py b/comicapi/comet.py
index d1741c5..52dc195 100644
--- a/comicapi/comet.py
+++ b/comicapi/comet.py
@@ -166,7 +166,2 @@ class CoMet:
- if credit['role'].lower() in set(self.editor_synonyms):
- ET.SubElement(
- root,
- 'editor').text = "{0}".format(
- credit['person'])
@@ -174,2 +169,4 @@ class CoMet:
self.indent(root)
+ if credit["role"].lower() in set(self.editor_synonyms):
+ ET.SubElement(root, "editor").text = str(credit["person"])
diff --git a/comictaggerlib/autotagmatchwindow.py b/comictaggerlib/autotagmatchwindow.py
index 4338176..9219f01 100644
--- a/comictaggerlib/autotagmatchwindow.py
+++ b/comictaggerlib/autotagmatchwindow.py
@@ -63,4 +63,3 @@ class AutoTagMatchWindow(QtWidgets.QDialog):
self.skipButton, QtWidgets.QDialogButtonBox.ActionRole)
- self.buttonBox.button(QtWidgets.QDialogButtonBox.Ok).setText(
- "Accept and Write Tags")
+ self.buttonBox.button(QtWidgets.QDialogButtonBox.StandardButton.Ok).setText("Accept and Write Tags")
diff --git a/comictaggerlib/cli.py b/comictaggerlib/cli.py
index 688907d..dbd0c2e 100644
--- a/comictaggerlib/cli.py
+++ b/comictaggerlib/cli.py
@@ -293,7 +293,3 @@ def process_file_cli(filename, opts, settings, match_results):
if opts.raw:
- print((
- "{0}".format(
- str(
- ca.readRawCIX(),
- errors='ignore'))))
+ print(ca.read_raw_cix())
else:
2022-04-01 16:50:46 -07:00
|
|
|
return zip_archiver.copy_from_archive(self.archiver)
|