Class: MultimediaParadise::Playlist

Inherits:
AudioBase show all
Defined in:
lib/multimedia_paradise/audio/playlist/playlist.rb

Overview

MultimediaParadise::Playlist

Constant Summary collapse

NAMESPACE =
#

NAMESPACE

#
inspect
REPORT_NAMESPACE =
#

REPORT_NAMESPACE

If true then we will use opnn to report the namespace.

#
false
PLAYLIST_M3U_FILE =
#

PLAYLIST_M3U_FILE

#
'playlist.m3u'
DEFAULT_NAME_FOR_THE_M3U_PLAYLIST =

DEFAULT_NAME_FOR_THE_M3U_PLAYLIST

PLAYLIST_M3U_FILE
ARRAY_REGISTERED_GENRES =
#

ARRAY_REGISTERED_GENRES

#
%w(
  eurodance
  trance
  hip_hop
  italian
  boogie
  the_1980s
)
ARRAY_REGISTERED_AUDIO_TAGS =
#

ARRAY_REGISTERED_AUDIO_TAGS

This is similar to registered genres but only valid for my local audio collection - meaning that we will use some extra tags.

As of May 2017, this has 6 registered entries. As of 2019, there are more than 6 registered entries now.

#
ARRAY_REGISTERED_GENRES + %w(
  movie
  pop
  techno
)
PLAYLIST_FILE =

This one should be valid for most users.

'/tmp/playlist.yml'

Constants inherited from Base

Base::ERROR, Base::ERROR_LINE, 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 AudioBase

#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, #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?, #use_which_video_player?, #verbose_truth, #video_collection?, #violet, #yaml_directory?, #yel

Methods included from CommandlineArgumentsModule

#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, &block) ⇒ Playlist

#

initialize

#


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/multimedia_paradise/audio/playlist/playlist.rb', line 46

def initialize(
    commandline_arguments = nil,
    run_already           = true,
    &block
  )
  register_sigint {
    :clear_kde_konsole_tab_on_exit_if_is_on_roebe
  }
  reset
  consider_requiring_the_kde_konsole_specific_files
  set_commandline_arguments(
    commandline_arguments
  )
  case run_already
  # ======================================================================= #
  # === :dont_run_yet
  # ======================================================================= #
  when :dont_run_yet,
       :do_not_run_yet
    run_already = false
  end
  # ======================================================================= #
  # === Handle blocks given to .new() next
  # ======================================================================= #
  if block_given?
    yielded = yield
    case yielded
    # ===================================================================== #
    # === :do_not_run_yet
    # ===================================================================== #
    when :do_not_run_yet,
         :dont_run_yet
      run_already = false
    # ===================================================================== #
    # === :be_quiet
    # ===================================================================== #
    when :be_quiet
      set_be_quiet
    end
  end
  run if run_already
end

Class Method Details

.add(i) ⇒ Object

#

MultimediaParadise::Playlist.add

#


188
189
190
191
192
193
194
# File 'lib/multimedia_paradise/audio/playlist/playlist.rb', line 188

def self.add(i)
  if i.is_a? Array
    i.each {|entry| Playlist.add(entry) } # A recursive call.
  else
    Playlist.new.add(i)
  end
end

.playlist?Boolean

#

MultimediaParadise::Playlist.playlist?

Feedback which playlist is in use.

#

Returns:

  • (Boolean)


1367
1368
1369
# File 'lib/multimedia_paradise/audio/playlist/playlist.rb', line 1367

def self.playlist?
  MultimediaParadise::Playlist.new(:dont_run_yet) { :be_quiet }.playlist?
end

.show_playlistObject

#

MultimediaParadise::Playlist.show_playlist

#


1647
1648
1649
# File 'lib/multimedia_paradise/audio/playlist/playlist.rb', line 1647

def self.show_playlist
  new { :do_not_run_yet }.show_playlist
end

Instance Method Details

#add(i) ⇒ Object

#

add (add tag)

Use this method to add a song to the playlist.

#


167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/multimedia_paradise/audio/playlist/playlist.rb', line 167

def add(i)
  i = i.to_s
  i = rds(return_pwd+i) unless i.include? '/'
  if @playlist.include?(i)
    opne rev+'We will not add the file '+konsole_colour_peru(i)
    opne 'as it already is a part of this playlist.'
  elsif File.exist?(i) and File.directory?(i)
    opne 'Can not add '+sdir(i)+' because it is a directory.'
    opne 'We can only add files to the playlist, for now.'
    opne 'Please provide a file as argument.'
  else
    opne "#{rev}Now adding the file #{konsole_colour_peru(i)}"
    opne "to our playlist at `#{sfile(playlist_location?)}`."
    @playlist << i
    save_yaml_dataset
  end
end

#add_this_entry(i) ⇒ Object

#

add_this_entry

Pass a file to this method.

#


144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/multimedia_paradise/audio/playlist/playlist.rb', line 144

def add_this_entry(i)
  i = i.join(' ') if i.is_a? Array
  i = i.to_s.delete('+')
  i = i.dup if i.frozen?
  if i.start_with? '-add'
    i[0, '-add'.size] = ''
  end
  i.strip!
  if File.exist? i # If the file exists in the current directory.
    this_entry = i
  elsif File.exist? SONG_DIR+i
    this_entry = SONG_DIR+i
  else
    this_entry = return_entry_from_this_position(i)
  end
  add(this_entry)
end

#add_to_play_these_songs(*i) ⇒ Object Also known as: add_to_playlist

#

add_to_play_these_songs

#


132
133
134
135
136
137
# File 'lib/multimedia_paradise/audio/playlist/playlist.rb', line 132

def add_to_play_these_songs(*i)
  i.flatten.each {|entry|
    @array_these_songs_will_be_played << entry
    @array_these_songs_will_be_played.flatten!
  }
end

#all_songsBoolean

#

playlist?

#

all_songs

Returns:

  • (Boolean)


992
993
994
# File 'lib/multimedia_paradise/audio/playlist/playlist.rb', line 992

def playlist?
  @playlist
end

#array_these_songs_will_be_played?Boolean

#

array_these_songs_will_be_played?

#

Returns:

  • (Boolean)


1619
1620
1621
# File 'lib/multimedia_paradise/audio/playlist/playlist.rb', line 1619

def array_these_songs_will_be_played?
  @array_these_songs_will_be_played
end

#ask_interactively_in_batch_format_for_each_audio_fileObject

#

ask_interactively_in_batch_format_for_each_audio_file

To invoke this, try:

playlist --batch
#


1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
# File 'lib/multimedia_paradise/audio/playlist/playlist.rb', line 1034

