class MultimediaParadise::Playlist

Constants

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
#

ARRAY_REGISTERED_GENRES

#
DEFAULT_NAME_FOR_THE_M3U_PLAYLIST
NAMESPACE
#

NAMESPACE

#
PLAYLIST_FILE
PLAYLIST_M3U_FILE
#

PLAYLIST_M3U_FILE

#
REPORT_NAMESPACE
#

REPORT_NAMESPACE

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

#

Public Class Methods

add(i) click to toggle source
#

MultimediaParadise::Playlist.add

#
# File lib/multimedia_paradise/audio/playlist/playlist.rb, line 185
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
new( commandline_arguments = nil, run_already = true ) { || ... } click to toggle source
#

initialize

#
# File lib/multimedia_paradise/audio/playlist/playlist.rb, line 45
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
      @be_verbose = false
    end
  end
  run if run_already
end
playlist?() click to toggle source
#

MultimediaParadise::Playlist.playlist?

Feedback which playlist is in use.

#
# File lib/multimedia_paradise/audio/playlist/playlist.rb, line 1336
def self.playlist?
  MultimediaParadise::Playlist.new(:dont_run_yet) { :be_quiet }.playlist?
end
show_playlist() click to toggle source
#

MultimediaParadise::Playlist.show_playlist

#
# File lib/multimedia_paradise/audio/playlist/playlist.rb, line 1592
def self.show_playlist
  new { :do_not_run_yet }.show_playlist
end

Public Instance Methods

[]( be_verbose = @be_verbose )
Alias for: show_playlist
add(i) click to toggle source
#

add (add tag)

Use this method to add a song to the playlist.

#
# File lib/multimedia_paradise/audio/playlist/playlist.rb, line 164
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
Also aliased as: add_this_song
add_this_entry(i) click to toggle source
#

add_this_entry

Pass a file to this method.

#
# File lib/multimedia_paradise/audio/playlist/playlist.rb, line 141
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_this_song(i)
Alias for: add
add_to_play_these_songs(*i) click to toggle source
#

add_to_play_these_songs

#
# File lib/multimedia_paradise/audio/playlist/playlist.rb, line 129
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
Also aliased as: add_to_playlist
add_to_playlist(*i)
all_songs()
Alias for: playlist?
ask_interactively_in_batch_format_for_each_audio_file() click to toggle source
#

ask_interactively_in_batch_format_for_each_audio_file

To invoke this, try:

playlist --batch
#
# File lib/multimedia_paradise/audio/playlist/playlist.rb, line 1013
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) click to toggle source
#

at?

This method returns the entry at a specific location.

#
# File lib/multimedia_paradise/audio/playlist/playlist.rb, line 861
def at?(i = 1)
  playlist?[i.to_i - 1]
end
consider_requiring_the_kde_konsole_specific_files() click to toggle source
#

consider_requiring_the_kde_konsole_specific_files

#
# File lib/multimedia_paradise/audio/playlist/playlist.rb, line 1250
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) click to toggle source
#

convert_english_number_to_letter

#
# File lib/multimedia_paradise/audio/playlist/playlist.rb, line 926
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 ) click to toggle source
#

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
#
# File lib/multimedia_paradise/audio/playlist/playlist.rb, line 1268
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 ) click to toggle source
#

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.

#
# File lib/multimedia_paradise/audio/playlist/playlist.rb, line 1323
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 ) click to toggle source
#

create_this_m3u_file

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

To trigger this, do:

playlist --convert
#
# File lib/multimedia_paradise/audio/playlist/playlist.rb, line 1293
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?()
Alias for: playlist?
dataset()
Alias for: playlist?
dataset?()
Alias for: playlist?
do_report_the_namespace() click to toggle source
#

do_report_the_namespace

#
# File lib/multimedia_paradise/audio/playlist/playlist.rb, line 959
def do_report_the_namespace
  @report_namespace = true
end
exchange_these_two_positions( one, two ) click to toggle source
#

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.

#
# File lib/multimedia_paradise/audio/playlist/playlist.rb, line 828
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 'Entry '+simp(one.to_s)+' ('+sfile(entry_one)+') with '\
       'Entry '+simp(two.to_s)+' ('+sfile(entry_two)+').'
  opne '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 'Exchange operation between '+
       steelblue(one.to_s)+' and '+
       steelblue(two.to_s)+
       ' finished! '+
       gold('\o/')
end
is_a_registered_genre?(this_genre) click to toggle source
#

is_a_registered_genre?

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

#
# File lib/multimedia_paradise/audio/playlist/playlist.rb, line 605
def is_a_registered_genre?(this_genre)
  ARRAY_REGISTERED_GENRES.include?(
    this_genre.to_s.delete('-')
  )
