Class: Daisy::Book
- Inherits:
-
Object
- Object
- Daisy::Book
- Defined in:
- lib/daisy/book.rb
Overview
A whole book.
Instance Attribute Summary collapse
-
#chapters ⇒ Object
readonly
array of Chapter objects, one by input mp3 file.
-
#creator ⇒ Object
readonly
book author.
-
#identifier ⇒ Object
readonly
generated unique identifier.
-
#language ⇒ Object
readonly
book language.
-
#narrator ⇒ Object
readonly
book narrator.
-
#publisher ⇒ Object
readonly
book publisher.
-
#re_encode ⇒ Object
readonly
re-encode with lame?.
-
#rights ⇒ Object
readonly
book rights.
-
#source_dir ⇒ Object
readonly
directory for source mp3 files.
-
#source_edition ⇒ Object
readonly
book source edition.
-
#source_publisher ⇒ Object
readonly
book source publisher.
-
#target_dir ⇒ Object
readonly
directory where the DAISY files will be stored.
-
#title ⇒ Object
readonly
book title.
Instance Method Summary collapse
-
#create_daisy ⇒ Object
Create all the DAISY metadata for the book.
-
#initialize(source_dir, target_dir, re_encode: false) ⇒ Book
constructor
Creates a new Book: - input mp3 files are in
source_dir
- output mp3 files & daisy files will go totarget_dir
- ifre_encode
is true, each mp3 will be re-encoded using lame. -
#total_duration ⇒ Object
total book duration from chapter durations.
Constructor Details
#initialize(source_dir, target_dir, re_encode: false) ⇒ Book
Creates a new Book:
-
input mp3 files are in
source_dir
-
output mp3 files & daisy files will go to
target_dir
-
if
re_encode
is true, each mp3 will be re-encoded using lame
Raises an error if no mp3 file is found.
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/daisy/book.rb', line 56 def initialize(source_dir, target_dir, re_encode: false) @source_dir = source_dir @target_dir = target_dir @re_encode = re_encode @chapters = Dir["#{File.(source_dir)}/*.mp3"].map { |path| Chapter.new(self, path) } @chapters.empty? and raise Error, "no mp3 file in #{source_dir.inspect}" @chapters.sort_by!(&:file) @chapters.each.with_index(1) { |c, i| c.position = i } @identifier = SecureRandom.uuid read_book_info end |
Instance Attribute Details
#chapters ⇒ Object (readonly)
array of Chapter objects, one by input mp3 file
21 22 23 |
# File 'lib/daisy/book.rb', line 21 def chapters @chapters end |
#creator ⇒ Object (readonly)
book author
30 31 32 |
# File 'lib/daisy/book.rb', line 30 def creator @creator end |
#identifier ⇒ Object (readonly)
generated unique identifier
24 25 26 |
# File 'lib/daisy/book.rb', line 24 def identifier @identifier end |
#language ⇒ Object (readonly)
book language
36 37 38 |
# File 'lib/daisy/book.rb', line 36 def language @language end |
#narrator ⇒ Object (readonly)
book narrator
33 34 35 |
# File 'lib/daisy/book.rb', line 33 def narrator @narrator end |
#publisher ⇒ Object (readonly)
book publisher
39 40 41 |
# File 'lib/daisy/book.rb', line 39 def publisher @publisher end |
#re_encode ⇒ Object (readonly)
re-encode with lame?
18 19 20 |
# File 'lib/daisy/book.rb', line 18 def re_encode @re_encode end |
#rights ⇒ Object (readonly)
book rights
42 43 44 |
# File 'lib/daisy/book.rb', line 42 def rights @rights end |
#source_dir ⇒ Object (readonly)
directory for source mp3 files
12 13 14 |
# File 'lib/daisy/book.rb', line 12 def source_dir @source_dir end |
#source_edition ⇒ Object (readonly)
book source edition
48 49 50 |
# File 'lib/daisy/book.rb', line 48 def source_edition @source_edition end |
#source_publisher ⇒ Object (readonly)
book source publisher
45 46 47 |
# File 'lib/daisy/book.rb', line 45 def source_publisher @source_publisher end |
#target_dir ⇒ Object (readonly)
directory where the DAISY files will be stored
15 16 17 |
# File 'lib/daisy/book.rb', line 15 def target_dir @target_dir end |
#title ⇒ Object (readonly)
book title
27 28 29 |
# File 'lib/daisy/book.rb', line 27 def title @title end |
Instance Method Details
#create_daisy ⇒ Object
Create all the DAISY metadata for the book.
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/daisy/book.rb', line 132 def create_daisy puts "Creating DAISY format in #{target_dir}" puts "Title: #{title.inspect}" FileUtils.mkpath target_dir unless File.directory?(target_dir) write_ncc_html write_title_smil puts "Contents:" elapsed_time = 0.0 chapters.each do |c| puts "- #{c.position}. #{c.chapter_title}" c.copy_mp3 re_encode: re_encode c.write_smil elapsed_time elapsed_time += c.duration end write_master_smil end |
#total_duration ⇒ Object
total book duration from chapter durations
127 128 129 |
# File 'lib/daisy/book.rb', line 127 def total_duration chapters.map(&:duration).sum end |