def ask_interactively_in_batch_format_for_each_audio_file
  opne 'We will now ask you for every audio file in the current'
  opne 'directory whether you want to add it into the playlist.'
  audio_files = Dir['*'].select {|file|
    MultimediaParadise.is_audio_file? file
  }.sort
  audio_files.each {|file|
    e 'Do you want to add the file '+sfile(file)+' to the playlist? [y/n]'
    user_input = $stdin.getch # Only evaluate the first character, at once.
    case user_input
    when 'y'
      add file
    when 'n' # pass through.
    end
  }
end

#at?(i = 1) ⇒ Boolean

#

at?

This method returns the entry at a specific location.

#

Returns:

  • (Boolean)


887
888
889
# File 'lib/multimedia_paradise/audio/playlist/playlist.rb', line 887

def at?(i = 1)
  playlist?[i.to_i - 1]
end

#consider_requiring_the_kde_konsole_specific_filesObject

#

consider_requiring_the_kde_konsole_specific_files

#


1279
1280
1281
1282
1283
1284
1285
# File 'lib/multimedia_paradise/audio/playlist/playlist.rb', line 1279

def consider_requiring_the_kde_konsole_specific_files
  if is_on_roebe?
    begin
      require 'roebe/classes/kde/kde_konsole/kde_konsole.rb'
    rescue LoadError; end
  end
end

#convert_english_number_to_letter(i) ⇒ Object

#

convert_english_number_to_letter

#


954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
# File 'lib/multimedia_paradise/audio/playlist/playlist.rb', line 954

def convert_english_number_to_letter(i)
  case i
  when 'one'
    1
  when 'two'
    2
  when 'three'
    3
  when 'four'
    4
  when 'five'
    5
  when 'six'
    6
  when 'seven'
    7
  when 'eight'
    8
  when 'nine'
    9
  end
end

#convert_to_m3u_playlist(i = store_where?, , use_this_name_for_the_m3u_file = DEFAULT_NAME_FOR_THE_M3U_PLAYLIST) ⇒ Object

#

convert_to_m3u_playlist

Use this method if you wish to create a .m3u list.

More information about .m3u files can be found here:

https://en.wikipedia.org/wiki/M3U
#


1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
# File 'lib/multimedia_paradise/audio/playlist/playlist.rb', line 1297

def convert_to_m3u_playlist(
    i                              = store_where?,
    use_this_name_for_the_m3u_file = DEFAULT_NAME_FOR_THE_M3U_PLAYLIST 
  )
  opne 'We will next create a new .m3u file at '\
       '`'+sfile(use_this_name_for_the_m3u_file)+'`.'
  if File.exist? i
    dataset = load_dataset(i) # ← This is a Hash.
    create_this_m3u_file(dataset, 'tales_from_the_crypt.m3u')
  else
    opnn; no_file_exists_at(i)
  end
end

#create_tales_from_the_crypt_playlist(use_this_yaml_file = ::MultimediaParadise.file_tales_from_the_crypt) ⇒ Object

#

create_tales_from_the_crypt_playlist

This method will generate a .m3u playlist for the tales-from-the-crypt videos. The input should be a yaml file.

#


1354
1355
1356
1357
1358
1359
1360
# File 'lib/multimedia_paradise/audio/playlist/playlist.rb', line 1354

def create_tales_from_the_crypt_playlist(
    use_this_yaml_file =
      ::MultimediaParadise.file_tales_from_the_crypt
  )
  do_report_the_namespace
  convert_to_m3u_playlist(use_this_yaml_file)
end

#create_this_m3u_file(dataset_that_is_to_be_used, name_of_the_file = PLAYLIST_M3U_FILE) ⇒ Object

#

create_this_m3u_file

The first argument should be the dataset that contains all the files.

To trigger this, do:

playlist --convert
#


1322
1323
1324
1325
1326
1327
1328
1329
# File 'lib/multimedia_paradise/audio/playlist/playlist.rb', line 1322

def create_this_m3u_file(
    dataset_that_is_to_be_used,
    name_of_the_file = PLAYLIST_M3U_FILE
  )
  CreateM3uPlaylist.new(
    dataset_that_is_to_be_used, name_of_the_file
  ) # This comes from $MULTIMEDIA_PARADISE/audio/create_m3u_playlist.rb
end

#data?Boolean

#

playlist?

#

data?

Returns:

  • (Boolean)


991
992
993
# File 'lib/multimedia_paradise/audio/playlist/playlist.rb', line 991

def playlist?
  @playlist
end

#datasetBoolean

#

playlist?

#

dataset

Returns:

  • (Boolean)


990
991
992
# File 'lib/multimedia_paradise/audio/playlist/playlist.rb', line 990

def playlist?
  @playlist
end

#dataset?Boolean

#

playlist?

#

dataset?

Returns:

  • (Boolean)


989
990
991
# File 'lib/multimedia_paradise/audio/playlist/playlist.rb', line 989

def playlist?
  @playlist
end

#do_report_the_namespaceObject

#

do_report_the_namespace

#


980
981
982
# File 'lib/multimedia_paradise/audio/playlist/playlist.rb', line 980

def do_report_the_namespace
  @internal_hash[:report_namespace] = true
end

#exchange_these_two_positions(one, two) ⇒ Object

#

exchange_these_two_positions

The user can use this method should she/she wish to exchange two entries in the given playlist at hand. Logically this requires two different arguments.

#


855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
# File 'lib/multimedia_paradise/audio/playlist/playlist.rb', line 855

def exchange_these_two_positions(
    one, two
  )
  if one == two
    opne 'Please provide different positions. Given position '\
         'was: '+steelblue(one)
    return
  end
  entry_one = @playlist[one.to_i - 1]
  entry_two = @playlist[two.to_i - 1]
  opne rev+'We will next exchange two positions in our playlist.'
  opne "#{rev}Entry "+simp(one.to_s)+' ('+sfile(entry_one)+') with '+
       "#{rev}Entry "+simp(two.to_s)+' ('+sfile(entry_two)+').'
  opne "#{rev}The new playlist will also be shown."
  # ======================================================================= #
  # Here, we do the manipulation.
  # ======================================================================= #
  @playlist[one.to_i - 1] = entry_two
  @playlist[two.to_i - 1] = entry_one
  show_playlist # Show it here to see that we did a change.
  save_dataset
  opne "#{rev}Exchange operation between "+
       steelblue(one.to_s)+"#{rev} and "+
       steelblue(two.to_s)+"#{rev} finished! "+
       gold('\o/')+rev
end

#fancy_display_the_playlistObject

#

show_playlist (show tag)

This method will display, on the commandline, the current playlist in use.

#

fancy_display_the_playlist



1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
# File 'lib/multimedia_paradise/audio/playlist/playlist.rb', line 1614

