Class: MultimediaParadise::Audio::AudioPlayer
Overview
Constant Summary
collapse
- MY_SONGS =
AUDIO_DIRECTORY
- AUDIO_DIR =
MY_SONGS
- RENAME_KDE_KONSOLE_TAB =
#
RENAME_KDE_KONSOLE_TAB
#
true
- DEFAULT_DELAY_PLAYING_SONGS =
#
DEFAULT_DELAY_PLAYING_SONGS
The following constant is used for determining the audio delay between two songs.
A value of 0.0 would mean no delay, aka “instant play”, logically.
#
1.8
- MAIN_AUDIO_PLAYER_TO_USE =
We default to mpv since as of 2021.
'mpv'
- LAST_SONG_PLAYED =
'LAST_SONG_PLAYED.md'
- USE_OSS_FOR_AUDIO_PLAYER =
#
USE_OSS_FOR_AUDIO_PLAYER
#
false
- FULL_LOCATION_FOR_LAST_SONG_PLAYED =
#
FULL_LOCATION_FOR_LAST_SONG_PLAYED
#
HOME+LAST_SONG_PLAYED
- MAXIMUM_ALLOWED_FILE_SIZE =
#
MAXIMUM_ALLOWED_FILE_SIZE
#
1_350_000
- DEFAULT_PLAYMODE =
'once'
- NAME_OF_AUDIO_PLAYER =
'AudioPlayer'
- PLAY_MAX_N_SONGS =
1250
- USE_FAVOURITE_PLAYLIST =
#
USE_FAVOURITE_PLAYLIST
#
false
- AVAILABLE_SONGS =
#
AVAILABLE_SONGS
Obtain all available songs - and shuffle them a bit.
#
Dir["#{MY_SONGS}*"].shuffle
- SHALL_WE_DEBUG =
false
- PLAYLIST_CONSTANTS =
PlaylistProfile.constants
- THE_LOG_FILE_IS_STORED_HERE =
#
THE_LOG_FILE_IS_STORED_HERE
#
"#{MultimediaParadise.log_dir?}"\
"log_file_for_played_songs_via_the_audio_player.md"
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
-
#add_all_songs ⇒ Object
(also: #play_all_songs)
# === add_all_songs ========================================================================= #.
-
#add_random_song ⇒ Object
# === add_random_song.
-
#add_song(i = nil) ⇒ Object
(also: #add, #add_to_playlist, #add_this_song_to_playlist, #add_this_song, #add_songs)
# === add_song (add tag).
-
#audio_dir? ⇒ Boolean
# === audio_dir? ========================================================================= #.
-
#audio_player_to_use? ⇒ Boolean
(also: #audio_player?, #use_which_audio_player?)
# === audio_player_to_use? ========================================================================= #.
-
#check_whether_the_song_directory_is_empty ⇒ Object
# === check_whether_the_song_directory_is_empty ========================================================================= #.
-
#consider_renaming_the_kde_konsole_tab(i) ⇒ Object
# === consider_renaming_the_kde_konsole_tab ========================================================================= #.
-
#consider_resetting_kde_konsole_tab(use_this_as_the_new_title = '.') ⇒ Object
# === consider_resetting_kde_konsole_tab.
-
#delay? ⇒ Boolean
# === delay? ========================================================================= #.
-
#determine_which_audio_player_to_use(i = @main_audio_player_to_use, overrule_if_environment_variable_was_set = true) ⇒ Object
# === determine_which_audio_player_to_use.
-
#do_play_in_a_loop ⇒ Object
# === do_play_in_a_loop ========================================================================= #.
-
#do_rename_konsole(i = '.', *optional_arguments_that_are_irrelevant) ⇒ Object
# === do_rename_konsole ========================================================================= #.
-
#exit_program(shall_we_exit = shall_we_exit?, , be_verbose = true, &block) ⇒ Object
# === exit_program.
-
#get_file_size(of_this_file = the_songs_played_will_be_stored_where? ) ⇒ Object
# === get_file_size ========================================================================= #.
-
#initialize(i = nil, run_already = true) ⇒ AudioPlayer
constructor
# === initialize ========================================================================= #.
-
#input? ⇒ Boolean
(also: #play_these_songs, #playlist?)
-
#main_colour? ⇒ Boolean
(also: #mcol?)
# === main_colour? ========================================================================= #.
-
#menu(i) ⇒ Object
(also: #check_against_menu)
-
#obtain_file_duration_from_this_file(i) ⇒ Object
# === obtain_file_duration_from_this_file(i) ========================================================================= #.
-
#pause(n_seconds = delay? ) ⇒ Object
# === pause (pause tag).
-
#perform_cleanup ⇒ Object
-
#play_the_playlist(playlist = playlist? ) ⇒ Object
# === play_the_playlist ========================================================================= #.
-
#play_this_song(i, be_verbose = true) ⇒ Object
# === play_this_song (play tag).
-
#populate_hash_songs_played ⇒ Object
# === populate_hash_songs_played.
-
#refresh_playlist ⇒ Object
# === refresh_playlist.
-
#register_sigint ⇒ Object
# === register_sigint.
-
#register_this_song(this_song) ⇒ Object
# === register_this_song.
-
#register_which_song_was_last_played(this_song, store_where_to = the_songs_played_will_be_stored_where? ) ⇒ Object
(also: #register_which_song_will_be_played_next)
# === register_which_song_was_last_played.
-
#report_which_audio_player_to_use ⇒ Object
# === report_which_audio_player_to_use ========================================================================= #.
-
#reset ⇒ Object
# === reset (reset tag) ========================================================================= #.
-
#reset_playlist ⇒ Object
(also: #clear_playlist)
# === reset_playlist ========================================================================= #.
-
#return_all_songs ⇒ Object
(also: #all_songs, #get_all_songs, #determine_available_songs, #all_songs?)
# === return_all_songs.
-
#return_random_song ⇒ Object
(also: #fetch_random_song, #get_random_song)
# === return_random_song.
-
#run ⇒ Object
# === run (run tag) ========================================================================= #.
-
#sanitize_songs ⇒ Object
# === sanitize_songs ========================================================================= #.
-
#set_commandline_options_and_return_the_other_options(i) ⇒ Object
# === set_commandline_options_and_return_the_other_options ========================================================================= #.
-
#set_delay(i = DEFAULT_DELAY_PLAYING_SONGS) ⇒ Object
# === set_delay.
-
#set_shall_we_exit(i = true) ⇒ Object
# === set_shall_we_exit ========================================================================= #.
-
#shall_we_exit? ⇒ Boolean
# === shall_we_exit? ========================================================================= #.
-
#show_available_genres ⇒ Object
# === show_available_genres ========================================================================= #.
-
#show_help(optional_shall_we_exit = false) ⇒ Object
# === show_help (help tag).
-
#show_last_file_played(_ = the_songs_played_will_be_stored_where? ) ⇒ Object
# === show_last_file_played.
-
#show_startup_message ⇒ Object
# === show_startup_message.
-
#show_the_last_songs_that_were_played ⇒ Object
# === show_the_last_songs_that_were_played.
-
#show_the_log_file_if_it_exists(log_file = THE_LOG_FILE_IS_STORED_HERE) ⇒ Object
# === show_the_log_file_if_it_exists.
-
#show_the_playlist ⇒ Object
(also: #show_songs)
# === show_the_playlist ========================================================================= #.
-
#shuffle_the_playlist ⇒ Object
(also: #shuffle)
# === shuffle_the_playlist ========================================================================= #.
-
#store_data_about_this_song_into_a_local_file(this_song) ⇒ Object
# === store_data_about_this_song_into_a_local_file ========================================================================= #.
-
#the_songs_played_will_be_stored_where? ⇒ Boolean
# === the_songs_played_will_be_stored_where? ========================================================================= #.
-
#try_to_find_genre_song(i) ⇒ Object
# === try_to_find_genre_song.
-
#try_to_play_playlist ⇒ Object
# === try_to_play_playlist ========================================================================= #.
#directory_to_the_local_songs?, #return_random_audio_file
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(i = nil, run_already = true) ⇒ AudioPlayer
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
# File 'lib/multimedia_paradise/audio/audio_player/audio_player.rb', line 176
def initialize(
i = nil,
run_already = true
)
register_sigint { :pretty }
reset
if i
i = set_commandline_options_and_return_the_other_options(i)
(i)
end
case run_already
when :default
run_already = true
when :dont_run_yet,
:do_not_run_yet
run_already = false
end
run if run_already
end
|
Instance Method Details
#add_all_songs ⇒ Object
Also known as:
play_all_songs
532
533
534
|
# File 'lib/multimedia_paradise/audio/audio_player/audio_player.rb', line 532
def add_all_songs
add(all_songs?)
end
|
#add_random_song ⇒ Object
#
add_random_song
This will add exactly one random song.
#
431
432
433
|
# File 'lib/multimedia_paradise/audio/audio_player/audio_player.rb', line 431
def add_random_song
add_song(return_random_song)
end
|
#add_song(i = nil) ⇒ Object
Also known as:
add, add_to_playlist, add_this_song_to_playlist, add_this_song, add_songs
#
add_song (add tag)
This method will add the particular song to the playlist.
It will check whether it is an multimedia-file prior to adding it, though.
#
640
641
642
643
644
645
646
647
648
649
650
651
|
# File 'lib/multimedia_paradise/audio/audio_player/audio_player.rb', line 640
def add_song(
i = nil
)
unless i.nil?
[i].flatten.compact.each {|this_song|
if is_a_multimedia_file?(this_song)
@array_play_these_songs << this_song
end
}
sanitize_songs
end
end
|
#audio_dir? ⇒ Boolean
507
508
509
|
# File 'lib/multimedia_paradise/audio/audio_player/audio_player.rb', line 507
def audio_dir?
AUDIO_DIR
end
|
#audio_player_to_use? ⇒ Boolean
Also known as:
audio_player?, use_which_audio_player?
817
818
819
|
# File 'lib/multimedia_paradise/audio/audio_player/audio_player.rb', line 817
def audio_player_to_use?
@audio_player_to_use
end
|
#check_whether_the_song_directory_is_empty ⇒ Object
#
check_whether_the_song_directory_is_empty
#
558
559
560
561
562
563
564
|
# File 'lib/multimedia_paradise/audio/audio_player/audio_player.rb', line 558
def check_whether_the_song_directory_is_empty
if return_all_songs.empty?
opne 'No songs found in `'+sdir(audio_dir?)+'`.'
opne 'Perhaps you forgot to copy some songs first?'
exit_program(:force_exit)
end
end
|
#consider_renaming_the_kde_konsole_tab(i) ⇒ Object
#
consider_renaming_the_kde_konsole_tab
#
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
|
# File 'lib/multimedia_paradise/audio/audio_player/audio_player.rb', line 929
def consider_renaming_the_kde_konsole_tab(i)
if Object.const_defined? :Roebe
begin
i = File.basename(i).
gsub(/#{File.extname(i)}$/,'').
tr('_',' ')
rescue ArgumentError => error
opne 'An error happened (ArgumentError) which is now displayed:'
pp error
end
Roebe.rename_konsole(i)
end if RENAME_KDE_KONSOLE_TAB
end
|
#consider_resetting_kde_konsole_tab(use_this_as_the_new_title = '.') ⇒ Object
#
consider_resetting_kde_konsole_tab
This method can be used to re-set the KDE konsole tab name.
#
674
675
676
677
678
679
680
|
# File 'lib/multimedia_paradise/audio/audio_player/audio_player.rb', line 674
def consider_resetting_kde_konsole_tab(
use_this_as_the_new_title = '.'
)
do_rename_konsole(
use_this_as_the_new_title, RENAME_KDE_KONSOLE_TAB
)
end
|
#delay? ⇒ Boolean
825
826
827
|
# File 'lib/multimedia_paradise/audio/audio_player/audio_player.rb', line 825
def delay?
@internal_hash[:delay].to_s
end
|
#determine_which_audio_player_to_use(i = @main_audio_player_to_use, overrule_if_environment_variable_was_set = true) ⇒ Object
#
determine_which_audio_player_to_use
This method will determine which audio play is to be used, for playing the audio files. Currently the two primary ones that I use are mplayer and mpv. Note that the environment variable MAIN_AUDIO_PLAYER can overrule this completely, if set.
#
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
|
# File 'lib/multimedia_paradise/audio/audio_player/audio_player.rb', line 277
def determine_which_audio_player_to_use(
i = @main_audio_player_to_use,
overrule_if_environment_variable_was_set = true
)
case overrule_if_environment_variable_was_set
when :ignore_environment_variable
overrule_if_environment_variable_was_set = false
end
case i
when 'sox',
:sox
i = 'play' end
if overrule_if_environment_variable_was_set
if ENV.has_key? 'MAIN_AUDIO_PLAYER'
i = ENV['MAIN_AUDIO_PLAYER'].to_s.dup
end
end
@audio_player_to_use = i.to_s end
|
#do_play_in_a_loop ⇒ Object
445
446
447
|
# File 'lib/multimedia_paradise/audio/audio_player/audio_player.rb', line 445
def do_play_in_a_loop
@play_in_a_loop = true
end
|
#do_rename_konsole(i = '.', *optional_arguments_that_are_irrelevant) ⇒ Object
768
769
770
771
772
773
774
|
# File 'lib/multimedia_paradise/audio/audio_player/audio_player.rb', line 768
def do_rename_konsole(
i = '.', *optional_arguments_that_are_irrelevant
)
if Object.const_defined? :Roebe
Roebe.rename_konsole(i)
end
end
|
#exit_program(shall_we_exit = shall_we_exit?,
, be_verbose = true, &block) ⇒ Object
#
exit_program
This method can be used to exit this program.
#
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
|
# File 'lib/multimedia_paradise/audio/audio_player/audio_player.rb', line 571
def exit_program(
shall_we_exit = shall_we_exit?,
be_verbose = true,
&block
)
case shall_we_exit
when :force_exit
shall_we_exit = true
when :force_exit_but_be_quiet
shall_we_exit = true
be_verbose = false
end
if block_given?
yielded = yield
case yielded
when :be_quiet
be_verbose = false
end
end
if shall_we_exit
@mrxvt.set_title('') if @mrxvt
if be_verbose
efancy 'Leaving ...'
efancy 'Hopefully you had fun and found class'\
'MultimediaParadise::Audio::AudioPlayer useful. Bye!'
end
consider_resetting_kde_konsole_tab
exit
else
e "Won't exit as we are not allowed to exit."
end
end
|
#get_file_size(of_this_file = the_songs_played_will_be_stored_where?
) ⇒ Object
372
373
374
375
376
377
378
|
# File 'lib/multimedia_paradise/audio/audio_player/audio_player.rb', line 372
def get_file_size(
of_this_file = the_songs_played_will_be_stored_where?
)
size = 0
size = File.size(of_this_file) if File.exist?(of_this_file)
size
end
|
620
621
622
|
# File 'lib/multimedia_paradise/audio/audio_player/audio_player.rb', line 620
def input?
@array_play_these_songs
end
|
#main_colour? ⇒ Boolean
Also known as:
mcol?
471
472
473
|
# File 'lib/multimedia_paradise/audio/audio_player/audio_player.rb', line 471
def main_colour?
@main_colour
end
|
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
|
# File 'lib/multimedia_paradise/audio/audio_player/audio_player.rb', line 953
def (i)
if i.is_a? Array
if i.empty?
i = 'loop'
else
i = i.join(' ').strip
end
end
i = i.to_s.strip
if i =~ /^\d+$/ opne "#{rev}We will next play #{simp(i.to_s)} #{rev}songs."
i.to_i.times { add_random_song }
elsif i =~ /^\d{1,2}:\d{1,2}:\d{1,2}$/ begin
require 'roebe/classes/at.rb'
Roebe::At.new(i)
do_play_in_a_loop rescue LoadError
e 'The file roebe/classes/at.rb is not available.'
end
else
case i when 'once','noloop','default','all', '','true','false',
'all_songs',
'play_all_songs'
opne 'We will play all available Audio files once.'
add_all_songs
when *ARRAY_HELP_OPTIONS
show_help :then_exit
when /^-?-?last(-|_)?songs\??$/i
show_the_last_songs_that_were_played
exit_program { :be_quiet }
when /^-?-?use(-|_)?sox/
determine_which_audio_player_to_use(
:sox, :ignore_environment_variable
)
when /^-?-?use(-|_)?mplayer/
determine_which_audio_player_to_use(
:mplayer, :ignore_environment_variable
)
when /^-?-?log\??$/i
show_the_log_file_if_it_exists
exit_program(:force_exit_but_be_quiet)
when /^-?-?OPEN$/i
esystem "bluefish #{__FILE__}"
exit_program(:force_exit)
when /^-?-?player\??$/
report_which_audio_player_to_use
exit_program { :be_quiet }
when 'random',
'return_random_song',
'rand',
'one' add_random_song
when 'list','chill','1'
if Object.const_defined? :PlaylistProfile
these_songs = PlaylistProfile::GOOD_CHILL_SONGS.map {|entry|
audio_dir?+entry
}
add(these_songs.shuffle)
end
when /playlist\??/i
try_to_play_playlist
when 'last?'
show_last_file_played
when 'dance','bdance','breakdance' these_songs = PlaylistProfile::GOOD_BDANCE_SONGS.shuffle.map {|entry|
audio_dir?+entry
}
add(these_songs.shuffle)
when 'loop','l','nil'
opne "#{main_colour?}Playing in a neverending #{sfancy('loop')}"\
"#{main_colour?} next:"
do_play_in_a_loop
when 'genre','GENRES','genres','GENRE'
unless ARGV[1]
show_available_genres
exit_program(:force_exit)
end
else entries = Dir['*'+i+'*']
unless entries.empty?
add_songs(entries)
else
try_to_find_genre_song(i)
end
end
end
end
|
#obtain_file_duration_from_this_file(i) ⇒ Object
#
obtain_file_duration_from_this_file(i)
#
169
170
171
|
# File 'lib/multimedia_paradise/audio/audio_player/audio_player.rb', line 169
def obtain_file_duration_from_this_file(i)
action(:FileDuration, i)
end
|
#pause(n_seconds = delay?
) ⇒ Object
#
pause (pause tag)
Pause for n_seconds (the first input to this method).
This method will NOT seet a new, random song - for this, you need to use another method.
#
709
710
711
712
713
714
715
716
717
718
719
720
|
# File 'lib/multimedia_paradise/audio/audio_player/audio_player.rb', line 709
def pause(
n_seconds = delay?
)
n_seconds = n_seconds.to_f cliner
e "#{true_rev}We will pause for #{sfancy(n_seconds)} #{rev}seconds."
cliner_with_time_stamp
e "#{rev}The next song will be: "\
"#{sfancy(playlist?[@n_songs_played])}"
cliner
sleep(n_seconds)
end
|
#
We get rid of @ivars which are not too useful.
#
551
552
553
|
# File 'lib/multimedia_paradise/audio/audio_player/audio_player.rb', line 551
def perform_cleanup
remove_instance_variable :@available_genres
end
|
#play_the_playlist(playlist = playlist?
) ⇒ Object
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
|
# File 'lib/multimedia_paradise/audio/audio_player/audio_player.rb', line 857
def play_the_playlist(
playlist = playlist?
)
if @play_in_a_loop counter = 0
loop {
playlist.each {|song|
play_this_song(song)
pause unless @n_songs_played == playlist.size
counter += 1
break if counter > @play_max_n_songs
}
refresh_playlist
}
else
playlist.each {|song|
play_this_song(song)
pause unless @n_songs_played == playlist.size
} end
end
|
#play_this_song(i, be_verbose = true) ⇒ Object
#
play_this_song (play tag)
This is the actual method that will play the song.
We will also append the filename last played.
#
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
|
# File 'lib/multimedia_paradise/audio/audio_player/audio_player.rb', line 729
def play_this_song(
i, be_verbose = true
)
if be_verbose
e; opne 'The next song we will play via '+
simp(audio_player_to_use?)+"#{rev} is:"
e "#{N} #{sfancy(i)}#{N}#{N}"
end
if File.extname(i) == '.mp3'
begin
@file_duration_in_seconds = obtain_file_duration_from_this_file(i)
if be_verbose
e "#{rev}The length of this song is: "+
sfancy(@file_duration_in_seconds.to_i)+rev+' seconds.'
end
rescue Exception => error
e error
end
end
e " #{sfile(i)}" if be_verbose
consider_renaming_the_kde_konsole_tab(i)
_ = audio_player?.dup
_ << ' -ao oss' if @use_oss_for_audio_player
_ << ' '+i.dup
register_which_song_will_be_played_next(i)
esystem _
@n_songs_played += 1
end
|
#populate_hash_songs_played ⇒ Object
#
populate_hash_songs_played
Fills up our hash with available data for the first time. Basically right now, only manipulates @hash_songs_played
#
352
353
354
355
356
357
|
# File 'lib/multimedia_paradise/audio/audio_player/audio_player.rb', line 352
def populate_hash_songs_played
playlist?.each { |song|
song = File.basename(song)
@hash_songs_played[song] = 0
}
end
|
#refresh_playlist ⇒ Object
#
refresh_playlist
First clears the playlist, then adds all available songs.
#
541
542
543
544
|
# File 'lib/multimedia_paradise/audio/audio_player/audio_player.rb', line 541
def refresh_playlist
clear_playlist
add_all_songs
end
|
#register_sigint ⇒ Object
#
register_sigint
Will act upon SIGINT recieved, and properly shut down.
#
662
663
664
665
666
667
|
# File 'lib/multimedia_paradise/audio/audio_player/audio_player.rb', line 662
def register_sigint
Signal.trap('SIGINT') {
consider_resetting_kde_konsole_tab
exit_program(true)
}
end
|
#register_this_song(this_song) ⇒ Object
#
register_this_song
This method should be invoked whenever you want to play a new song.
We will only keep the filename, not the full location.
#
518
519
520
521
522
523
524
525
526
527
|
# File 'lib/multimedia_paradise/audio/audio_player/audio_player.rb', line 518
def register_this_song(this_song)
if @hash_songs_played
this_song = File.basename(this_song)
if @hash_songs_played.has_key? this_song
@hash_songs_played[this_song] = @hash_songs_played[this_song] + 1
else
@hash_songs_played[this_song] = 1 end
end
end
|
#register_which_song_was_last_played(this_song, store_where_to = the_songs_played_will_be_stored_where?
) ⇒ Object
Also known as:
register_which_song_will_be_played_next
#
register_which_song_was_last_played
This method will also check if the file that is being played is too big. If it is, we will remove the log-file.
#
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
|
# File 'lib/multimedia_paradise/audio/audio_player/audio_player.rb', line 885
def register_which_song_was_last_played(
this_song,
store_where_to = the_songs_played_will_be_stored_where?
)
$stdout.flush FileUtils.touch(store_where_to) unless File.exist?(store_where_to)
if get_file_size(store_where_to) > MAXIMUM_ALLOWED_FILE_SIZE
remove_file(store_where_to)
end
unless store_where_to.include? '/'
store_where_to = HOME_DIRECTORY+store_where_to
end append_what_into(this_song+N, store_where_to)
register_this_song(this_song)
store_data_about_this_song_into_a_local_file(this_song)
end
|
#report_which_audio_player_to_use ⇒ Object
#
report_which_audio_player_to_use
#
307
308
309
310
|
# File 'lib/multimedia_paradise/audio/audio_player/audio_player.rb', line 307
def report_which_audio_player_to_use
opne rev+'The audio player '+sfancy(@audio_player_to_use)+
rev+' will be used.'
end
|
#reset ⇒ Object
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
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
260
261
262
263
264
265
266
267
|
# File 'lib/multimedia_paradise/audio/audio_player/audio_player.rb', line 205
def reset
super()
clear_playlist
set_delay set_shall_we_exit
infer_the_namespace
set_use_colours @main_colour = Colours.parse('green')
@play_in_a_loop = false
determine_which_audio_player_to_use
@internal_hash[:debug] = SHALL_WE_DEBUG
@hash_songs_played = {} @play_max_n_songs = PLAY_MAX_N_SONGS if Object.const_defined? :MrxvtOptions
@mrxvt = MrxvtOptions.new
else
@mrxvt = nil
end
@main_audio_player_to_use = MAIN_AUDIO_PLAYER_TO_USE
@use_oss_for_audio_player = USE_OSS_FOR_AUDIO_PLAYER
@file_duration_in_seconds = 0 @n_songs_played = 0 @available_genres = nil @available_genres = PLAYLIST_CONSTANTS.map {|song|
song.to_s.sub(/GOOD_/,'').
sub(/_SONGS/,'').
sub(/MY_/,'').
sub(/CURRENT_/,'')
} if defined? PLAYLIST_CONSTANTS
end
|
#reset_playlist ⇒ Object
Also known as:
clear_playlist
500
501
502
|
# File 'lib/multimedia_paradise/audio/audio_player/audio_player.rb', line 500
def reset_playlist
@array_play_these_songs = [] end
|
#return_all_songs ⇒ Object
Also known as:
all_songs, get_all_songs, determine_available_songs, all_songs?
#
return_all_songs
By default, we will shuffle.
#
480
481
482
|
# File 'lib/multimedia_paradise/audio/audio_player/audio_player.rb', line 480
def return_all_songs
return AVAILABLE_SONGS.shuffle
end
|
#return_random_song ⇒ Object
Also known as:
fetch_random_song, get_random_song
#
return_random_song
This method will return one random song.
#
492
493
494
|
# File 'lib/multimedia_paradise/audio/audio_player/audio_player.rb', line 492
def return_random_song
return_all_songs.first
end
|
#run ⇒ Object
1108
1109
1110
1111
1112
1113
1114
|
# File 'lib/multimedia_paradise/audio/audio_player/audio_player.rb', line 1108
def run
populate_hash_songs_played
show_startup_message
check_whether_the_song_directory_is_empty
play_the_playlist
perform_cleanup
end
|
#sanitize_songs ⇒ Object
628
629
630
|
# File 'lib/multimedia_paradise/audio/audio_player/audio_player.rb', line 628
def sanitize_songs
playlist?.flatten! end
|
#set_commandline_options_and_return_the_other_options(i) ⇒ Object
#
set_commandline_options_and_return_the_other_options
#
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
|
# File 'lib/multimedia_paradise/audio/audio_player/audio_player.rb', line 326
def set_commandline_options_and_return_the_other_options(i)
unless i.is_a? Symbol
if i.respond_to?(:any?) and i.any? {|line|
line.start_with? '--'
}
@commandline_options = i.select {|inner_line|
inner_line.start_with? '--'
}
(@commandline_options)
i.reject! {|entry|
entry.start_with? '--'
}
end
end
i
end
|
#set_delay(i = DEFAULT_DELAY_PLAYING_SONGS) ⇒ Object
#
set_delay
This sets the default delay, when playing the audio songs in a loop.
#
365
366
367
|
# File 'lib/multimedia_paradise/audio/audio_player/audio_player.rb', line 365
def set_delay(i = DEFAULT_DELAY_PLAYING_SONGS)
@internal_hash[:delay] = i
end
|
#set_shall_we_exit(i = true) ⇒ Object
383
384
385
|
# File 'lib/multimedia_paradise/audio/audio_player/audio_player.rb', line 383
def set_shall_we_exit(i = true)
@shall_we_exit = i
end
|
#shall_we_exit? ⇒ Boolean
398
399
400
|
# File 'lib/multimedia_paradise/audio/audio_player/audio_player.rb', line 398
def shall_we_exit?
@shall_we_exit
end
|
#show_available_genres ⇒ Object
#
show_available_genres
#
390
391
392
393
|
# File 'lib/multimedia_paradise/audio/audio_player/audio_player.rb', line 390
def show_available_genres
opne "#{rev}The available genres are:"
pp @available_genres
end
|
#show_help(optional_shall_we_exit = false) ⇒ Object
#
show_help (help tag)
Show help here, then exit.
#
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
|
# File 'lib/multimedia_paradise/audio/audio_player/audio_player.rb', line 834
def show_help(
optional_shall_we_exit = false
)
cliner
opne 'Showing the available help options next:'
e
' - OPEN # open this file in the editor'
' - loop # play in an eternal loop'
' - rand # play one random song'
' - once # play all songs once, then quit'
' - last? # show the last song played'
' - player? # show which multimedia-player we will use'
' - log? # show the log file of last-songs-played (if this file exists)'
' - last-songs? # show the last songs that '\
'were played, in a time-sorted manner'
e
cliner
exit_program(true, false) if optional_shall_we_exit == :then_exit
end
|
#show_last_file_played(_ = the_songs_played_will_be_stored_where?
) ⇒ Object
#
show_last_file_played
This method will show the last song played.
#
407
408
409
410
411
412
413
414
415
416
417
|
# File 'lib/multimedia_paradise/audio/audio_player/audio_player.rb', line 407
def show_last_file_played(
_ = the_songs_played_will_be_stored_where?
)
if File.exist? _
e 'The last song played was:'
efancy(' '+File.readlines(_)[-1])
exit_program
else
ewarn 'But the file '+sfile(_)+RED+' does not exist.'
end
end
|
#show_startup_message ⇒ Object
#
show_startup_message
Display a fancy startup message.
#
317
318
319
320
321
|
# File 'lib/multimedia_paradise/audio/audio_player/audio_player.rb', line 317
def show_startup_message
e N+main_colour?+' => Starting Audio Player '+
simp(use_which_audio_player?)+main_colour?+' ('+
sfancy('Default delay: ')+delay?+mcol?+').'+N
end
|
#show_the_last_songs_that_were_played ⇒ Object
#
show_the_last_songs_that_were_played
The songs played will be stored in a .md file.
Invocation example:
rsong --last-songs?
#
916
917
918
919
920
921
922
923
924
|
# File 'lib/multimedia_paradise/audio/audio_player/audio_player.rb', line 916
def show_the_last_songs_that_were_played
_ = the_songs_played_will_be_stored_where?
if File.exist? _
dataset = File.readlines(_)
dataset.each {|this_song| e steelblue(this_song.strip) }
else
no_file_exists_at(_)
end
end
|
#show_the_log_file_if_it_exists(log_file = THE_LOG_FILE_IS_STORED_HERE) ⇒ Object
#
show_the_log_file_if_it_exists
Invocation example:
rsong --log?
#
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
|
# File 'lib/multimedia_paradise/audio/audio_player/audio_player.rb', line 798
def show_the_log_file_if_it_exists(
log_file = THE_LOG_FILE_IS_STORED_HERE
)
if File.exist? log_file
opne 'Displaying the content of the file at'
opne '`'+sfile(log_file)+'`:'
dataset = File.readlines(log_file).map {|entry| entry.rstrip }
e
e mediumpurple(
dataset.map {|entry| " #{entry}" }.join("\n")
)
else
opnn; no_file_exists_at(log_file)
end
end
|
#show_the_playlist ⇒ Object
Also known as:
show_songs
463
464
465
466
|
# File 'lib/multimedia_paradise/audio/audio_player/audio_player.rb', line 463
def show_the_playlist
opne 'The playlist is:'
pp playlist?
end
|
#shuffle_the_playlist ⇒ Object
Also known as:
shuffle
438
439
440
|
# File 'lib/multimedia_paradise/audio/audio_player/audio_player.rb', line 438
def shuffle_the_playlist
playlist?.shuffle!
end
|
#store_data_about_this_song_into_a_local_file(this_song) ⇒ Object
#
store_data_about_this_song_into_a_local_file
#
779
780
781
782
783
784
785
786
787
788
|
# File 'lib/multimedia_paradise/audio/audio_player/audio_player.rb', line 779
def store_data_about_this_song_into_a_local_file(
this_song
)
into = THE_LOG_FILE_IS_STORED_HERE
what = "song name: #{this_song.ljust(30)}, "\
"played on #{dd_mm_yyyy}, #{hh_mm_ss}\n"
dirname = File.dirname(into)
mkdir(dirname) unless File.directory? dirname
append_what_into(what, into)
end
|
#the_songs_played_will_be_stored_where? ⇒ Boolean
#
the_songs_played_will_be_stored_where?
#
422
423
424
|
# File 'lib/multimedia_paradise/audio/audio_player/audio_player.rb', line 422
def the_songs_played_will_be_stored_where?
FULL_LOCATION_FOR_LAST_SONG_PLAYED
end
|
#try_to_find_genre_song(i) ⇒ Object
#
try_to_find_genre_song
This tries to find a (random) genre song.
#
687
688
689
690
691
692
693
694
695
696
697
698
699
|
# File 'lib/multimedia_paradise/audio/audio_player/audio_player.rb', line 687
def try_to_find_genre_song(i)
upcased = i.to_s.upcase
if @available_genres.grep(/#{upcased}/)
matches = PLAYLIST_CONSTANTS.select {|entry| entry =~ /#{upcased}/ }[0]
if matches.nil? these_songs = Dir[audio_dir?+'*'+i+'*']
end
these_songs = PlaylistProfile.module_eval(matches.to_s).map {|entry|
audio_dir?+entry
} if matches
add_song(these_songs.shuffle)
end if @available_genres
end
|
#try_to_play_playlist ⇒ Object
452
453
454
455
456
457
458
|
# File 'lib/multimedia_paradise/audio/audio_player/audio_player.rb', line 452
def try_to_play_playlist
begin
require 'x/AUD/playlist.rb'
add(Playlist.playlist?)
shuffle
rescue LoadError; end
end
|