Compare commits
No commits in common. "master" and "v0.9.0" have entirely different histories.
3 changed files with 37 additions and 32 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -396,7 +396,7 @@ checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pbdbfixer"
|
name = "pbdbfixer"
|
||||||
version = "0.9.0"
|
version = "0.8.3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"quick-xml",
|
"quick-xml",
|
||||||
"rusqlite",
|
"rusqlite",
|
||||||
|
|
|
@ -25,6 +25,8 @@ This program has been tested on a PocketBook
|
||||||
|
|
||||||
It might work with other PocketBook devices/software versions. Please tell me if it works for you (and do make a backup of the explorer-3.db file before trying!).
|
It might work with other PocketBook devices/software versions. Please tell me if it works for you (and do make a backup of the explorer-3.db file before trying!).
|
||||||
|
|
||||||
|
**Please note:** As I do not currently own a PocketBook device, I am unfortunately unable to react to changes in the database structure. Perhaps you can send me your `explorer-3.db` so that I can take a look at the changes. Just get in touch with me.
|
||||||
|
|
||||||
## Installation and Usage
|
## Installation and Usage
|
||||||
---
|
---
|
||||||
**WARNING**:
|
**WARNING**:
|
||||||
|
|
59
src/epub.rs
59
src/epub.rs
|
@ -1,4 +1,5 @@
|
||||||
use std::{
|
use std::{
|
||||||
|
borrow::Borrow,
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
fs::{self, File},
|
fs::{self, File},
|
||||||
io::Read,
|
io::Read,
|
||||||
|
@ -60,17 +61,18 @@ fn get_rootfile(archive: &mut ZipArchive<File>) -> String {
|
||||||
loop {
|
loop {
|
||||||
match reader.read_event_into(&mut buf) {
|
match reader.read_event_into(&mut buf) {
|
||||||
Ok(Event::Start(ref e)) | Ok(Event::Empty(ref e))
|
Ok(Event::Start(ref e)) | Ok(Event::Empty(ref e))
|
||||||
if e.name().as_ref() == b"rootfile" =>
|
if e.local_name().into_inner() == b"rootfile" =>
|
||||||
{
|
{
|
||||||
opf_filename = e
|
opf_filename = String::from_utf8(
|
||||||
.attributes()
|
e.attributes()
|
||||||
.filter(|attr| attr.as_ref().unwrap().key.as_ref() == b"full-path")
|
.filter(|attr| attr.as_ref().unwrap().key.into_inner() == b"full-path")
|
||||||
.next()
|
.next()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.unescape_value()
|
.value
|
||||||
.unwrap()
|
.to_vec(),
|
||||||
.to_string();
|
)
|
||||||
|
.unwrap();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Ok(Event::Eof) => break,
|
Ok(Event::Eof) => break,
|
||||||
|
@ -131,20 +133,20 @@ pub fn get_epub_metadata(filename: &str) -> Option<EpubMetadata> {
|
||||||
loop {
|
loop {
|
||||||
match reader.read_event_into(&mut buf) {
|
match reader.read_event_into(&mut buf) {
|
||||||
// See if we have EPUB3 or EPUB2
|
// See if we have EPUB3 or EPUB2
|
||||||
Ok(Event::Start(ref e)) if e.name().as_ref() == b"package" => {
|
Ok(Event::Start(ref e)) if e.local_name().into_inner() == b"package" => {
|
||||||
if e.attributes().any(|attr| {
|
if e.attributes().any(|attr| {
|
||||||
attr.as_ref().unwrap().key.as_ref() == b"version"
|
attr.as_ref().unwrap().key.into_inner() == b"version"
|
||||||
&& attr.as_ref().unwrap().value.starts_with(b"3")
|
&& attr.as_ref().unwrap().value.starts_with(b"3")
|
||||||
}) {
|
}) {
|
||||||
is_epub3 = true;
|
is_epub3 = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(Event::Start(ref e)) if e.local_name().as_ref() == b"creator" => {
|
Ok(Event::Start(ref e)) if e.local_name().into_inner() == b"creator" => {
|
||||||
creator_found = true;
|
creator_found = true;
|
||||||
if is_epub3 {
|
if is_epub3 {
|
||||||
if let Some(idval) = e
|
if let Some(idval) = e
|
||||||
.attributes()
|
.attributes()
|
||||||
.filter(|attr| attr.as_ref().unwrap().key.as_ref() == b"id")
|
.filter(|attr| attr.as_ref().unwrap().key.into_inner() == b"id")
|
||||||
.next()
|
.next()
|
||||||
{
|
{
|
||||||
curr_id = "#".to_string()
|
curr_id = "#".to_string()
|
||||||
|
@ -164,7 +166,7 @@ pub fn get_epub_metadata(filename: &str) -> Option<EpubMetadata> {
|
||||||
attr.as_ref()
|
attr.as_ref()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.key
|
.key
|
||||||
.as_ref()
|
.into_inner()
|
||||||
.ends_with(b"file-as")
|
.ends_with(b"file-as")
|
||||||
})
|
})
|
||||||
.next()
|
.next()
|
||||||
|
@ -173,13 +175,13 @@ pub fn get_epub_metadata(filename: &str) -> Option<EpubMetadata> {
|
||||||
let entry = xml_authors.entry(curr_id.clone()).or_insert(XmlAut::new());
|
let entry = xml_authors.entry(curr_id.clone()).or_insert(XmlAut::new());
|
||||||
entry.sort = file_as_val
|
entry.sort = file_as_val
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.unescape_value()
|
.decode_and_unescape_value(*reader.decoder().borrow())
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
.to_string();
|
.to_string();
|
||||||
entry.role = "aut".to_string();
|
entry.role = "aut".to_string();
|
||||||
} else if let Some(_role_val) = e
|
} else if let Some(_role_val) = e
|
||||||
.attributes()
|
.attributes()
|
||||||
.filter(|attr| attr.as_ref().unwrap().key.as_ref().ends_with(b"role"))
|
.filter(|attr| attr.as_ref().unwrap().key.into_inner().ends_with(b"role"))
|
||||||
.next()
|
.next()
|
||||||
{
|
{
|
||||||
curr_id = "none".to_string() + xml_authors.len().to_string().as_str();
|
curr_id = "none".to_string() + xml_authors.len().to_string().as_str();
|
||||||
|
@ -198,33 +200,33 @@ pub fn get_epub_metadata(filename: &str) -> Option<EpubMetadata> {
|
||||||
|
|
||||||
creator_found = false;
|
creator_found = false;
|
||||||
}
|
}
|
||||||
Ok(Event::Start(ref e)) if e.local_name().as_ref() == b"meta" && is_epub3 => {
|
Ok(Event::Start(ref e)) if e.local_name().into_inner() == b"meta" && is_epub3 => {
|
||||||
if let Some(refines) = e
|
if let Some(refines) = e
|
||||||
.attributes()
|
.attributes()
|
||||||
.filter(|attr| attr.as_ref().unwrap().key.as_ref() == b"refines")
|
.filter(|attr| attr.as_ref().unwrap().key.into_inner() == b"refines")
|
||||||
.next()
|
.next()
|
||||||
{
|
{
|
||||||
if e.attributes().any(|attr| {
|
if e.attributes().any(|attr| {
|
||||||
attr.as_ref().unwrap().key.as_ref() == b"property"
|
attr.as_ref().unwrap().key.into_inner() == b"property"
|
||||||
&& attr.as_ref().unwrap().value.ends_with(b"file-as")
|
&& attr.as_ref().unwrap().value.ends_with(b"file-as")
|
||||||
}) {
|
}) {
|
||||||
curr_id = String::from_utf8(refines.unwrap().value.to_vec()).unwrap();
|
curr_id = String::from_utf8(refines.unwrap().value.to_vec()).unwrap();
|
||||||
file_as_found = true;
|
file_as_found = true;
|
||||||
} else if e.attributes().any(|attr| {
|
} else if e.attributes().any(|attr| {
|
||||||
attr.as_ref().unwrap().key.as_ref() == b"property"
|
attr.as_ref().unwrap().key.into_inner() == b"property"
|
||||||
&& attr.as_ref().unwrap().value.ends_with(b"role")
|
&& attr.as_ref().unwrap().value.ends_with(b"role")
|
||||||
}) {
|
}) {
|
||||||
curr_id = String::from_utf8(refines.unwrap().value.to_vec()).unwrap();
|
curr_id = String::from_utf8(refines.unwrap().value.to_vec()).unwrap();
|
||||||
role_found = true;
|
role_found = true;
|
||||||
} else if e.attributes().any(|attr| {
|
} else if e.attributes().any(|attr| {
|
||||||
attr.as_ref().unwrap().key.as_ref() == b"property"
|
attr.as_ref().unwrap().key.into_inner() == b"property"
|
||||||
&& attr.as_ref().unwrap().value.ends_with(b"group-position")
|
&& attr.as_ref().unwrap().value.ends_with(b"group-position")
|
||||||
}) {
|
}) {
|
||||||
series_index_found = true;
|
series_index_found = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if e.attributes().any(|attr| {
|
if e.attributes().any(|attr| {
|
||||||
attr.as_ref().unwrap().key.as_ref() == b"property"
|
attr.as_ref().unwrap().key.into_inner() == b"property"
|
||||||
&& attr
|
&& attr
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -234,9 +236,9 @@ pub fn get_epub_metadata(filename: &str) -> Option<EpubMetadata> {
|
||||||
series_found = true;
|
series_found = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(Event::Empty(ref e)) if e.local_name().as_ref() == b"meta" && !is_epub3 => {
|
Ok(Event::Empty(ref e)) if e.local_name().into_inner() == b"meta" && !is_epub3 => {
|
||||||
if e.attributes().any(|attr| {
|
if e.attributes().any(|attr| {
|
||||||
attr.as_ref().unwrap().key.as_ref() == b"name"
|
attr.as_ref().unwrap().key.into_inner() == b"name"
|
||||||
&& attr
|
&& attr
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -246,15 +248,15 @@ pub fn get_epub_metadata(filename: &str) -> Option<EpubMetadata> {
|
||||||
}) {
|
}) {
|
||||||
epub_meta.series.name = e
|
epub_meta.series.name = e
|
||||||
.attributes()
|
.attributes()
|
||||||
.filter(|attr| attr.as_ref().unwrap().key.as_ref() == b"content")
|
.filter(|attr| attr.as_ref().unwrap().key.into_inner() == b"content")
|
||||||
.next()
|
.next()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.unescape_value()
|
.decode_and_unescape_value(*reader.decoder().borrow())
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
.to_string();
|
.to_string();
|
||||||
} else if e.attributes().any(|attr| {
|
} else if e.attributes().any(|attr| {
|
||||||
attr.as_ref().unwrap().key.as_ref() == b"name"
|
attr.as_ref().unwrap().key.into_inner() == b"name"
|
||||||
&& attr
|
&& attr
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -264,11 +266,11 @@ pub fn get_epub_metadata(filename: &str) -> Option<EpubMetadata> {
|
||||||
}) {
|
}) {
|
||||||
let index_float = e
|
let index_float = e
|
||||||
.attributes()
|
.attributes()
|
||||||
.filter(|attr| attr.as_ref().unwrap().key.as_ref() == b"content")
|
.filter(|attr| attr.as_ref().unwrap().key.into_inner() == b"content")
|
||||||
.next()
|
.next()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.unescape_value()
|
.decode_and_unescape_value(*reader.decoder().borrow())
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
.parse::<f32>()
|
.parse::<f32>()
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
@ -300,10 +302,11 @@ pub fn get_epub_metadata(filename: &str) -> Option<EpubMetadata> {
|
||||||
|
|
||||||
series_index_found = false;
|
series_index_found = false;
|
||||||
}
|
}
|
||||||
Ok(Event::Start(ref e)) if e.local_name().as_ref() == b"subject" => {
|
Ok(Event::Start(ref e)) if e.local_name().into_inner() == b"subject" => {
|
||||||
genre_found = true;
|
genre_found = true;
|
||||||
}
|
}
|
||||||
Ok(Event::Text(ref e)) if genre_found => {
|
Ok(Event::Text(ref e)) if genre_found => {
|
||||||
|
//epub_meta.genre = e.unescape_and_decode(&reader).unwrap();
|
||||||
epub_meta.genre = e.unescape().unwrap().to_string();
|
epub_meta.genre = e.unescape().unwrap().to_string();
|
||||||
genre_found = false;
|
genre_found = false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue