module MultimediaParadise::EmbeddableInterface

Constants

BASE_DIR_TO_THE_REALVIDS
#

BASE_DIR_TO_THE_REALVIDS

#
TITLE
#

TITLE

#
TITLE_TAG
#

TITLE_TAG

#
USE_THIS_ENCODING
#

USE_THIS_ENCODING

#
USE_THIS_PORT
#

USE_THIS_PORT

#

Public Class Methods

route_name?() click to toggle source
#

MultimediaParadise::EmbeddableInterface.route_name?

#
# File lib/multimedia_paradise/sinatra/embeddable_interface.rb, line 73
def self.route_name?
  @route_name
end
set_route_name(i) click to toggle source
#

MultimediaParadise::EmbeddableInterface.set_route_name

#
# File lib/multimedia_paradise/sinatra/embeddable_interface.rb, line 66
def self.set_route_name(i)
  @route_name = i
end
sub_routes?() click to toggle source
#

MultimediaParadise::EmbeddableInterface.sub_routes?

Define all sub-routes here.

#
# 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

Public Instance Methods

html_and_body_start() click to toggle source
#

html_and_body_start

#
# 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() click to toggle source
#

return_available_actions (main index)

This method provides an overview, as HTML string, over the available actions.

#
# 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**/**'] ) click to toggle source
#

return_available_simpsons_files

#
# 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
    entry_embedded_as_a_href = '<a href="'+_.to_s+'">'+entry+'</a>'
    result << "<b style=\"margin-left:3em\">#{entry_embedded_as_a_href}</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 ) click to toggle source
#

return_available_video_files

#
# 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']
      entry_embedded_as_a_href = '<a href="'+_.to_s+'">'+entry+'</a>'
      result << "<b style=\"margin-left:3em\">#{entry_embedded_as_a_href}</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() click to toggle source
#

return_html_head_and_title_and_body

#
# 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() click to toggle source
#

return_listing

This is accessible via:

http://localhost:5580/listing
#
# 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() click to toggle source
#

return_main_index (main index)

#
# 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() click to toggle source
#

return_n_local_videos

This method will show how many local videos are available.

#
# 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() click to toggle source
#

return_play_splat

#
# 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() click to toggle source
#

return_random_video

#
# 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() click to toggle source
#

return_root_string

#
# 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_view() click to toggle source
#

return_view

#
# 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?() click to toggle source
#

route_name?

#
# File lib/multimedia_paradise/sinatra/embeddable_interface.rb, line 80
def route_name?
  ::MultimediaParadise::EmbeddableInterface.route_name?
end
sub_routes?() click to toggle source
#

sub_routes?

#
# File lib/multimedia_paradise/sinatra/embeddable_interface.rb, line 87
def sub_routes?
  ::MultimediaParadise::EmbeddableInterface.sub_routes?
end
title?() click to toggle source
#

title?

#
# File lib/multimedia_paradise/sinatra/embeddable_interface.rb, line 216
def title?
  TITLE
end