class MultimediaParadise::FindVideo

Constants

BASE_DIRECTORY
#

BASE_DIRECTORY

#
NAMESPACE
#

NAMESPACE

#

Public Class Methods

[](i, flatten_result = false) click to toggle source
#

MultimediaParadise::FindVideo[]

Usage example would be like:

MultimediaParadise::FindVideo['ninja']
MultimediaParadise::FindVideo['ninja', :flatten_result]
#
# File lib/multimedia_paradise/video/find_video/find_video.rb, line 295
def self.[](i, flatten_result = false)
  case flatten_result
  when :do_flatten, :flatten, :flatten_result
    flatten_result = true
  end
  _ = new(i)
  _.be_silent
  _.find_video
  _ = _.candidates?
  _.flatten! if flatten_result
  return _
end
new( search_term = '*', be_silent_or_be_verbose = :be_verbose ) { || ... } click to toggle source
#

initialize

The first argument is the search term.

#
# File lib/multimedia_paradise/video/find_video/find_video.rb, line 32
def initialize(
    search_term             = '*',
    be_silent_or_be_verbose = :be_verbose
  )
  reset
  set_search_term(
    search_term
  )
  set_verbosity_level(
    be_silent_or_be_verbose
  )
  # ======================================================================= #
  # === Handle blocks
  # ======================================================================= #
  if block_given?
    yielded = yield
    if yielded.is_a? Symbol
      case yielded
      when :be_quiet
        @be_verbose = false
      end
    end
  end
  check_on_search_term
end

Public Instance Methods

candidates()
Alias for: candidates?
candidates?() click to toggle source
#

candidates?

#
# File lib/multimedia_paradise/video/find_video/find_video.rb, line 92
def candidates?
  @candidates
end
Also aliased as: candidates
check_on_search_term(i = search_term?) click to toggle source
#

check_on_search_term

menu() is an alias to this method.

#
# File lib/multimedia_paradise/video/find_video/find_video.rb, line 215
def check_on_search_term(i = search_term?)
  case i # case tag.
  when 'OPEN'
    open_yaml_file; exit
  when 'list?','?','help','HELP','--help'
    show_help_then_exit
  end
end
Also aliased as: menu
ef(i) click to toggle source
#

ef

#
# File lib/multimedia_paradise/video/find_video/find_video.rb, line 182
def ef(i)
  e i, false
end
enable_debug(i = false)
Alias for: set_debug
find( search_term = search_term?, be_verbose = be_verbose? )
Alias for: find_video
find_video( search_term = search_term?, be_verbose = be_verbose? ) click to toggle source
#

find_video (find tag)

I use this method to find a specific video. The first example should be a string, the actual search term in question.

Usage examples:

