Class: Abrizer::Canvas
Overview
Creates a IIIF Canvas JSON-LD document.
Instance Method Summary
collapse
#audio_filepath, #audio_filepath_fragmented, #basename, #canvas_filepath, #canvas_partial_filepath, #filename_directory, #first_image_filepath, #hlsts_filepath, #hlsts_partial_filepath, #mp4_filepath, #mp4_partial_filepath, #mpd_filepath, #mpd_partial_filepath, #output_directory, #output_directory_basename, #poster_image_filepath, #poster_partial_filepath, #sprites_filepath, #sprites_partial_filepath, #vp9_filepath, #vp9_partial_filepath, #webvtt_input_filepath
Constructor Details
#initialize(filepath, output_directory, base_url) ⇒ Canvas
TODO: allow control of items/versions listed on canvas
8
9
10
11
12
13
14
|
# File 'lib/abrizer/canvas.rb', line 8
def initialize(filepath, output_directory, base_url)
@filename = filepath
@output_directory = output_directory
@base_url = base_url
finder = AdaptationFinder.new(@filename)
@adaptations = finder.adaptations
end
|
Instance Method Details
#canvas_id ⇒ Object
149
150
151
|
# File 'lib/abrizer/canvas.rb', line 149
def canvas_id
File.join media_base_url, canvas_partial_filepath
end
|
#captions_seealso(json) ⇒ Object
120
121
122
123
124
125
126
127
128
129
130
131
132
|
# File 'lib/abrizer/canvas.rb', line 120
def captions_seealso(json)
captions_file = File.join output_directory, 'vtt/captions.vtt'
if File.exist? captions_file
json.child! do
json.id vtt_id
json.format 'application/webvtt'
json.label 'English captions'
json.language 'en'
json. "How make explicit how whether to use these as captions or subtitles?"
end
end
end
|
#create ⇒ Object
16
17
18
19
20
|
# File 'lib/abrizer/canvas.rb', line 16
def create
File.open(canvas_filepath, 'w') do |fh|
fh.puts create_json
end
end
|
#create_json ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/abrizer/canvas.rb', line 22
def create_json
Jbuilder.encode do |json|
json.set! '@context', 'http://iiif.io/api/presentation/3/context.json'
json.id canvas_id
json.type "Canvas"
json.width max_width
json.height max_height
json.duration duration
thumbnail_json(json)
media_json(json)
end
end
|
#duration ⇒ Object
181
182
183
184
|
# File 'lib/abrizer/canvas.rb', line 181
def duration
informer = Abrizer::FfprobeInformer.new(mp4_filename)
informer.duration.to_f
end
|
#hlsts_id ⇒ Object
161
162
163
|
# File 'lib/abrizer/canvas.rb', line 161
def hlsts_id
File.join media_base_url, hlsts_partial_filepath
end
|
#hlsts_item(json) ⇒ Object
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/abrizer/canvas.rb', line 81
def hlsts_item(json)
if File.exist? hlsts_filepath
json.child! do
json.id hlsts_id
json.type "Video"
json.format "application/x-mpegURL"
json.width max_width
json.height max_height
end
end
end
|
#max_height ⇒ Object
194
195
196
|
# File 'lib/abrizer/canvas.rb', line 194
def max_height
@adaptations.last.height
end
|
#max_width ⇒ Object
186
187
188
|
# File 'lib/abrizer/canvas.rb', line 186
def max_width
@adaptations.last.width
end
|
145
146
147
|
# File 'lib/abrizer/canvas.rb', line 145
def media_base_url
File.join @base_url, output_directory_basename
end
|
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/abrizer/canvas.rb', line 45
def media_json(json)
json.media do
json.child! do
json.type "Annotation"
json.motivation 'painting'
json.target canvas_id
json.body do
json.type "Choice"
json.items do
mpd_item(json)
hlsts_item(json)
vp9_item(json)
mp4_item(json)
end
json.seeAlso do
captions_seealso(json)
sprites_seealso(json)
end
end
end
end
end
|
#min_height ⇒ Object
198
199
200
|
# File 'lib/abrizer/canvas.rb', line 198
def min_height
@adaptations.first.height
end
|
#min_width ⇒ Object
190
191
192
|
# File 'lib/abrizer/canvas.rb', line 190
def min_width
@adaptations.first.width
end
|
#mp4_filename ⇒ Object
TODO: DRY up with progressive_mp4.rb
211
212
213
|
# File 'lib/abrizer/canvas.rb', line 211
def mp4_filename
File.join output_directory, "progressive.mp4"
end
|
#mp4_height ⇒ Object
206
207
208
|
# File 'lib/abrizer/canvas.rb', line 206
def mp4_height
@adaptations[-2].height
end
|
#mp4_id ⇒ Object
165
166
167
|
# File 'lib/abrizer/canvas.rb', line 165
def mp4_id
File.join media_base_url, mp4_partial_filepath
end
|
#mp4_item(json) ⇒ Object
107
108
109
110
111
112
113
114
115
116
117
118
|
# File 'lib/abrizer/canvas.rb', line 107
def mp4_item(json)
if File.exist? mp4_filepath
json.child! do
json.id mp4_id
json.type "Video"
json.format "video/mp4"
json.width mp4_width
json.height mp4_height
end
end
end
|
#mp4_width ⇒ Object
202
203
204
|
# File 'lib/abrizer/canvas.rb', line 202
def mp4_width
@adaptations[-2].width
end
|
#mpd_id ⇒ Object
157
158
159
|
# File 'lib/abrizer/canvas.rb', line 157
def mpd_id
File.join media_base_url, mpd_partial_filepath
end
|
#mpd_item(json) ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/abrizer/canvas.rb', line 69
def mpd_item(json)
if File.exist? mpd_filepath
json.child! do
json.id mpd_id
json.type "Video"
json.format "application/dash+xml"
json.width max_width
json.height max_height
end
end
end
|
#poster_id ⇒ Object
153
154
155
|
# File 'lib/abrizer/canvas.rb', line 153
def poster_id
File.join media_base_url, poster_partial_filepath
end
|
#sprites_id ⇒ Object
177
178
179
|
# File 'lib/abrizer/canvas.rb', line 177
def sprites_id
File.join media_base_url, sprites_partial_filepath
end
|
#sprites_seealso(json) ⇒ Object
134
135
136
137
138
139
140
141
142
143
|
# File 'lib/abrizer/canvas.rb', line 134
def sprites_seealso(json)
if File.exist? sprites_filepath
json.child! do
json.id sprites_id
json.format 'application/webvtt'
json.label 'image sprite metadata'
json. "How to include resources like video image sprites like those created by https://github.com/jronallo/video_sprites and used by various players?"
end
end
end
|
#thumbnail_json(json) ⇒ Object
35
36
37
38
39
40
41
42
43
|
# File 'lib/abrizer/canvas.rb', line 35
def thumbnail_json(json)
if File.exist? poster_image_filepath
json.thumbnail do
json.id poster_id
json.type 'Image'
json.format 'image/jpeg'
end
end
end
|
#vp9_id ⇒ Object
169
170
171
|
# File 'lib/abrizer/canvas.rb', line 169
def vp9_id
File.join media_base_url, vp9_partial_filepath
end
|
#vp9_item(json) ⇒ Object
94
95
96
97
98
99
100
101
102
103
104
105
|
# File 'lib/abrizer/canvas.rb', line 94
def vp9_item(json)
if File.exist? vp9_filepath
json.child! do
json.id vp9_id
json.type "Video"
json.format "video/webm"
json.width max_width
json.height max_height
end
end
end
|
#vtt_id ⇒ Object
173
174
175
|
# File 'lib/abrizer/canvas.rb', line 173
def vtt_id
File.join media_base_url, 'vtt/captions.vtt'
end
|