Class: MultimediaParadise::Video::RandomVideo
- Inherits:
-
Base
- Object
- Base
- MultimediaParadise::Video::RandomVideo
show all
- Defined in:
- lib/multimedia_paradise/video/random_video.rb
Overview
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?, #verbose_truth, #video_collection?, #violet, #yaml_directory?, #yel
#all_input_starts_with_a_number?, #commandline_arguments_as_a_string, #first_argument?, #first_non_hyphened_commandline_argument?
Constructor Details
#initialize(commandline_arguments = return_pwd, run_already = true) ⇒ RandomVideo
#
initialize
The first argument is usually the target directory.
#
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/multimedia_paradise/video/random_video.rb', line 33
def initialize(
commandline_arguments = return_pwd,
run_already = true
)
reset
set_commandline_arguments(
commandline_arguments
)
set_play_from_this_directory(
Dir.pwd )
run if run_already
end
|
Class Method Details
.[](i = '') ⇒ Object
283
284
285
|
# File 'lib/multimedia_paradise/video/random_video.rb', line 283
def self.[](i = '')
new
end
|
Instance Method Details
142
143
144
145
146
147
|
# File 'lib/multimedia_paradise/video/random_video.rb', line 142
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? ⇒ Boolean
Also known as:
input?
#
commandline_arguments?
#
108
109
110
|
# File 'lib/multimedia_paradise/video/random_video.rb', line 108
def commandline_arguments?
@commandline_arguments
end
|
#do_use_mplayer ⇒ Object
#
do_use_mplayer
This method can be used to specifically use mplayer rather than, for example, mpv.
#
73
74
75
|
# File 'lib/multimedia_paradise/video/random_video.rb', line 73
def do_use_mplayer
@which_video_player_to_use = 'mplayer'
end
|
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
|
# File 'lib/multimedia_paradise/video/random_video.rb', line 202
def (
i = @commandline_arguments
)
if i.is_a? Array
i.each {|entry| (entry) }
else
case i when /-?-?use(-|_)?mplayer$/,
/-?-?mplayer$/
do_use_mplayer
when /-?-?from(-|_)?realvids$/
@from_where = realvids_directory?+'*'
set_target_directory(realvids_directory?)
when /help$/
show_help
exit
end
end
end
|
#obtain_all_files(from_where = @from_where) ⇒ Object
#
obtain_all_files
By default, we will grab entries from the current directory.
This can be modified by the input.
#
238
239
240
241
242
243
244
245
246
247
|
# File 'lib/multimedia_paradise/video/random_video.rb', line 238
def obtain_all_files(
from_where = @from_where )
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 ⇒ Object
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
# File 'lib/multimedia_paradise/video/random_video.rb', line 152
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
if input?.first =~ /^\d+$/ input?.first.to_i.times {
play_video(_.sample)
}
else
play_video(_.sample)
end
end
end
|
#play_from_this_directory? ⇒ Boolean
Also known as:
target_directory?, target_dir?
#
play_from_this_directory?
#
89
90
91
|
# File 'lib/multimedia_paradise/video/random_video.rb', line 89
def play_from_this_directory?
@play_from_this_directory
end
|
#play_video(i) ⇒ Object
#
play_video
This method is the one that will play the video-file at hand.
#
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
# File 'lib/multimedia_paradise/video/random_video.rb', line 175
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 ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/multimedia_paradise/video/random_video.rb', line 50
def reset
super()
infer_the_namespace
@which_video_player_to_use = ::MultimediaParadise.which_video_player_to_use?
@from_where = '*'
end
|
#run ⇒ Object
272
273
274
275
276
277
278
|
# File 'lib/multimedia_paradise/video/random_video.rb', line 272
def run
obtain_all_files
select_only_multimedia_files
sort
play_a_random_video
end
|
#
We can only play video or audio files. This method will take care of that constraint, by selecting only files that are multimedia files.
#
119
120
121
122
123
|
# File 'lib/multimedia_paradise/video/random_video.rb', line 119
def select_only_multimedia_files
@all_files.select! {|entry|
is_a_multimedia_file?(entry)
}
end
|
#set_commandline_arguments(i = '') ⇒ Object
#
set_commandline_arguments
#
97
98
99
100
101
102
103
|
# File 'lib/multimedia_paradise/video/random_video.rb', line 97
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) ⇒ Object
Also known as:
set_target_directory
#
set_play_from_this_directory
#
80
81
82
83
84
|
# File 'lib/multimedia_paradise/video/random_video.rb', line 80
def set_play_from_this_directory(i)
i = i.dup if i.frozen?
i << '/' unless i.end_with? '/'
@play_from_this_directory = i
end
|
#show_help ⇒ Object
#
show_help (help tag)
Invocation example:
random_video --help
#
257
258
259
260
261
262
263
264
265
266
267
|
# File 'lib/multimedia_paradise/video/random_video.rb', line 257
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 ⇒ Object
135
136
137
|
# File 'lib/multimedia_paradise/video/random_video.rb', line 135
def sort
@all_files.sort!
end
|
#use_which_video_player? ⇒ Boolean
Also known as:
use_this_video_player
#
use_which_video_player?
#
195
196
197
|
# File 'lib/multimedia_paradise/video/random_video.rb', line 195
def use_which_video_player?
@which_video_player_to_use
end
|