end
load_dataset(i = store_where?)
Alias for: load_yaml_dataset
load_yaml_dataset(i = store_where?) click to toggle source
#

load_yaml_dataset (load tag)

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

#
# File lib/multimedia_paradise/audio/playlist/playlist.rb, line 1308
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( i = commandline_arguments? ) click to toggle source
#

menu (menu tag)

#
now_removing_this_entry(i) click to toggle source
#

now_removing_this_entry

#
# File lib/multimedia_paradise/audio/playlist/playlist.rb, line 1001
def now_removing_this_entry(i)
  opne 'Now removing the entry '+sfile(i)+' (from the playlist).'
end
only_numbers?(i) click to toggle source
#

only_numbers?

#
# File lib/multimedia_paradise/audio/playlist/playlist.rb, line 888
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_editor() click to toggle source
#

open_yaml_file_in_editor

#
# File lib/multimedia_paradise/audio/playlist/playlist.rb, line 899
def open_yaml_file_in_editor
  _ = "bluefish #{playlist_file?}"
  esystem(_)
end
opne(i = '') click to toggle source
#

opne

#
# File lib/multimedia_paradise/audio/playlist/playlist.rb, line 1222
def opne(i = '')
  opnn; e i
end
opnn() click to toggle source
#

opnn

#
Calls superclass method MultimediaParadise::Base#opnn
# File lib/multimedia_paradise/audio/playlist/playlist.rb, line 1215
def opnn
  super(NAMESPACE) if @report_namespace
end
play(i = '') click to toggle source
#

play (play tag)

This will always output the file that will be played.

#
# File lib/multimedia_paradise/audio/playlist/playlist.rb, line 1498
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
Also aliased as: play_this_song
play_all_audio_files_based_on_this_genre( i, use_this_song_dir = SONG_DIR ) click to toggle source
#

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
#
# File lib/multimedia_paradise/audio/playlist/playlist.rb, line 642
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
      }
      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) click to toggle source
#

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..

#
# File lib/multimedia_paradise/audio/playlist/playlist.rb, line 873
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() click to toggle source
#

play_random_song

#
# File lib/multimedia_paradise/audio/playlist/playlist.rb, line 1033
def play_random_song
  play playlist?.sample
end
play_song( i, optional_special_instructions = nil )
play_these_songs( i, optional_special_instructions = nil )
play_these_songs_based_on_numbered_input( i, optional_original_input_to_menu = nil ) click to toggle source
#

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”.

#
# File lib/multimedia_paradise/audio/playlist/playlist.rb, line 1182
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
play_this_song(i = '')
Alias for: play
playlist?() click to toggle source
#

playlist?

#
# File lib/multimedia_paradise/audio/playlist/playlist.rb, line 966
def playlist?
  @playlist
end
playlist_file?() click to toggle source
#

playlist_file?

#
# File lib/multimedia_paradise/audio/playlist/playlist.rb, line 907
def playlist_file?
  @playlist_file
end
Also aliased as: yaml_file?
playlist_location?()
Alias for: store_where?
populate_the_playlist(i = store_where?)
Alias for: load_yaml_dataset
purge_non_existing_files_from_playlist() click to toggle source
#

purge_non_existing_files_from_playlist

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

#
# File lib/multimedia_paradise/audio/playlist/playlist.rb, line 978
def purge_non_existing_files_from_playlist
  opne '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_playlist() click to toggle source
#

purge_the_playlist

#
# File lib/multimedia_paradise/audio/playlist/playlist.rb, line 1050
def purge_the_playlist
  save_yaml_dataset(:reset)
  opne 'The playlist was emptied.'
end
remove(i) click to toggle source
#

remove (remove tag)

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

#
# File lib/multimedia_paradise/audio/playlist/playlist.rb, line 1101
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) click to toggle source
#

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.

#
# File lib/multimedia_paradise/audio/playlist/playlist.rb, line 1234
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_where_to_find_the_yaml_file() click to toggle source
#

report_where_to_find_the_yaml_file

#
# File lib/multimedia_paradise/audio/playlist/playlist.rb, line 1040
def report_where_to_find_the_yaml_file
  opne 'The yaml file can be found here:'
  e
  e '  `'+sfile(yaml_file?)+'`'
  e
end
reset() click to toggle source
#

reset (reset tag)

