Class: MultimediaParadise::Genre
- Inherits:
-
Base
- Object
- Base
- MultimediaParadise::Genre
show all
- Includes:
- Genres
- Defined in:
- lib/multimedia_paradise/audio/genres/genre.rb
Overview
Constant Summary
collapse
- DEFAULT_FILE =
MultimediaParadise::Genres::EURODANCE_FILE
Constants included
from Genres
MultimediaParadise::Genres::BOOGIE_FILE, MultimediaParadise::Genres::CONCERTS_SONGS_FILE, MultimediaParadise::Genres::EURODANCE_FILE, MultimediaParadise::Genres::GENRE_DIR, MultimediaParadise::Genres::HIP_HOP_FILE, MultimediaParadise::Genres::ITALIAN_SONGS_FILE, MultimediaParadise::Genres::THE_1980s_FILE, MultimediaParadise::Genres::TRANCE_FILE
Constants inherited
from Base
Base::ERROR, Base::ERROR_LINE, Base::NAMESPACE, Base::USE_THIS_NAMESPACE_FOR_THE_COLOURS, Base::USE_THIS_NAMESPACE_FOR_THE_CORE_COLOURS
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#actions, #append_what_into, #be_silent, #be_verbose?, #beautiful_url, #cartoons_directory?, #clear_the_internal_hash, #cliner, #cliner_with_time_stamp, #colourized_comment, #copy_file, #crimson, #dataset_from_file_video_collection, #dd_mm_yyyy, #debug?, #default_readlines, #directory_to_realvids?, #do_not_use_opn, #dodgerblue, #does_the_video_player_support_this_commandline?, #e, #ecomment, #ecrimson, #efancy, #enable_debug, #ensure_main_encoding, #ensure_that_the_output_directory_exists, #eparse, #erev, #esystem, #ewarn, #file_video_collection?, #filter_for_audio_files, #filter_for_video_files, #forestgreen, #gold, #grey, #hh_mm_ss, #home_x_video?, #indianred, #infer_the_namespace, #internal_hash?, #is_audio_file?, #is_mkv?, #is_mp3?, #is_mp4?, #is_multimedia_file?, #is_on_roebe?, #is_video_file?, #konsole_colour_peru, #lightblue, #lightgreen, #load_yaml, #local_audio_directory?, #log_dir?, #map_symbol_to_locally_existing_file, #mediumorchid, #mediumpurple, #mediumslateblue, #mkdir, #move_file, #namespace?, #no_file_exists, #no_file_exists_at, #olive, #olivedrab, #opne, #opnecomment, #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
#all_input_starts_with_a_number?, #commandline_arguments?, #commandline_arguments_as_a_string, #first_argument?, #first_non_hyphened_commandline_argument?, #set_commandline_arguments
Constructor Details
#initialize(i = nil, run_already = true) ⇒ Genre
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/multimedia_paradise/audio/genres/genre.rb', line 59
def initialize(
i = nil,
run_already = true
)
reset
set_yaml_file(
DEFAULT_FILE
)
set_commandline_arguments(i)
run if run_already
end
|
Class Method Details
.[](i = ARGV) ⇒ Object
686
687
688
|
# File 'lib/multimedia_paradise/audio/genres/genre.rb', line 686
def self.[](i = ARGV)
new(i)
end
|
Instance Method Details
#dataset? ⇒ Boolean
Also known as:
full_dataset?
427
428
429
|
# File 'lib/multimedia_paradise/audio/genres/genre.rb', line 427
def dataset?
@dataset
end
|
#do_the_default_action ⇒ Object
Also known as:
default_action
#
do_the_default_action
Presently, the default action is to show all available songs.
#
314
315
316
|
# File 'lib/multimedia_paradise/audio/genres/genre.rb', line 314
def do_the_default_action
show_available_songs(:then_exit)
end
|
#download_file_at_number(i) ⇒ Object
#
download_file_at_number
Invocation example:
eurodance 62
#
536
537
538
539
540
541
542
543
544
545
546
547
|
# File 'lib/multimedia_paradise/audio/genres/genre.rb', line 536
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(this_dataset = full_dataset?)
) ⇒ Object
Also known as:
download_remote_file
#
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
#
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
|
# File 'lib/multimedia_paradise/audio/genres/genre.rb', line 485
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]
opne
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 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
new_file_name = rename_this_file(new_file_name)
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, _)
opne rev+'The file name now is `'+sfile(_)+rev+'`, in the '\
'directory `'+sdir(store_here)+rev+'`.'
}
end
|
#files? ⇒ Boolean
#
files?
This method will return all remote files, aka URLs, in particular to youtube files. The user can then create a playlist from this or batch-download these files.
#
155
156
157
|
# File 'lib/multimedia_paradise/audio/genres/genre.rb', line 155
def files?
dataset?.values.map {|entry| entry[1] }
end
|
#generate_homepage ⇒ Object
#
generate_homepage
This will generate a webpage/homepage, by using the links from the genre.
Invocation example:
eurodance --homepage
#
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
|
# File 'lib/multimedia_paradise/audio/genres/genre.rb', line 648
def generate_homepage
_ = '<html><body>'.dup _ << '<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>'
into = self.class.inspect.to_s.split(':').last.downcase
into = log_dir?+into+'.html'
opne "#{rev}Now storing into the file `#{sfile(into)}#{rev}`."
write_what_into(_, into)
end
|
#generate_m3u_playlist ⇒ Object
#
generate_m3u_playlist
#
415
416
417
418
419
420
421
422
|
# File 'lib/multimedia_paradise/audio/genres/genre.rb', line 415
def generate_m3u_playlist
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 ⇒ Object
#
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"
#
615
616
617
|
# File 'lib/multimedia_paradise/audio/genres/genre.rb', line 615
def guess_the_title_based_on_the_yaml_file
File.basename(@yaml_file).sub(/\.yml$/,'')
end
|
#load_yaml_dataset ⇒ Object
#
load_yaml_dataset
This method will also make @dataset available.
#
134
135
136
137
138
139
140
141
142
143
144
145
146
|
# File 'lib/multimedia_paradise/audio/genres/genre.rb', line 134
def load_yaml_dataset
_ = yaml_file?
begin @dataset = YAML.load_file(_)
rescue ArgumentError @dataset = File.read(_)
rescue Exception => error
opne 'An error happened on line '+__LINE__.to_s+'.'
pp error
pp error.class
end
sanitize_yaml_dataset end
|
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
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
|
# File 'lib/multimedia_paradise/audio/genres/genre.rb', line 180
def (i = commandline_arguments?)
if i.is_a? Array
if i.last =~ /^\d+$/
i = [i.join(' ')]
end
i.each {|entry| (entry) }
else
case i.delete('-').downcase when /^-?-?download$/,
'--dl',
'dl'
download_remote_files
exit
when /^-?-?generate(_|-)?homepage$/i,
'genhomepage',
'homepage',
'web',
/^-?-?webpage$/i,
/^-?-?html$/i
generate_homepage
exit
when /^play (\d+)/,
/^open (\d+)/
require 'open'
url = obtain_url_from_entry_at_this_position($1.to_s.dup)
open_in_browser(url)
exit
when '--playlist',
'playlist',
'--generate_playlist',
'--generateplaylist',
'--generate-playlist',
'generateplaylist',
'm3u',
'--m3u'
generate_m3u_playlist exit
when /^-?-?show(_|-)?only(_|-)?the(_|-)?URLs$/i,
/^-?-?only(_|-)?URLs$/i,
/^-?-?URLs?$/i show_only_the_URLs
exit
when /^-?-?only(_|-)?names$/i
show_only_names
exit
when /^-?-?file\??/
show_the_location_of_the_yaml_file
exit
when '--help','help','?'
show_help(:then_exit)
when 'open','OPEN','--open','op','o'
open_playlist_in_your_editor
exit
when '--reverse-years','reverseyears','--sort-by-years-reverse',
'sortbyyearsreverse'
sort_playlist_via_years(:reverse)
do_the_default_action
when '--year','--years','--sort','--sort-via-year','--sort-by-years',
'sortbyyears','years','year','sort','sortviayear'
sort_playlist_via_years
do_the_default_action
when '--overview','overview'
show_available_songs(:then_exit)
when /^(\d+)$/
download_file_at_number($1.to_s.dup)
else
default_action
end
end
end
|
#name_of_the_genre? ⇒ Boolean
#
name_of_the_genre?
This method will return the genre in use.
#
624
625
626
627
628
|
# File 'lib/multimedia_paradise/audio/genres/genre.rb', line 624
def name_of_the_genre?
_ = self.class.name.to_s
_ = _.split(':').last if _.include? ':'
return _.gsub(/The/,'')
end
|
#obtain_url_from_entry_at_this_position(i) ⇒ Object
#
obtain_url_from_entry_at_this_position
We obtain (and return) the remote URL from this entry.
#
563
564
565
566
567
568
569
570
571
572
573
|
# File 'lib/multimedia_paradise/audio/genres/genre.rb', line 563
def obtain_url_from_entry_at_this_position(i)
i = i.to_i - 1
_ = full_dataset?
keys = _.keys
url = _[keys[i]][1]
return url
end
|
#open_playlist_in_your_editor ⇒ Object
#
open_playlist_in_your_editor
Invoke such as by doing:
trance --open
#
123
124
125
126
127
|
# File 'lib/multimedia_paradise/audio/genres/genre.rb', line 123
def open_playlist_in_your_editor
_ = yaml_file?
_ = 'bluefish '+_
esystem(_)
end
|
#opnn(i = NAMESPACE) ⇒ Object
633
634
635
|
# File 'lib/multimedia_paradise/audio/genres/genre.rb', line 633
def opnn(i = NAMESPACE)
super(i)
end
|
#rename_this_file(i) ⇒ Object
#
rename_this_file
This will rename the file and sanitize it, then return the new file name.
#
465
466
467
468
469
470
471
|
# File 'lib/multimedia_paradise/audio/genres/genre.rb', line 465
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 ⇒ Object
74
75
76
77
78
79
80
81
|
# File 'lib/multimedia_paradise/audio/genres/genre.rb', line 74
def reset
super()
@dataset = nil
infer_the_namespace
end
|
#return_all_remote_urls ⇒ Object
#
return_all_remote_urls
#
441
442
443
444
445
446
447
|
# File 'lib/multimedia_paradise/audio/genres/genre.rb', line 441
def return_all_remote_urls
dataset = dataset?
dataset.map! {|key, inner_array|
inner_array[1] }
return dataset
end
|
#return_dataset_from_one_random_song ⇒ Object
#
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.
#
455
456
457
|
# File 'lib/multimedia_paradise/audio/genres/genre.rb', line 455
def return_dataset_from_one_random_song
return dataset?.to_a.sample(1).to_h
end
|
#return_name_from_class_name(i = @namespace) ⇒ Object
#
return_name_from_class_name
#
552
553
554
555
556
|
# File 'lib/multimedia_paradise/audio/genres/genre.rb', line 552
def return_name_from_class_name(i = @namespace)
_ = @namespace.to_s.downcase
_ = _.split(':').last if _.include? ':'
return _
end
|
#run ⇒ Object
679
680
681
|
# File 'lib/multimedia_paradise/audio/genres/genre.rb', line 679
def run
end
|
#sanitize_yaml_dataset ⇒ Object
#
sanitize_yaml_dataset
#
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
# File 'lib/multimedia_paradise/audio/genres/genre.rb', line 162
def sanitize_yaml_dataset
if @dataset.is_a? String
_ = @dataset.split(N)
_.reject! {|entry| entry.start_with? '#' }
_.reject! {|entry| entry.strip.empty? }
end
end
|
#set_dataset(i) ⇒ Object
434
435
436
|
# File 'lib/multimedia_paradise/audio/genres/genre.rb', line 434
def set_dataset(i)
@dataset = i
end
|
#set_yaml_file(i) ⇒ Object
86
87
88
89
90
91
92
|
# File 'lib/multimedia_paradise/audio/genres/genre.rb', line 86
def set_yaml_file(i)
@yaml_file = i
load_yaml_dataset end
|
#show_available_songs(use_this_dataset = @dataset, shall_we_exit = :then_exit) ⇒ Object
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
|
# File 'lib/multimedia_paradise/audio/genres/genre.rb', line 321
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
_ = use_this_dataset n_entries = _.keys.size
opne 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)
left_pad = 7
e powderblue((' ' * left_pad)+url) }; e
exit if shall_we_exit
end
|
#show_help(shall_we_exit = true, show_opn = false) ⇒ Object
#
show_help (help tag)
To invoke this, try:
eurodance --help
#
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
|
# File 'lib/multimedia_paradise/audio/genres/genre.rb', line 583
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
|
#show_only_names ⇒ Object
#
show_only_names
To invoke this, do:
eurodance --onlynames
#
391
392
393
394
395
|
# File 'lib/multimedia_paradise/audio/genres/genre.rb', line 391
def show_only_names
@dataset.each_pair {|key, dataset|
e slateblue(key.to_s)
}
end
|
#show_only_the_URLs ⇒ Object
#
show_only_the_URLs
To invoke this, do:
eurodance --only-URLs
#
405
406
407
408
409
410
|
# File 'lib/multimedia_paradise/audio/genres/genre.rb', line 405
def show_only_the_URLs
@dataset.each_pair {|key, dataset|
url = dataset[1]
e slateblue(url.to_s)
}
end
|
#show_the_location_of_the_yaml_file ⇒ Object
#
show_the_location_of_the_yaml_file
To invoke this method, try:
eurodance --file?
#
111
112
113
|
# File 'lib/multimedia_paradise/audio/genres/genre.rb', line 111
def show_the_location_of_the_yaml_file
e sfile(@yaml_file)
end
|
#sort_playlist_via_years(sort_mode_to_use = :normal) ⇒ Object
#
sort_playlist_via_years
This method sorts the playlist via the years. We can work on the You can try this method like this:
trance --sort-by-years
#
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
|
# File 'lib/multimedia_paradise/audio/genres/genre.rb', line 366
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? value
}
else
_ = @dataset.sort_by {|key, array|
-array[2]
}
end
@dataset = Hash[_]
end
|
#yaml_file? ⇒ Boolean
#
yaml_file?
This will always point at the main yaml file.
#
99
100
101
|
# File 'lib/multimedia_paradise/audio/genres/genre.rb', line 99
def yaml_file?
@yaml_file
end
|