Compare commits
No commits in common. "65007fdf50b2e0cf41cf83334e82a663649a7bb1" and "9baff090a8b80c3693ec661d14716670798512a6" have entirely different histories.
65007fdf50
...
9baff090a8
5 changed files with 40 additions and 15 deletions
6
Cargo.lock
generated
6
Cargo.lock
generated
|
@ -47,9 +47,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cc"
|
name = "cc"
|
||||||
version = "1.0.67"
|
version = "1.0.66"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e3c69b077ad434294d3ce9f1f6143a2a4b89a8a2d54ef813d85003a4fd1137fd"
|
checksum = "4c0496836a84f8d0495758516b8621a622beb77c0fed418570e50764093ced48"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cfg-if"
|
name = "cfg-if"
|
||||||
|
@ -148,7 +148,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pbdbfixer"
|
name = "pbdbfixer"
|
||||||
version = "0.8.0"
|
version = "0.7.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"quick-xml",
|
"quick-xml",
|
||||||
"rusqlite",
|
"rusqlite",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "pbdbfixer"
|
name = "pbdbfixer"
|
||||||
version = "0.8.0"
|
version = "0.7.2"
|
||||||
authors = ["Martin Brodbeck <martin@brodbeck-online.de>"]
|
authors = ["Martin Brodbeck <martin@brodbeck-online.de>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ pub struct BookEntry {
|
||||||
filepath: String,
|
filepath: String,
|
||||||
author: String,
|
author: String,
|
||||||
firstauthor: String,
|
firstauthor: String,
|
||||||
|
has_drm: bool,
|
||||||
genre: String,
|
genre: String,
|
||||||
first_author_letter: String,
|
first_author_letter: String,
|
||||||
series: String,
|
series: String,
|
||||||
|
@ -44,6 +45,10 @@ fn get_epubs_from_database(tx: &Transaction) -> Vec<BookEntry> {
|
||||||
let filepath = format!("{}/{}", prefix, filename);
|
let filepath = format!("{}/{}", prefix, filename);
|
||||||
let firstauthor: String = row.get(3).unwrap_or_default();
|
let firstauthor: String = row.get(3).unwrap_or_default();
|
||||||
let author: String = row.get(4).unwrap_or_default();
|
let author: String = row.get(4).unwrap_or_default();
|
||||||
|
let has_drm = match prefix.as_str() {
|
||||||
|
"/mnt/ext1/Digital Editions" => true,
|
||||||
|
_ => false,
|
||||||
|
};
|
||||||
let genre: String = row.get(5).unwrap_or_default();
|
let genre: String = row.get(5).unwrap_or_default();
|
||||||
let first_author_letter = row.get(6).unwrap_or_default();
|
let first_author_letter = row.get(6).unwrap_or_default();
|
||||||
let series: String = row.get(7).unwrap_or_default();
|
let series: String = row.get(7).unwrap_or_default();
|
||||||
|
@ -53,6 +58,7 @@ fn get_epubs_from_database(tx: &Transaction) -> Vec<BookEntry> {
|
||||||
filepath,
|
filepath,
|
||||||
firstauthor,
|
firstauthor,
|
||||||
author,
|
author,
|
||||||
|
has_drm,
|
||||||
genre,
|
genre,
|
||||||
first_author_letter,
|
first_author_letter,
|
||||||
series,
|
series,
|
||||||
|
@ -113,6 +119,7 @@ fn remove_ghost_books_from_db(tx: &Transaction) -> usize {
|
||||||
pub struct Statistics {
|
pub struct Statistics {
|
||||||
pub authors_fixed: i32,
|
pub authors_fixed: i32,
|
||||||
pub ghost_books_cleaned: usize,
|
pub ghost_books_cleaned: usize,
|
||||||
|
pub drm_skipped: usize,
|
||||||
pub genres_fixed: usize,
|
pub genres_fixed: usize,
|
||||||
pub sorting_fixed: usize,
|
pub sorting_fixed: usize,
|
||||||
pub series_fixed: usize,
|
pub series_fixed: usize,
|
||||||
|
@ -132,6 +139,7 @@ pub fn fix_db_entries() -> Statistics {
|
||||||
let mut stat = Statistics {
|
let mut stat = Statistics {
|
||||||
authors_fixed: 0,
|
authors_fixed: 0,
|
||||||
ghost_books_cleaned: 0,
|
ghost_books_cleaned: 0,
|
||||||
|
drm_skipped: 0,
|
||||||
genres_fixed: 0,
|
genres_fixed: 0,
|
||||||
sorting_fixed: 0,
|
sorting_fixed: 0,
|
||||||
series_fixed: 0,
|
series_fixed: 0,
|
||||||
|
@ -144,6 +152,11 @@ pub fn fix_db_entries() -> Statistics {
|
||||||
let book_entries = get_epubs_from_database(&tx);
|
let book_entries = get_epubs_from_database(&tx);
|
||||||
|
|
||||||
for entry in book_entries {
|
for entry in book_entries {
|
||||||
|
if entry.has_drm {
|
||||||
|
stat.drm_skipped = stat.drm_skipped + 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(epub_metadata) = epub::get_epub_metadata(&entry.filepath) {
|
if let Some(epub_metadata) = epub::get_epub_metadata(&entry.filepath) {
|
||||||
// Fix firstauthor…
|
// Fix firstauthor…
|
||||||
let mut firstauthors = epub_metadata
|
let mut firstauthors = epub_metadata
|
||||||
|
@ -172,8 +185,7 @@ pub fn fix_db_entries() -> Statistics {
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
.to_string()
|
.to_string()
|
||||||
.to_uppercase();
|
.to_uppercase();
|
||||||
|
if entry.first_author_letter != first_author_letter {
|
||||||
if first_author_letter != "\0" && (entry.first_author_letter != first_author_letter) {
|
|
||||||
let mut stmt = tx
|
let mut stmt = tx
|
||||||
.prepare("UPDATE books_impl SET first_author_letter = :first_letter WHERE id = :book_id")
|
.prepare("UPDATE books_impl SET first_author_letter = :first_letter WHERE id = :book_id")
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
|
@ -151,10 +151,6 @@ pub fn get_epub_metadata(filename: &str) -> Option<EpubMetadata> {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.as_str();
|
.as_str();
|
||||||
xml_authors.insert(curr_id.clone(), XmlAut::new());
|
xml_authors.insert(curr_id.clone(), XmlAut::new());
|
||||||
} else {
|
|
||||||
curr_id = "none".to_string() + xml_authors.len().to_string().as_str();
|
|
||||||
let entry = xml_authors.entry(curr_id.clone()).or_insert(XmlAut::new());
|
|
||||||
entry.role = "aut".to_string();
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if let Some(file_as_val) = e
|
if let Some(file_as_val) = e
|
||||||
|
|
27
src/main.rs
27
src/main.rs
|
@ -25,12 +25,25 @@ fn main() {
|
||||||
|
|
||||||
if cfg!(target_arch = "arm") {
|
if cfg!(target_arch = "arm") {
|
||||||
if stat.anything_fixed() == false {
|
if stat.anything_fixed() == false {
|
||||||
pocketbook::dialog(
|
if stat.drm_skipped == 0 {
|
||||||
pocketbook::Icon::Info,
|
pocketbook::dialog(
|
||||||
"The database seems to be ok.\n\
|
pocketbook::Icon::Info,
|
||||||
|
"The database seems to be ok.\n\
|
||||||
Nothing had to be fixed.",
|
Nothing had to be fixed.",
|
||||||
&["OK"],
|
&["OK"],
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
pocketbook::dialog(
|
||||||
|
pocketbook::Icon::Info,
|
||||||
|
&format!(
|
||||||
|
"The database seems to be ok.\n\
|
||||||
|
Nothing had to be fixed.\n\
|
||||||
|
(Books skipped (DRM): {})",
|
||||||
|
&stat.drm_skipped
|
||||||
|
),
|
||||||
|
&["OK"],
|
||||||
|
);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
pocketbook::dialog(
|
pocketbook::dialog(
|
||||||
pocketbook::Icon::Info,
|
pocketbook::Icon::Info,
|
||||||
|
@ -39,11 +52,13 @@ fn main() {
|
||||||
Sorting fixed: {}\n\
|
Sorting fixed: {}\n\
|
||||||
Genres fixed: {}\n\
|
Genres fixed: {}\n\
|
||||||
Series fixed: {}\n\
|
Series fixed: {}\n\
|
||||||
|
Books skipped (DRM): {}\n\
|
||||||
Books cleaned from DB: {}",
|
Books cleaned from DB: {}",
|
||||||
&stat.authors_fixed,
|
&stat.authors_fixed,
|
||||||
&stat.sorting_fixed,
|
&stat.sorting_fixed,
|
||||||
&stat.genres_fixed,
|
&stat.genres_fixed,
|
||||||
&stat.series_fixed,
|
&stat.series_fixed,
|
||||||
|
&stat.drm_skipped,
|
||||||
&stat.ghost_books_cleaned
|
&stat.ghost_books_cleaned
|
||||||
),
|
),
|
||||||
&["OK"],
|
&["OK"],
|
||||||
|
@ -55,11 +70,13 @@ fn main() {
|
||||||
Sorting fixed: {}\n\
|
Sorting fixed: {}\n\
|
||||||
Genres fixed: {}\n\
|
Genres fixed: {}\n\
|
||||||
Series fixed: {}\n\
|
Series fixed: {}\n\
|
||||||
|
Books skipped (DRM): {}\n\
|
||||||
Books cleaned from DB: {}",
|
Books cleaned from DB: {}",
|
||||||
&stat.authors_fixed,
|
&stat.authors_fixed,
|
||||||
&stat.sorting_fixed,
|
&stat.sorting_fixed,
|
||||||
&stat.genres_fixed,
|
&stat.genres_fixed,
|
||||||
&stat.series_fixed,
|
&stat.series_fixed,
|
||||||
|
&stat.drm_skipped,
|
||||||
&stat.ghost_books_cleaned
|
&stat.ghost_books_cleaned
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue