Skip to content

Commit

Permalink
Added cb7 to supported comic files for upload and metadata extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
OzzieIsaacs committed Aug 16, 2023
1 parent d253804 commit 3a08b91
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
3 changes: 2 additions & 1 deletion cps/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@
mimetypes.add_type('application/x-cbr', '.cbr')
mimetypes.add_type('application/x-cbz', '.cbz')
mimetypes.add_type('application/x-cbt', '.cbt')
mimetypes.add_type('image/vnd.djvu', '.djvu')
mimetypes.add_type('application/x-cb7', '.cb7')
mimetypes.add_type('image/vnd.djv', '.djv')
mimetypes.add_type('application/mpeg', '.mpeg')
mimetypes.add_type('application/mpeg', '.mp3')
mimetypes.add_type('application/mp4', '.m4a')
Expand Down
22 changes: 20 additions & 2 deletions cps/comic.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@
except (ImportError, SyntaxError) as e:
log.debug('Cannot import rarfile, extracting cover files from rar files will not work: %s', e)
use_rarfile = False
try:
import py7zr
use_7zip = True
except (ImportError, SyntaxError) as e:
log.debug('Cannot import py7zr, extracting cover files from CB7 files will not work: %s', e)
use_7zip = False
use_comic_meta = False


Expand Down Expand Up @@ -84,10 +90,22 @@ def _extract_cover_from_archive(original_file_extension, tmp_file_name, rar_exec
if len(ext) > 1:
extension = ext[1].lower()
if extension in cover.COVER_EXTENSIONS:
cover_data = cf.read(name)
cover_data = cf.read([name])
break
except Exception as ex:
log.debug('Rarfile failed with error: {}'.format(ex))
log.error('Rarfile failed with error: {}'.format(ex))
elif original_file_extension.upper() == '.CB7' and use_7zip:
cf = py7zr.SevenZipFile(tmp_file_name)
for name in cf.getnames():
ext = os.path.splitext(name)
if len(ext) > 1:
extension = ext[1].lower()
if extension in cover.COVER_EXTENSIONS:
try:
cover_data = cf.read(name)[name].read()
except (py7zr.Bad7zFile, OSError) as ex:
log.error('7Zip file failed with error: {}'.format(ex))
break
return cover_data, extension


Expand Down
2 changes: 1 addition & 1 deletion cps/uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def process(tmp_file_path, original_file_name, original_file_extension, rar_exec
meta = epub.get_epub_info(tmp_file_path, original_file_name, original_file_extension)
elif ".FB2" == extension_upper and use_fb2_meta is True:
meta = fb2.get_fb2_info(tmp_file_path, original_file_extension)
elif extension_upper in ['.CBZ', '.CBT', '.CBR']:
elif extension_upper in ['.CBZ', '.CBT', '.CBR', ".CB7"]:
meta = comic.get_comic_info(tmp_file_path,
original_file_name,
original_file_extension,
Expand Down
1 change: 1 addition & 0 deletions optional-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ html2text>=2020.1.16,<2022.1.1
python-dateutil>=2.1,<2.9.0
beautifulsoup4>=4.0.1,<4.12.0
faust-cchardet>=2.1.18
py7zr>=0.15.0,<0.21.0

# Comics
natsort>=2.2.0,<8.4.0
Expand Down

0 comments on commit 3a08b91

Please sign in to comment.