Handle multiple authors in epub3.
This commit is contained in:
parent
049cd06b65
commit
bc2d4730f0
1 changed files with 25 additions and 6 deletions
31
src/main.rs
31
src/main.rs
|
@ -38,8 +38,9 @@ fn get_attribute_file_as(opf: ZipFile) -> Option<String> {
|
||||||
.create_reader(opf);
|
.create_reader(opf);
|
||||||
|
|
||||||
let mut refines_found = false;
|
let mut refines_found = false;
|
||||||
|
let mut refines_entries = Vec::new();
|
||||||
let mut is_epub3 = false;
|
let mut is_epub3 = false;
|
||||||
let mut creator_id = String::new();
|
let mut creator_ids = Vec::new();
|
||||||
|
|
||||||
for e in parser {
|
for e in parser {
|
||||||
match e {
|
match e {
|
||||||
|
@ -63,7 +64,7 @@ fn get_attribute_file_as(opf: ZipFile) -> Option<String> {
|
||||||
return Some(attr.value);
|
return Some(attr.value);
|
||||||
}
|
}
|
||||||
if is_epub3 && attr.name.local_name == "id" {
|
if is_epub3 && attr.name.local_name == "id" {
|
||||||
creator_id = attr.value;
|
creator_ids.push("#".to_owned() + attr.value.as_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,9 +72,7 @@ fn get_attribute_file_as(opf: ZipFile) -> Option<String> {
|
||||||
name, attributes, ..
|
name, attributes, ..
|
||||||
}) if name.local_name == "meta" => {
|
}) if name.local_name == "meta" => {
|
||||||
if attributes.iter().any(|attr| {
|
if attributes.iter().any(|attr| {
|
||||||
attr.name.local_name == "refines"
|
attr.name.local_name == "refines" && creator_ids.contains(&attr.value)
|
||||||
&& (attr.value == creator_id
|
|
||||||
|| attr.value == "#".to_owned() + creator_id.as_str())
|
|
||||||
}) && attributes
|
}) && attributes
|
||||||
.iter()
|
.iter()
|
||||||
.any(|attr| attr.name.local_name == "property" && attr.value == "file-as")
|
.any(|attr| attr.name.local_name == "property" && attr.value == "file-as")
|
||||||
|
@ -83,7 +82,8 @@ fn get_attribute_file_as(opf: ZipFile) -> Option<String> {
|
||||||
}
|
}
|
||||||
Ok(XmlEvent::Characters(value)) => {
|
Ok(XmlEvent::Characters(value)) => {
|
||||||
if refines_found == true {
|
if refines_found == true {
|
||||||
return Some(value);
|
refines_entries.push(value);
|
||||||
|
refines_found = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(XmlEvent::StartElement { .. }) => {
|
Ok(XmlEvent::StartElement { .. }) => {
|
||||||
|
@ -98,6 +98,12 @@ fn get_attribute_file_as(opf: ZipFile) -> Option<String> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if refines_entries.len() == 1 {
|
||||||
|
return Some(refines_entries.remove(0));
|
||||||
|
} else if refines_entries.len() >= 2 {
|
||||||
|
return Some(refines_entries.join(" & "));
|
||||||
|
}
|
||||||
|
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,6 +118,8 @@ fn main() {
|
||||||
let mut conn = Connection::open("/mnt/ext1/system/explorer-3/explorer-3.db").unwrap();
|
let mut conn = Connection::open("/mnt/ext1/system/explorer-3/explorer-3.db").unwrap();
|
||||||
let tx = conn.transaction().unwrap();
|
let tx = conn.transaction().unwrap();
|
||||||
{
|
{
|
||||||
|
// Get book ids from entries where we have something like "firstname lastname" in author
|
||||||
|
// but no "lastname, firstname" in fistauthor
|
||||||
let mut stmt = tx.prepare("SELECT id FROM books_impl WHERE ext LIKE 'epub' AND author LIKE '% %' AND (firstauthor NOT LIKE '%\\,%' ESCAPE '\\' OR firstauthor LIKE '%&%')").unwrap();
|
let mut stmt = tx.prepare("SELECT id FROM books_impl WHERE ext LIKE 'epub' AND author LIKE '% %' AND (firstauthor NOT LIKE '%\\,%' ESCAPE '\\' OR firstauthor LIKE '%&%')").unwrap();
|
||||||
let mut rows = stmt.query(NO_PARAMS).unwrap();
|
let mut rows = stmt.query(NO_PARAMS).unwrap();
|
||||||
let mut book_ids: Vec<i32> = Vec::new();
|
let mut book_ids: Vec<i32> = Vec::new();
|
||||||
|
@ -119,6 +127,17 @@ fn main() {
|
||||||
book_ids.push(row.get(0).unwrap());
|
book_ids.push(row.get(0).unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get also book ids from the special case where we have multiple authors (separated by ", " in authors)
|
||||||
|
// but no ampersand ("&") in firstauthor
|
||||||
|
let mut stmt = tx.prepare("SELECT id FROM books_impl WHERE ext LIKE 'epub' AND author LIKE '%\\, %' ESCAPE '\\' AND firstauthor NOT LIKE '%&%'").unwrap();
|
||||||
|
let mut rows = stmt.query(NO_PARAMS).unwrap();
|
||||||
|
while let Some(row) = rows.next().unwrap() {
|
||||||
|
book_ids.push(row.get(0).unwrap());
|
||||||
|
}
|
||||||
|
|
||||||
|
book_ids.sort();
|
||||||
|
book_ids.dedup();
|
||||||
|
|
||||||
let mut bookentries = Vec::new();
|
let mut bookentries = Vec::new();
|
||||||
|
|
||||||
for book_id in book_ids {
|
for book_id in book_ids {
|
||||||
|
|
Loading…
Reference in a new issue