#
Calls superclass method MultimediaParadise::AudioBase#reset
# File lib/multimedia_paradise/audio/playlist/playlist.rb, line 91
def reset
  super()
  # ======================================================================= #
  # === @be_verbose
  # ======================================================================= #
  set_be_verbose
  reset_the_internal_hash
  # ======================================================================= #
  # === :user_defined_multimedia_player
  # ======================================================================= #
  @internal_hash[:user_defined_multimedia_player] = nil
  # ======================================================================= #
  # === @playlist_file
  # ======================================================================= #
  @playlist_file = PLAYLIST_FILE
  # ======================================================================= #
  # === @report_namespace
  # ======================================================================= #
  @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) click to toggle source
#

reshuffle_the_playlist

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

#
# File lib/multimedia_paradise/audio/playlist/playlist.rb, line 1087
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_array()
Alias for: playlist?
return_entry_from_this_position(i) click to toggle source
#

return_entry_from_this_position (return tag)

#
# File lib/multimedia_paradise/audio/playlist/playlist.rb, line 914
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_number() click to toggle source
#

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).

#
# File lib/multimedia_paradise/audio/playlist/playlist.rb, line 618
def return_last_position_as_number
  @playlist.size - 1
end
run() click to toggle source
#

run (run tag)

#
# File lib/multimedia_paradise/audio/playlist/playlist.rb, line 1581
def run
  sanitize_the_commandline
  menu
  verbose_play_these_songs(
    @array_these_songs_will_be_played
  )
end
sanitize_the_commandline( i = commandline_arguments? ) click to toggle source
#

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.

#
# File lib/multimedia_paradise/audio/playlist/playlist.rb, line 700
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!
  @commandline_arguments = i
end
save_dataset( this_dataset = playlist? )
Alias for: save_yaml_dataset
save_playlist( this_dataset = playlist? )
Alias for: save_yaml_dataset
save_yaml_dataset( this_dataset = playlist? ) click to toggle source
#

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?.

#
# File lib/multimedia_paradise/audio/playlist/playlist.rb, line 1062
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_genres() click to toggle source
#

show_all_genres

#
# File lib/multimedia_paradise/audio/playlist/playlist.rb, line 586
def show_all_genres
  e
  e rev+'The available genres are:'
  e
  ARRAY_REGISTERED_GENRES.each_with_index {|this_genre, index| index += 1
    e royalblue(
      '  ('+index.to_s+') '
      )+
      steelblue(this_genre)
  }
  e
end
show_help() click to toggle source
#

show_help (help tag)

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

Invocation example:

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

show_playlist (show tag)

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

#
# File lib/multimedia_paradise/audio/playlist/playlist.rb, line 1548
def show_playlist(
    be_verbose = @be_verbose
  )
  if be_verbose
    _ = playlist?
    if _.is_a?(FalseClass) or _.empty?
      opne 'The playlist is currently empty.'
      e
      opne 'You can use '+steelblue('--add')+
           rev+' to add files to the playlist.'
      e
      opne 'Example:'
      e
      opne sfancy('  playlist -add UtahSaints_SomethingGood.mp3')
      e
    else
      opne "#{rev}We found these #{simp(_.size.to_s)} entries "\
           "as part of the playlist:"
      e
      _.each_with_index {|entry, index|
        index += 1
        left = '  '.dup
        left << (' ' * (3 - index.to_s.size))
        left << ('('+royalblue(index.to_s)+')')
        e "#{left} #{olivedrab(entry)}"
      }; e
    end
  end
end
Also aliased as: []
songs_whose_tag_matches_to(i) click to toggle source
#

songs_whose_tag_matches_to

This will select based on the file called song_tags.yml

#
# File lib/multimedia_paradise/audio/playlist/playlist.rb, line 1152
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
end
store_this_playlist( this_dataset = playlist? )
Alias for: save_yaml_dataset
store_where?() click to toggle source
#

store_where?

#
# File lib/multimedia_paradise/audio/playlist/playlist.rb, line 952
def store_where?
  @playlist_file
end
Also aliased as: playlist_location?
try_to_play_songs_matching_this_input(i) click to toggle source
#

try_to_play_songs_matching_this_input

#
# File lib/multimedia_paradise/audio/playlist/playlist.rb, line 1115
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
update_playlist(i = store_where?)
Alias for: load_yaml_dataset
use_which_multimedia_player?() click to toggle source
#

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.

#
# File lib/multimedia_paradise/audio/playlist/playlist.rb, line 1527
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 ) click to toggle source
#

verbose_play_these_songs

First argument should be an Array.

#
# File lib/multimedia_paradise/audio/playlist/playlist.rb, line 1345
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.return_audio_logo(use_this_as_tab_title)
    end
    e
    e yel(counter.to_s.rjust(3))+
      ') Playing the song `'+sfile(song)+'` 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
Also aliased as: play_song, play_these_songs
yaml_file?()
Alias for: playlist_file?