class MultimediaParadise::Genre
Constants
- DEFAULT_FILE
#¶ ↑
DEFAULT_FILE
¶ ↑# ¶ ↑
- NAMESPACE
#¶ ↑
NAMESPACE
¶ ↑#¶ ↑
Public Class Methods
Public Instance Methods
#¶ ↑
dataset?¶ ↑
#¶ ↑
# File lib/multimedia_paradise/audio/genres/genre.rb, line 438 def dataset? @dataset end
#¶ ↑
do_the_default_action
¶ ↑
Presently, the default action is to show all available songs.
#¶ ↑
# File lib/multimedia_paradise/audio/genres/genre.rb, line 325 def do_the_default_action show_available_songs(:then_exit) end
#¶ ↑
download_file_at_number
¶ ↑
Invocation example:
eurodance 62
#¶ ↑
# File lib/multimedia_paradise/audio/genres/genre.rb, line 538 def download_file_at_number(i) i = i.to_i _ = full_dataset? hash = {} _.each_pair.with_index {|data, index| if index == (i-1) data = Hash[*data] hash.update(data) end } download_remote_file(hash) end
#¶ ↑
download_remote_files
¶ ↑
Use this method when you want to download the remote files.
The input to this method should be a Hash.
Invocation example:
eurodance --download
#¶ ↑
# File lib/multimedia_paradise/audio/genres/genre.rb, line 489 def download_remote_files(this_dataset = full_dataset?) ::MultimediaParadise.ensure_that_the_output_directory_exists store_here = ::MultimediaParadise.output_directory?+return_name_from_class_name+'/' mkdir(store_here) cd(store_here) this_dataset.each_pair {|name_of_the_song, array| url = array[1] dataset = { name_of_the_song => array } _ = dataset key = _.keys.first name_of_the_group = _[key][0] opnn; e e ' Now downloading the song '+dodgerblue(name_of_the_song)+ ' (Group: '+simp(name_of_the_group)+') from the URL '+sfancy(url) name_of_the_song = key.to_s.delete('!') url = _[key][1] release_year = _[key][2].to_s # Need a String. # ======================================================================= # # Next, we will use youtube-dl to download this. # ======================================================================= # result = `youtube-dl #{url}` use_this_regex = /Merging formats into "(.+)"/ result.scan(use_this_regex) e 'Working on the song '+simp(name_of_the_song)+' next.' new_file_name = $1.to_s.dup # ======================================================================= # # The filename has to be sanitized and renamed. # ======================================================================= # new_file_name = rename_this_file(new_file_name) # ======================================================================= # # Ok, the file is already a bit sanitized, but we wish to make it even # nicer. So, we rename it based on 1) the name of the group, 2) the # name of the song and 3) the release year. # ======================================================================= # extension_name = File.extname(new_file_name) _ = name_of_the_group.tr(' ','_')+'-'+name_of_the_song.tr(' ','_')+ '_Year_'+release_year+extension_name mv(new_file_name, _) opnn; e 'The file name now is `'+sfile(_)+'`, in the '\ 'directory `'+sdir(store_here)+'`.' } end
#¶ ↑
generate_homepage
¶ ↑
This will generate a webpage/homepage, by using the links from the genre.
Invocation example:
eurodance --homepage
#¶ ↑
# File lib/multimedia_paradise/audio/genres/genre.rb, line 650 def generate_homepage _ = '<html><body>'.dup # This will be the return string. _ << '<title>'+guess_the_title_based_on_the_yaml_file+ ' ('+@dataset.keys.size.to_s+' entries)</title>' index = 0 dataset?.each_pair {|name_of_the_song, array| index += 1 name_of_the_group = array.first remote_URL = array[1] _ << HtmlTags.a(remote_URL, description: '('+index.to_s+') '+ name_of_the_song+' - '+ name_of_the_group ) _ << "<br>\n" } _ << '</body></html>' # ======================================================================= # # We determine into which file we will generate. Since as of October # 2020 we will use the general log-directory for the # MultimediaParadise project for this. # ======================================================================= # into = self.class.inspect.to_s.split(':').last.downcase into = log_dir?+into+'.html' opnn; e "Now storing into the file `#{sfile(into)}`." write_what_into(_, into) end
#¶ ↑
generate_m3u_playlist
¶ ↑
#¶ ↑
# File lib/multimedia_paradise/audio/genres/genre.rb, line 426 def generate_m3u_playlist # ======================================================================= # # We only need an Array of all URLs. # ======================================================================= # dataset = return_all_remote_urls into = '/Depot/j/'+return_name_from_class_name CreateM3uPlaylist.new(dataset, into) end
#¶ ↑
guess_the_title_based_on_the_yaml_file
¶ ↑
This method will try to guess the filename. It may use strings such as:
"/home/Programs/Ruby/2.7.2/lib/ruby/site_ruby/2.7.0/multimedia_paradise/yaml/genres/trance.yml"
#¶ ↑
# File lib/multimedia_paradise/audio/genres/genre.rb, line 617 def guess_the_title_based_on_the_yaml_file File.basename(@yaml_file).sub(/\.yml$/,'') end
#¶ ↑
load_yaml_dataset
¶ ↑
This method will also make @dataset available.
#¶ ↑
# File lib/multimedia_paradise/audio/genres/genre.rb, line 156 def load_yaml_dataset _ = yaml_file? begin # Must protect it because the yaml file may be buggy and raise Psych::SyntaxError. @dataset = YAML.load_file(_) rescue ArgumentError # This clause happens when syck raises an error. @dataset = File.read(_) rescue Exception => error opnn; e 'An error happened on line '+__LINE__.to_s+'.' pp error pp error.class end sanitize_yaml_dataset # Must sanitize it. end
#¶ ↑
obtain_url_from_entry_at_this_position
¶ ↑
We obtain (and return) the remote URL from this entry.
#¶ ↑
# File lib/multimedia_paradise/audio/genres/genre.rb, line 565 def obtain_url_from_entry_at_this_position(i) # ======================================================================= # # Input must be an Integer. We also must deduct -1 because Ruby Array # start to count at 0. # ======================================================================= # i = i.to_i - 1 _ = full_dataset? keys = _.keys url = _[keys[i]][1] return url end
#¶ ↑
rename_this_file
¶ ↑
This will rename the file and sanitize it, then return the new file name.
#¶ ↑
# File lib/multimedia_paradise/audio/genres/genre.rb, line 469 def rename_this_file(i) old_filename = i.to_s.dup new_filename = old_filename.delete('(').delete(')'). gsub(/ - /,'-').tr(' ','_').delete('!') mv(old_filename, new_filename) return new_filename end
#¶ ↑
reset (reset tag)¶ ↑
#¶ ↑
MultimediaParadise::Base#reset
# File lib/multimedia_paradise/audio/genres/genre.rb, line 79 def reset super() # ======================================================================= # # === @dataset # ======================================================================= # @dataset = nil set_commandline_arguments set_namespace end
#¶ ↑
return_dataset_from_one_random_song
¶ ↑
This is sort of a debug-method. What we do here is that we will randomly return one element from the main dataset.
#¶ ↑
# File lib/multimedia_paradise/audio/genres/genre.rb, line 459 def return_dataset_from_one_random_song return dataset?.to_a.sample(1).to_h end
#¶ ↑
sanitize_yaml_dataset
¶ ↑
#¶ ↑
# File lib/multimedia_paradise/audio/genres/genre.rb, line 173 def sanitize_yaml_dataset if @dataset.is_a? String # ===================================================================== # # Do the manual parsing on your own if it is a String. # ===================================================================== # _ = @dataset.split(N) _.reject! {|entry| entry.start_with? '#' } _.reject! {|entry| entry.strip.empty? } # ===================================================================== # # This is presently unfinished. I may continue working on this if # I happen to use a plain textfile rather than a yaml file. # ===================================================================== # end end
#¶ ↑
set_yaml_file
¶ ↑
#¶ ↑
# File lib/multimedia_paradise/audio/genres/genre.rb, line 92 def set_yaml_file(i) @yaml_file = i # ======================================================================= # # === Initialize the yaml dataset # ======================================================================= # load_yaml_dataset # Must re-initialize @dataset whenever set_input() is called. end
#¶ ↑
show_available_songs
¶ ↑
#¶ ↑
# File lib/multimedia_paradise/audio/genres/genre.rb, line 332 def show_available_songs( use_this_dataset = @dataset, shall_we_exit = :then_exit ) if use_this_dataset == :then_exit use_this_dataset = @dataset shall_we_exit = :then_exit end case shall_we_exit when :then_exit shall_we_exit = true end # ======================================================================= # # Work with a pointer variable. # ======================================================================= # _ = use_this_dataset # We assume that this will always be a Hash. n_entries = _.keys.size opnn; e simp(n_entries.to_s)+' entries were registered in the yaml file.' e _.each_pair.with_index {|inner_hash, index| key, _array = *inner_hash url = _array[1] index += 1 group_name = _array[0] release_year = _array[2].to_s group_and_release_year = ' ('+group_name+', '+release_year+')' e slateblue(index.to_s.rjust(3)+') ')+simp(key)+dodgerblue(group_and_release_year) # ===================================================================== # # Next line displays the URL # ===================================================================== # left_pad = 7 e powderblue((' ' * left_pad)+url) # Left-padded URL. }; e exit if shall_we_exit end
#¶ ↑
show_help
(help tag)¶ ↑
To invoke this, try:
eurodance --help
#¶ ↑
# File lib/multimedia_paradise/audio/genres/genre.rb, line 585 def show_help( shall_we_exit = true, show_opn = false ) if shall_we_exit == :then_exit shall_we_exit = true end e opnn if show_opn; e ' --download # to download all '+name_of_the_genre?+ ' songs locally' opnn if show_opn; e ' --generate-homepage # to generate a homepage' opnn if show_opn; e ' --m3u # to generate a .m3u playlist (a file)' opnn if show_opn; e ' --open # to open the respective playlist in your editor' opnn if show_opn; e ' --overview # to show which entries are registered' opnn if show_opn; e ' --years # to sort via years (most recent year will come last)' opnn if show_opn; e ' --file? # to show where the yaml file is stored' opnn if show_opn; e ' --reverse-years # to sort via years in a reverse manner '\ '(most recent year will come first)' opnn if show_opn; e ' play 17 # open the track at position 17 in the browser' opnn if show_opn; e ' # so that you can play it' e exit if shall_we_exit end
#¶ ↑
sort_playlist_via_years
¶ ↑
This method sorts the playlist via the years. We can work on the @dataset variable for this to work.
You can try this method like this:
trance --sort-by-years
#¶ ↑
# File lib/multimedia_paradise/audio/genres/genre.rb, line 377 def sort_playlist_via_years( sort_mode_to_use = :normal ) if sort_mode_to_use == :normal _ = @dataset.sort_by {|key, array| value = array[2] value = 0 if value.nil? # "Rescue". value } else _ = @dataset.sort_by {|key, array| -array[2] } end @dataset = Hash[_] end