def upload_apnx(self, path, filename, metadata, filepath): from calibre.devices.kindle.apnx import APNXBuilder opts = self.settings() if not opts.extra_customization[self.OPT_APNX]: return if os.path.splitext(filepath.lower())[1] not in ('.azw', '.mobi', '.prc', '.azw3'): return # Create the sidecar folder if necessary if (self.sidecar_apnx): path = os.path.join(os.path.dirname(filepath), filename+".sdr") if not os.path.exists(path): os.makedirs(path) cust_col_name = opts.extra_customization[self.OPT_APNX_CUST_COL] custom_page_count = 0 if cust_col_name: try: custom_page_count = int(metadata.get(cust_col_name, 0)) except: pass apnx_path = '%s.apnx' % os.path.join(path, filename) apnx_builder = APNXBuilder() try: method = opts.extra_customization[self.OPT_APNX_METHOD] apnx_builder.write_apnx(filepath, apnx_path, method=method, page_count=custom_page_count) except: print 'Failed to generate APNX' import traceback traceback.print_exc()
def upload_apnx(self, path, filename, metadata, filepath): from calibre.devices.kindle.apnx import APNXBuilder opts = self.settings() if not opts.extra_customization[self.OPT_APNX]: return if os.path.splitext(filepath.lower())[1] not in ('.azw', '.mobi', '.prc', '.azw3'): return # Create the sidecar folder if necessary if (self.sidecar_apnx): path = os.path.join(os.path.dirname(filepath), filename + ".sdr") if not os.path.exists(path): os.makedirs(path) cust_col_name = opts.extra_customization[self.OPT_APNX_CUST_COL] custom_page_count = 0 if cust_col_name: try: custom_page_count = int(metadata.get(cust_col_name, 0)) except: pass apnx_path = '%s.apnx' % os.path.join(path, filename) apnx_builder = APNXBuilder() # Check to see if there is an existing apnx file on Kindle we should keep. if opts.extra_customization[ self.OPT_APNX_OVERWRITE] or not os.path.exists(apnx_path): try: method = opts.extra_customization[self.OPT_APNX_METHOD] cust_col_name = opts.extra_customization[ self.OPT_APNX_METHOD_COL] if cust_col_name: try: temp = unicode_type( metadata.get(cust_col_name)).lower() if temp in self.EXTRA_CUSTOMIZATION_CHOICES[ self.OPT_APNX_METHOD]: method = temp else: print( "Invalid method choice for this book (%r), ignoring." % temp) except: print( 'Could not retrieve override method choice, using default.' ) apnx_builder.write_apnx(filepath, apnx_path, method=method, page_count=custom_page_count) except: print('Failed to generate APNX') import traceback traceback.print_exc()
def upload_apnx(self, path, filename, metadata, filepath): from calibre.devices.kindle.apnx import APNXBuilder opts = self.settings() if not opts.extra_customization[self.OPT_APNX]: return if os.path.splitext(filepath.lower())[1] not in ('.azw', '.mobi', '.prc', '.azw3'): return # Create the sidecar folder if necessary if (self.sidecar_apnx): path = os.path.join(os.path.dirname(filepath), filename+".sdr") if not os.path.exists(path): os.makedirs(path) cust_col_name = opts.extra_customization[self.OPT_APNX_CUST_COL] custom_page_count = 0 if cust_col_name: try: custom_page_count = int(metadata.get(cust_col_name, 0)) except: pass apnx_path = '%s.apnx' % os.path.join(path, filename) apnx_builder = APNXBuilder() # ## Check to see if there is an existing apnx file on Kindle we should keep. if opts.extra_customization[self.OPT_APNX_OVERWRITE] or not os.path.exists(apnx_path): try: method = opts.extra_customization[self.OPT_APNX_METHOD] cust_col_name = opts.extra_customization[self.OPT_APNX_METHOD_COL] if cust_col_name: try: temp = unicode(metadata.get(cust_col_name)).lower() if temp in self.EXTRA_CUSTOMIZATION_CHOICES[self.OPT_APNX_METHOD]: method = temp else: print ("Invalid method choice for this book (%r), ignoring." % temp) except: print 'Could not retrieve override method choice, using default.' print 'Generating apnx with', method apnx_builder.write_apnx(filepath, apnx_path, method=method, page_count=custom_page_count) except: print 'Failed to generate APNX' import traceback traceback.print_exc()
def upload_apnx(self, path, filename, metadata, filepath): from calibre.devices.kindle.apnx import APNXBuilder opts = self.settings() if not opts.extra_customization[self.OPT_APNX]: return if os.path.splitext(filepath.lower())[1] not in (".azw", ".mobi", ".prc", ".azw3"): return # Create the sidecar folder if necessary if self.sidecar_apnx: path = os.path.join(os.path.dirname(filepath), filename + ".sdr") if not os.path.exists(path): os.makedirs(path) cust_col_name = opts.extra_customization[self.OPT_APNX_CUST_COL] custom_page_count = 0 if cust_col_name: try: custom_page_count = int(metadata.get(cust_col_name, 0)) except: pass apnx_path = "%s.apnx" % os.path.join(path, filename) apnx_builder = APNXBuilder() try: apnx_builder.write_apnx( filepath, apnx_path, accurate=opts.extra_customization[self.OPT_APNX_ACCURATE], page_count=custom_page_count, ) except: print "Failed to generate APNX" import traceback traceback.print_exc()
def upload_apnx(self, path, filename, metadata, filepath): from calibre.devices.kindle.apnx import APNXBuilder opts = self.settings() if not opts.extra_customization[self.OPT_APNX]: return if os.path.splitext(filepath.lower())[1] not in ('.azw', '.mobi', '.prc', '.azw3'): return # Create the sidecar folder if necessary if (self.sidecar_apnx): path = os.path.join(os.path.dirname(filepath), filename + ".sdr") if not os.path.exists(path): os.makedirs(path) cust_col_name = opts.extra_customization[self.OPT_APNX_CUST_COL] custom_page_count = 0 if cust_col_name: try: custom_page_count = int(metadata.get(cust_col_name, 0)) except: pass apnx_path = '%s.apnx' % os.path.join(path, filename) apnx_builder = APNXBuilder() try: apnx_builder.write_apnx( filepath, apnx_path, accurate=opts.extra_customization[self.OPT_APNX_ACCURATE], page_count=custom_page_count) except: print 'Failed to generate APNX' import traceback traceback.print_exc()
#!/usr/bin/env python import sys from calibre.devices.kindle.apnx import APNXBuilder apnx_builder = APNXBuilder() docs = "./output" method = "accurate" for root, dirs, files in os.walk(docs): for name in files: mobi_path = os.path.join(root, name) if name.lower().endswith('.azw3'): apnx_path = os.path.join(root, os.path.splitext(name)[0] + '.apnx') apnx_builder.write_apnx(mobi_path, apnx_path, method)