basic_usage/
basic_usage.rs1use epubie_lib::Epub;
2
3fn main() {
4 let epub_path = "./example-files/iia.epub";
6
7 println!("Attempting to parse EPUB: {}", epub_path);
8
9 match Epub::new(epub_path.to_string()) {
10 Ok(epub) => {
11 println!("\n=== EPUB Metadata ===");
13 println!("Title: {}", epub.get_title());
14 println!("Creator: {}", epub.get_creator());
15 println!("Language: {}", epub.get_language());
16 println!("Identifier: {}", epub.get_identifier());
17 println!("Date: {}", epub.get_date());
18
19 if let Some(publisher) = epub.get_publisher() {
20 println!("Publisher: {}", publisher);
21 }
22
23 if let Some(description) = epub.get_description() {
24 println!("Description: {}", description);
25 }
26
27 println!("\n=== Chapters ({}) ===", epub.get_chapter_count());
29 for (i, chapter) in epub.get_chapters().iter().enumerate() {
30 println!(
31 "Chapter {}: {} ({} file{})",
32 i + 1,
33 chapter.get_title(),
34 chapter.get_file_count(),
35 if chapter.get_file_count() == 1 {
36 ""
37 } else {
38 "s"
39 }
40 );
41
42 for (j, file) in chapter.get_files().iter().enumerate() {
44 println!(
45 " File {}: {} ({})",
46 j + 1,
47 file.get_title().unwrap_or("No title"),
48 file.get_href()
49 );
50
51 if file.is_html() {
53 println!(" [HTML file - {} bytes]", file.get_html_bytes().len());
54 }
55 }
56 }
57
58 let toc = epub.get_table_of_contents();
60 println!(
61 "\n=== Table of Contents ({} entries) ===",
62 toc.get_entry_count()
63 );
64 for (i, entry) in toc.get_entries().iter().enumerate() {
65 let indent = " ".repeat(entry.get_level() as usize);
66 println!(
67 "{}{}: {} ({})",
68 indent,
69 i + 1,
70 entry.get_title(),
71 entry.get_href()
72 );
73 }
74
75 println!("\n=== File Summary ===");
77 println!("Total files: {}", epub.get_file_count());
78 println!("All files:");
79 for (i, file) in epub.get_all_files().iter().enumerate() {
80 println!(
81 " {}: {} ({}) - {}",
82 i + 1,
83 file.get_title().unwrap_or("No title"),
84 file.get_href(),
85 file.get_media_type()
86 );
87 }
88 }
89 Err(e) => {
90 eprintln!("Error parsing EPUB: {}", e);
91 eprintln!("Make sure the file exists and is a valid EPUB file.");
92 }
93 }
94}