def show_playlist(
    be_verbose = be_verbose?
  )
  if be_verbose
    _ = playlist?
    if _.is_a?(FalseClass) or _.empty?
      opne "#{rev}The playlist is currently empty."
      e
      opne "#{rev}You can use #{steelblue('--add')}"\
           "#{rev} to add files to the playlist."
      e
      opne "#{rev}Example:"
      e
      opne sfancy('  playlist -add UtahSaints_SomethingGood.mp3')
      e
    else
      opne "#{rev}We found these #{simp(_.size.to_s)} "\
           "#{rev}entries as part of the playlist:"
      e
      _.each_with_index {|entry, index|
        index += 1
        left = '  '.dup
        left << (' ' * (3 - index.to_s.size))
        left << (rev+'('+royalblue(index.to_s)+rev+')')
        e "#{left} #{olivedrab(entry)}"
      }; e
    end
  end
end

#is_a_registered_genre?(this_genre) ⇒ Boolean

#

is_a_registered_genre?

This method will return true if the given input is part of the Array containing all registered genres.

#

Returns:

  • (Boolean)


630
631
632
633
634
# File 'lib/multimedia_paradise/audio/playlist/playlist.rb', line 630

def is_a_registered_genre?(this_genre)
  ARRAY_REGISTERED_GENRES.include?(
    this_genre.to_s.delete('-')
  )
end

#load_yaml_dataset(i = store_where? ) ⇒ Object Also known as: load_dataset, update_playlist, populate_the_playlist

#

load_yaml_dataset (load tag)

This method will populate the instance variable @playlist with the proper dataset.

#


1337
1338
1339
1340
1341
1342
1343
1344
# File 'lib/multimedia_paradise/audio/playlist/playlist.rb', line 1337

def load_yaml_dataset(
    i = store_where?
  )
  if File.exist? i
    @playlist = YAML.load_file(i)
  end
  return @playlist # Return it as well here.
end
#

menu (menu tag)

#


270
271
272
273
274
275
276
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
303
304
305
306
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
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
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
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
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
# File 'lib/multimedia_paradise/audio/playlist/playlist.rb', line 270

