def parse_entries(cursor, ignore_empty_collections=False): db_ebooks = [] db_collections = [] cursor.execute(SELECT_COLLECTION_ENTRIES) for (c_uuid, label) in cursor.fetchall(): db_collections.append(Collection(c_uuid, label)) cursor.execute(SELECT_EBOOK_ENTRIES) for (e_uuid, location, cdekey, cdetype) in cursor.fetchall(): # only consider user ebooks if location is not None and KINDLE_EBOOKS_ROOT in location: db_ebooks.append(Ebook(e_uuid, location, cdekey, cdetype)) cursor.execute(SELECT_EXISTING_COLLECTIONS) for (collection_uuid, ebook_uuid) in cursor.fetchall(): collection_idx = find_collection(db_collections, collection_uuid) ebook_idx_list = find_ebook(db_ebooks, ebook_uuid) if collection_idx != -1 and ebook_idx_list != []: for ebook_idx in ebook_idx_list: db_collections[collection_idx].add_ebook( db_ebooks[ebook_idx], True) db_ebooks[ebook_idx].add_collection( db_collections[collection_idx], True) else: log(LIBRARIAN_SYNC, "parse_entries", "Skipping collection {} (collection_idx: {}, ebook_uuid: {})". format(collection_uuid, collection_idx, ebook_uuid), "W", display=False) # remove empty collections: if ignore_empty_collections: db_collections = [ c for c in db_collections if len(c.original_ebooks) != 0 ] return db_ebooks, db_collections
def update_lists_from_calibre_plugin_json(db_ebooks, db_collections, collection_contents): for (collection_label, ebook_hashes_list) in collection_contents.items(): # find collection by label collection_idx = find_collection(db_collections, collection_label) if collection_idx == -1: # creating new collection object db_collections.append( Collection(uuid.uuid4(), collection_label, is_new=True)) collection_idx = len(db_collections) - 1 for ebook_hash in ebook_hashes_list: cdekey, cdetype = parse_legacy_hash(ebook_hash) # NOTE: We don't actually use the cdeType. We shouldn't need to, # unless we run into the extremely unlikely case of two items with # the same cdeKey, but different cdeTypes # find ebook by cdeKey ebook_idx_list = find_ebook(db_ebooks, cdekey) if ebook_idx_list == []: log(LIBRARIAN_SYNC, "update calibre", "Couldn't match a db uuid to cdeKey %s" "(book not on device?)" % cdekey, "W", display=False) continue # invalid for ebook_idx in ebook_idx_list: # update ebook db_ebooks[ebook_idx].add_collection( db_collections[collection_idx]) # update collection db_collections[collection_idx].add_ebook(db_ebooks[ebook_idx]) # remove empty collections: db_collections = [c for c in db_collections if len(c.ebooks) != 0] return db_ebooks, db_collections
def update_lists_from_librarian_json(db_ebooks, db_collections, collection_contents): for (ebook_location, ebook_collection_labels_list) in collection_contents.items(): # find ebook by location if ebook_location.startswith("re:"): ebook_idx_list = find_ebook(db_ebooks, ebook_location, regexp=True) else: ebook_idx_list = find_ebook( db_ebooks, os.path.join(KINDLE_EBOOKS_ROOT, ebook_location)) if ebook_idx_list == []: log(LIBRARIAN_SYNC, "update librarian", "Invalid location: %s" % ebook_location.encode("utf8"), "W", display=False) continue # invalid for collection_label in ebook_collection_labels_list: # find collection by label collection_idx = find_collection(db_collections, collection_label) if collection_idx == -1: # creating new collection object db_collections.append( Collection(uuid.uuid4(), collection_label, is_new=True)) collection_idx = len(db_collections) - 1 for ebook_idx in ebook_idx_list: # udpate ebook db_ebooks[ebook_idx].add_collection( db_collections[collection_idx]) # update collection db_collections[collection_idx].add_ebook(db_ebooks[ebook_idx]) # remove empty collections: db_collections = [c for c in db_collections if len(c.ebooks) != 0] return db_ebooks, db_collections
def update_lists_from_librarian_json(db_ebooks, db_collections, collection_contents): for (ebook_location, ebook_collection_labels_list) in collection_contents.items(): # find ebook by location if ebook_location.startswith("re:"): ebook_idx_list = find_ebook(db_ebooks, ebook_location, regexp=True) else: ebook_idx_list = find_ebook(db_ebooks, os.path.join( KINDLE_EBOOKS_ROOT, ebook_location)) if ebook_idx_list == []: log(LIBRARIAN_SYNC, "update librarian", "Invalid location: %s" % ebook_location.encode("utf8"), "W", display=False) continue # invalid for collection_label in ebook_collection_labels_list: # find collection by label collection_idx = find_collection(db_collections, collection_label) if collection_idx == -1: # creating new collection object db_collections.append(Collection(uuid.uuid4(), collection_label, is_new=True)) collection_idx = len(db_collections)-1 for ebook_idx in ebook_idx_list: # udpate ebook db_ebooks[ebook_idx].add_collection( db_collections[collection_idx]) # update collection db_collections[collection_idx].add_ebook(db_ebooks[ebook_idx]) # remove empty collections: db_collections = [c for c in db_collections if len(c.ebooks) != 0] return db_ebooks, db_collections
def parse_entries(cursor, ignore_empty_collections=False): db_ebooks = [] db_collections = [] cursor.execute(SELECT_COLLECTION_ENTRIES) for (c_uuid, label) in cursor.fetchall(): db_collections.append(Collection(c_uuid, label)) cursor.execute(SELECT_EBOOK_ENTRIES) for (e_uuid, location, cdekey, cdetype) in cursor.fetchall(): # only consider user ebooks if location is not None and KINDLE_EBOOKS_ROOT in location: db_ebooks.append(Ebook(e_uuid, location, cdekey, cdetype)) cursor.execute(SELECT_EXISTING_COLLECTIONS) for (collection_uuid, ebook_uuid) in cursor.fetchall(): collection_idx = find_collection(db_collections, collection_uuid) ebook_idx_list = find_ebook(db_ebooks, ebook_uuid) if collection_idx != -1 and ebook_idx_list != []: for ebook_idx in ebook_idx_list: db_collections[collection_idx].add_ebook(db_ebooks[ebook_idx], True) db_ebooks[ebook_idx].add_collection( db_collections[collection_idx], True) else: log(LIBRARIAN_SYNC, "parse_entries", "Skipping collection {} (collection_idx: {}, ebook_uuid: {})" .format(collection_uuid, collection_idx, ebook_uuid), "W", display=False) # remove empty collections: if ignore_empty_collections: db_collections = [c for c in db_collections if len(c.original_ebooks) != 0] return db_ebooks, db_collections
def update_lists_from_calibre_plugin_json(db_ebooks, db_collections, collection_contents): for (collection_label, ebook_hashes_list) in collection_contents.items(): # find collection by label collection_idx = find_collection(db_collections, collection_label) if collection_idx == -1: # creating new collection object db_collections.append(Collection(uuid.uuid4(), collection_label, is_new=True)) collection_idx = len(db_collections)-1 for ebook_hash in ebook_hashes_list: cdekey, cdetype = parse_legacy_hash(ebook_hash) # NOTE: We don't actually use the cdeType. We shouldn't need to, # unless we run into the extremely unlikely case of two items with # the same cdeKey, but different cdeTypes # find ebook by cdeKey ebook_idx_list = find_ebook(db_ebooks, cdekey) if ebook_idx_list == []: log(LIBRARIAN_SYNC, "update calibre", "Couldn't match a db uuid to cdeKey %s" "(book not on device?)" % cdekey, "W", display=False) continue # invalid for ebook_idx in ebook_idx_list: # update ebook db_ebooks[ebook_idx].add_collection( db_collections[collection_idx]) # update collection db_collections[collection_idx].add_ebook(db_ebooks[ebook_idx]) # remove empty collections: db_collections = [c for c in db_collections if len(c.ebooks) != 0] return db_ebooks, db_collections