Class: MultimediaParadise::Video::Genres

Inherits:
Base
  • Object
show all
Defined in:
lib/multimedia_paradise/video/genres.rb

Overview

MultimediaParadise::Video::Genres

Constant Summary

Constants inherited from Base

Base::ERROR, Base::ERROR_LINE, Base::NAMESPACE, Base::USE_THIS_NAMESPACE_FOR_THE_COLOURS, Base::USE_THIS_NAMESPACE_FOR_THE_CORE_COLOURS

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#actions, #append_what_into, #be_silent, #be_verbose?, #beautiful_url, #cartoons_directory?, #clear_the_internal_hash, #cliner, #cliner_with_time_stamp, #colourized_comment, #copy_file, #crimson, #dataset_from_file_video_collection, #dd_mm_yyyy, #debug?, #default_readlines, #directory_to_realvids?, #do_not_use_opn, #dodgerblue, #does_the_video_player_support_this_commandline?, #e, #ecomment, #ecrimson, #efancy, #enable_debug, #ensure_main_encoding, #ensure_that_the_output_directory_exists, #eparse, #erev, #esystem, #ewarn, #file_video_collection?, #filter_for_audio_files, #filter_for_video_files, #forestgreen, #gold, #grey, #hh_mm_ss, #home_x_video?, #indianred, #infer_the_namespace, #internal_hash?, #is_audio_file?, #is_mkv?, #is_mp3?, #is_mp4?, #is_multimedia_file?, #is_on_roebe?, #is_video_file?, #konsole_colour_peru, #lightblue, #lightgreen, #load_yaml, #local_audio_directory?, #log_dir?, #map_symbol_to_locally_existing_file, #mediumorchid, #mediumpurple, #mediumslateblue, #mkdir, #move_file, #namespace?, #no_file_exists, #no_file_exists_at, #olive, #olivedrab, #opne, #opnecomment, #opnn, #orange, #palegoldenrod, #palegreen, #powderblue, #project_base_directory?, #rds, #register_sigint, #remove_file, #report_pwd, #reset_the_internal_hash, #return_all_video_files, #return_pwd, #return_random_video, #rev, #royalblue, #save_what_into, #sdir, #seagreen, #seconds_to_time_format, #select_only_video_files_from, #set_be_verbose, #set_use_colours, #sfancy, #sfile, #simp, #skyblue, #slateblue, #springgreen, #steelblue, #swarn, #teal, #time_right_now, #to_hh_mm_ss, #tomato, #true_rev, #try_to_rename_kde_konsole_tab, #ucliner, #use_colours?, #use_opn?, #use_which_video_player?, #verbose_truth, #video_collection?, #violet, #yaml_directory?, #yel

Methods included from CommandlineArgumentsModule

#all_input_starts_with_a_number?, #commandline_arguments?, #commandline_arguments_as_a_string, #first_argument?, #first_non_hyphened_commandline_argument?, #set_commandline_arguments

Constructor Details

#initialize(i = nil, run_already = true) ⇒ Genres

#

initialize

#


35
36
37
38
39
40
41
42
# File 'lib/multimedia_paradise/video/genres.rb', line 35

def initialize(
    i           = nil,
    run_already = true
  )
  reset
  set_input(i)
  run if run_already
end

Class Method Details

.[](i = ARGV) ⇒ Object

#

MultimediaParadise::Video::Genres[]

#


325
326
327
# File 'lib/multimedia_paradise/video/genres.rb', line 325

def self.[](i = ARGV)
  new(i)
end

Instance Method Details

#display_these_entries(i) ⇒ Object

#

display_these_entries

This method will report the given input, which should be a Hash - a Hash containing the video files.

#


184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/multimedia_paradise/video/genres.rb', line 184