def menu(
    i = commandline_arguments?
  )
  if i.is_a? Array
    if i.empty?
      show_playlist
    else
      i.each {|entry| menu(entry) }
    end
  else
    case i # case tag
    # ===================================================================== #
    # === playlist 5
    #
    # This handles numbered input. The specified number will be played
    # from the playlist. 
    #
    # Usage example:
    #
    #   playlist 32
    #
    # ===================================================================== #
    when /^(\d+)$/
      _ = $1.to_s.dup.to_i # Work on a copy past this point.
      _ = at?(_)
      add_to_play_these_songs(_)
    # ===================================================================== #
    # === playlist --stored-where?
    # ===================================================================== #
    when /^-?-?stored(-|_)?where\??$/i
      e sfancy(PLAYLIST_FILE)+rev
      exit
    # ===================================================================== #
    # === playlist --random=15
    # ===================================================================== #
    when /^-?-?random=(\d+)$/i
      play_random_song($1.to_s.to_i)
      exit
    # ===================================================================== #
    # === playlist --random
    # ===================================================================== #
    when /^-?-?random$/i
      play_random_song(1)
      exit
    # ===================================================================== #
    # === playlist --reshuffle
    # ===================================================================== #
    when /^-?-?re(-|_)?shuffle$/ # playlist --reshuffle
      reshuffle_the_playlist
      exit
    # ===================================================================== #
    # === playlist --remove=38
    #
    # This entry point is a bit different to the variant defined
    # below. Here we will provide the positional argument already,
    # whereas in the variant below we depend on a ' ' token before
    # the number appears.
    #
    # Usage example:
    #
    #   playlist --remove-entry=126
    #
    # ===================================================================== #
    when /^-?-?remove=(\d+)$/i,           # === $1
         /^-?-?remove(-|_)?entry=(\d+)$/i # === $2
      _ = $1.to_s.dup
      _ = $2.to_s.dup if $2
      remove_this_entry(_)
    # ===================================================================== #
    # === Create a playlist from an existing .yml file
    # ===================================================================== #
    when /.yml$/i
      MultimediaParadise::CreateM3uPlaylist.new(i)
      exit
    # ===================================================================== #
    # === use vlc
    # ===================================================================== #
    when /^-?-?use(-|_)?vlc$/i
      @internal_hash[:user_defined_multimedia_player] = :vlc
    # ===================================================================== #
    # === use mplayer
    # ===================================================================== #
    when /^-?-?use(-|_)?mplayer$/i
      @internal_hash[:user_defined_multimedia_player] = :mplayer
    # ===================================================================== #
    # === use mpv
    # ===================================================================== #
    when /^-?-?use(-|_)?mpv$/i
      @internal_hash[:user_defined_multimedia_player] = :mpv
    # ===================================================================== #
    # === playlist --add
    #
    # Usage example:
    #
    #   playlist --add=Cu_Chill_Thoi_DJ_TuSo_And_LEA_remix.mp3
    #
    # ===================================================================== #
    when /^-?-?add=(.+)$/i
      add_this_entry($1.to_s.dup)
      exit
    # ===================================================================== #
    # === playlist --add
    # ===================================================================== #
    when /^-?-?add$/i
      add_this_entry(commandline_arguments_as_string)
      exit
    # ===================================================================== #
    # === playlist "95 -> 94"
    #
    # This entry point can be used to exchange two positions with
    # one another, e. g. in the example above, position 95 with
    # position 94.
    #
    # You can also use this here:
    #
    #   playlist --exchange=114,113
    #
    # ===================================================================== #
    when /^(\d{1,4})\s?->\s?(\d{1,4})$/,
         /^(\d{1,4})\s?→\s?(\d{1,4})$/,
         /^-?-?exchange=(\d+),(\d+)$/i
      exchange_these_two_positions(
        $1.to_s.dup,
        $2.to_s.dup
      )
      exit
    # ===================================================================== #
    # === playlist --last=20
    #
    # This entry point can be used to play e. g. the last 20 songs, in
    # reverse order - starting with the very last song, down to and
    # including the entry at position 20. 
    # ===================================================================== #
    when /^-?-?last=(\d+)$/i
      _ = $1.to_s.dup
      opne rev+'Now playing the last '+steelblue(_.size.to_s)+' songs.'
      play_song(:last_songs, _) # Just play the last song.
      exit
    # ===================================================================== #
    # === playlist --last
    # ===================================================================== #
    when /^-?-?last$/i
      play_song(:last_song) # Just play the last song.
      exit
    # ===================================================================== #
    # === playlist --delete-last-entry
    # ===================================================================== #
    when '-',
         /^-?-?delete(-|_)?last(-|_)?entry/
      remove_this_entry :last
    # ===================================================================== #
    # === playlist --tales-from-the-crypt
    #
    # This will generate the file tales_from_the_crypt.m3u.
    # ===================================================================== #
    when /^-?-?tales(-|_)?from(-|_)?the(-|_)?crypt$/i
      # =================================================================== #
      # Hardcoded for my system. This will create the tales from the
      # crypt playlist.
      # =================================================================== #
      create_tales_from_the_crypt_playlist
    # ===================================================================== #
    # === playlist 10-20
    #
    # This entry point allows us to handle numbers.
    #
    # Invocation examples:
    #
    #   playlist 10-20
    #   playlist 111-115
    #   playlist 82..33
    #
    # ===================================================================== #
    when /(\d{1,3}-\d{1,3})/,
         /(\d{1,3}\.\.\d{1,3})/
      _ = $1.to_s.dup.sub(/\.\./,'-')
      play_these_songs_based_on_numbered_input(_)
      exit
    # ===================================================================== #
    # === playlist +
    # ===================================================================== #
    when /\+/ # We will catch all '+' characters here.
      add_this_entry(i)
    # ===================================================================== #
    # === playlist 5,7
    #
    # This handles numbered input separated by ',' tokens. The user
    # wants to play more than one song when yielding these instructions.
    #
    # Usage examples:
    #
    #   playlist 6,7
    #   playlist 114,115
    #
    # ===================================================================== #
    when /^(\d+),+(\d+)*$/
      add_to_play_these_songs($1.to_s.dup.to_i, $2.to_s.dup.to_i,)
    # ===================================================================== #
    # === playlist --genres
    #
    # This entry point can be used to show all genres.
    # ===================================================================== #
    when /^-?-?genres$/
      show_all_genres
    # ===================================================================== #
    # === playlist --help
    # ===================================================================== #
    when /^-?-?show_?all/,
         /^-?-?help?$/i,
         /^-?-?all$/i,
         'he'
      show_help
    # ===================================================================== #
    # === playlist --use-this-yaml-file=/home/x/data/video/yaml/tales_from_the_crypt.yml
    # ===================================================================== #
    when /^-?-?use(-|_)?this(-|_)?yaml(-|_)?file=(.+)/ # === $4
      do_report_the_namespace
      use_this_file = $4.to_s.dup
      convert_to_m3u_playlist(use_this_file)
    # ===================================================================== #
    # === playlist --convert
    # ===================================================================== #
    when /convert(-|_)?to(-|_)?playlist/,
         /^-?-?convert$/i,
         /^-?-?generate$/i,'GENERATE',
         /^-?-?generate(-|_)?playlist$/i,
         /^-?-?create(-|_)?playlist$/i
      convert_to_m3u_playlist
      exit
    # ===================================================================== #
    # === playlist --purge-everything
    # ===================================================================== #
    when /^-?-?purge(-|_)?everything$/,
         'reset'
      purge_the_playlist
      exit
    # ===================================================================== #
    # === playlist --location?
    # ===================================================================== #
    when '--location?',
         '--location',
         '--file?',
         '--file'
      report_where_to_find_the_yaml_file
      exit
    # ===================================================================== #
    # === playlist --purge
    # ===================================================================== #
    when /^-?-?purge$/i
      purge_non_existing_files_from_playlist
      exit
    # ===================================================================== #
    # === playlist --last-two
    # ===================================================================== #
    when /-?-?last-?(\w+)/ # See: https://rubular.com/r/7gsa4hhPBW
      # =================================================================== #
      # The variable number will tell us how many of the last songs
      # we will play.
      # =================================================================== #
      number = convert_english_number_to_letter($1.to_s.dup) # playlist --last-three
      size = playlist?.size
      array = size.downto(size - (number - 1)).map {|entry|
        entry
      }.reverse # Reverse because we start at 1, and so we end with the last. 
      play_these_songs_based_on_numbered_input(array)
      exit
    # ===================================================================== #
    # === playlist --play
    # ===================================================================== #
    when /^-?-?play$/i,
         /^-?-?play(-|_)?all$/i,
         /^-?-?play(-|_)?everything$/i
      play_every_song_in_the_playlist
      exit
    # ===================================================================== #
    # === playlist --open
    # ===================================================================== #
    when /^-?-?open$/i
      open_yaml_file_in_editor
      exit
    # ===================================================================== #
    # === playlist --batch
    # ===================================================================== #
    when /^-?-?batch$/i
      ask_interactively_in_batch_format_for_each_audio_file
      exit
    # ===================================================================== #
    # === playlist --play_shuffle
    # ===================================================================== #
    when /^-?-?play(_|-)?shuffle$/i,
         /^-?-?shuffle$/,
         /^-?-?play(-|_)?random/,
         /shuffle$/,
         /^-?-?random(-|_)?play/,
         /^-?-?play(-|_)?all(-|_)?random$/,
         /^-?-?all$/
      play_every_song_in_the_playlist :shuffle # Play every song in a random way.
      exit
    # ===================================================================== #
    # === playlist --only-names
    #
    # This entry point allows us to show only the names of the song,
    # without seeing the full path (pathname) to the song at hand.
    # ===================================================================== #
    when /^-?-?only(-|_)?names$/
      playlist?.map! {|entry| File.basename(entry) }
      show_playlist
    # ===================================================================== #
    # === playlist --reverse-play
    #
    # This entry point can be used to play the songs of the playlist
    # in reverse, starting with the last entry, and finishing up to
    # the first entry.
    # ===================================================================== #
    when /^-?-?reverse$/,
         /^-?-?reverse(-| )?play$/i
      play_every_song_in_the_playlist(:reversed)
      exit
    # ===================================================================== #
    # === playlist --show
    # ===================================================================== #
    when 'playlist?',
         'SHOW',
         'FEEDBACK',
         'ALL',
         '?',
         /^-?-?show(_|-)?playlist/,
         /^-?-?show$/,
         /^-?-?view$/,
         ''
      show_playlist
    else
      if File.exist?(i.to_s)
        add_to_playlist(i.to_s)
      else
        show_playlist
      end
    end
  end
end

#no_song_was_found_as_part_of_the_playlistObject

#

no_song_was_found_as_part_of_the_playlist

#


1626
1627
1628
# File 'lib/multimedia_paradise/audio/playlist/playlist.rb', line 1626

def no_song_was_found_as_part_of_the_playlist
  opne "#{rev}No song was found as part of the playlist."
end

#now_removing_this_entry(i) ⇒ Object

#

now_removing_this_entry

#


1022
1023
1024
# File 'lib/multimedia_paradise/audio/playlist/playlist.rb', line 1022

def now_removing_this_entry(i)
  opne "#{rev}Now removing the entry #{sfile(i)} (from the playlist)."
end

#only_numbers?(i) ⇒ Boolean

#

only_numbers?

#

Returns:

  • (Boolean)


914
915
916
917
918
919
920
# File 'lib/multimedia_paradise/audio/playlist/playlist.rb', line 914

def only_numbers?(i)
  return_value = false
  if i.is_a? Array
    return_value = i.all? {|entry| entry =~ /\d+/ }
  end
  return return_value
end

#open_yaml_file_in_editorObject

#

open_yaml_file_in_editor

#


