From 05d0f12608a3083eaae446606fd649a74f2ea44e Mon Sep 17 00:00:00 2001 From: Iris Wildthyme <46726098+wildthyme@users.noreply.github.com> Date: Tue, 2 Apr 2019 18:52:45 -0400 Subject: [PATCH 1/4] redid comic importing support to handle metadata properly using comicapi from comictagger. needs work to automate installation --- .gitignore | 4 ++++ cps/comic.py | 65 ++++++++++++++++++++++++++++------------------------ 2 files changed, 39 insertions(+), 30 deletions(-) mode change 100644 => 100755 cps/comic.py diff --git a/.gitignore b/.gitignore index 09bf3faa..b3c3d439 100644 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,7 @@ gdrive_credentials vendor client_secrets.json + +# External dependencies - need proper integrating +comicapi +libunrar diff --git a/cps/comic.py b/cps/comic.py old mode 100644 new mode 100755 index 91cb325d..cc1b0600 --- a/cps/comic.py +++ b/cps/comic.py @@ -17,33 +17,21 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -import zipfile -import tarfile import os import uploader - +from comicapi.comicarchive import * +from comicapi.issuestring import * +from iso639 import languages as isoLanguages def extractCover(tmp_file_name, original_file_extension): + archive = ComicArchive(tmp_file_name) cover_data = None - if original_file_extension.upper() == '.CBZ': - cf = zipfile.ZipFile(tmp_file_name) - for name in cf.namelist(): - ext = os.path.splitext(name) - if len(ext) > 1: - extension = ext[1].lower() - if extension == '.jpg': - cover_data = cf.read(name) - break - elif original_file_extension.upper() == '.CBT': - cf = tarfile.TarFile(tmp_file_name) - for name in cf.getnames(): - ext = os.path.splitext(name) - if len(ext) > 1: - extension = ext[1].lower() - if extension == '.jpg': - cover_data = cf.extractfile(name).read() - break - + ext = os.path.splitext(archive.getPageName(0)) + if len(ext) > 1: + extension = ext[1].lower() + if extension == '.jpg' or extension == '.jpeg': + cover_data = archive.getPage(0) + print(archive.getPageName(0)) prefix = os.path.dirname(tmp_file_name) if cover_data: tmp_cover_name = prefix + '/cover' + extension @@ -56,17 +44,34 @@ def extractCover(tmp_file_name, original_file_extension): def get_comic_info(tmp_file_path, original_file_name, original_file_extension): + archive = ComicArchive(tmp_file_path) + if archive.seemsToBeAComicArchive(): + if archive.hasMetadata(MetaDataStyle.CIX): + style = MetaDataStyle.CIX + elif archive.hasMetadata(MetaDataStyle.CBI): + style = MetaDataStyle.CBI + else: + style = None - coverfile = extractCover(tmp_file_path, original_file_extension) + if style is not None: + loadedMetadata = archive.readMetadata(style) + + lang = loadedMetadata.language + if len(lang) == 2: + loadedMetadata.language = isoLanguages.get(part1=lang).name + elif len(lang) == 3: + loadedMetadata.language = isoLanguages.get(part3=lang).name + else: + loadedMetadata.language = "" return uploader.BookMeta( file_path=tmp_file_path, extension=original_file_extension, - title=original_file_name, - author=u"Unknown", - cover=coverfile, - description="", + title=loadedMetadata.title or original_file_name, + author=" & ".join([credit["person"] for credit in loadedMetadata.credits if credit["role"] == "Writer"]) or u"Unknown", + cover=extractCover(tmp_file_path, original_file_extension), + description=loadedMetadata.comments or "", tags="", - series="", - series_id="", - languages="") + series=loadedMetadata.series or "", + series_id=loadedMetadata.issue or "", + languages=loadedMetadata.language) From cbdc9876b2b39b15e2081d0c71fc102d722d10a2 Mon Sep 17 00:00:00 2001 From: Iris Wildthyme <46726098+wildthyme@users.noreply.github.com> Date: Tue, 2 Apr 2019 20:58:23 -0400 Subject: [PATCH 2/4] comicapi dependency now pippable --- .gitignore | 1 - cps/comic.py | 4 +--- requirements.txt | 1 + 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index b3c3d439..ee415c42 100644 --- a/.gitignore +++ b/.gitignore @@ -31,5 +31,4 @@ vendor client_secrets.json # External dependencies - need proper integrating -comicapi libunrar diff --git a/cps/comic.py b/cps/comic.py index cc1b0600..7622a072 100755 --- a/cps/comic.py +++ b/cps/comic.py @@ -19,8 +19,7 @@ import os import uploader -from comicapi.comicarchive import * -from comicapi.issuestring import * +from comicapi.comicarchive import ComicArchive, MetaDataStyle from iso639 import languages as isoLanguages def extractCover(tmp_file_name, original_file_extension): @@ -31,7 +30,6 @@ def extractCover(tmp_file_name, original_file_extension): extension = ext[1].lower() if extension == '.jpg' or extension == '.jpeg': cover_data = archive.getPage(0) - print(archive.getPageName(0)) prefix = os.path.dirname(tmp_file_name) if cover_data: tmp_cover_name = prefix + '/cover' + extension diff --git a/requirements.txt b/requirements.txt index 3fb23ea3..b2561849 100644 --- a/requirements.txt +++ b/requirements.txt @@ -13,3 +13,4 @@ SQLAlchemy>=1.1.0 tornado>=4.1 Wand>=0.4.4 unidecode>=0.04.19 +git+https://github.com/wildthyme/comicapi.git@c57bda958e56cf1ae23bec1cde974b4c424b2eb4#egg=comicapi From b7e30644abe80e508f68df895efcab06997c879a Mon Sep 17 00:00:00 2001 From: Iris W <46726098+wildthyme@users.noreply.github.com> Date: Wed, 3 Apr 2019 15:36:05 -0400 Subject: [PATCH 3/4] =?UTF-8?q?updated=20comicapi=20requirement=E2=80=94li?= =?UTF-8?q?bunrar=20no=20longer=20necessary=20(CBR=20parsing=20support=20w?= =?UTF-8?q?as=20always=20disabled=20anyway)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 --- requirements.txt | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index ee415c42..09bf3faa 100644 --- a/.gitignore +++ b/.gitignore @@ -29,6 +29,3 @@ gdrive_credentials vendor client_secrets.json - -# External dependencies - need proper integrating -libunrar diff --git a/requirements.txt b/requirements.txt index b2561849..55a67a3e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -13,4 +13,4 @@ SQLAlchemy>=1.1.0 tornado>=4.1 Wand>=0.4.4 unidecode>=0.04.19 -git+https://github.com/wildthyme/comicapi.git@c57bda958e56cf1ae23bec1cde974b4c424b2eb4#egg=comicapi +git+https://github.com/wildthyme/comicapi.git@0f36fdd81bd03d6a979bebf03f907a1405d992c4#egg=comicapi From 029d299067422246e553edc096f16c05ed5961b8 Mon Sep 17 00:00:00 2001 From: Iris W <46726098+wildthyme@users.noreply.github.com> Date: Tue, 9 Apr 2019 15:22:03 -0400 Subject: [PATCH 4/4] updated comicapi version to fix installation error --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 55a67a3e..7f2776d7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -13,4 +13,4 @@ SQLAlchemy>=1.1.0 tornado>=4.1 Wand>=0.4.4 unidecode>=0.04.19 -git+https://github.com/wildthyme/comicapi.git@0f36fdd81bd03d6a979bebf03f907a1405d992c4#egg=comicapi +git+https://github.com/wildthyme/comicapi.git@cb279168f9c5cec742b5a05ac8326b9c168a8a91#egg=comicapi