def display_these_entries(i)
  if i.is_a?(Hash) and !i.empty?
    n_entries = i.keys.size
    result = 'Displaying the following '+
              sfancy(n_entries.to_s+' entries').dup+' next'
    opnn; e result
    result = ''.dup
    if @search_for_this_genre
      result << 'for the genre '+simp(@search_for_this_genre)
    end 
    result << ':' 
    opnn; e result
    e
    i.each_pair {|position, hash_dataset_including_the_title|
      title = hash_dataset_including_the_title['title']
      e simp(title.ljust(40))+
        ' (at position '+
        springgreen(position.to_s.rjust(3))+')'
    }
    e
  end
end

#do_search_for_this_genre(i) ⇒ Object

#

do_search_for_this_genre

This is the action-method that allows you tos earch for a specific genre in our yaml dataset.

Invocation examples:

video_genres --genre="Science Fiction"
video_genres --genre="eastern"
video_genres --genre="horror"
video_genres --genre=horror
video_genres --science-fiction
#


288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
# File 'lib/multimedia_paradise/video/genres.rb', line 288

def do_search_for_this_genre(i)
  search_for_this_genre = i.to_s.dup
  set_search_for_this_genre(search_for_this_genre)
  _ = file_video_collection?
  if File.exist? _
    opne "Selecting all genres fitting the search term `"\
         "#{simp(@search_for_this_genre)}`."
    dataset = YAML.load_file(_)
    selection = dataset.select {|key, hash_value|
      if hash_value and hash_value.has_key?('genre')
        genre_entry = hash_value['genre']
        if genre_entry
          genre_entry.downcase.delete(' ').include?(@search_for_this_genre.downcase.delete(' '))
        else
          opne "Warning: key #{key} has no genre tag."
          false
        end
      else
        false
      end
    }
    display_these_entries(selection)
  else
    opnn; e "No file called #{sfile(_)} could be found."
  end
end

#input?Boolean

#

input?

#

Returns:

  • (Boolean)


78
79
80
# File 'lib/multimedia_paradise/video/genres.rb', line 78

def input?
  @input
end

#main_yaml_file?Boolean

#

main_yaml_file?

#

Returns:

  • (Boolean)


139
140
141
# File 'lib/multimedia_paradise/video/genres.rb', line 139

def main_yaml_file?
  file_video_collection?
end
#

menu (menu tag)

#


96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/multimedia_paradise/video/genres.rb', line 96

def menu(
    i = @input
  )
  if i.is_a? Array
    i.each {|entry| menu(entry) }
  else
    case i # case tag
    # ===================================================================== #
    # === video_genres --play-random-video-from-this-genre=horror
    # ===================================================================== #
    when /-?-?play(-|_)?random(-|_)?video(-|_)?from(-|_)?this(-|_)?genre=(.+)/
      this_genre = $6.to_s.dup
      play_a_random_video_from(this_genre)
    # ===================================================================== #
    # === video_genres --show_available_genres
    # ===================================================================== #
    when /^-?-?show(-|_)?available(-|_)?genres$/,
         /^-?-?available(-|_)?genres\??$/,
         /^-?-?available(-|_)?video(-|_)?genres$/
      show_available_genres
    # ===================================================================== #
    # === video_genres --show_help
    # ===================================================================== #
    when /-?-?help/
      show_help
    # ===================================================================== #
    # === video_genres --genre="Science Fiction"
    # ===================================================================== #
    when /^-?-?genre="?(.+)"?$/
      do_search_for_this_genre($1)
    else
      if i.start_with?('/') and i.end_with?('/')
        do_search_for_this_genre(
          i.delete('/')
        )
      end
    end
  end
end

#play_a_random_video_from(this_genre) ⇒ Object

#

play_a_random_video_from

Use this method if you wish to play a random video from a given genre. The genre must exist, of course - and so must the file that you wish to play.

The first argument to this method determines the genre in use.

To invoke this, try:

video_genres --play-random-video-from-this-genre=horror
#


221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
# File 'lib/multimedia_paradise/video/genres.rb', line 221

