def lastpage_extractor_for_blacklist(self): print "Extract Last Pages" query = self.getSession.query(Comic) x = os.path.join(AppFolders.appBlacklistPages(),"lastpage") y = os.path.join(AppFolders.appBlacklistPages(),"lastpage_double") z = os.path.join(AppFolders.appBlacklistPages(),"firstpage") w = os.path.join(AppFolders.appBlacklistPages(),"firstpage_double") if not os.path.isdir(x): os.makedirs(x) if not os.path.isdir(y): os.makedirs(y) if not os.path.isdir(z): os.makedirs(z) if not os.path.isdir(w): os.makedirs(w) c = 0 for row in query: print('Extracting last page from ' + str(c) + ' ' + row.path) c += 1 ca = self.getComicArchive(row.id,row.path) # auto convert webp (disable for chunky or fix web book reader) image_data = ca.getPage(row.page_count-1) hash = utils.hash(image_data) # ascept ratio check #im = Image.open(StringIO.StringIO(image_data)) #w,h = im.size #if h > w: # continue image_cover = ca.getPage(0) image_page2 = ca.getPage(1) if image_page2: imc = Image.open(StringIO.StringIO(image_cover)) hash2 = utils.hash(image_cover) im2 = Image.open(StringIO.StringIO(image_page2)) w1,h1 = imc.size w2,h2 = im2.size if h1 <= w1 and h2 > w2 and not self.checkHashBlacklist(hash2): if os.path.isfile(os.path.join(z,str(hash2))): if os.path.isfile(os.path.join(w,str(hash2))): print "Double Already Exists" else: print "Adding Double" file2 = open(os.path.join(w,str(hash2)), "w") file2.write(image_cover) file2.close() else: print "Adding Firstpage" file2 = open(os.path.join(z,str(hash2)), "w") #file2.write("1") file2.write(image_cover) file2.close() """
def lastpage_extractor_for_blacklist(self): print "Extract Last Pages" query = self.getSession.query(Comic) x = os.path.join(AppFolders.appBlacklistPages(), "lastpage") y = os.path.join(AppFolders.appBlacklistPages(), "lastpage_double") z = os.path.join(AppFolders.appBlacklistPages(), "firstpage") w = os.path.join(AppFolders.appBlacklistPages(), "firstpage_double") if not os.path.isdir(x): os.makedirs(x) if not os.path.isdir(y): os.makedirs(y) if not os.path.isdir(z): os.makedirs(z) if not os.path.isdir(w): os.makedirs(w) c = 0 for row in query: print('Extracting last page from ' + str(c) + ' ' + row.path) c += 1 ca = self.getComicArchive(row.id, row.path) # auto convert webp (disable for chunky or fix web book reader) image_data = ca.getPage(row.page_count - 1) hash = utils.hash(image_data) # ascept ratio check #im = Image.open(StringIO.StringIO(image_data)) #w,h = im.size #if h > w: # continue image_cover = ca.getPage(0) image_page2 = ca.getPage(1) if image_page2: imc = Image.open(StringIO.StringIO(image_cover)) hash2 = utils.hash(image_cover) im2 = Image.open(StringIO.StringIO(image_page2)) w1, h1 = imc.size w2, h2 = im2.size if h1 <= w1 and h2 > w2 and not self.checkHashBlacklist(hash2): if os.path.isfile(os.path.join(z, str(hash2))): if os.path.isfile(os.path.join(w, str(hash2))): print "Double Already Exists" else: print "Adding Double" file2 = open(os.path.join(w, str(hash2)), "w") file2.write(image_cover) file2.close() else: print "Adding Firstpage" file2 = open(os.path.join(z, str(hash2)), "w") #file2.write("1") file2.write(image_cover) file2.close() """
def comicBlacklist(self,comic_id, pagenum): #obj = session.query(database.Blacklist).filter(database.Blacklist.comic_id == int(comic_id),database.Blacklist.page == int(pagenum)).first() # if obj is None: session = self.getSession() #self.getComic() #x = self.getSession().query(Comic.id, Comic.path, Comic.mod_ts) image_data = self.getComicPage(comic_id, pagenum, False) hash = utils.hash(image_data) #comichash = self.getHashEntity(Blacklist, hash) #self.getComic(comic_id).blacklist(comichash) obj = self.getSession().query(Blacklist.hash).filter(Blacklist.hash == hash).first() if obj is None: try: blacklist = Blacklist() blacklist.hash = hash blacklist.detect = len(image_data) file = open(os.path.join(AppFolders.appBlacklistPages(),str(blacklist.hash)), "w") file.write(image_data) file.close() #blacklist.comic_id = int(comic_id) #blacklist.page = int(pagenum) blacklist.ts = datetime.datetime.utcnow() session.add(blacklist) session.commit() session.close() except Exception, e: print str(e) logging.error("Blacklist: Problem blocking page {} on comic {}".format(pagenum, comic_id))
def createBlacklistFromFolder(self,file): # loop over files in blacklist folder # and save them to a file with \n seperated # untested for root, dirs, filenames in os.walk(AppFolders.appBlacklistPages()): for f in filenames: with open(file) as f: f.write(str(f)+str(os.stat(file).st_size)+'\n')
def createBlacklistFromFolder(self, file): # loop over files in blacklist folder # and save them to a file with \n seperated # untested for root, dirs, filenames in os.walk(AppFolders.appBlacklistPages()): for f in filenames: with open(file) as f: f.write(str(f) + str(os.stat(file).st_size) + '\n')
def lastpage_extractor_for_blacklist(self): print "Extract Last Pages" query = self.getSession.query(Comic) x = os.path.join(AppFolders.appBlacklistPages(), "lastpage") y = os.path.join(AppFolders.appBlacklistPages(), "lastpage_double") if not os.path.isdir(x): os.makedirs(x) if not os.path.isdir(y): os.makedirs(y) c = 0 for row in query: print('Extracting last page from ' + str(c) + ' ' + row.path) c += 1 ca = self.getComicArchive(row.id, row.path) # auto convert webp (disable for chunky or fix web book reader) image_data = ca.getPage(row.page_count - 1) hash = utils.hash(image_data) # ascept ratio check #im = Image.open(StringIO.StringIO(image_data)) #w,h = im.size #if h > w: # continue if self.checkHashBlacklist(hash): continue if os.path.isfile(os.path.join(x, str(hash))): if os.path.isfile(os.path.join(y, str(hash))): print "Double Already Exists" continue else: print "Adding Double" file = open(os.path.join(y, str(hash)), "w") file.write(image_data) else: print "Adding Lastpage" file = open(os.path.join(x, str(hash)), "w") #file.write("1") file.write(image_data) file.close()
def comicBlacklist(self, comic_id, pagenum): #obj = session.query(database.Blacklist).filter(database.Blacklist.comic_id == int(comic_id),database.Blacklist.page == int(pagenum)).first() # if obj is None: session = self.getSession() #self.getComic() #x = self.getSession().query(Comic.id, Comic.path, Comic.mod_ts) image_data = self.getComicPage(comic_id, pagenum, False) hash = utils.hash(image_data) #comichash = self.getHashEntity(Blacklist, hash) #self.getComic(comic_id).blacklist(comichash) obj = self.getSession().query( Blacklist.hash).filter(Blacklist.hash == hash).first() if obj is None: try: blacklist = Blacklist() blacklist.hash = hash blacklist.detect = len(image_data) file = open( os.path.join(AppFolders.appBlacklistPages(), str(blacklist.hash)), "w") file.write(image_data) file.close() #blacklist.comic_id = int(comic_id) #blacklist.page = int(pagenum) blacklist.ts = datetime.datetime.utcnow() session.add(blacklist) session.commit() session.close() except Exception, e: print str(e) logging.error( "Blacklist: Problem blocking page {} on comic {}".format( pagenum, comic_id))