Class: MultimediaParadise::VideoPlayer
- Inherits:
-
Base
- Object
- Base
- MultimediaParadise::VideoPlayer
show all
- Defined in:
- lib/multimedia_paradise/video/video_player.rb
Overview
Constant Summary
collapse
- BE_VERBOSE =
true
- DEBUG =
false
- DEFAULT_PLAY_MODE =
'loop'
- USE_VO_X11 =
#
USE_VO_X11
If true then we will use ‘-vo x11’
#
true
- DEFAULT_COLOUR =
#
Setup the colours to use.
#
'green'
- FANCY_COLOUR =
'cyanb'
- COLOUR_WARN =
'redb'
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, #rev, #royalblue, #save_what_into, #sdir, #seagreen, #seconds_to_time_format, #select_only_video_files_from, #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_options = nil, run_already = true) ⇒ VideoPlayer
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
# File 'lib/multimedia_paradise/video/video_player.rb', line 92
def initialize(
commandline_options = nil,
run_already = true
)
register_sigint
reset
set_runmode :standalone
set_commandline_options(
commandline_options
)
case run_already
when :dont_run_yet, :do_not_run_yet
run_already = false
end
run if run_already
end
|
Instance Method Details
#add(i = nil) ⇒ Object
245
246
247
248
249
|
# File 'lib/multimedia_paradise/video/video_player.rb', line 245
def add(i = nil)
if i
@array_play_these_video_files << i unless i.empty?
end
end
|
#add_all_videos ⇒ Object
480
481
482
|
# File 'lib/multimedia_paradise/video/video_player.rb', line 480
def add_all_videos
add(obtain_all_video_files.sort)
end
|
#commandline_options? ⇒ Boolean
Also known as:
commandline?
350
351
352
|
# File 'lib/multimedia_paradise/video/video_player.rb', line 350
def commandline_options?
@commandline_options
end
|
#disable_video ⇒ Object
#
disable_video
Use this method to disable video playback. You still get the audio output of the video file of course.
#
193
194
195
|
# File 'lib/multimedia_paradise/video/video_player.rb', line 193
def disable_video
@disable_video = true
end
|
#exit_program ⇒ Object
#
exit_program
Use only this method when you want to exit from this program.
#
502
503
504
505
506
507
508
|
# File 'lib/multimedia_paradise/video/video_player.rb', line 502
def exit_program
case runmode?
when 'standalone'
exit
else end
end
|
#feedback_available_videos ⇒ Object
#
feedback_available_videos (listing tag)
Use this method to feedback all available video files.
#
489
490
491
492
493
494
495
|
# File 'lib/multimedia_paradise/video/video_player.rb', line 489
def feedback_available_videos
videos?.uniq.sort_by {|line| File.basename(line)}.each {|entry|
file = File.basename(entry)
dir = File.dirname(entry)
e ' '+sdir(dir)+'/'+sfile(file)
}
end
|
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
411
412
413
414
415
416
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
465
466
467
468
469
470
471
472
473
474
475
|
# File 'lib/multimedia_paradise/video/video_player.rb', line 380
def (
i = commandline_options?
)
if i.is_a? Array
i.each {|entry| (entry) }
else
case i when /^-?-?mma$/i
@target_location << 'Mma'
when /^-?-?breakdance$/i,
/^-?-?bdance$/i
@target_location << 'Bboying'
when /^-?-?married$/i,
/^-?-?married(_|-)?with(_|-)?children$/i,
/^-?-?with(_|-)?children$/i
@target_location << 'Comedy/MarriedWithChildren'
when /^-?-?sexy?$/i,
/^-?-?se$/i,
/^-?-?x$/i
@target_location << 'xx'
when /^-?-?simpsons?$/i,
/^-?-?cartoons?$/i,
/^-?-?s$/i,
/^-?-?simp$/i
@target_location << 'Cartoons/Simpsons' when 'HELP','--help','help?','help','hel','h','h?','?'
show_help_then_exit
when 'THIS_DIR','Dir.pwd','pwd','here','HERE'
@target_location << rds('/'+Dir.pwd+'/')
when 'listing','listing?','videos?','list',
'videos','' add_all_videos
feedback_available_videos
exit
when 'science'
@target_location << 'Science'
when 'loop',
'l',
'rvid',
'realvid',
'realvids' @target_location << File.basename(MultimediaParadise.realvids_directory?)
end
add_all_videos
end
end
|
#obtain_all_video_files ⇒ Object
#
obtain_all_video_files
#
369
370
371
372
373
374
375
|
# File 'lib/multimedia_paradise/video/video_player.rb', line 369
def obtain_all_video_files
files = Dir[@target_location+'**/**']
filter_for_video_files(files)
end
|
#play(i) ⇒ Object
#
play (play tag)
Use this method to play the respective video file in question.
We will also pad the filename.
#
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
|
# File 'lib/multimedia_paradise/video/video_player.rb', line 307
def play(i)
e 'In play() the argument was '+sfancy(i.to_s) if @debug
if i.is_a? Array
i.each {|entry| play(entry) }
else
i.strip!
i.gsub!(/ /,' ') if i.include? ' '
@count_how_many_times_we_played_already += 1
if @count_how_many_times_we_played_already > 1000
e 'We played more than 1000 files. We will exit now.'
@shall_we_exit = true
end
if @use_wrapper_over_mplayer Mplayer.new(i)
else _ = ::MultimediaParadise.which_video_player_to_use?.dup
if @disable_video
_ << ' -vo null '
else
_ << ' -vo x11' if USE_VO_X11
_ << ' -zoom' if PLAY_ZOOMED and _.include? 'mplayer'
end
save_last_video_file_played(i)
i = '"'+i+'"'
_ << ' '+i
e _
system _ end
end
end
|
#play_in_a_loop? ⇒ Boolean
261
262
263
|
# File 'lib/multimedia_paradise/video/video_player.rb', line 261
def play_in_a_loop?
@play_in_a_loop
end
|
#play_video_files(i = @array_play_these_video_files) ⇒ Object
Also known as:
play_video_file
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
|
# File 'lib/multimedia_paradise/video/video_player.rb', line 268
def play_video_files(
i = @array_play_these_video_files
)
if i.empty?
opnn; e 'Can not play any video file - our collection is empty.'
else
if play_in_a_loop?
loop {
play(random_video)
break if @shall_we_exit
}
else
play(video_files?)
end
end
end
|
#random_video(i = @matches) ⇒ Object
Also known as:
return_random_video, random_video?
#
random_video
This will return a random video.
It assumes that the @matches array exists; otherwise you will have to provide an array with all videos to this method.
#
552
553
554
|
# File 'lib/multimedia_paradise/video/video_player.rb', line 552
def random_video(i = @matches)
i[rand(i.size)]
end
|
#register_sigint ⇒ Object
#
register_sigint
Silently restore the prompt again here via reset, which is done via a system() call.
#
217
218
219
220
221
222
223
224
225
|
# File 'lib/multimedia_paradise/video/video_player.rb', line 217
def register_sigint
sigint_proc = proc {
system 'reset'
efancy 'Requested to exit from MultimediaParadise::VideoPlayer. Exiting now.'
@shall_we_exit = true
exit_program
}
Signal.trap 'SIGINT', sigint_proc
end
|
#report_filename ⇒ Object
#
report_filename
Simply prepend the filename.
#
183
184
185
|
# File 'lib/multimedia_paradise/video/video_player.rb', line 183
def report_filename
File.basename(__FILE__)+': '
end
|
#reset ⇒ Object
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
# File 'lib/multimedia_paradise/video/video_player.rb', line 112
def reset
super()
infer_the_namespace
set_be_verbose
@use_wrapper_over_mplayer = false
@debug = false @target_location = '/home/x/video/'.dup @shall_we_exit = false
@colour = DEFAULT_COLOUR
@disable_video = false
@array_play_these_video_files = []
@count_how_many_times_we_played_already = 0
@play_in_a_loop = false
set_runmode :standalone end
|
#run ⇒ Object
560
561
562
563
|
# File 'lib/multimedia_paradise/video/video_player.rb', line 560
def run
play_video_files
end
|
#runmode? ⇒ Boolean
230
231
232
|
# File 'lib/multimedia_paradise/video/video_player.rb', line 230
def runmode?
@runmode
end
|
#save_last_video_file_played(i = nil) ⇒ Object
#
save_last_video_file_played
This method saves which video file was last played.
By default it stores into “$HOME/last_video_file_played”.
#
292
293
294
295
296
297
298
|
# File 'lib/multimedia_paradise/video/video_player.rb', line 292
def save_last_video_file_played(i = nil)
if i
store_where = HOME_DIR+'last_video_file_played'
opnn; e 'Storing at `'+sfile(store_where)+'`.'
save_file(i, store_where)
end
end
|
#set_be_verbose(i = BE_VERBOSE) ⇒ Object
200
201
202
|
# File 'lib/multimedia_paradise/video/video_player.rb', line 200
def set_be_verbose(i = BE_VERBOSE)
@be_verbose = i
end
|
#set_commandline_options(i) ⇒ Object
#
set_commandline_options
#
357
358
359
360
361
362
363
364
|
# File 'lib/multimedia_paradise/video/video_player.rb', line 357
def set_commandline_options(i)
i = i.join(' ').strip if i.is_a? Array
i.delete!(',') if i.include? ','
@commandline_options = i end
|
#set_debug(i = DEBUG) ⇒ Object
207
208
209
|
# File 'lib/multimedia_paradise/video/video_player.rb', line 207
def set_debug(i = DEBUG)
@debug = DEBUG
end
|
#set_runmode(i = 'standalone') ⇒ Object
#
set_runmode
This method can be used to set the runmode.
We currently support only two runmodes:
- standalone, or
- connected.
‘s’ is an alias to standalone. Some more aliases exist, see the case menu below for details.
#
167
168
169
170
171
172
173
174
175
176
|
# File 'lib/multimedia_paradise/video/video_player.rb', line 167
def set_runmode(i = 'standalone')
i = i.to_s
case i
when 'conn'
i = 'connected'
when 's','solo','stand'
i = 'standalone'
end
@runmode = i
end
|
#show_help(prepend_this = 'Help requested. ') ⇒ Object
#
show_help (help tag)
This method will tell us which options are available for this class.
It can be invoked via these keywords:
help? help hel h h? ?
rvid –help
#
529
530
531
532
533
534
535
536
537
538
539
540
541
542
|
# File 'lib/multimedia_paradise/video/video_player.rb', line 529
def show_help(
prepend_this = 'Help requested. '
)
e prepend_this+N+N unless prepend_this.empty?
e 'These options are available:'
e
e simp(' loop')
e simp(' simpsons')
e simp(' science')
e simp(' married')
e simp(' mma')
e simp(' pwd')
e
end
|
#show_help_then_exit ⇒ Object
#
show_help_then_exit (help tag)
#
513
514
515
516
|
# File 'lib/multimedia_paradise/video/video_player.rb', line 513
def show_help_then_exit
show_help
exit
end
|
#video_files? ⇒ Boolean
Also known as:
videos?
254
255
256
|
# File 'lib/multimedia_paradise/video/video_player.rb', line 254
def video_files?
@array_play_these_video_files.flatten
end
|
#warn_then_exit(i) ⇒ Object
237
238
239
240
|
# File 'lib/multimedia_paradise/video/video_player.rb', line 237
def warn_then_exit(i)
e Colours::RED+i
exit_program
end
|