def play_a_random_video_from(
    this_genre
  )
  set_search_for_this_genre(this_genre)
  dataset = YAML.load_file(main_yaml_file?)
  selection = dataset.select {|key, hash_value|
    if hash_value and hash_value.has_key?('genre')
      genre_entry = hash_value['genre']
      if genre_entry
        search_term = @search_for_this_genre.downcase.delete(' _')
        genre_entry.downcase.delete(' _').include?(search_term)
      end
    else
      false
    end
  }
  # ======================================================================= #
  # Now we need to pick a random key.
  # ======================================================================= #
  play_for_this_key = selection.keys.sample.to_s.rjust(3,'0')
  target = "#{DEPOT_VIDEO}"\
           "#{File.basename(MultimediaParadise.realvids_directory?)}/"\
           "#{play_for_this_key}*"
  location = Dir[target]
  if location.is_a? Array
    play_this_file = location.first
  end
  if play_this_file
    if File.exist?(play_this_file)
      opne "Now playing the videofile `#{sfile(play_this_file)}`."
      play_this_video_file(play_this_file)
    else
      opne 'No file was found at `'+sfile(play_this_file)+'`.'
    end
  else
    opne 'No result found for `'+sfancy(target)+'`.'
    pp selection[play_for_this_key.to_i]
  end
end

#play_this_video_file(i) ⇒ Object

#

play_this_video_file

#


264
265
266
267
268
269
270
271
# File 'lib/multimedia_paradise/video/genres.rb', line 264

def play_this_video_file(i)
  if i.is_a? Array
    i.each {|entry| play_this_video_file(entry) }
  else
    _ = "#{use_which_multimedia_player?} -vo x11 #{i}"
    esystem _
  end
end

#resetObject

#

reset (reset tag)

#


47
48
49
50
51
52
53
54
# File 'lib/multimedia_paradise/video/genres.rb', line 47

def reset
  super()
  infer_the_namespace
  # ======================================================================= #
  # === @search_for_this_genre
  # ======================================================================= #
  @search_for_this_genre = nil
end

#runObject

#

run (run tag)

#


318
319
320
# File 'lib/multimedia_paradise/video/genres.rb', line 318

def run
  menu
end

#set_input(i = '') ⇒ Object

#

set_input

#


59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/multimedia_paradise/video/genres.rb', line 59

def set_input(i = '')
  i = i.first if i.is_a? Array
  i = i.to_s.dup
  # ======================================================================= #
  # Do a bit of sanitizing next:
  # ======================================================================= #
  case i # case tag
  # ======================================================================= #
  # === video_genres --science-fiction
  # ======================================================================= #
  when /^-?-?science(-| |_)?fiction$/
    i = '--genre="Science Fiction"'
  end
  @input = i
end

#set_search_for_this_genre(i) ⇒ Object

#

set_search_for_this_genre

#


173
174
175
176
# File 'lib/multimedia_paradise/video/genres.rb', line 173

def set_search_for_this_genre(i)
  i.delete!('"') if i.include? '"'
  @search_for_this_genre = i
end

#show_available_genresObject

#

show_available_genres (available tag)

This method will show the available genres. For this it will tap into the .yml file and simply colllect all genres into an Array.

Invocation example:

video_genres --available_genres
#


154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/multimedia_paradise/video/genres.rb', line 154

def show_available_genres
  _ = main_yaml_file?
  hash = YAML.load_file(_)
  array = []
  hash.each_pair {|key, value_hash|
    if value_hash.has_key? 'genre'
      genre = value_hash['genre']
      array << genre
    end
  }
  array.sort!
  array.uniq!
  opnn; e 'These '+sfancy(array.size.to_s)+' genres are available:'
  array.each {|this_genre| e sfancy("  #{this_genre}") }
end

#show_helpObject

#

show_help

#


85
86
87
88
89
90
91
# File 'lib/multimedia_paradise/video/genres.rb', line 85

def show_help
  opnn; e 'The following help options are available:'
  e
  e '  video_genres --genre="Science Fiction" # <- to search for a genre'
  e '  video_genres --science-fiction         # an alias to the ^^^ above'
  e
end