find_video Amelie
find_video Tanz der Vampire
#
# File lib/multimedia_paradise/video/find_video/find_video.rb, line 343
def find_video(
    search_term = search_term?,
    be_verbose  = be_verbose?
  )
  if @debug
    opnn; e '(Debug Mode) The search term to find_video() method '\
            'was '+sfancy(search_term)+'.'
  end
  load_video_yaml_file
  # ======================================================================= #
  # Select all possible candidates in that hash next. The Hash will have
  # key value structures that look like this:
  #
  #   "Ice Age"=>58
  #
  # ======================================================================= #
  if (search_term =~ /^\d+$/) # If only numbers
    hash_candidates = @hash_video_collection_name.select { |key, value|
      value.to_i == search_term.to_i
    }
  else
    hash_candidates = @hash_video_collection_name.reject { |key, value|
      begin
        # =================================================================== #
        # Next match the key onto the given search term.
        # =================================================================== #
        ! (key =~ /#{search_term}/) # The /i was removed in June 2021.
      rescue Exception => error
        pp error
      end
    }
  end
  if !hash_candidates.empty?
    return report_candidates(hash_candidates)
  else
    # ===================================================================== #
    # Ok, we did not find it up to here, but perhaps we try one last
    # strategy here, and remove all ' ' in the search string. We could
    # then find another result. And we will also downcase the keys. But if
    # we then still do not find a result, we report to the user.
    #
    # Since as of June 2021 we will no longer downcase, because
    # "W" is different to "w", e. g. "Watchmen" versus "watchmen".
    # ===================================================================== #
    hash_candidates = @hash_video_collection_name.reject { |key, value|
      if key
        key = ensure_main_encoding(key)
        key = key.dup if key.frozen?
        key.delete!(' ') # .downcase # .downcase was commented out in June 2021.
      end
      search_term = search_term.downcase
      ! (key =~ /#{search_term}/) # The /i part was removed in June 2021.
    }
    if hash_candidates.empty?
      if be_verbose
        opnn; ewarn 'No match for `'+sfancy(search_term)+
                     swarn('` could be found.')
      end
      e @hash_video_collection_name.keys.join ', ' if @debug
      return false
    else # else, really report that we found none.
      return report_candidates(hash_candidates)
    end
  end
end
Also aliased as: try_to_find, find
load_video_yaml_file( i = video_collection? ) click to toggle source
#

load_video_yaml_file

#
# File lib/multimedia_paradise/video/find_video/find_video.rb, line 149
def load_video_yaml_file(
    i = video_collection?
  )
  dataset = load_yaml(i)
  dataset.each { |t|
    new_number = t[0] # This is the number.
    new_title  = t[1]['title']
    if new_title.nil?
      opnn; e "The position at #{new_number} is nil."
      opnn; e 'The assumed dataset was:'
      pp t
    end
    # We must be careful - there may be entries with the same title.
    if @hash_video_collection_name.has_key? new_title
      warn_about_this_old_title(new_title)
    else
      @hash_video_collection_name[new_title] = new_number
    end
  }
end
menu(i = search_term?)
raise_and_exit(i) click to toggle source
#

raise_and_exit

#
# File lib/multimedia_paradise/video/find_video/find_video.rb, line 189
def raise_and_exit(i)
  e i; exit
end
report_candidates(hash) click to toggle source
#

report_candidates

Output the result through this method. Since as of December 2013, we will pad the result.

#
# File lib/multimedia_paradise/video/find_video/find_video.rb, line 257
def report_candidates(hash)
  reset_candidates # Reset the candidates here again.
  if be_verbose?
    e N+sfancy('find_video.rb: ')+'Results for the search '\
      'term `'+simp(search_term?.to_s)+'` are as follows: ✅'
    cliner
  end
  set_results(hash.values)
  longest_video_title = hash.keys.map(&:size).max
  # e N+sfancy('find_video.rb: ')+'The longest title is: '+
  #   sfancy(longest_video_title)
  hash.each { |the_video_title, position_of_the_video_file|
    position_of_the_video_file = '%03d' % position_of_the_video_file 
    _ = '%-'+longest_video_title.to_s+'s'
    the_video_title = _ % the_video_title
    if be_verbose?
      e sfancy('  `'+the_video_title)+'` can be found at position `'+
        sfancy(position_of_the_video_file.to_s)+'`.'
    end
    # ===================================================================== #
    # We store more information in the Array @candidates,
    # including the Title.
    # ===================================================================== #
    @candidates << [the_video_title.strip, position_of_the_video_file]
  }
  cliner if be_verbose?
  return @candidates
end
reset() click to toggle source
#

reset (reset tag)

#
Calls superclass method MultimediaParadise::Base#reset
# File lib/multimedia_paradise/video/find_video/find_video.rb, line 61
def reset
  super()
  # ======================================================================= #
  # === @namespace
  # ======================================================================= #
  @namespace = NAMESPACE
  # ======================================================================= #
  # === @results
  # ======================================================================= #
  @results = nil
  # ======================================================================= #
  # === @debug
  # ======================================================================= #
  @debug = false
  # ======================================================================= #
  # === @hash_video_collection_name
  # ======================================================================= #
  @hash_video_collection_name = {}
  # ======================================================================= #
  # === @video_collection
  # ======================================================================= #
  @video_collection = VIDEO_COLLECTION
  # ======================================================================= #
  # === @candidates
  # ======================================================================= #
  @candidates = []
end
reset_candidates() click to toggle source
#

reset_candidates

Reset the candidates here again.

#
# File lib/multimedia_paradise/video/find_video/find_video.rb, line 142
def reset_candidates
  @candidates = []
end
results()
Alias for: results?
results?() click to toggle source
#

results

Returns the positional values in Array format. This can then be used to find the corresponding match when playing a video.

Example:

[242, 250, 266]
#
# File lib/multimedia_paradise/video/find_video/find_video.rb, line 133
def results?
  @results
end
Also aliased as: results
search_term?() click to toggle source
#

search_term?

#
# File lib/multimedia_paradise/video/find_video/find_video.rb, line 118
def search_term?
  @search_term
end
set_debug(i = false) click to toggle source
#

set_debug

#
# File lib/multimedia_paradise/video/find_video/find_video.rb, line 111
def set_debug(i = false)
  @debug = i
end
Also aliased as: enable_debug
set_results(i = nil) click to toggle source
#

set_results

#
# File lib/multimedia_paradise/video/find_video/find_video.rb, line 203
def set_results(i = nil)
  if i.nil?
    raise_and_exit 'Please supply a search term. Thanks.'
  end
  @results = i
end
set_search_term(i) click to toggle source
#

set_search_term

We will assign the search term here in this method.

#
# File lib/multimedia_paradise/video/find_video/find_video.rb, line 101
def set_search_term(i)
  i = i.first if i.is_a? Array
  i = i.to_s
  i = i.strip
  @search_term = i
end
set_verbosity_level(i) click to toggle source
#

set_verbosity_level

#
# File lib/multimedia_paradise/video/find_video/find_video.rb, line 321
def set_verbosity_level(i)
  case i.to_s
  when 'be_verbose'
    i = true
  when 'be_silent'
    i = false
  end
  @be_verbose = i
end
show_available_videos_in_raw_format() click to toggle source
#

show_available_videos_in_raw_format

The purpose of this method is to show the raw dataset, via pp.

#
# File lib/multimedia_paradise/video/find_video/find_video.rb, line 313
def show_available_videos_in_raw_format
  load_video_yaml_file
  pp @hash_video_collection_name.sort_by {|key, value| value }
end
show_commandline_help() click to toggle source
#

show_commandline_help

In order to invoke this, do:

find_video --help
#
# File lib/multimedia_paradise/video/find_video/find_video.rb, line 241
def show_commandline_help
  _ = MultimediaParadise.location_of_yaml_file_with_registered_videofiles
  opnn; e 'This script will attempt to find a given video, if it was registered'
  opnn; e 'in the yaml file.'
  opnn; e 'This yaml file can be found here:'
  opnn; e '  '+sfile(_)
  opnn; e 'You can also try to do a partial match. For instance, searching for'
  opnn; e '"con" will try to find "Conan" but also "L.A. Confidential".'
end
show_help_then_exit() click to toggle source
#

show_help_then_exit

#
# File lib/multimedia_paradise/video/find_video/find_video.rb, line 227
def show_help_then_exit
  show_available_videos_in_raw_format
  show_commandline_help
  exit
end
try_to_find( search_term = search_term?, be_verbose = be_verbose? )
Alias for: find_video
video_collection?() click to toggle source
#

video_collection?

#
# File lib/multimedia_paradise/video/find_video/find_video.rb, line 196
def video_collection?
  @video_collection
end
warn_about_this_old_title(new_title) click to toggle source
#

warn_about_this_old_title

#
# File lib/multimedia_paradise/video/find_video/find_video.rb, line 173
def warn_about_this_old_title(new_title)
  opnn; e 'Warning! We already have an old title called '+
          sfancy(new_title.to_s)+'.'
  pp @hash_video_collection_name.invert[new_title]
end