925
926
927
928
# File 'lib/multimedia_paradise/audio/playlist/playlist.rb', line 925

def open_yaml_file_in_editor
  _ = "bluefish #{playlist_file?}"
  esystem(_)
end

#opnnObject

#

opnn

#


1244
1245
1246
# File 'lib/multimedia_paradise/audio/playlist/playlist.rb', line 1244

def opnn
  super(namespace?) if report_namespace?
end

#play(i = '') ⇒ Object Also known as: play_this_song

#

play (play tag)

This will always output the file that will be played.

#


1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
# File 'lib/multimedia_paradise/audio/playlist/playlist.rb', line 1534

def play(
    i = ''
  )
  case i
  when :last_song
    i = playlist?[-1]
  end
  if i.is_a? Array
    i.each {|entry| play(entry) }
  else
    unless File.exist?(i) 
      i.prepend(directory_to_the_local_songs?) unless i.include?(directory_to_the_local_songs?)
    end
    # ===================================================================== #
    # Next we must use the default, designated multimedia player:
    # ===================================================================== #
    _ = "#{use_which_multimedia_player?} #{i}"
    e _
    system _
  end
end

#play_all_audio_files_based_on_this_genre(i, use_this_song_dir = SONG_DIR) ⇒ Object

#

play_all_audio_files_based_on_this_genre

Use this method to play all audio files based on the given genre at hand, such as “trance” or “eurodance”.

This presently works solely on the audio name of the file in question.

Note that you have to add the genre file manually to the following case menu.

Also note that this is far from perfect - it is more of a hack. If I use it more regularly then perhaps I will invest more time into this code.

Invocation example:

playlist --trance
#


667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
# File 'lib/multimedia_paradise/audio/playlist/playlist.rb', line 667

def play_all_audio_files_based_on_this_genre(
    i,
    use_this_song_dir = SONG_DIR
  )
  i = i.dup if i.frozen? and i.is_a?(String)
  i.delete!('-')
  # ======================================================================= #
  # Load up the playlist file here.
  # ======================================================================= #
  case i # case tag
  when 'trance'
    array_holding_all_files_that_can_be_played = []
    _ = MultimediaParadise::Genres::TRANCE_FILE
    if File.exist? _
      dataset = YAML.load_file(_)
      array_allowed_keys = dataset.keys.map {|entry|
        entry = entry.dup
        # entry.force_encoding(USE_THIS_ENCODING).delete(' ').downcase
        entry
      }
      files = Dir[use_this_song_dir+'*'].select {|entry|
        is_audio_file?(entry)
      }.map {|entry| File.basename(entry)}
      # =================================================================== #
      # We obtain all audio songs.
      # =================================================================== #
      files.each {|this_audio_file|
        downcased = this_audio_file.downcase
        result = array_allowed_keys.any? {|substring|
          downcased.include?(substring)
        }
        if result # if true
          array_holding_all_files_that_can_be_played << this_audio_file
        end
      }
      opne rev+
          'We will play '+
            sfancy(array_holding_all_files_that_can_be_played.size.to_s)+
            ' songs next.'
      play_song(
        array_holding_all_files_that_can_be_played.shuffle.map {|entry|
          "#{use_this_song_dir}#{entry}"
        }
      )
    end
  when *ARRAY_REGISTERED_AUDIO_TAGS
    array_holding_all_files_that_can_be_played = songs_whose_tag_matches_to(i)
    play_song(
      array_holding_all_files_that_can_be_played
    )
  end
end

#play_every_song_in_the_playlist(optional_input = nil) ⇒ Object

#

play_every_song_in_the_playlist

The optional argument determines how to play the songs or whether to apply some changes, before playing the songs. For instance, :reverse means that we will play the songs in the reverse order, that is, starting with the last song first etc..

#


899
900
901
902
903
904
905
906
907
908
909
# File 'lib/multimedia_paradise/audio/playlist/playlist.rb', line 899

def play_every_song_in_the_playlist(optional_input = nil)
  update_playlist
  _ = playlist?
  case optional_input
  when :shuffle
    _.shuffle!
  when :reversed
    _ = _.reverse
  end
  verbose_play_these_songs(_)
end

#play_random_song(n_times = 1) ⇒ Object

#

play_random_song

The default argument to this method is 1, which means “play one song”.

The user can provide another number here.

#


1058
1059
1060
1061
1062
1063
1064
# File 'lib/multimedia_paradise/audio/playlist/playlist.rb', line 1058

def play_random_song(
    n_times = 1
  )
  n_times.times {
    play playlist?.sample
  }
end

#play_these_songs_based_on_numbered_input(i, optional_original_input_to_menu = nil) ⇒ Object

#

play_these_songs_based_on_numbered_input

The input to this method should be numbers.

The second argument will rarely be necessary.

The input can be a String such as “5-12”, which means “play all songs from position 5 up to, and including, 12”.

#


1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
# File 'lib/multimedia_paradise/audio/playlist/playlist.rb', line 1211

def play_these_songs_based_on_numbered_input(
    i,
    optional_original_input_to_menu = nil
  )
  if i.is_a?(String) and i.include?('-') and i =~ /\d{1,2}-\d{1,2}/ # Handle 5-10
    splitted = i.split('-').map(&:to_i)
    range = splitted # <- may be [10, 20] or [76, 56] now.
    if range.last < range.first
      i = range.first.downto(range.last).to_a
    else
      i = Range.new(*range).to_a
    end
  end
  if i.is_a? Array
    i.each {|entry|
      play_these_songs_based_on_numbered_input(
        entry, optional_original_input_to_menu
      )
    }
  else
    this_song = playlist?[i - 1]
    if optional_original_input_to_menu
      if optional_original_input_to_menu.include?(',') and $2
        this_song = [this_song, playlist?[$2.to_s.dup.to_i - 1]]
      end
    end
    verbose_play_these_songs(this_song) # play_this_song(this_song)
  end
end

#playlist?Boolean

#

playlist?

#

Returns:

  • (Boolean)


987
988
989
# File 'lib/multimedia_paradise/audio/playlist/playlist.rb', line 987

def playlist?
  @playlist
end

#purge_non_existing_files_from_playlistObject

#

purge_non_existing_files_from_playlist

This method will purge non-existing files from the playlist.

#


999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
# File 'lib/multimedia_paradise/audio/playlist/playlist.rb', line 999

def purge_non_existing_files_from_playlist
  opne "#{rev}Now purging non-existing files from the playlist."
  new_array = []
  # ======================================================================= #
  # Next, make sure that the dataset was properly loaded.
  # ======================================================================= #
  load_yaml_dataset if playlist?.empty?
  playlist?.each {|entry|
    # ===================================================================== #
    # We store only multimedia files, hence the following check.
    # ===================================================================== #
    if File.exist?(entry) and MultimediaParadise.is_audio_file?(entry)
      new_array << entry
    else
      now_removing_this_entry(entry)
    end
  }
  store_this_playlist(new_array)
end

#purge_the_playlistObject

#

purge_the_playlist

#


1079
1080
1081
1082
# File 'lib/multimedia_paradise/audio/playlist/playlist.rb', line 1079

def purge_the_playlist
  save_yaml_dataset(:reset)
  opne "#{rev}The playlist was emptied."
end

#remove(i) ⇒ Object

#

remove (remove tag)

This method will notify the user that we will remove an entry, and then proceed to do so.

#


1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
# File 'lib/multimedia_paradise/audio/playlist/playlist.rb', line 1130

def remove(i)
  if playlist?.include? i
    now_removing_this_entry(i)
    @playlist.delete(i)
    save_yaml_dataset
  else
    e 'The entry '+sfancy(i)+' was not found in the playlist, thus'
    e 'it can not be removed.'
  end
end

#remove_this_entry(i) ⇒ Object

#

remove_this_entry

This method can be used to remove an entry from our playlist.

The input to this method should ideally be a number, such as

  1. This refers to removing the song number 5.

#


1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
# File 'lib/multimedia_paradise/audio/playlist/playlist.rb', line 1263

def remove_this_entry(i)
  i = i.join(' ') if i.is_a? Array
  case i
  when :last
    i = data?.last
  end
  i = i.to_s.delete('-')
  if i =~ /^\d+$/ # If only numbers, then fetch the entry
    i = playlist?[i.to_i - 1]
  end
  remove i
end

#report_namespace?Boolean

#

report_namespace?

#

Returns:

  • (Boolean)


1251
1252
1253
# File 'lib/multimedia_paradise/audio/playlist/playlist.rb', line 1251

def report_namespace?
  @internal_hash[:report_namespace]
end

#report_where_to_find_the_yaml_fileObject

#

report_where_to_find_the_yaml_file

#


1069
1070
1071
1072
1073
1074
# File 'lib/multimedia_paradise/audio/playlist/playlist.rb', line 1069

def report_where_to_find_the_yaml_file
  opne "#{rev}The yaml file can be found here:"
  e
  e "#{rev}  `#{sfile(yaml_file?)}#{rev}`"
  e
end

#resetObject

#

reset (reset tag)

#


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
126
127
# File 'lib/multimedia_paradise/audio/playlist/playlist.rb', line 92

def reset
  super()
  # ======================================================================= #
  # === :be_verbose
  # ======================================================================= #
  set_be_verbose
  infer_the_namespace
  # ======================================================================= #
  # === :playlist_file
  #
  # Designate where the playlist-file can be found.
  # ======================================================================= #
  @internal_hash[:playlist_file] = PLAYLIST_FILE
  # ======================================================================= #
  # === :user_defined_multimedia_player
  # ======================================================================= #
  @internal_hash[:user_defined_multimedia_player] = nil
  # ======================================================================= #
  # === :report_namespace
  # ======================================================================= #
  @internal_hash[:report_namespace] = REPORT_NAMESPACE
  # ======================================================================= #
  # === @playlist
  #
  # The main Array containing all songs that can be played is stored 
  # here.
  # ======================================================================= #
  @playlist = []
  # ======================================================================= #
  # === @array_these_songs_will_be_played
  #
  # This variable keeps track as to which songs will be played.
  # ======================================================================= #
  @array_these_songs_will_be_played = []
  populate_the_playlist
end

#reshuffle_the_playlist(be_verbose = true) ⇒ Object

#

reshuffle_the_playlist

This method will randomly re-arrange the playlist in use.

#


1116
1117
1118
1119
1120
1121
1122
# File 'lib/multimedia_paradise/audio/playlist/playlist.rb', line 1116

def reshuffle_the_playlist(be_verbose = true)
  if be_verbose
    opne 'Reshuffling the playlist next.'
  end
  dataset = all_songs.shuffle
  save_playlist(dataset)
end

#return_entry_from_this_position(i) ⇒ Object

#

return_entry_from_this_position (return tag)

#


942
943
944
945
946
947
948
949
# File 'lib/multimedia_paradise/audio/playlist/playlist.rb', line 942

def return_entry_from_this_position(i)
  entries = Dir['*'].sort
  position = i.to_i - 1
  if position > entries.size
    position = (entries.size - 1)
  end
  return entries[position]
end

#return_last_position_as_numberObject

#

return_last_position_as_number

We return the position of the last song here. If we have 42 entries then we will return as number 41 (Arrays start as 0 in Ruby).

#


643
644
645
# File 'lib/multimedia_paradise/audio/playlist/playlist.rb', line 643

def return_last_position_as_number
  @playlist.size - 1
end

#runObject

#

run (run tag)

#


1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
# File 'lib/multimedia_paradise/audio/playlist/playlist.rb', line 1633

def run
  sanitize_the_commandline
  menu
  array = array_these_songs_will_be_played?
  if array.empty?
    fancy_display_the_playlist
  else
    verbose_play_these_songs(array)
  end
end

#sanitize_the_commandline(i = commandline_arguments? ) ⇒ Object

#

sanitize_the_commandline

This method name is a slight misnomer, as it will also intercept “faulty” commandline arguments which we do not want to handle at a later point.

#


727
728
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
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
# File 'lib/multimedia_paradise/audio/playlist/playlist.rb', line 727

