Class: Abrizer::Canvas

Inherits:
Object
  • Object
show all
Includes:
FilepathHelpers, IdentifierHelpers, InformationHelpers, ReadAdaptations
Defined in:
lib/abrizer/canvas.rb

Overview

Creates a IIIF Canvas JSON-LD document.

Instance Method Summary collapse

Methods included from ReadAdaptations

#find_adaptations, #read_adaptations

Methods included from InformationHelpers

#duration, #max_height, #max_width, #min_height, #min_width, #mp4_height, #mp4_width

Methods included from IdentifierHelpers

#canvas_id, #data_id, #hlsts_aac_id, #hlsts_id, #media_base_url, #mp3_id, #mp4_id, #mpd_id, #poster_id, #sprites_id, #vp9_id, #vtt_id

Methods included from FilepathHelpers

#adaptations_filepath, #all_media_paths, #audio_filepath, #audio_filepath_fragmented, #basename, #canvas_filepath, #canvas_partial_filepath, #captions_filepath, #data_filepath, #data_partial_filepath, #ffprobe_filepath, #filename_directory, #first_image_filepath, #hlsts_aac_filepath, #hlsts_aac_partial_filepath, #hlsts_filepath, #hlsts_partial_filepath, #mp3_filepath, #mp3_partial_filepath, #mp4_filepath, #mp4_partial_filepath, #mpd_filepath, #mpd_partial_filepath, #output_directory, #output_directory_basename, #poster_filepath, #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



11
12
13
14
15
16
17
# File 'lib/abrizer/canvas.rb', line 11

def initialize(filepath, output_directory, base_url)
  @filepath = filepath
  @output_directory = output_directory
  FileUtils.mkdir_p output_directory unless File.exist? output_directory
  @base_url = base_url
  read_adaptations
end

Instance Method Details

#aac_item(json) ⇒ Object



141
142
143
144
145
146
147
148
149
# File 'lib/abrizer/canvas.rb', line 141

def aac_item(json)
  if File.exist? hlsts_aac_filepath
    json.child! do
      json.id hlsts_aac_id
      json.type "Audio"
      json.format 'audio/aac'
    end
  end
end

#captions_item(json) ⇒ Object



151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/abrizer/canvas.rb', line 151

def captions_item(json)
  # TODO: update captions for multiple captions
  if File.exist? captions_filepath
    json.child! do
      json.id vtt_id
      json.type 'Text'
      json.format 'text/vtt'
      json.kind 'captions'
      json.label 'English captions'
      json.language 'en'
      json._comments "How make explicit how whether to use these as captions or subtitles, descriptions, or chapters?"
    end
  end
end

#createObject



19
20
21
22
23
# File 'lib/abrizer/canvas.rb', line 19

def create
  File.open(canvas_filepath, 'w') do |fh|
    fh.puts create_json
  end
end

#create_jsonObject



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/abrizer/canvas.rb', line 25

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) if media_content?
  end
end

#hlsts_item(json) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/abrizer/canvas.rb', line 102

def hlsts_item(json)
  if File.exist? hlsts_filepath
    json.child! do
      json.id hlsts_id
      json.type "Video"
      # TODO: or "vnd.apple.mpegURL"
      json.format "application/x-mpegURL"
      json.width max_width
      json.height max_height
    end
  end
end

#media_content?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/abrizer/canvas.rb', line 48

def media_content?
  all_media_paths.any? { |f| File.exist? f }
end

#media_json(json) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/abrizer/canvas.rb', line 52

def media_json(json)
  json.content do
    json.child! do
      json.type "AnnotationPage"

      json.items do
        json.child! do
          json.type 'Annotation'
          json.motivation 'painting'
          json.target canvas_id
          json.body do
            json.child! do
              json.type "Choice"
              json.choiceHint 'client'
              json.items do
                mpd_item(json)
                hlsts_item(json)
                vp9_item(json)
                mp4_item(json)
                aac_item(json)
              end
            end
            json.child! do
              json.type 'Choice'
              json.choiceHint 'client'
              json.items do
                captions_item(json)
              end
            end
          end
        end
        sprites_item(json)
      end

    end
  end
end

#mp4_item(json) ⇒ Object



128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/abrizer/canvas.rb', line 128

def mp4_item(json)
  if File.exist? mp4_filepath
    json.child! do
      json.id mp4_id
      json.type "Video"
      #TODO: add mp4 codecs
      json.format "video/mp4"
      json.width mp4_width
      json.height mp4_height
    end
  end
end

#mpd_item(json) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
# File 'lib/abrizer/canvas.rb', line 90

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

#sprites_item(json) ⇒ Object



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/abrizer/canvas.rb', line 166

def sprites_item(json)
  if File.exist? sprites_filepath
    json.child! do
      json.type 'Annotation'
      json.motivation 'video-thumbnails'
      json.target canvas_id
      json.body do
        json.child! do
          json.id sprites_id
          json.type 'Text'
          json.format 'text/vtt'
          json.kind 'metadata'
          json.label 'image sprite metadata'
          json._comments "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
  end
end

#thumbnail_json(json) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/abrizer/canvas.rb', line 38

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_item(json) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/abrizer/canvas.rb', line 115

def vp9_item(json)
  if File.exist? vp9_filepath
    json.child! do
      json.id vp9_id
      json.type "Video"
      #TODO: add webm codecs
      json.format "video/webm"
      json.width max_width
      json.height max_height
    end
  end
end