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 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 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 getComicPage(self, comic_id, page_number, cache = True, max_height = None): (path, page_count) = self.getSession().query(Comic.path, Comic.page_count) \ .filter(Comic.id == int(comic_id)).first() image_data = None default_img_file = AppFolders.missingPath("page.png") if path is not None: if int(page_number) < page_count: if cache: image_data = self.cache_load(comic_id,page_number,path) else: ca = self.getComicArchive(comic_id,path) # auto convert webp (disable for chunky or fix web book reader) image_data = utils.webp_patch_convert(self.isBlacklist(ca.getPage(int(page_number)))) if image_data is None: with open(default_img_file, 'rb') as fd: image_data = fd.read() return image_data # resize image if max_height is not None: try: image_data = utils.resizeImage(int(max_height), image_data) except Exception as e: #logging.error(e) pass return image_data
def getComicPage(self, comic_id, page_number, cache=True, max_height=None): (path, page_count) = self.getSession().query(Comic.path, Comic.page_count) \ .filter(Comic.id == int(comic_id)).first() image_data = None default_img_file = AppFolders.missingPath("page.png") if path is not None: if int(page_number) < page_count: if cache: image_data = self.cache_load(comic_id, page_number, path) else: ca = self.getComicArchive(comic_id, path) # auto convert webp (disable for chunky or fix web book reader) image_data = utils.webp_patch_convert( self.isBlacklist(ca.getPage(int(page_number)))) if image_data is None: with open(default_img_file, 'rb') as fd: image_data = fd.read() return image_data # resize image if max_height is not None: try: image_data = utils.resizeImage(int(max_height), image_data) except Exception as e: #logging.error(e) pass return image_data
def isBlacklist(self,image, hash=None): if hash is None: hash = utils.hash(image) # should be replaced with database query... obj = self.getSession().query(Blacklist.hash).filter(Blacklist.hash == hash).first() if obj is not None: with open(AppFolders.missingPath("blacklist.png"), 'rb') as fd: image_data = fd.read() return image_data else: return image
def getComicArchive(self, id, 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.missingPath("page.png")) self.comicArchiveList.append(ca) if len(self.comicArchiveList) > 10: self.comicArchiveList.pop(0) return ca
def isBlacklist(self, image, hash=None): if hash is None: hash = utils.hash(image) # should be replaced with database query... obj = self.getSession().query( Blacklist.hash).filter(Blacklist.hash == hash).first() if obj is not None: with open(AppFolders.missingPath("blacklist.png"), 'rb') as fd: image_data = fd.read() return image_data else: return image
def getComicArchive(self, id, 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.missingPath("page.png")) self.comicArchiveList.append(ca) if len(self.comicArchiveList) > 10: self.comicArchiveList.pop(0) return ca
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