class MultimediaParadise::SimulateYoutubePlaylist
Constants
- FILE_YOUTUBE_PLAYLIST
#¶ ↑
FILE_YOUTUBE_PLAYLIST
¶ ↑#¶ ↑
- NAMESPACE
#¶ ↑
NAMESPACE
¶ ↑#¶ ↑
Public Class Methods
[](i = '')
click to toggle source
new( commandline_arguments = nil, run_already = true )
click to toggle source
Public Instance Methods
opnn(&block)
click to toggle source
reset()
click to toggle source
#¶ ↑
reset (reset tag)¶ ↑
#¶ ↑
Calls superclass method
MultimediaParadise::Base#reset
# File lib/multimedia_paradise/multimedia/simulate_youtube_playlist.rb, line 52 def reset super() # ======================================================================= # # === @inner_hash # ======================================================================= # @inner_hash = {} # ======================================================================= # # === :shall_we_download_these_files # ======================================================================= # @inner_hash[:shall_we_download_these_files] = true # ======================================================================= # # === :work_on_this_subsection # ======================================================================= # set_work_on_this_subsection(:eurodance) set_work_on_this_subsection(:married_with_children) end
run()
click to toggle source
#¶ ↑
run (run tag)¶ ↑
#¶ ↑
# File lib/multimedia_paradise/multimedia/simulate_youtube_playlist.rb, line 183 def run if File.exist? FILE_YOUTUBE_PLAYLIST dataset = YAML.load_file(FILE_YOUTUBE_PLAYLIST) # ===================================================================== # # First sanitize the dataset. # ===================================================================== # dataset = sanitize_dataset(dataset) # ===================================================================== # # Now we assume the dataset has been sanitized. Delegate to another # method next. # ===================================================================== # work_on_this_hash(dataset) end end
sanitize_dataset(hash)
click to toggle source
#¶ ↑
sanitize_dataset
¶ ↑
#¶ ↑
# File lib/multimedia_paradise/multimedia/simulate_youtube_playlist.rb, line 93 def sanitize_dataset(hash) hash.each_pair {|key, value| value.map! {|remote_URL| unless remote_URL.start_with? 'http' remote_URL = beautiful_url(remote_URL) end remote_URL } } return hash end
set_work_on_this_subsection(i)
click to toggle source
shall_we_download_these_files?()
click to toggle source
work_on_this_hash( hash, work_on_this_subsection = @inner_hash[:work_on_this_subsection] )
click to toggle source
#¶ ↑
work_on_this_hash
¶ ↑
#¶ ↑
# File lib/multimedia_paradise/multimedia/simulate_youtube_playlist.rb, line 111 def work_on_this_hash( hash, work_on_this_subsection = @inner_hash[:work_on_this_subsection] ) work_on_this_subsection = work_on_this_subsection.to_s if hash.has_key? work_on_this_subsection work_on_these_remote_URLs = hash[work_on_this_subsection] e rev+ 'This playlist contains '+ steelblue(work_on_these_remote_URLs.size.to_s)+ ' entries.' # ===================================================================== # # Consider downloading these remote files next: # ===================================================================== # if shall_we_download_these_files? e 'Now downloading these files.' cd log_dir? e 'Trying to create a playlist next:' require 'multimedia_paradise/audio/create_m3u_playlist.rb' MultimediaParadise.create_m3u_playlist( work_on_these_remote_URLs ) mkdir 'youtube_playlist' unless File.directory? 'youtube_playlist' cd 'youtube_playlist' e 'Working from the directory `'+sdir(return_pwd)+'`.' work_on_these_remote_URLs.each_with_index {|remote_URL, index| index += 1 e 'Working on the remote URL `'+steelblue(remote_URL)+'` next.' download_command = "youtube-dl #{remote_URL}" e lightblue(download_command) result = `#{download_command}` # ================================================================= # # Try to rename it next: # ================================================================= # if result.include? 'Merging formats into' splitted = result.split("\n") new_filename = splitted.select {|line| line.include? 'Merging formats into ' } new_filename = new_filename.first if new_filename.is_a? Array filename = '"'+new_filename.dup+"'" regex_to_use = /(Merging formats into) "([-A-Za-z0-9._ ]+)"/ # See: https://rubular.com/r/uLTQUI5FbxDssJ new_filename =~ regex_to_use if $2 filename = $2.to_s.dup new_filename = '00'+index.to_s+'_'+$2.to_s. tr(' ','_') end new_filename.delete!("'") new_filename.squeeze!('_') unless File.exist? new_filename e 'Now renaming from '+ sfile(filename)+' to '+ sfile(new_filename)+ '.' rename_file(filename, new_filename) end end } end work_on_these_remote_URLs.each {|remote_URL| e sfancy(remote_URL) Open.in_browser(remote_URL) { :do_not_open_in_the_background } } else e 'No subsection called '+work_on_this_subsection+' found.' end end