Module: MultimediaParadise::EmbeddableInterface
- Defined in:
- lib/multimedia_paradise/sinatra/embeddable_interface.rb
Overview
MultimediaParadise::EmbeddableInterface
Constant Summary collapse
- TITLE =
#
TITLE
#
'MultimediaParadise Web-API'
- TITLE_TAG =
#
TITLE_TAG
#
'<title>'+TITLE+'</title>'
- USE_THIS_PORT =
#
USE_THIS_PORT
#
'5580'
- USE_THIS_ENCODING =
#
USE_THIS_ENCODING
#
MultimediaParadise::USE_THIS_ENCODING
- BASE_DIR_TO_THE_REALVIDS =
#
BASE_DIR_TO_THE_REALVIDS
#
'/home/x/video/Realvids/'
Class Method Summary collapse
-
.route_name? ⇒ Boolean
# === MultimediaParadise::EmbeddableInterface.route_name? ========================================================================= #.
-
.set_route_name(i) ⇒ Object
# === MultimediaParadise::EmbeddableInterface.set_route_name ========================================================================= #.
-
.sub_routes? ⇒ Boolean
# === MultimediaParadise::EmbeddableInterface.sub_routes?.
Instance Method Summary collapse
-
#html_and_body_start ⇒ Object
# === html_and_body_start ========================================================================= #.
-
#return_available_actions ⇒ Object
# === return_available_actions (main index).
-
#return_available_simpsons_files(simpsons_files = Dir['/home/x/video/Cartoons/Simpsons**/**']) ⇒ Object
# === return_available_simpsons_files ========================================================================= #.
-
#return_available_video_files(i = MultimediaParadise.available_video_files) ⇒ Object
# === return_available_video_files ========================================================================= #.
-
#return_html_head_and_title_and_body ⇒ Object
# === return_html_head_and_title_and_body ========================================================================= #.
-
#return_listing ⇒ Object
# === return_listing.
-
#return_main_index ⇒ Object
# === return_main_index (main index) ========================================================================= #.
-
#return_n_local_videos ⇒ Object
# === return_n_local_videos.
-
#return_play_splat ⇒ Object
# === return_play_splat ========================================================================= #.
-
#return_random_video ⇒ Object
# === return_random_video ========================================================================= #.
-
#return_root_string ⇒ Object
# === return_root_string ========================================================================= #.
-
#return_to_root_link ⇒ Object
# === return_to_root_link ========================================================================= #.
-
#return_view ⇒ Object
# === return_view ========================================================================= #.
-
#route_name? ⇒ Boolean
# === route_name? ========================================================================= #.
-
#sub_routes? ⇒ Boolean
# === sub_routes? ========================================================================= #.
-
#title? ⇒ Boolean
# === title? ========================================================================= #.
Class Method Details
.route_name? ⇒ Boolean
#
MultimediaParadise::EmbeddableInterface.route_name?
#
73 74 75 |
# File 'lib/multimedia_paradise/sinatra/embeddable_interface.rb', line 73 def self.route_name? @route_name end |
.set_route_name(i) ⇒ Object
#
MultimediaParadise::EmbeddableInterface.set_route_name
#
66 67 68 |
# File 'lib/multimedia_paradise/sinatra/embeddable_interface.rb', line 66 def self.set_route_name(i) @route_name = i end |
.sub_routes? ⇒ Boolean
#
MultimediaParadise::EmbeddableInterface.sub_routes?
Define all sub-routes here.
#
177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/multimedia_paradise/sinatra/embeddable_interface.rb', line 177 def self.sub_routes? { view: route_name?+'/view', n_local_videos: route_name?+'/n_local_videos', available_video_files: route_name?+'/available_video_files', available_simpsons_files: route_name?+'/available_simpsons_files', listing: route_name?+'/listing', play: route_name?+'/play', random_video: route_name?+'/random_video' } end |
Instance Method Details
#html_and_body_start ⇒ Object
#
html_and_body_start
#
208 209 210 211 |
# File 'lib/multimedia_paradise/sinatra/embeddable_interface.rb', line 208 def html_and_body_start '<html>'+TITLE_TAG+ '<body style="font-size: 1.3em">' end |
#return_available_actions ⇒ Object
#
return_available_actions (main index)
This method provides an overview, as HTML string, over the available actions.
#
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 |
# File 'lib/multimedia_paradise/sinatra/embeddable_interface.rb', line 285 def return_available_actions hash = MultimediaParadise::EmbeddableInterface.sub_routes? html_and_body_start+ p( 'The following entry points are available so far:' )+ p(css_style: 'padding:10px; margin-left: 2em') { abr(hash[:view], content: '/view', css_style: :bold)+ # /view abr(hash[:n_local_videos], content: '/n_local_videos', css_style: :bold)+ # /n_local_videos abr(hash[:available_video_files], content: '/available_video_files', css_style: :bold)+ # /available_video_files abr(hash[:available_simpsons_files], content: '/available_simpsons_files', css_style: :bold)+ # /available_simpsons_files abr(hash[:listing], content: '/listing', css_style: :bold)+ # /listing abr(hash[:play], content: '/play', css_style: :bold)+ # /play abr(hash[:random_video], content: '/random_video', css_style: :bold) # /random_video } end |
#return_available_simpsons_files(simpsons_files = Dir['/home/x/video/Cartoons/Simpsons**/**']) ⇒ Object
#
return_available_simpsons_files
#
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/multimedia_paradise/sinatra/embeddable_interface.rb', line 143 def return_available_simpsons_files( simpsons_files = Dir['/home/x/video/Cartoons/Simpsons**/**'] ) result = ''.dup result << html_and_body_start result << p('The following simpsons files are available locally:') result << '<div style="padding: 0.7em">' simpsons_files.each.each {|entry| _ = entry = '<a href="'+_.to_s+'">'+entry+'</a>' result << "<b style=\"margin-left:3em\">#{}</b> "\ " ("+ "<a href=\"#{File.basename(entry)}\">Play local file here)</a>"+ "<br>\n" } result << '</div>' result << 'The current public directory is: '+ MultimediaParadise::Sinatra.simpsons_directory?.to_s result << return_to_root_link result end |
#return_available_video_files(i = MultimediaParadise.available_video_files) ⇒ Object
#
return_available_video_files
#
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 |
# File 'lib/multimedia_paradise/sinatra/embeddable_interface.rb', line 247 def return_available_video_files( i = MultimediaParadise.available_video_files ) dataset = YAML.load_file(MultimediaParadise.file_video_collection) # ======================================================================= # # The 'imdb' entry is relevant here, such as: # "imdb"=>"https://www.imdb.com/title/tt0074285/" # As key we need the number. # ======================================================================= # result = ''.dup result << html_and_body_start result << p('The following video files are available locally:') result << '<div style="padding: 0.7em">' i.each {|entry| # ===================================================================== # # duration = MultimediaParadise.duration_of?(entry) # ===================================================================== # number = File.basename(entry)[0,4].to_i # Must be an integer. if dataset[number] _ = dataset[number]['imdb'] = '<a href="'+_.to_s+'">'+entry+'</a>' result << "<b style=\"margin-left:3em\">#{}</b> "\ " ("+ "<a href=\"/#{File.basename(entry)}\">Play local file here)</a>"+ "<br>\n" end } result << '</div>' result << return_to_root_link result end |
#return_html_head_and_title_and_body ⇒ Object
#
return_html_head_and_title_and_body
#
168 169 170 |
# File 'lib/multimedia_paradise/sinatra/embeddable_interface.rb', line 168 def return_html_head_and_title_and_body '<html><head>'+TITLE_TAG+'</head><body>' end |
#return_listing ⇒ Object
#
return_listing
This is accessible via:
http://localhost:5580/listing
#
310 311 312 313 314 315 316 317 318 319 320 321 322 |
# File 'lib/multimedia_paradise/sinatra/embeddable_interface.rb', line 310 def return_listing result = ''.dup result << html_and_body_start result << p('The following video files are available locally:') result << '<div style="font-size: 0.8em; padding: 0.1em">' MultimediaParadise.available_video_files.each {|entry| result << "<b style=\"margin-left:1em\">#{File.basename(entry)}</b> "\ "<br>" } result << '</div>' result << return_to_root_link result end |
#return_main_index ⇒ Object
#
return_main_index (main index)
#
223 224 225 226 227 228 229 230 |
# File 'lib/multimedia_paradise/sinatra/embeddable_interface.rb', line 223 def return_main_index '<html>'+TITLE_TAG+ '<body style="font-size: larger">This is the <b>www-interface</b> '\ 'for the sinatra interface of the <b>MultimediaParadise</b> project. '\ 'The encoding that will be used is: <b>'+USE_THIS_ENCODING.to_s+'</b>'+ return_available_actions+ '<body></html>' end |
#return_n_local_videos ⇒ Object
#
return_n_local_videos
This method will show how many local videos are available.
#
237 238 239 240 241 242 |
# File 'lib/multimedia_paradise/sinatra/embeddable_interface.rb', line 237 def return_n_local_videos html_and_body_start+ p('There are <b>'+MultimediaParadise.n_local_videos?.to_s+ '</b> local videos available.')+ return_to_root_link end |
#return_play_splat ⇒ Object
#
return_play_splat
#
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 |
# File 'lib/multimedia_paradise/sinatra/embeddable_interface.rb', line 327 def return_play_splat _ = params[:splat] _ = _.first if _.is_a? Array result = ''.dup if _.nil? # ===================================================================== # # In this case the user did not supply any argument, e. g. no video # file to play. # ===================================================================== # result << p('This API lets you play video files (if they are available locally).') result << p('Simply pass the name of the video file to the URL.') else result << p("The following video files are available locally:\n") unless File.exist?(_) target = BASE_DIR_TO_THE_REALVIDS+_+'*' globbed = Dir[target] unless globbed.empty? globbed = globbed.sort_by {|entry| entry[0,1] }.reverse # This will sort .mp4 before .avi. _ = globbed.first.to_s end end relative_target = '../' * (_.count('/')+1) result << '<div class="darkblue" style="font-size: 0.8em; padding: 0.1em">' result << '<video controls width="1024" autoplay><source src="'+relative_target+File.basename(_)+'"></video>' # result << '<video controls autoplay><source src="'+ # BASE_DIR_TO_THE_REALVIDS+ # File.basename(_)+'"></video>' result << '</div>' end result << return_to_root_link Cyberweb::HtmlTemplate[ title: title?, body: result, body_css_style: 'font-size: 1.2em;', css_classes: 'darkblue' ].to_s end |
#return_random_video ⇒ Object
#
return_random_video
#
192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/multimedia_paradise/sinatra/embeddable_interface.rb', line 192 def return_random_video this_video = Dir[BASE_DIR_TO_THE_REALVIDS+'*'].sample abr( '/'+File.basename(this_video), content: this_video )+ br+ abr( '/', content: 'Back to the main index' ) end |
#return_root_string ⇒ Object
#
return_root_string
#
94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/multimedia_paradise/sinatra/embeddable_interface.rb', line 94 def return_root_string _ = ''.dup MultimediaParadise::EmbeddableInterface.sub_routes?.each_pair {|key, value| _ << abr(value) } html { '<title>Multimedia Paradise Embeddable Interface</title>'+ '<body>'+ p(_,'','', 'font-size: 1.6em' )+'</body>' } end |
#return_to_root_link ⇒ Object
#
return_to_root_link
#
134 135 136 137 138 |
# File 'lib/multimedia_paradise/sinatra/embeddable_interface.rb', line 134 def return_to_root_link p { a('/', content: 'Home') } end |
#return_view ⇒ Object
#
return_view
#
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/multimedia_paradise/sinatra/embeddable_interface.rb', line 111 def return_view route_to_this_action = sub_routes?[:view] result = html_and_body_start+ p('View the following package:') result = result.dup if result.frozen? result << div(css_style: 'padding: 0.2em') { p( '<b>Search for a local video file:</b>', css_style: 'padding:0.75em' )+ '<form id="view" style="margin-left:2em; margin-top:2px" action="'+route_to_this_action+'"> <input type="text" name="user_input" style="border:3px solid slateblue; padding: 4px"><br> <input type="submit" name="user_input_submit" value="Display" style="2px dotted royalblue; '\ 'color: white; background-color: olive; font-size: 1.40em; margin:2px; padding: 4px"> </form>'+ return_to_root_link } result end |
#route_name? ⇒ Boolean
#
route_name?
#
80 81 82 |
# File 'lib/multimedia_paradise/sinatra/embeddable_interface.rb', line 80 def route_name? ::MultimediaParadise::EmbeddableInterface.route_name? end |
#sub_routes? ⇒ Boolean
#
sub_routes?
#
87 88 89 |
# File 'lib/multimedia_paradise/sinatra/embeddable_interface.rb', line 87 def sub_routes? ::MultimediaParadise::EmbeddableInterface.sub_routes? end |
#title? ⇒ Boolean
#
title?
#
216 217 218 |
# File 'lib/multimedia_paradise/sinatra/embeddable_interface.rb', line 216 def title? TITLE end |