def sanitize_the_commandline(
    i = commandline_arguments?
  )
  #if all_input_starts_with_a_number?(i) and (i.size > 1)
  #  # ===================================================================== #
  #  # === If the user did input only numbers and there are at the least two arguments
  #  #
  #  # This entry point can be used to change two positions in the
  #  # playlist.
  #  #
  #  # Usage example:
  #  #
  #  #   playlist 114 113
  #  #
  #  # ===================================================================== #
  #  exchange_these_two_positions(i[0], i[1])
  #  exit
  #  ^^^ not sure if we retain this; at a later time we should reconsider
  # ======================================================================= #
  # === playlist --remove 38
  # ======================================================================= #
  if commandline_arguments_as_a_string.include?('remove')
    remove_this_entry(
      commandline_arguments_as_a_string.scan(/remove ?(\d+)/).
                                        flatten.first.to_s
    )
  # ======================================================================= #
  # === playlist --delete 38
  # ======================================================================= #
  elsif commandline_arguments_as_a_string.include?('delete')
    remove_this_entry(
      commandline_arguments_as_a_string.scan(/delete ?(\d+)/).
                                        flatten.first.to_s
    ) 
  # ======================================================================= #
  # === Handle String input that includes ',' and has only numbers
  # ======================================================================= #
  elsif i.is_a?(String) and 
        i.include?(',') and
        only_numbers?(i.split(','))
    # ===================================================================== #
    # Ok, the user did input something like this here then:
    #
    #   playlist 10,9,18
    #
    # So now we must grab the relevant entries.
    # ===================================================================== #
    splitted = i.split(',')
    i = splitted.map {|inner_entry| at?(inner_entry.to_i - 1) }
  # ======================================================================= #
  # === Handle String input that includes ',' and has only numbers
  # ======================================================================= #
  elsif i and !i.empty? and i.first and i.first.respond_to?(:include?) and i.first.include?(',')
    i.map! {|entry|
      if entry.is_a?(String) and
         entry.include?(',') and
         only_numbers?(entry.split(',')) and
         !entry.include?('=')
        # =================================================================== #
        # Ok, the user did input something like this here then:
        #   playlist 10,9,18
        # So now we must grab the relevant entries. But the user could
        # also input "--exchange=114,113" so we made the exception as
        # specified above.
        # =================================================================== #
        splitted = entry.split(',')
        entry = splitted.map {|inner_entry| at?(inner_entry.to_i) }
        entry
      end
      entry
    }
  end
  i.flatten!
  # local_audio_directory = directory_containing_the_local_songs?
  i.each {|entry|
    # ===================================================================== #
    # Add the file to the playlist if it exists.
    # ===================================================================== #
    # if File.exist? entry
    #   add(entry)
    # # ===================================================================== #
    # # === Also check the AUDIO_DIRECTORY
    # # ===================================================================== #
    # elsif File.exist?(local_audio_directory+entry) and
    #       File.file?(local_audio_directory+entry)
    #   add("#{local_audio_directory}#{entry}")
    # ===================================================================== #
    # === Query whether it is a registered genre or not
    # ===================================================================== #
    if is_a_registered_genre?(entry)
      # =================================================================== #
      # Then this is a registered genre, such as "trance" or
      # "eurodance".
      #
      # Invocation example:
      #
      #   playlist --trance
      #
      # =================================================================== #
      play_all_audio_files_based_on_this_genre(entry)
    # ===================================================================== #
    # === Handle registered audio tags next
    # ===================================================================== #
    elsif ARRAY_REGISTERED_AUDIO_TAGS.include? entry.to_s.delete('-')
      # =================================================================== #
      # Find out whether this is a registered audio tag.
      #
      # Invocation example:
      #
      #   playlist eurodance
      #
      # =================================================================== #
      play_song(
        songs_whose_tag_matches_to(entry)
      )
    end
  }
  i.flatten!
  set_commandline_arguments(i)
end

#save_yaml_dataset(this_dataset = playlist? ) ⇒ Object Also known as: store_this_playlist, save_dataset, save_playlist

#

save_yaml_dataset (save tag)

The first argument should be an Array containing all the songs that are part of your playlist. We will then store it into the default file location, specified by store_what?.

#


1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
# File 'lib/multimedia_paradise/audio/playlist/playlist.rb', line 1091

def save_yaml_dataset(
    this_dataset = playlist?
  )
  case this_dataset
  when :reset
    dataset = []
  else # This is the default here.
    dataset = YAML.dump(this_dataset)
    dataset << N unless dataset.end_with? N
    # Next we prepend a ' - ' but only if we don't start with this
    # token OR if we do not start with '---'
    unless dataset.start_with? ' - '
      dataset.prepend(' - ') unless dataset.start_with?('---')
    end
  end
  SaveFile.write_what_into(dataset, store_where?)
end

#show_all_genresObject

#

show_all_genres

#


614
615
616
617
618
619
620
621
622
# File 'lib/multimedia_paradise/audio/playlist/playlist.rb', line 614

def show_all_genres
  e
  e rev+'The available genres are:'
  e
  ARRAY_REGISTERED_GENRES.each_with_index {|this_genre, index| index += 1
    e rev+'  ('+royalblue(index.to_s)+rev+') '+steelblue(this_genre)
  }
  e
end

#show_helpObject

#

show_help (help tag)

This is the generic help-section for all playlist-based classes.

Invocation example:

playlist --help
#


1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
# File 'lib/multimedia_paradise/audio/playlist/playlist.rb', line 1449

def show_help
  e
  opne "#{rev}This class (#{steelblue('class MultimediaParadise::Playlist')}"\
       "#{rev}) will provide/handle an audio playlist. #{lightgreen('🎵\o/ 🎵')}"
  opne
  opne mediumslateblue('The documented options for this class are as follows:')
  opne
  opnecomment '  -                              # delete the last entry; '\
              'this also works via --delete-last-entry'
  opnecomment '  --batch                        # process all audio files from the '\
              'current directory'
  opnecomment '  --generate                     # generate a .m3u playlist'
  opnecomment '  --show_playlist                # show the playlist '\
              '(this is the default - SHOW is an alias)'
  opnecomment '  --play                         # play the files in the playlist'
  opnecomment '  --play_shuffle                 # shuffle, then play all '\
              'files in the playlist'
  opnecomment '  --delete 38                    # remove the entry at '\
              'position 38 from our playlist'
  opnecomment '  --remove=38                    # this works the same as ^^^, '\
              'merely uses a = instead'
  opnecomment '  --purge-everything             # empty the playlist. That '\
              'way you can start to populate a new one, from scratch.'
  opnecomment '  --reshuffle                    # permanently reshuffle '\
              'the playlist - the songs will have different '\
              'entries as a result'
  opnecomment '  --random                       # play ONE random song'
  opnecomment '  --random=25                    # play 25 random '\
              'songs (or whatever other value is passed here)'
  opnecomment '  --reverse-play                 # play in reverse, '\
              'from last to first song'
  opnecomment '  --reverse                      # ^^^ a convenience alias '\
              'to the above'
  opnecomment '  --trance                       # play all (local) trance songs'
  opnecomment '  --last-two                     # play the last '\
              'two songs. Works as well with other english language'
  opnecomment '                                 # words, such as three '\
              'and four and so on'
  opnecomment '  number1 number 2               # exchange these two '\
              'entries in the playlist with one another such'
  opnecomment '                                 # as: playlist '\
              '5 6 would swap position'
  opnecomment '  --exchange=114,113             # the same as '\
              '^^^ above, essentially'
  opnecomment '  add <NUMBER/NAME>              # add the file '\
              'at position NUMBER or the FILENAME to the playlist'
  opnecomment '  eurodance                      # this would play all '\
              'eurodance-songs. The songs must be available'
  opnecomment '                                 # locally though, '\
              'where the AUDIO_DIR constant points at.'
  opnecomment '  playlist --genres              # show all '\
              'registered music-genres (in the '\
              'multimedia_paradise gem)'
  opnecomment '  playlist --only-names          # show only '\
              'the names of the songs, not the full path'
  opnecomment '  playlist 88,87,86,85,84,83     # play songs '\
              'at these positions from the playlist'
  opnecomment '  playlist 88 87 86 85 84 83     # same as ^^^ '\
              'above, just without ","'
  opnecomment '  playlist "95 -> 94"            # exchange these '\
              'two positions with one another e. g. '\
              'position 95 to 94 and vice versa'
  opnecomment '  playlist --use-mplayer         # specifically '\
              'use mplayer for playing audio files'
  opnecomment '  playlist --use-mpv             # specifically '\
              'use mpv for playing audio files'
  opnecomment '  playlist --stored-where?       # tell us '\
              'where the main .yml file is stored'
  if is_on_roebe?
    # ===================================================================== #
    # Display extra options on roebe-systems only.
    # ===================================================================== #
    e
    opnecomment '  playlist --tales-from-the-crypt # generate '\
                'tales-from-the-crypt .m3u playlist'
    e
  end
  e
