def compare(self, comic_filename, comic_compare_filename): """ Compare a comic file """ """ md = self.getComicMetadata(comic_filename) md_compare = self.getComicMetadata(comic_compare_filename) if md_compare is not None: compare_comic = self.createComicFromMetadata(md_compare) if md is not None: comic = self.createComicFromMetadata(md) if comic is None or compare_comic is None: return False """ # preform metadata check.... # FIX fingerprint_compare = ComicArchive( comic_filename, default_image_path=AppFolders.missingPath("page.png")).fingerprint( sort=False) fingerprint = ComicArchive( comic_compare_filename, default_image_path=AppFolders.missingPath("page.png")).fingerprint( sort=False) if fingerprint == fingerprint_compare: return True return False
def _extractCover(tmp_file_name, original_file_extension, rarExceutable): cover_data = extension = None if use_comic_meta: archive = ComicArchive(tmp_file_name) for index, name in enumerate(archive.getPageNameList()): ext = os.path.splitext(name) if len(ext) > 1: extension = ext[1].lower() if extension == '.jpg' or extension == '.jpeg': cover_data = archive.getPage(index) break else: 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' or extension == '.jpeg': 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' or extension == '.jpeg': cover_data = cf.extractfile(name).read() break elif original_file_extension.upper() == '.CBR' and use_rarfile: try: rarfile.UNRAR_TOOL = rarExceutable cf = rarfile.RarFile(tmp_file_name) for name in cf.getnames(): ext = os.path.splitext(name) if len(ext) > 1: extension = ext[1].lower() if extension == '.jpg' or extension == '.jpeg': cover_data = cf.read(name) break except Exception as e: log.debug('Rarfile failed with error: %s', e) prefix = os.path.dirname(tmp_file_name) if cover_data: tmp_cover_name = prefix + '/cover' + extension image = open(tmp_cover_name, 'wb') image.write(cover_data) image.close() else: tmp_cover_name = None return tmp_cover_name
def _extract_cover(tmp_file_name, original_file_extension, rar_executable): cover_data = extension = None if use_comic_meta: archive = ComicArchive(tmp_file_name, rar_exe_path=rar_executable) for index, name in enumerate(archive.getPageNameList()): ext = os.path.splitext(name) if len(ext) > 1: extension = ext[1].lower() if extension in cover.COVER_EXTENSIONS: cover_data = archive.getPage(index) break else: cover_data, extension = _extract_cover_from_archive( original_file_extension, tmp_file_name, rar_executable) return cover.cover_processing(tmp_file_name, cover_data, extension)
def extractCover(tmp_file_name, original_file_extension): archive = ComicArchive(tmp_file_name) cover_data = None 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) prefix = os.path.dirname(tmp_file_name) if cover_data: tmp_cover_name = prefix + '/cover' + extension image = open(tmp_cover_name, 'wb') image.write(cover_data) image.close() else: tmp_cover_name = None return tmp_cover_name
def _extractCover(tmp_file_name, original_file_extension, rarExecutable): cover_data = extension = None if use_comic_meta: archive = ComicArchive(tmp_file_name, rar_exe_path=rarExecutable) for index, name in enumerate(archive.getPageNameList()): ext = os.path.splitext(name) if len(ext) > 1: extension = ext[1].lower() if extension in ('.jpg', '.jpeg', '.png', '.webp'): cover_data = archive.getPage(index) break else: 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 in ('.jpg', '.jpeg', '.png', '.webp'): 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 in ('.jpg', '.jpeg', '.png', '.webp'): cover_data = cf.extractfile(name).read() break elif original_file_extension.upper() == '.CBR' and use_rarfile: try: rarfile.UNRAR_TOOL = rarExecutable cf = rarfile.RarFile(tmp_file_name) for name in cf.getnames(): ext = os.path.splitext(name) if len(ext) > 1: extension = ext[1].lower() if extension in ('.jpg', '.jpeg', '.png', '.webp'): cover_data = cf.read(name) break except Exception as e: log.debug('Rarfile failed with error: %s', e) return _cover_processing(tmp_file_name, cover_data, 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 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=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=loadedMetadata.series or "", series_id=loadedMetadata.issue or "", languages=loadedMetadata.language)
def extractCover(tmp_file_name, original_file_extension): if use_comic_meta: archive = ComicArchive(tmp_file_name) cover_data = None for index, name in enumerate(archive.getPageNameList()): ext = os.path.splitext(name) if len(ext) > 1: extension = ext[1].lower() if extension == '.jpg' or extension == '.jpeg': cover_data = archive.getPage(index) break else: 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' or extension == '.jpeg': 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' or extension == '.jpeg': cover_data = cf.extractfile(name).read() break prefix = os.path.dirname(tmp_file_name) if cover_data: tmp_cover_name = prefix + '/cover' + extension image = open(tmp_cover_name, 'wb') image.write(cover_data) image.close() else: tmp_cover_name = None return tmp_cover_name
def getComicArchive(self, path): # should also look at modified time of file for ca in self.comicArchiveList: if ca.path == path: # remove from list and put at end self.comicArchiveList.remove(ca) self.comicArchiveList.append(ca) return ca else: ca = ComicArchive(path, default_image_path=AppFolders.imagePath("default.jpg")) self.comicArchiveList.append(ca) if len(self.comicArchiveList) > 10: self.comicArchiveList.pop(0) return ca
def get_comic_info(tmp_file_path, original_file_name, original_file_extension, rar_executable): if use_comic_meta: archive = ComicArchive(tmp_file_path, rar_exe_path=rar_executable) if archive.seemsToBeAComicArchive(): if archive.hasMetadata(MetaDataStyle.CIX): style = MetaDataStyle.CIX elif archive.hasMetadata(MetaDataStyle.CBI): style = MetaDataStyle.CBI else: style = None # if style is not None: loaded_metadata = archive.readMetadata(style) lang = loaded_metadata.language or "" loaded_metadata.language = isoLanguages.get_lang3(lang) return BookMeta(file_path=tmp_file_path, extension=original_file_extension, title=loaded_metadata.title or original_file_name, author=" & ".join([ credit["person"] for credit in loaded_metadata.credits if credit["role"] == "Writer" ]) or 'Unknown', cover=_extract_cover(tmp_file_path, original_file_extension, rar_executable), description=loaded_metadata.comments or "", tags="", series=loaded_metadata.series or "", series_id=loaded_metadata.issue or "", languages=loaded_metadata.language, publisher="", pubdate="", identifiers=[]) return BookMeta(file_path=tmp_file_path, extension=original_file_extension, title=original_file_name, author=u'Unknown', cover=_extract_cover(tmp_file_path, original_file_extension, rar_executable), description="", tags="", series="", series_id="", languages="", publisher="", pubdate="", identifiers=[])
def getComicMetadata(self, path): ca = ComicArchive(path, default_image_path=AppFolders.missingPath("page.png")) if ca.seemsToBeAComicArchive(): if ca.hasMetadata( MetaDataStyle.CIX ): style = MetaDataStyle.CIX elif ca.hasMetadata( MetaDataStyle.CBI ): style = MetaDataStyle.CBI elif ca.hasMetadata( MetaDataStyle.COMET ): style = MetaDataStyle.COMET elif ca.hasMetadata( MetaDataStyle.CBW ): style = MetaDataStyle.CBW else: logging.warning(u"Library: File Has No ComicMeta Data") if ca.hasMetadata( MetaDataStyle.CALIBRE ): style = MetaDataStyle.CALIBRE elif ca.hasMetadata( MetaDataStyle.EPUB ): style = MetaDataStyle.EPUB else: style = None if style is not None: md = ca.readMetadata(style) if md.isEmpty: md = ca.metadataFromFilename() else: # No metadata in comic. make some guesses from the filename md = ca.metadataFromFilename() # patch version 2 if (md.title is None or md.title == "") and md.issue is None and not md.series is None: md.title = md.series md.series = None md.fingerprint = ca.fingerprint() md.path = ca.path md.page_count = ca.page_count md.mod_ts = datetime.utcfromtimestamp(getmtime(ca.path)) md.filesize = os.path.getsize(md.path) md.hash = "" #thumbnail generation image_data = ca.getPage(0, AppFolders.missingPath("cover.png")) #now resize it thumb = StringIO.StringIO() try: utils.resize(image_data, (400, 400), thumb) md.thumbnail = thumb.getvalue() except: md.thumbnail = None return md return None
def getComicMetadata(self, path): ca = ComicArchive( path, default_image_path=AppFolders.missingPath("page.png")) if ca.seemsToBeAComicArchive(): if ca.hasMetadata(MetaDataStyle.CIX): style = MetaDataStyle.CIX elif ca.hasMetadata(MetaDataStyle.CBI): style = MetaDataStyle.CBI elif ca.hasMetadata(MetaDataStyle.COMET): style = MetaDataStyle.COMET elif ca.hasMetadata(MetaDataStyle.CBW): style = MetaDataStyle.CBW else: logging.warning(u"Library: File Has No ComicMeta Data") if ca.hasMetadata(MetaDataStyle.CALIBRE): style = MetaDataStyle.CALIBRE elif ca.hasMetadata(MetaDataStyle.EPUB): style = MetaDataStyle.EPUB else: style = None if style is not None: md = ca.readMetadata(style) if md.isEmpty: md = ca.metadataFromFilename() else: # No metadata in comic. make some guesses from the filename md = ca.metadataFromFilename() # patch version 2 if (md.title is None or md.title == "") and md.issue is None and not md.series is None: md.title = md.series md.series = None md.fingerprint = ca.fingerprint() md.path = ca.path md.page_count = ca.page_count md.mod_ts = datetime.utcfromtimestamp(getmtime(ca.path)) md.filesize = os.path.getsize(md.path) md.hash = "" #thumbnail generation image_data = ca.getPage(0, AppFolders.missingPath("cover.png")) #now resize it thumb = StringIO.StringIO() try: utils.resize(image_data, (400, 400), thumb) md.thumbnail = thumb.getvalue() except: md.thumbnail = None return md return None
def getComicMetadata(self, path): ca = ComicArchive( path, default_image_path=AppFolders.missingPath("page.png")) if ca.seemsToBeAComicArchive(): if ca.hasMetadata(MetaDataStyle.CIX): style = MetaDataStyle.CIX elif ca.hasMetadata(MetaDataStyle.CBI): style = MetaDataStyle.CBI elif ca.hasMetadata(MetaDataStyle.COMET): style = MetaDataStyle.COMET elif ca.hasMetadata(MetaDataStyle.CBW): style = MetaDataStyle.CBW else: logging.warning(u"Library: File Has No ComicMeta Data") if ca.hasMetadata(MetaDataStyle.CALIBRE): style = MetaDataStyle.CALIBRE elif ca.hasMetadata(MetaDataStyle.EPUB): style = MetaDataStyle.EPUB else: style = None if style is not None: md = ca.readMetadata(style) if md.isEmpty: md = ca.metadataFromFilename() else: # No metadata in comic. make some guesses from the filename md = ca.metadataFromFilename() # patch version 2 if (md.title is None or md.title == "") and md.issue is None and not md.series is None: md.title = md.series md.series = None md.fingerprint = ca.fingerprint() md.path = ca.path md.page_count = ca.page_count md.mod_ts = datetime.utcfromtimestamp(getmtime(ca.path)) md.filesize = os.path.getsize(md.path) md.hash = "" #thumbnail generation image_data = ca.getPage(0, AppFolders.missingPath("cover.png")) #now resize it thumb = StringIO.StringIO() #Lets right thumbs to files. large libraries cause the database to bloat try: utils.resize(image_data, (400, 400), thumb) filename = md.fingerprint + ".png" foldername = filename[0] thumbSubFolder = AppFolders.appThumbFolder(foldername) if not os.path.exists(thumbSubFolder): os.makedirs(thumbSubFolder) folderpath = AppFolders.appThumbPath(foldername, filename) with open(folderpath, 'wb') as f: f.write(thumb.getvalue()) print("Extracted thumb: " + filename) except: print("Thumbnail extraction failed") # print md return md return None