Class: MultimediaParadise::SimulateYoutubePlaylist
- Inherits:
-
Base
- Object
- Base
- MultimediaParadise::SimulateYoutubePlaylist
show all
- Defined in:
- lib/multimedia_paradise/multimedia/simulate_youtube_playlist.rb
Overview
Constant Summary
collapse
- NAMESPACE =
inspect
- FILE_YOUTUBE_PLAYLIST =
#
FILE_YOUTUBE_PLAYLIST
#
::MultimediaParadise.project_base_dir?+
'yaml/youtube_playlist/youtube_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 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(commandline_arguments = nil, run_already = true) ⇒ SimulateYoutubePlaylist
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/multimedia_paradise/multimedia/simulate_youtube_playlist.rb', line 38
def initialize(
commandline_arguments = nil,
run_already = true
)
reset
set_commandline_arguments(
commandline_arguments
)
run if run_already
end
|
Class Method Details
.[](i = '') ⇒ Object
201
202
203
|
# File 'lib/multimedia_paradise/multimedia/simulate_youtube_playlist.rb', line 201
def self.[](i = '')
new(i)
end
|
Instance Method Details
#opnn(&block) ⇒ Object
86
87
88
|
# File 'lib/multimedia_paradise/multimedia/simulate_youtube_playlist.rb', line 86
def opnn(&block)
super(NAMESPACE, &block)
end
|
#reset ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/multimedia_paradise/multimedia/simulate_youtube_playlist.rb', line 52
def reset
super()
@inner_hash = {}
@inner_hash[:shall_we_download_these_files] = true
set_work_on_this_subsection(:eurodance)
set_work_on_this_subsection(:married_with_children)
end
|
#run ⇒ Object
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
# 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)
dataset = sanitize_dataset(dataset)
work_on_this_hash(dataset)
end
end
|
#sanitize_dataset(hash) ⇒ Object
93
94
95
96
97
98
99
100
101
102
103
|
# 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) ⇒ Object
#
set_work_on_this_subsection
#
72
73
74
|
# File 'lib/multimedia_paradise/multimedia/simulate_youtube_playlist.rb', line 72
def set_work_on_this_subsection(i)
@inner_hash[:work_on_this_subsection] = i.to_s
end
|
#shall_we_download_these_files? ⇒ Boolean
#
shall_we_download_these_files?
#
79
80
81
|
# File 'lib/multimedia_paradise/multimedia/simulate_youtube_playlist.rb', line 79
def shall_we_download_these_files?
@inner_hash[:shall_we_download_these_files]
end
|
#work_on_this_hash(hash, work_on_this_subsection = ) ⇒ Object
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
# 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.'
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}`
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._ ]+)"/ 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
|