From 226ce76c162a9ebca4a865c7507d23d370d132d8 Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Tue, 2 Feb 2021 19:44:31 +0100 Subject: [PATCH] Skipping Adobe drm encoded files since we can't read metadata. fixes #1 --- src/main.rs | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 153c9fb..6a23de2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -304,6 +304,7 @@ struct BookEntry { filepath: String, author: String, firstauthor: String, + has_drm: bool, } fn get_epubs_from_database(tx: &Transaction) -> Vec { @@ -331,12 +332,17 @@ fn get_epubs_from_database(tx: &Transaction) -> Vec { let filepath = format!("{}/{}", prefix, filename); let firstauthor: String = row.get(3).unwrap(); let author: String = row.get(4).unwrap(); + let has_drm = match prefix.as_str() { + "/mnt/ext1/Digital Editions" => true, + _ => false, + }; let entry = BookEntry { id: book_id, filepath, firstauthor, author, + has_drm, }; book_entries.push(entry); @@ -394,15 +400,22 @@ fn remove_ghost_books_from_db(tx: &Transaction) -> usize { struct Statistics { authors_fixed: i32, ghost_books_cleaned: usize, + drm_skipped: usize, } fn fix_db_entries(tx: &Transaction, book_entries: &Vec) -> Statistics { let mut stat = Statistics { authors_fixed: 0, ghost_books_cleaned: 0, + drm_skipped: 0, }; for entry in book_entries { + if entry.has_drm { + stat.drm_skipped = stat.drm_skipped + 1; + continue; + } + let file = File::open(entry.filepath.as_str()); let file = match file { Err(_) => continue, @@ -489,16 +502,20 @@ fn main() { pocketbook::dialog( pocketbook::Icon::Info, &format!( - "Authors fixed: {}\nBooks cleaned from DB: {}", - &stat.authors_fixed, &stat.ghost_books_cleaned + "Authors fixed: {}\n\ + Books skipped (DRM): {}\n\ + Books cleaned from DB: {}", + &stat.authors_fixed, &stat.drm_skipped, &stat.ghost_books_cleaned ), &["OK"], ); } } else { println!( - "Authors fixed: {}\nBooks cleaned from DB: {}", - &stat.authors_fixed, &stat.ghost_books_cleaned + "Authors fixed: {}\n\ + Books skipped (DRM): {}\n\ + Books cleaned from DB: {}", + &stat.authors_fixed, &stat.drm_skipped, &stat.ghost_books_cleaned ); } }