end

#show_playlist(be_verbose = be_verbose? ) ⇒ Object

#

show_playlist (show tag)

This method will display, on the commandline, the current playlist in use.

#


1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
# File 'lib/multimedia_paradise/audio/playlist/playlist.rb', line 1586

def show_playlist(
    be_verbose = be_verbose?
  )
  if be_verbose
    _ = playlist?
    if _.is_a?(FalseClass) or _.empty?
      opne "#{rev}The playlist is currently empty."
      e
      opne "#{rev}You can use #{steelblue('--add')}"\
           "#{rev} to add files to the playlist."
      e
      opne "#{rev}Example:"
      e
      opne sfancy('  playlist -add UtahSaints_SomethingGood.mp3')
      e
    else
      opne "#{rev}We found these #{simp(_.size.to_s)} "\
           "#{rev}entries as part of the playlist:"
      e
      _.each_with_index {|entry, index|
        index += 1
        left = '  '.dup
        left << (' ' * (3 - index.to_s.size))
        left << (rev+'('+royalblue(index.to_s)+rev+')')
        e "#{left} #{olivedrab(entry)}"
      }; e
    end
  end
end

#songs_whose_tag_matches_to(i) ⇒ Object

#

songs_whose_tag_matches_to

This will select based on the file called song_tags.yml

#


1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
# File 'lib/multimedia_paradise/audio/playlist/playlist.rb', line 1181

def songs_whose_tag_matches_to(i)
  i = i.dup if i.frozen?
  i.delete!('-')
  dataset = YAML.load_file(FILE_SONG_TAGS)
  dataset.select! {|key, value|
    value.include?(i) if value
  }
  keys = dataset.keys
  # ======================================================================= #
  # Next, add the filepath to them.
  # ======================================================================= #
  keys.map! {|file|
    file = file.dup if file.frozen?
    file.prepend(SONG_DIR)
    file = Dir[file+'*']
    file
  }
  return keys.shuffle # And shuffle it since as of December 2023.
end

#store_where?Boolean Also known as: playlist_location?, yaml_file?, playlist_file?

#

store_where?

#

Returns:

  • (Boolean)


933
934
935
# File 'lib/multimedia_paradise/audio/playlist/playlist.rb', line 933

def store_where?
  @internal_hash[:playlist_file]
end

#try_to_play_songs_matching_this_input(i) ⇒ Object

#

try_to_play_songs_matching_this_input

#


1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
# File 'lib/multimedia_paradise/audio/playlist/playlist.rb', line 1144

def try_to_play_songs_matching_this_input(i)
  if i.is_a? Array
    i.each {|entry|
      try_to_play_songs_matching_this_input(entry)
    }
  else
    if i.include? ', ' # In this case, sanitize the input first.
      i = i.dup if i.frozen?
      i.delete!(' ')
    end if i.is_a? String
    if i.include? 'last'
      i.sub!(/last/, return_last_position_as_number.to_s)
    end
    if i =~ /^\d+$/ # If it is a number
      i = @playlist[i.to_i - 1]
    end
    if i.include? ','
      try_to_play_songs_matching_this_input(
        i.split(',')
      )
    else
      possible_matches = @playlist.grep(/#{i}/)
      unless possible_matches.empty?
        # =================================================================== #
        # Play these songs then.
        # =================================================================== #
        play_these_songs(possible_matches)
      end
    end
  end
end

#use_which_multimedia_player?Boolean

#

use_which_multimedia_player?

This query method will determine which audio-player is to be used.

By default the environment variable USE_THIS_VIDEO_PLAYER will be honoured, but the user can specifically override this and designate

    1. mpv or mplayer to paly these audio-files.

#

Returns:

  • (Boolean)


1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
# File 'lib/multimedia_paradise/audio/playlist/playlist.rb', line 1565

def use_which_multimedia_player?
  _ = 'mplayer'
  if ENV.has_key? 'USE_THIS_VIDEO_PLAYER'
    _ = ENV['USE_THIS_VIDEO_PLAYER'].to_s.dup
  end
  # ======================================================================= #
  # The next variable is allowed to overrule the ENV variable
  # defined above.
  # ======================================================================= #
  if @internal_hash[:user_defined_multimedia_player]
    _ = @internal_hash[:user_defined_multimedia_player].to_s
  end
  return _
end

#verbose_play_these_songs(i, optional_special_instructions = nil) ⇒ Object Also known as: play_song, play_these_songs

#

verbose_play_these_songs

First argument should be an Array.

#


1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
# File 'lib/multimedia_paradise/audio/playlist/playlist.rb', line 1376

def verbose_play_these_songs(
    i, optional_special_instructions = nil
  )
  case i
  # ======================================================================= #
  # === :last_songs
  #
  # This is deliberately distinct from :last_song.
  #
  # Usage example:
  #
  #   playlist --last=20
  #
  # ======================================================================= #
  when :last_songs
    i = playlist?.reverse[0 .. optional_special_instructions.to_i]
  # ======================================================================= #
  # === :last_song
  # ======================================================================= #
  when :last_song
    i = playlist?[-1]
  end
  unless i.is_a? Array
    i = [i]
  end # We require an Array past this point.
  i.flatten!
  i.map! {|entry|
    if !File.exist?(entry.to_s) and (entry.to_s =~ /\d+/)
      entry = at?(entry)
    end
    entry
  }
  return if i.empty? # Early return if the array is empty.
  # ======================================================================= #
  # Play these songs next, via a main loop:
  # ======================================================================= #
  i.each_with_index {|song, counter|
    song = song.first if song.is_a? Array
    counter += 1
    if Object.const_defined?(:Roebe)
      use_this_as_tab_title = 'Playlist - '.dup
      use_this_as_tab_title << File.basename(song).
                               tr('_',' ').
                               sub(/#{File.extname(song)}$/, '')
      e Roebe.(use_this_as_tab_title)
    end
    e
    e yel(counter.to_s.rjust(3))+
      rev+') Playing the song `'+
      sfile(song)+rev+
      '` next.'
    e
    play song # Delegate towards play().
  }
  if is_on_roebe?
    begin
      require 'roebe/classes/kde/kde_konsole/kde_konsole.rb'
      e Roebe.konsole_tab_title('.') # Rename the tab again.
    rescue LoadError; end
  end
end