def get_pages(self, comic, tdir2): from calibre.ebooks.comic.input import (extract_comic, process_pages, find_pages) tdir = extract_comic(comic) new_pages = find_pages(tdir, sort_on_mtime=self.opts.no_sort, verbose=self.opts.verbose) thumbnail = None if not new_pages: raise ValueError('Could not find any pages in the comic: %s' % comic) if self.opts.no_process: n2 = [] for i, page in enumerate(new_pages): n2.append( os.path.join(tdir2, '{} - {}'.format(i, os.path.basename(page)))) shutil.copyfile(page, n2[-1]) new_pages = n2 else: new_pages, failures = process_pages(new_pages, self.opts, self.report_progress, tdir2) if failures: self.log.warning('Could not process the following pages ' '(run with --verbose to see why):') for f in failures: self.log.warning('\t', f) if not new_pages: raise ValueError( 'Could not find any valid pages in comic: %s' % comic) thumbnail = os.path.join( tdir2, 'thumbnail.' + self.opts.output_format.lower()) if not os.access(thumbnail, os.R_OK): thumbnail = None return new_pages
def get_pages(self, comic, tdir2): from calibre.ebooks.comic.input import (extract_comic, process_pages, find_pages) tdir = extract_comic(comic) new_pages = find_pages(tdir, sort_on_mtime=self.opts.no_sort, verbose=self.opts.verbose) thumbnail = None if not new_pages: raise ValueError('Could not find any pages in the comic: %s' %comic) if self.opts.no_process: n2 = [] for page in new_pages: n2.append(os.path.join(tdir2, os.path.basename(page))) shutil.copyfile(page, n2[-1]) new_pages = n2 else: new_pages, failures = process_pages(new_pages, self.opts, self.report_progress, tdir2) if failures: self.log.warning('Could not process the following pages ' '(run with --verbose to see why):') for f in failures: self.log.warning('\t', f) if not new_pages: raise ValueError('Could not find any valid pages in comic: %s' % comic) thumbnail = os.path.join(tdir2, 'thumbnail.'+self.opts.output_format.lower()) if not os.access(thumbnail, os.R_OK): thumbnail = None return new_pages
def get_work_folder(comic_file): from calibre.ebooks.comic.input import extract_comic target_dir = extract_comic(comic_file) _log.prints(INFO, "Extracted images into " + target_dir) # move file structure up subdirectories = os.listdir(target_dir) # delete all not-images for file in os.listdir(target_dir): if os.path.isdir(os.path.join(target_dir, file)) \ or file.lower().endswith('.png') \ or file.lower().endswith('.jpg') \ or file.lower().endswith('.jpeg') \ or file.lower().endswith('.tif') \ or file.lower().endswith('.tiff'): continue os.remove(os.path.join(target_dir, file)) if len(subdirectories) == 1 and os.path.isdir( os.path.join(target_dir, subdirectories[0])): for f in os.listdir(os.path.join(target_dir, subdirectories[0])): move(os.path.join(target_dir, subdirectories[0], f), target_dir) os.rmdir(os.path.join(target_dir, subdirectories[0])) new_path = PersistentTemporaryDirectory(suffix='_oebps') copytree(target_dir, os.path.join(new_path, 'OEBPS', 'Images')) rmtree(target_dir) _log.prints(INFO, "Moved images to structure in " + new_path) return new_path