diff --git a/.gitignore b/.gitignore index 7c904e9..c332287 100644 --- a/.gitignore +++ b/.gitignore @@ -138,3 +138,4 @@ dmypy.json cython_debug/ EmbedComicMetadata.zip +Embed Comic Metadata.zip diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..7266524 --- /dev/null +++ b/Makefile @@ -0,0 +1,3 @@ +zip: + rm -f 'Embed Comic Metadata.zip' + zip -r 'Embed Comic Metadata.zip' . \ No newline at end of file diff --git a/comicbookinfo.py b/comicbookinfo.py index 8081aaa..7838af4 100644 --- a/comicbookinfo.py +++ b/comicbookinfo.py @@ -53,6 +53,7 @@ def xlate(cbi_entry): metadata.month = xlate('publicationMonth') metadata.year = xlate('publicationYear') metadata.issueCount = xlate('numberOfIssues') + metadata.pageCount = xlate('pageCount') metadata.comments = xlate('comments') metadata.credits = xlate('credits') metadata.genre = xlate('genre') @@ -123,6 +124,7 @@ def toInt(s): assign('publicationMonth', toInt(metadata.month)) assign('publicationYear', toInt(metadata.year)) assign('numberOfIssues', toInt(metadata.issueCount)) + assign('pageCount', toInt(metadata.pageCount)) assign('comments', metadata.comments) assign('genre', metadata.genre) assign('volume', toInt(metadata.volume)) diff --git a/comicinfoxml.py b/comicinfoxml.py index d1b57dd..3701e31 100644 --- a/comicinfoxml.py +++ b/comicinfoxml.py @@ -97,6 +97,20 @@ def assign(cix_entry, md_entry): if md_entry is not None: ET.SubElement(root, cix_entry).text = u"{0}".format(md_entry) + def clean_tags(tag_list): + # Remove Goodreads tags + gr_tags = [ + 'gr-read', + 'gr-want-to-read', + 'gr-reading' + ] + + for t in gr_tags: + if t in tag_list: + tag_list.remove(t) + + return tag_list + assign('Title', md.title) assign('Series', md.series) assign('Number', md.issue) @@ -181,7 +195,7 @@ def assign(cix_entry, md_entry): md.teams = tuple_to_string(md.teams) md.locations = tuple_to_string(md.locations) md.genre = tuple_to_string(md.genre) - md.tags = tuple_to_string(md.tags) + md.tags = tuple_to_string(clean_tags(md.tags)) assign('Publisher', md.publisher) assign('Imprint', md.imprint) diff --git a/comicmetadata.py b/comicmetadata.py index 011c74d..75165bc 100644 --- a/comicmetadata.py +++ b/comicmetadata.py @@ -1,5 +1,9 @@ from __future__ import (unicode_literals, division, absolute_import, print_function) +import io +import pathlib +import re +import unicodedata __license__ = 'GPL v3' __copyright__ = '2015, dloraine' @@ -14,6 +18,7 @@ from calibre_plugins.EmbedComicMetadata.genericmetadata import GenericMetadata from calibre_plugins.EmbedComicMetadata.comicinfoxml import ComicInfoXml from calibre_plugins.EmbedComicMetadata.comicbookinfo import ComicBookInfo +from calibre.utils.zipfile import safe_replace import os import sys @@ -75,6 +80,7 @@ def __init__(self, book_id, ia): def __del__(self): delete_temp_file(self.file) + # Metadata embed def get_comic_metadata_from_file(self): if self.checked_for_metadata: return @@ -155,9 +161,13 @@ def convert_calibre_md_to_comic_md(self): role = partial(set_role, credits=self.calibre_md_in_comic_format.credits) update_field = partial(update_comic_field, target=self.calibre_md_in_comic_format) + # Hack for no_sync authors + author_clean = clean_authors(mi.authors) + # update the fields of comic metadata update_field("title", mi.title) - role("Writer", mi.authors) + # role("Writer", mi.authors) + role("Writer", author_clean) update_field("series", mi.series) update_field("issue", mi.series_index) update_field("tags", mi.tags) @@ -277,7 +287,6 @@ def convert_comic_md_to_calibre_md(self, comic_metadata): # gtin if co.gtin: mi.set_identifiers({"gtin": co.gtin}) - # custom columns update_column = partial(update_custom_column, calibre_metadata=mi, custom_cols=self.db.field_metadata.custom_field_metadata()) @@ -307,10 +316,18 @@ def convert_comic_md_to_calibre_md(self, comic_metadata): self.comic_md_in_calibre_format = mi + # Conversion def make_temp_cbz_file(self): if not self.file and self.format == "cbz": self.file = self.db.format(self.book_id, "cbz", as_path=True) + def add_dir_to_zip(self, zf, tdir, arcname): + import os + for dirpath, dirs, files in os.walk(tdir): + for f in files: + fn = os.path.join(dirpath, f) + zf.write(fn, f'{arcname}/{f}') + def convert_cbr_to_cbz(self): ''' Converts a rar or cbr-comic to a cbz-comic @@ -327,7 +344,7 @@ def convert_cbr_to_cbz(self): # make the cbz file with TemporaryFile("comic.cbz") as tf: zf = ZipFile(tf, "w") - add_dir_to_zipfile(zf, tdir) + self.add_dir_to_zip(zf, tdir, clean_title(self.calibre_metadata.title)) if comments: zf.comment = comments.encode("utf-8") zf.close() @@ -335,6 +352,9 @@ def convert_cbr_to_cbz(self): self.db.add_format(self.book_id, "cbz", tf) self.format = "cbz" + if prefs['clean_cbz']: + self.clean_cbz() + def convert_zip_to_cbz(self): import os @@ -345,6 +365,193 @@ def convert_zip_to_cbz(self): delete_temp_file(new_fname) self.format = "cbz" + if prefs['clean_cbz']: + self.clean_cbz() + + # CBZ mark + def is_cbi_valid(self): + # Ensure metadata is set + self.overlay_metadata() + + # Generate what the string should be + cbi_string = ComicBookInfo().stringFromMetadata(self.comic_metadata) + if not python3: + cbi_string = cbi_string.decode('utf-8', 'ignore') + + # ensure we have a temp file + self.make_temp_cbz_file() + + # Read current cbi comment + zf = ZipFile(self.file, "r") + curr_str = zf.comment + zf.close() + + return cbi_string == curr_str + + def is_cbi_empty(self): + # ensure we have a temp file + self.make_temp_cbz_file() + + # Read current cbi comment + zf = ZipFile(self.file, "r") + curr_str = zf.comment + zf.close() + + return curr_str == None or curr_str == "".encode("utf-8") + + def is_cix_valid(self): + # Ensure metadata is set + self.overlay_metadata() + + # Generate what the string should be + cix_string = ComicInfoXml().stringFromMetadata(self.comic_metadata) + if not python3: + cix_string = cix_string.decode('utf-8', 'ignore') + + # ensure we have a temp file + self.make_temp_cbz_file() + + # Read current xml file + zf = ZipFile(self.file, "r") + curr_file = zf.open('ComicInfo.xml', 'r') + curr_str = io.TextIOWrapper(curr_file).read() + curr_file.close() + + # count current # of pages + pages = 0 + for name in zf.namelist(): + if name.lower().rpartition('.')[-1] in IMG_EXTENSIONS: + pages += 1 + zf.close() + + if self.comic_metadata.pageCount != pages: + return False + + return cix_string == curr_str + + def is_cbz_dirty(self): + ''' + Determines if a CBZ file has a dirty/unwanted file structure + ''' + ffile = self.db.format(self.book_id, self.format, as_path=True) + tmpf = ZipFile(ffile) + filename_list = tmpf.namelist() + + # A 'dirty' zip has one (or more) of these cases: + # Case 1: Metadata is not clean + # a. There are duplicate files + # b. ComicInfo.xml does not exist at /ComicInfo.xml + # c. ComicInfo.xml content is not up to date + # d. ComicBookInfo comment is not up to date + # Case 2: Directory structure is up to date + # a. file name matches //* + # b. filename does not contain invalid extension + # c. filename does not match scanner tag + # d. filename does not match embedded cover + + # Case 1a + if len(set(filename_list)) < len(filename_list): + return True + # Case 1b + if 'ComicInfo.xml' not in filename_list: + return True + else: + # Case 1c + if not self.is_cix_valid(): + return True + # Case 1d + if not self.is_cbi_empty(): + return True + + for f in filename_list: + # We already checked ComicInfo.xml, so ignore it here + if f == 'ComicInfo.xml': + continue + # Case 2a + if os.path.dirname(f) != clean_title(self.calibre_metadata.title): + return True + # Case 2b + if pathlib.Path(f).suffix in [".xhtml", ".html", ".css", ".xml", ".sfv"]: + return True + # Case 2c+d + if os.path.basename(f).__contains__('zz'): + return True + # Case 2c+d + if os.path.basename(f) in ['cover.jpeg', 'cover.jpeg', 'page.jpg', 'zSoU-Nerd.jpg']: + return True + + return False + + def action_mark_cbz(self): + should_mark = True if self.format in ["cbr", "zip"] else self.is_cbz_dirty() + if should_mark: + self.ia.gui.current_db.data.add_marked_ids({self.book_id: 'shit_files_m8'}) + + return should_mark + + # CBZ cleanup + def clean_cbz(self): + ''' + cleans directory structure for a cbz comic + ''' + + # Shortcut for files that are already cleaned + should_clean = self.is_cbz_dirty() + if not should_clean: + return False + + with TemporaryDirectory('_extractedfiles') as tdir: + # extract the zip file + ffile = self.db.format(self.book_id, self.format, as_path=True) + tmpf = ZipFile(ffile) + tmpf.extractall(tdir) + comments = tmpf.comment + delete_temp_file(ffile) + tmpf.close() + + # Gather file paths from extracted zip + all_files = [] + for root, _, files in os.walk(tdir): + for f in files: + all_files.append(os.path.abspath(os.path.join(root, f))) + + # clean up dir structure + with TemporaryDirectory('_cleancbz') as cleandir: + with TemporaryFile("comic.cbz") as tf: + zf = ZipFile(tf, "w") + + for f in all_files: + # Skip non-image files + if pathlib.Path(f).suffix in [".xhtml", ".html", ".css", ".xml", ".sfv"]: + continue + # Remove scanner tags + if os.path.basename(f).__contains__('zz'): + continue + # Remove embedded covers and scanner tags + if os.path.basename(f) in ['cover.jpg', 'cover.jpeg', 'page.jpg', 'zSoU-Nerd.jpg']: + continue + else: + zf.write(f, f'{clean_title(self.calibre_metadata.title)}/{os.path.basename(f)}') + + if comments: + zf.comment = "".encode("utf-8") + + self.overlay_metadata() + if prefs['cix_embed']: + cix_string = ComicInfoXml().stringFromMetadata(self.comic_metadata) + zf.writestr("ComicInfo.xml", cix_string) + + zf.close() + + # add the cbz format to calibres library + self.db.add_format(self.book_id, "cbz", tf) + self.format = "cbz" + + delete_temp_file(tf) + self.file = self.db.format(self.book_id, "cbz", as_path=True) + + return True + def update_cover(self): # get the calibre cover cover_path = self.db.cover(self.book_id, as_path=True) @@ -378,11 +585,14 @@ def update_cover(self): def count_pages(self): self.make_temp_cbz_file() zf = ZipFile(self.file) + namelist = zf.namelist() + zf.close() + pages = 0 - for name in zf.namelist(): + for name in namelist: if name.lower().rpartition('.')[-1] in IMG_EXTENSIONS: pages += 1 - zf.close() + return pages def action_count_pages(self): @@ -465,6 +675,7 @@ def remove_embedded_metadata(self): return True + # Metadata import def get_comic_metadata_from_cbz(self): ''' Reads the comic metadata from the comic cbz file as comictagger metadata @@ -592,7 +803,6 @@ def swap_author_names_back(author): def delete_temp_file(ffile): try: - import os if os.path.exists(ffile): os.remove(ffile) except: @@ -634,6 +844,17 @@ def add_dir_to_zipfile(zf, path, prefix=''): zf.write(f, arcname) +def clean_title(s): + return re.sub(r'[^\w_,\-\.\(\)\s]', '_', strip_accents(s)) + + +def clean_authors(l: list[str]): + return [a.replace("_no_sync", "") for a in l] + + +def strip_accents(s): + return ''.join(c for c in unicodedata.normalize('NFD', s) if unicodedata.category(c) != 'Mn') + def safe_delete(zipstream, name): ''' Delete a file in a zip file in a safe manner. This proceeds by extracting @@ -664,4 +885,4 @@ def safe_delete(zipstream, name): zipstream.seek(0) zipstream.truncate() shutil.copyfileobj(temp, zipstream) - zipstream.flush() + zipstream.flush() \ No newline at end of file diff --git a/ini.py b/ini.py index 5d354c5..7a6521f 100644 --- a/ini.py +++ b/ini.py @@ -49,7 +49,9 @@ def get_configuration(): ''' from calibre_plugins.EmbedComicMetadata.languages.lang import _L from calibre_plugins.EmbedComicMetadata.main import (embed_into_comic, - import_to_calibre, embed_cover, convert, count_pages, get_image_size, remove_metadata) + import_to_calibre, embed_cover, convert, count_pages, get_image_size, remove_metadata, + mark_cbz, clean_cbz + ) # configuration config = [ @@ -104,7 +106,9 @@ def get_configuration(): ["import_tags", _L['Import tags from comic metadata'], False], ["overwrite_calibre_tags", _L['If checked, overwrites the tags in calibre.'], False], ["auto_count_pages", _L['Auto count pages if importing'], False], - ["get_image_sizes", _L['Get the image size if importing'], False] + ["get_image_sizes", _L['Get the image size if importing'], False], + ["clean_cbz", _L['Clean up directory struture inside CBZ files'], False], + ["mark_cbz", _L['Mark CBZ files with improper file struture'], False] ] }, { @@ -115,9 +119,11 @@ def get_configuration(): "Items": [ ["main_embed", _L['Embed metadata'], True], ["main_import", _L['Import metadata'], False], + ["main_mark", _L['Mark dirty comics'], False], + ["main_clean", _L['Clean dirty comics'], False], ], "Exclusive_Items": [ - ["main_embed", "main_import"] + ["main_embed", "main_import", "main_mark", "main_clean"] ] }, { @@ -134,6 +140,8 @@ def get_configuration(): ["import_cbi", _L['Show import cbi button'], False], ["convert", _L['Show convert button'], True], ["count_pages", _L['Show count pages button'], True], + ["mark_cbz", _L['Show mark CBZ button'], True], + ["clean_cbz", _L['Show clean CBZ button'], True], ["image_size", _L['Show get image size button'], False], ["remove_metadata", _L['Show remove metadata button'], False], ["cover", _L['Show embed cover button (experimental)'], False] @@ -150,6 +158,8 @@ def get_configuration(): ["convert", _L["Only convert to cbz"], convert, None], ["cover", _L["Embed the calibre cover"], embed_cover, None], ["count_pages", _L["Count pages"], count_pages, None], + ["mark_cbz", _L["Mark dirty comics"], mark_cbz, None], + ["clean_cbz", _L["Clean dirty comics"], clean_cbz, None], ["image_size", _L["Get image size"], get_image_size, None], ["remove_metadata", _L["Remove metadata"], remove_metadata, None], ["seperator"] diff --git a/languages/en.py b/languages/en.py index 146d4f2..28b9030 100644 --- a/languages/en.py +++ b/languages/en.py @@ -39,10 +39,14 @@ 'If checked, overwrites the tags in calibre.': 'If checked, overwrites the tags in calibre.', 'Auto count pages if importing': 'Auto count pages if importing', 'Get the image size if importing': 'Get the image size if importing', + 'Clean up directory struture inside CBZ files': 'Clean up directory struture inside CBZ files', + 'Mark CBZ files with improper file struture': 'Mark CBZ files with improper file struture', # main_buton (ini.py) 'Main Button Action (needs a calibre restart):': 'Main Button Action (needs a calibre restart):', 'Embed metadata': 'Embed metadata', 'Import metadata': 'Import metadata', + 'Mark dirty comics': 'Mark dirty comics', + 'Clean dirty comics': 'Clean dirty comics', # toolbar_buttons (ini.py) 'Menu Buttons:': 'Menu Buttons:', 'Show embed both button': 'Show embed both button', @@ -54,6 +58,8 @@ 'Show convert button': 'Show convert button', 'Show embed cover button (experimental)': 'Show embed cover button (experimental)', 'Show count pages button': 'Show count pages button', + 'Show mark CBZ button': 'Show mark CBZ button', + 'Show clean CBZ button': 'Show clean CBZ button', 'Show get image size button': 'Show get image size button', 'Show remove metadata button': 'Show remove metadata button', @@ -75,25 +81,35 @@ 'Imports the metadata from the comic to calibre': 'Imports the metadata from the comic to calibre', 'Embed Comic Metadata': 'Embed Comic Metadata', 'Embeds calibres metadata into the comic': 'Embeds calibres metadata into the comic', + 'Mark Dirty Comics': 'Mark Dirty Comics', + 'Marks comics with dirty file structure': 'Marks comics with dirty file structure', + 'Clean Dirty Comics': 'Clean Dirty Comics', + 'Cleans comics with dirty file structure': 'Cleans comics with dirty file structure', # config button (ui.py) 'Configure': 'Configure', # COMPLETED MESSAGES (main.py) 'Updated Calibre Metadata': 'Updated Calibre Metadata', - 'Updated calibre metadata for {} book(s)': 'Updated calibre metadata for {} book(s)', - 'The following books had no metadata: {}': 'The following books had no metadata: {}', + 'Updated calibre metadata for: {}': 'Updated calibre metadata for: {}', + '{} books had no metadata': '{} books had no metadata', 'Updated comics': 'Updated comics', - 'Updated the metadata in the files of {} comics': 'Updated the metadata in the files of {} comics', - 'The following books were not updated: {}': 'The following books were not updated: {}', + 'Updated metadata for the following comics: {}': 'Updated metadata for the following comics: {}', + '{} books were not updated': '{} books were not updated', 'Converted files': 'Converted files', - 'Converted {} book(s) to cbz': 'Converted {} book(s) to cbz', - 'The following books were not converted: {}': 'The following books were not converted: {}', + 'Converted the following book(s) to cbz: {}': 'Converted the following book(s) to cbz: {}', + '{} books were not converted': '{} books were not converted', 'Updated Covers': 'Updated Covers', - 'Embeded {} covers': 'Embeded {} covers', - 'The following covers were not embeded: {}': 'The following covers were not embeded: {}', + 'Embeded covers for the following books: {}': 'Embeded covers for the following books: {}', + '{} covers were not embeded': '{} covers were not embeded', 'Counted pages': 'Counted pages', - 'Counted pages in {} comics': 'Counted pages in {} comics', - 'The following comics were not counted: {}': 'The following comics were not counted: {}', + 'Counted pages for the following comics: {}': 'Counted pages for the following comics: {}', + '{} comics were not counted': '{} comics were not counted', + 'Marked comics': 'Marked comics', + 'Marked the following comics: {}': 'Marked the following comics: {}', + '{} comics were not marked': '{} comics were not marked', + 'Cleaned comics': 'Cleaned comics', + 'Cleaned the following comics: {}': 'Cleaned the following comics: {}', + '{} comics were not cleaned': '{} comics were not cleaned', 'The following comics were converted to cbz: {}': 'The following comics were converted to cbz: {}', 'Removed metadata': 'Removed metadata', 'Removed metadata in {} comics': 'Removed metadata in {} comics', diff --git a/main.py b/main.py index e279833..20a404c 100644 --- a/main.py +++ b/main.py @@ -31,8 +31,8 @@ def _import_to_calibre(metadata): iterate_over_books(ia, _import_to_calibre, _L["Updated Calibre Metadata"], - _L['Updated calibre metadata for {} book(s)'], - _L['The following books had no metadata: {}'], + _L['Updated calibre metadata for: {}'], + _L['{} books had no metadata'], prefs['convert_reading']) @@ -50,15 +50,15 @@ def _embed_into_comic(metadata): iterate_over_books(ia, _embed_into_comic, _L["Updated comics"], - _L['Updated the metadata in the files of {} comics'], - _L['The following books were not updated: {}']) + _L['Updated metadata for the following comics: {}'], + _L['{} books were not updated']) def convert(ia): iterate_over_books(ia, partial(convert_to_cbz, ia), _L["Converted files"], - _L['Converted {} book(s) to cbz'], - _L['The following books were not converted: {}'], + _L['Converted the following book(s) to cbz: {}'], + _L['{} books were not converted'], False) @@ -72,8 +72,8 @@ def _embed_cover(metadata): iterate_over_books(ia, _embed_cover, _L["Updated Covers"], - _L['Embeded {} covers'], - _L['The following covers were not embeded: {}']) + _L['Embeded covers for the following books: {}'], + _L['{} covers were not embeded']) def count_pages(ia): @@ -84,8 +84,35 @@ def _count_pages(metadata): iterate_over_books(ia, _count_pages, _L["Counted pages"], - _L['Counted pages in {} comics'], - _L['The following comics were not counted: {}']) + _L['Counted pages for the following comics: {}'], + _L['{} comics were not counted']) + + +def mark_cbz(ia): + def _mark_cbz(metadata): + if metadata.format not in ["cbr", "zip", "cbz"]: + return False + return metadata.action_mark_cbz() + + iterate_over_books(ia, _mark_cbz, + _L["Marked comics"], + _L['Marked the following comics: {}'], + _L['{} comics were not marked'], + False) + + +def clean_cbz(ia): + def _clean_cbz(metadata): + if metadata.format != "cbz": + return False + metadata.action_count_pages() + return metadata.clean_cbz() + + iterate_over_books(ia, _clean_cbz, + _L["Cleaned comics"], + _L['Cleaned the following comics: {}'], + _L['{} comics were not cleaned']) + def remove_metadata(ia): @@ -110,8 +137,8 @@ def _get_image_size(metadata): iterate_over_books(ia, _get_image_size, _L["Updated Calibre Metadata"], - _L['Updated calibre metadata for {} book(s)'], - _L['The following books were not updated: {}']) + _L['Updated calibre metadata for: {}'], + _L['{} books were not updated']) def iterate_over_books(ia, func, title, ptext, notptext, @@ -146,26 +173,30 @@ def iterate_over_books(ia, func, title, ptext, notptext, else: not_processed.append(metadata.info) - # show a completion message - msg = ptext.format(len(processed)) - if should_convert and len(converted) > 0: - msg += '\n' + convtext.format(lst2string(converted)) - if len(not_processed) > 0: - msg += '\n' + notptext.format(lst2string(not_processed)) - info_dialog(ia.gui, title, msg, show=True) + if len(processed) != 0 or len(not_processed) != 0 or len(converted) != 0: + # show a completion message + msg = ptext.format(lst2string(processed)) + if should_convert and len(converted) > 0: + msg += '\n' + convtext.format(lst2string(converted)) + if len(not_processed) > 0: + msg += '\n' + notptext.format(len(not_processed)) + info_dialog(ia.gui, title, msg, show=True) def get_selected_books(ia): # Get currently selected books rows = ia.gui.library_view.selectionModel().selectedRows() if not rows or len(rows) == 0: - return error_dialog(ia.gui, _L['Cannot update metadata'], - _L['No books selected'], show=True) + error_dialog(ia.gui, _L['Cannot update metadata'], + _L['No books selected'], show=True) + return [] # Map the rows to book ids return map(ia.gui.library_view.model().id, rows) def lst2string(lst): + if len(lst) == 0: + return "\n " + "[None]\n " if python3: return "\n " + "\n ".join(lst) return "\n " + "\n ".join(item.encode('utf-8') for item in lst) diff --git a/ui.py b/ui.py index 9fcab13..5a6e1a6 100644 --- a/ui.py +++ b/ui.py @@ -35,9 +35,15 @@ class EmbedComicMetadata(InterfaceAction): if prefs["main_import"]: action_spec = (_L['Import Comic Metadata'], None, _L['Imports the metadata from the comic to calibre'], None) - else: + elif prefs["main_embed"]: action_spec = (_L['Embed Comic Metadata'], None, _L['Embeds calibres metadata into the comic'], None) + elif prefs["main_mark"]: + action_spec = (_L['Mark Dirty Comics'], None, + _L['Marks comics with dirty file structure'], None) + elif prefs["main_clean"]: + action_spec = (_L['Clean Dirty Comics'], None, + _L['Cleans comics with dirty file structure'], None) def genesis(self): # menu @@ -77,24 +83,32 @@ def toggle_menu_items(self): action.setVisible(prefs[item[CONFIG_NAME]]) def main_menu_triggered(self): - from calibre_plugins.EmbedComicMetadata.main import embed_into_comic, import_to_calibre + from calibre_plugins.EmbedComicMetadata.main import embed_into_comic, import_to_calibre, mark_cbz, clean_cbz - i = prefs["main_import"] + if prefs["main_mark"]: + mark_cbz(self) + return + if prefs["main_clean"]: + clean_cbz(self) + return + + action_i = prefs["main_import"] + action_e = prefs["main_embed"] # Check the preferences for what should be done - if (i and prefs['read_cbi'] and prefs['read_cix']) or ( - not i and prefs['cbi_embed'] and prefs['cix_embed']): + if (action_i and prefs['read_cbi'] and prefs['read_cix']) or ( + action_e and prefs['cbi_embed'] and prefs['cix_embed']): action = "both" - elif (i and prefs['read_cbi']) or (not i and prefs['cbi_embed']): + elif (action_i and prefs['read_cbi']) or (action_e and prefs['cbi_embed']): action = "cbi" - elif (i and prefs['read_cix']) or (not i and prefs['cix_embed']): + elif (action_i and prefs['read_cix']) or (action_e and prefs['cix_embed']): action = "cix" else: return error_dialog(self.gui, _L['Cannot update metadata'], _L['No embed format selected'], show=True) - if i: + if action_i: import_to_calibre(self, action) - else: + elif action_e: embed_into_comic(self, action) def apply_settings(self):