class MultimediaParadise::Video::RandomVideo

Constants

NAMESPACE
#

NAMESPACE

#

Public Class Methods

[](i = '') click to toggle source
#

MultimediaParadise[]

#
# File lib/multimedia_paradise/video/random_video.rb, line 292
def self.[](i = '')
  new
end
new( commandline_arguments = Dir.pwd, run_already = true ) click to toggle source
#

initialize

The first argument is usually the target directory.

#
# File lib/multimedia_paradise/video/random_video.rb, line 39
def initialize(
    commandline_arguments = Dir.pwd,
    run_already           = true
  )
  reset
  set_commandline_arguments(
    commandline_arguments
  )
  set_play_from_this_directory(
    Dir.pwd # Default.
  )
  run if run_already
end

Public Instance Methods

can_not_play_any_file_as_we_did_not_find_a_multimedia_file_in_this_directory( this_directory = target_dir? ) click to toggle source
#

can_not_play_any_file_as_we_did_not_find_a_multimedia_file_in_this_directory

#
# File lib/multimedia_paradise/video/random_video.rb, line 151
def can_not_play_any_file_as_we_did_not_find_a_multimedia_file_in_this_directory(
    this_directory = target_dir?
  )
  opnn; e 'Can not play any file as we did not find a multimedia '\
          'file in this ('+sdir(this_directory)+') directory.'
end
commandline_arguments?() click to toggle source
#

commandline_arguments?

#
# File lib/multimedia_paradise/video/random_video.rb, line 117
def commandline_arguments?
  @commandline_arguments
end
Also aliased as: input?
do_use_mplayer() click to toggle source
#

do_use_mplayer

This method can be used to specifically use mplayer rather than, for example, mpv.

#
# File lib/multimedia_paradise/video/random_video.rb, line 82
def do_use_mplayer
  @which_video_player_to_use = 'mplayer'
end
input?()
is_a_multimedia_file?(i) click to toggle source
#

is_a_multimedia_file?

#
# File lib/multimedia_paradise/video/random_video.rb, line 137
def is_a_multimedia_file?(i)
  ::MultimediaParadise.is_a_multimedia_file?(i)
end
menu( i = @commandline_arguments ) click to toggle source
#

menu (menu tag)

#
obtain_all_files( from_where = @from_where ) click to toggle source
#

obtain_all_files

By default, we will grab entries from the current directory.

This can be modified by the input.

#
# File lib/multimedia_paradise/video/random_video.rb, line 247
def obtain_all_files(
    from_where = @from_where # This defaults to the current working directory.
  )
  unless target_directory?.empty?
    from_where = target_directory?.dup
  end
  from_where << '*' unless from_where.end_with? '*'
  all_files = Dir[from_where]
  @all_files = all_files
end
play_a_random_video() click to toggle source
#

play_a_random_video

#
# File lib/multimedia_paradise/video/random_video.rb, line 161
def play_a_random_video
  _ = @all_files
  if _.empty?
    can_not_play_any_file_as_we_did_not_find_a_multimedia_file_in_this_directory
  else
    # ===================================================================== #
    # Keep in mind that the input may be a number.
    # ===================================================================== #
    if input?.first =~ /^\d+$/ # If only numbers.
      input?.first.to_i.times {
        play_video(_.sample)
      }
    else
      play_video(_.sample)
    end
  end
end
play_from_this_directory?() click to toggle source
#

play_from_this_directory?

#
# File lib/multimedia_paradise/video/random_video.rb, line 98
def play_from_this_directory?
  @play_from_this_directory
end
Also aliased as: target_directory?, target_dir?
play_video(i) click to toggle source
#

play_video

This method is the one that will play the video-file at hand.

#
# File lib/multimedia_paradise/video/random_video.rb, line 184
def play_video(i)
  if i.is_a? Array
    i.each {|this_file| play_video(this_file) }
  else
    if i.include?("'") or i.include?(' ')
      i = '"'+i+'"'
    end
    begin
      require 'roebe/classes/kde/kde_konsole/kde_konsole.rb'
      Roebe.rename_konsole(:television, :be_quiet)
    rescue; end
    _ = use_which_video_player?+' -vo x11 '+i
    _.squeeze!(' ')
    esystem _
  end
end
reset() click to toggle source
#

reset (reset tag)

#
Calls superclass method MultimediaParadise::Base#reset
# File lib/multimedia_paradise/video/random_video.rb, line 56
def reset
  super()
  # ======================================================================= #
  # === @namespace
  # ======================================================================= #
  @namespace = NAMESPACE
  # ======================================================================= #
  # === @which_video_player_to_use
  # ======================================================================= #
  @which_video_player_to_use = ::MultimediaParadise.which_video_player_to_use?
  # ======================================================================= #
  # === @from_where
  #
  # The next variable determines from where we will pick our video
  # files. If it is '*' then this means the current working
  # directory.
  # ======================================================================= #
  @from_where = '*'
end
run() click to toggle source
#

run (run tag)

#
# File lib/multimedia_paradise/video/random_video.rb, line 281
def run
  menu
  obtain_all_files
  select_only_multimedia_files
  sort
  play_a_random_video
end
select_only_multimedia_files() click to toggle source
#

select_only_multimedia_files

We can only play video or audio files. This method will take care of that constraint, by selecting only files that are multimedia files.

#
# File lib/multimedia_paradise/video/random_video.rb, line 128
def select_only_multimedia_files
  @all_files.select! {|entry|
    is_a_multimedia_file?(entry)
  }
end
set_commandline_arguments(i = '') click to toggle source
#

set_commandline_arguments

#
# File lib/multimedia_paradise/video/random_video.rb, line 106
def set_commandline_arguments(i = '')
  unless i.is_a? Array
    i = [i]
  end
  i.flatten!
  @commandline_arguments = i
end
set_play_from_this_directory(i) click to toggle source
#

set_play_from_this_directory

#
# File lib/multimedia_paradise/video/random_video.rb, line 89
def set_play_from_this_directory(i)
  i = i.dup if i.frozen?
  i << '/' unless i.end_with? '/'
  @play_from_this_directory = i
end
Also aliased as: set_target_directory
set_target_directory(i)
show_help() click to toggle source
#

show_help (help tag)

Invocation example:

random_video --help
#
# File lib/multimedia_paradise/video/random_video.rb, line 266
  def show_help
    help_string = <<-EOF

The following help options are available and documented:

  --use-mplayer   # use mplayer to play a random video
  --from-realvids # play from the realvids directory

EOF
    e help_string
  end
sort() click to toggle source
#

sort

#
# File lib/multimedia_paradise/video/random_video.rb, line 144
def sort
  @all_files.sort!
end
target_dir?()
target_directory?()
use_this_video_player()
use_which_video_player?() click to toggle source
#

use_which_video_player?

#
# File lib/multimedia_paradise/video/random_video.rb, line 204
def use_which_video_player?
  @which_video_player_to_use
end
Also aliased as: use_this_video_player