Class: MultimediaParadise::MplayerWrapper
- Inherits:
-
Base
- Object
- Base
- MultimediaParadise::MplayerWrapper
show all
- Defined in:
- lib/multimedia_paradise/video/mplayer_wrapper.rb
Overview
Constant Summary
collapse
- ALSA_OPTIONS =
'-ao alsa '
- VO_X11 =
'-vo x11'
- APPEND_THESE_OPTIONS_TO_MPLAYER =
#
APPEND_THESE_OPTIONS_TO_MPLAYER
#
' '+VO_X11
- USE_THIS_MULTIMEDIA_PLAYER =
#
#
USE_THIS_MULTIMEDIA_PLAYER = ‘mpv’ # Can also be mplayer.
::MultimediaParadise.use_this_player
- STORE_WHERE =
"#{HOME_DIR}mplayer_favourite_files.yml"
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
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, #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
#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(commandline_arguments = nil, run_already = true) ⇒ MplayerWrapper
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/multimedia_paradise/video/mplayer_wrapper.rb', line 64
def initialize(
commandline_arguments = nil,
run_already = true
)
register_sigint
reset
set_commandline_arguments(
commandline_arguments
)
run if run_already
end
|
Instance Method Details
#_(i) ⇒ Object
Also known as:
append
469
470
471
472
|
# File 'lib/multimedia_paradise/video/mplayer_wrapper.rb', line 469
def _(i)
@_ << " #{i}"
@_.squeeze!(' ')
end
|
#add(i) ⇒ Object
215
216
217
218
219
|
# File 'lib/multimedia_paradise/video/mplayer_wrapper.rb', line 215
def add(i)
@play_these_multimedia_files << [i].flatten.compact
@play_these_multimedia_files.flatten!
@play_these_multimedia_files.uniq! end
|
#consider_to_notify_the_user_if_more_than_one_video_file ⇒ Object
#
consider_to_notify_the_user_if_more_than_one_video_file
#
293
294
295
296
297
298
299
300
301
302
303
|
# File 'lib/multimedia_paradise/video/mplayer_wrapper.rb', line 293
def consider_to_notify_the_user_if_more_than_one_video_file
if @play_these_multimedia_files.size > 1
e "#{rev}More than one audio/video file was found. "\
"We will output these now:"
e
@play_these_multimedia_files.each {|entry|
e "#{sfancy(' - ')}#{entry}"
}
e
end
end
|
#cyan(i) ⇒ Object
263
264
265
|
# File 'lib/multimedia_paradise/video/mplayer_wrapper.rb', line 263
def cyan(i)
"#{Colours::CYAN}#{i}#{Colours::GREEN}"
end
|
#exit_program ⇒ Object
#
exit_program
Use this method when exiting from this class.
#
279
280
281
|
# File 'lib/multimedia_paradise/video/mplayer_wrapper.rb', line 279
def exit_program
exit if @may_we_exit
end
|
#main_string? ⇒ Boolean
270
271
272
|
# File 'lib/multimedia_paradise/video/mplayer_wrapper.rb', line 270
def main_string?
@_
end
|
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
|
# File 'lib/multimedia_paradise/video/mplayer_wrapper.rb', line 327
def (
i = @commandline_arguments
)
if i and i.is_a?(Array)
i.each {|entry| (entry) }
else
case i when /^-?-?simpsons=(\d+)$/i
i = ::MultimediaParadise::Video.return_good_the_simpsons_episodes.shuffle
n_files_to_play = $1.to_s.dup.to_i
play_these_episodes = i[0 .. (n_files_to_play - 1)]
notify_the_user_that_these_simpsons_episodes_will_be_played(play_these_episodes)
when /^-?-?simpsons?\??$/i
i = ::MultimediaParadise::Video.return_good_the_simpsons_episodes.shuffle if is_on_roebe?
i << MultimediaParadise.return_path_to_random_simpsons_video_file
i << MultimediaParadise.return_path_to_random_simpsons_video_file
i.uniq! end
notify_the_user_that_these_simpsons_episodes_will_be_played(i)
when /^-?-?use(-|_)?mplayer$/i
@use_this_multimedia_player = 'mplayer'
when :halloween, ':halloween',
:predator, ':predator'
add map_symbol_to_locally_existing_file(i)
when '-nosound',
'silence',
/^nosound$/i
@append_this << '-nosound '
i[1] = nil
when /^-?-?version\??$/i,
'-v',
'?'
show_version_then_exit
when /^-?-?help$/i
show_help_then_exit
else
if File.exist? i
add(i)
else
return i
end
end
end
end
|
#notify_the_user_that_these_simpsons_episodes_will_be_played(i) ⇒ Object
#
notify_the_user_that_these_simpsons_episodes_will_be_played
#
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
|
# File 'lib/multimedia_paradise/video/mplayer_wrapper.rb', line 308
def notify_the_user_that_these_simpsons_episodes_will_be_played(i)
e "#{rev}A total of #{i.size} different simpson episodes will be played."
e "#{rev}The total duration of these files will be:"
n_seconds = MultimediaParadise::FileDuration.total_time_of(i)
e
e sfancy(' '+n_seconds.to_s+' seconds')+
' ('+
(n_seconds / 60.0).round(1).to_s+' minutes; '+
slateblue(
(n_seconds / 3600).round(1).to_s+' hours'
)+
')'
e
set_use_these_files(i)
end
|
#
Here we finally iterate over the collection and play every file.
#
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
|
# File 'lib/multimedia_paradise/video/mplayer_wrapper.rb', line 417
def play_each_multimedia_file(
i = @play_these_multimedia_files
)
i.each {|file|
if File.directory? file
opnn; e 'This is a directory. We will try to play every'
opnn; e 'file in this directory next.'
play_each_multimedia_file(
Dir["#{file}/*"]
)
else
register_file(file)
reset_main_string
_ "#{@use_this_multimedia_player} "
_ APPEND_THESE_OPTIONS_TO_MPLAYER if APPEND_THESE_OPTIONS_TO_MPLAYER
if @use_this_multimedia_player == 'mplayer'
_ ' -fs -zoom ' if @play_zoomed
end
_ ' -vo null ' if @disable_video
if @use_mplayer_colours
if main_string?.start_with? 'mpv '
cmd = ' --msg-color '
if does_the_video_player_support_this_commandline?
_ cmd
else
_ ' -msgcolor '
end
else _ ' -msgcolor '
end
end
_ @append_this e(@_+'"'+cyan(file)+'"') _ '"'+file+'"'
system(@_) end
}
end
|
#register_file(i = @file_name) ⇒ Object
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
|
# File 'lib/multimedia_paradise/video/mplayer_wrapper.rb', line 224
def register_file(
i = @file_name )
number = 1
if i
if @hash.is_a? Hash
_ = File.basename( i.delete('"') ) if @hash.has_key? _
@hash[_] = @hash[_] + number
else
@hash[_] = number
end
save_what_into_this_file
else
e 'Something went wrong - @hash variable is not a hash.'
e "Make sure to check the file #{sfile(@store_where)}."
exit
end
end
end
|
#register_sigint ⇒ Object
286
287
288
|
# File 'lib/multimedia_paradise/video/mplayer_wrapper.rb', line 286
def register_sigint Signal.trap('SIGINT') { exit_program }
end
|
#reset ⇒ Object
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
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
|
# File 'lib/multimedia_paradise/video/mplayer_wrapper.rb', line 79
def reset
super()
infer_the_namespace
@play_these_multimedia_files = [] @use_this_multimedia_player = USE_THIS_MULTIMEDIA_PLAYER
@store_where = STORE_WHERE
@append_this = ''
@play_zoomed = PLAY_ZOOMED
@disable_video = false
@use_mplayer_colours = false
@hash = {} @hash = YAML.load_file(@store_where) if File.exist? @store_where
@hash = {} if @hash == false
@may_we_exit = true
end
|
#reset_main_string ⇒ Object
130
131
132
|
# File 'lib/multimedia_paradise/video/mplayer_wrapper.rb', line 130
def reset_main_string
@_ = ''.dup end
|
#run ⇒ Object
477
478
479
480
481
|
# File 'lib/multimedia_paradise/video/mplayer_wrapper.rb', line 477
def run
consider_to_notify_the_user_if_more_than_one_video_file
play_each_multimedia_file
end
|
#
We need to be careful here.
#
166
167
168
169
170
171
172
173
174
175
|
# File 'lib/multimedia_paradise/video/mplayer_wrapper.rb', line 166
def sanitize_input(i)
if i.is_a? Array return i.map {|entry| entry.to_s.tr('+','*') }
else
return i
end
end
|
#save_what_into_this_file(what = @hash, where = STORE_WHERE) ⇒ Object
#
save_what_into_this_file
Use this to save the file played.
#
250
251
252
253
254
255
256
257
258
|
# File 'lib/multimedia_paradise/video/mplayer_wrapper.rb', line 250
def save_what_into_this_file(
what = @hash, where = STORE_WHERE
)
begin
File.open(where, 'w+') { |f| YAML.dump(what, f) }
rescue Exception => error
opnn; pp error
end
end
|
#
This will always return an Array.
#
198
199
200
201
202
203
204
205
206
207
208
209
210
|
# File 'lib/multimedia_paradise/video/mplayer_wrapper.rb', line 198
def set_play_these_multimedia_files(
i
)
verbose_exit if i.to_s.empty?
i = i.dup if i.is_a? String
@play_these_multimedia_files << sanitize_input(i)
@play_these_multimedia_files.flatten!
@play_these_multimedia_files.compact!
try_to_ensure_that_the_files_exist
end
|
#show_help_then_exit ⇒ Object
146
147
148
149
|
# File 'lib/multimedia_paradise/video/mplayer_wrapper.rb', line 146
def show_help_then_exit
esystem "#{@use_this_multimedia_player} --help"
exit
end
|
#show_version_then_exit ⇒ Object
#
show_version_then_exit
#
154
155
156
157
158
159
|
# File 'lib/multimedia_paradise/video/mplayer_wrapper.rb', line 154
def show_version_then_exit
_ = `#{@use_this_multimedia_player} -version 2>&1`
_ = _.split("\n")[-1]
e(_)
exit
end
|
#try_to_ensure_that_the_files_exist ⇒ Object
#
try_to_ensure_that_the_files_exist
Here we try to make sure that the files exist, by applying a glob on it.
#
183
184
185
186
187
188
189
190
191
|
# File 'lib/multimedia_paradise/video/mplayer_wrapper.rb', line 183
def try_to_ensure_that_the_files_exist
@play_these_multimedia_files.map! {|file|
unless File.exist? file globbed = Dir[file+'*']
file = globbed.first unless globbed.empty?
end
file
}
end
|
#verbose_exit ⇒ Object
137
138
139
140
141
|
# File 'lib/multimedia_paradise/video/mplayer_wrapper.rb', line 137
def verbose_exit
opnn; e 'You did not provide a multimedia file to play.'
opnn; e 'Thus exiting now.'
exit_program
end
|