Class: MultimediaParadise::Video::PrepareVideoLecture
- Inherits:
-
Base
- Object
- Base
- MultimediaParadise::Video::PrepareVideoLecture
show all
- Defined in:
- lib/multimedia_paradise/video/prepare_video_lecture.rb
Overview
Constant Summary
collapse
- DEFAULT_URLS =
#
DEFAULT_URLS
Which URLS to use by default.
#
%w(
https://www.youtube.com/watch?v=tyANFcnrM8I
https://www.youtube.com/watch?v=4zHm_6AQ7CY
https://www.youtube.com/watch?v=0OCnHNk2Hac
)
- BASE_DIRECTORY =
#
BASE_DIRECTORY
This is the directory we will log the output to.
On my system, this will be at:
"/Depot/Temp/MultimediaProject/video_lectures/"
#
"#{::MultimediaParadise.log_directory?}video_lectures/"
- DELAY_IN_N_SECONDS =
#
DELAY_IN_N_SECONDS
Specify the delay that the interval-video will use.
#
8
- USE_DELAY_WHEN_MERGING_THE_VIDEO_FILES =
#
USE_DELAY_WHEN_MERGING_THE_VIDEO_FILES
#
true
- BLACK_MP4_VIDEO_FILE =
'black.mp4'
- OUTPUT_FILE =
'output.mp4'
- COMMAND =
'youtube-dl'
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
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, #opnn, #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(these_urls = nil, run_already = true) ⇒ PrepareVideoLecture
#
initialize
The first argument is the list of remote URLs.
#
88
89
90
91
92
93
94
95
|
# File 'lib/multimedia_paradise/video/prepare_video_lecture.rb', line 88
def initialize(
these_urls = nil,
run_already = true
)
reset
set_work_on_these_urls(these_urls)
run if run_already
end
|
Instance Method Details
#create_base_directory ⇒ Object
#
create_base_directory
#
129
130
131
|
# File 'lib/multimedia_paradise/video/prepare_video_lecture.rb', line 129
def create_base_directory
mkdir(download_dir?)
end
|
#create_black_image ⇒ Object
#
create_black_image
We will use ImageMagick convert to create a black .png file.
#
152
153
154
155
|
# File 'lib/multimedia_paradise/video/prepare_video_lecture.rb', line 152
def create_black_image
_ = 'convert -size 320x240 xc:black black.png'
system _
end
|
#create_black_mp4_video_file ⇒ Object
#
create_black_mp4_video_file
#
160
161
162
163
164
|
# File 'lib/multimedia_paradise/video/prepare_video_lecture.rb', line 160
def create_black_mp4_video_file
output_file = BLACK_MP4_VIDEO_FILE
_ = 'ffmpeg -f lavfi -i color=color=black -t '+DELAY_IN_N_SECONDS.to_s+' '+output_file
system _ unless File.exist? output_file
end
|
#download_dir? ⇒ Boolean
136
137
138
|
# File 'lib/multimedia_paradise/video/prepare_video_lecture.rb', line 136
def download_dir?
BASE_DIRECTORY
end
|
#download_the_videos ⇒ Object
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
|
# File 'lib/multimedia_paradise/video/prepare_video_lecture.rb', line 220
def download_the_videos
@array_downloaded_files = [] opne 'Now downloading the URLs. The download directory will be at:'+
sdir(download_dir?)
urls?.each {|remote_url|
opne 'Now working on the URL `'+sfancy(remote_url)+'` via '+
simp(COMMAND)+'.'
cmd = COMMAND+' '+remote_url
result = `#{cmd}` File.delete('gmon.out') if File.exist? 'gmon.out' regex = /Merging formats into "(.*)"/
result =~ regex
this_file = $1.to_s.dup
if File.exist? this_file
new_filename = this_file.tr(' ','_').tr("'",'').tr('-','_').
tr('(','').tr(')','').tr('&','')
new_filename.squeeze! '_'
opnn; rename(this_file, new_filename)
this_file = new_filename end
@array_downloaded_files << this_file
opne 'The final file result is: `'+sfile(this_file)+'`.'
}
end
|
#enter_base_directory ⇒ Object
143
144
145
|
# File 'lib/multimedia_paradise/video/prepare_video_lecture.rb', line 143
def enter_base_directory
cd download_dir?
end
|
#merge_the_videos ⇒ Object
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
# File 'lib/multimedia_paradise/video/prepare_video_lecture.rb', line 197
def merge_the_videos
n_videos = @array_downloaded_files.size.to_s
opne 'These videos ('+simp(n_videos)+') will next be merged.'
if USE_DELAY_WHEN_MERGING_THE_VIDEO_FILES
_ = @array_downloaded_files
array = Array.new(_.size, BLACK_MP4_VIDEO_FILE)
_ = _.zip(array).flatten
_.pop if _.last == BLACK_MP4_VIDEO_FILE
@array_downloaded_files = _
end
pp @array_downloaded_files
::MultimediaParadise.merge(@array_downloaded_files)
end
|
#remove_base_directory ⇒ Object
178
179
180
|
# File 'lib/multimedia_paradise/video/prepare_video_lecture.rb', line 178
def remove_base_directory
FileUtils.rm_rf(download_dir?) unless download_dir? == '/'
end
|
#report_everything_has_finished ⇒ Object
#
report_everything_has_finished
#
185
186
187
188
189
190
191
192
|
# File 'lib/multimedia_paradise/video/prepare_video_lecture.rb', line 185
def report_everything_has_finished
result = 'Everything has now finished.'
if File.exist? OUTPUT_FILE
result << ' It may be available here: '+
sfile((Dir.pwd+'/'+OUTPUT_FILE).squeeze('/'))
end
opne result
end
|
#reset ⇒ Object
100
101
102
103
104
|
# File 'lib/multimedia_paradise/video/prepare_video_lecture.rb', line 100
def reset
super()
infer_the_namespace
@array_downloaded_files = []
end
|
#run ⇒ Object
249
250
251
252
253
254
255
256
257
258
259
260
261
|
# File 'lib/multimedia_paradise/video/prepare_video_lecture.rb', line 249
def run
show_welcome_message
remove_base_directory
create_base_directory
enter_base_directory
if USE_DELAY_WHEN_MERGING_THE_VIDEO_FILES
create_black_mp4_video_file
end
download_the_videos
merge_the_videos
report_everything_has_finished
end
|
#set_work_on_these_urls(i = DEFAULT_URLS) ⇒ Object
#
set_work_on_these_urls
Pass here the remote URLS to use.
#
111
112
113
114
115
|
# File 'lib/multimedia_paradise/video/prepare_video_lecture.rb', line 111
def set_work_on_these_urls(i = DEFAULT_URLS)
i = [i] unless i.is_a? Array
i = DEFAULT_URLS if i.empty?
@work_on_these_urls = i end
|
#show_welcome_message ⇒ Object
169
170
171
172
173
|
# File 'lib/multimedia_paradise/video/prepare_video_lecture.rb', line 169
def show_welcome_message
unless input?.empty?
opne 'Welcome! We will next work on the given URLs.'
end
end
|
#work_on_these_urls? ⇒ Boolean
Also known as:
work_on_these_urls, urls?, input?
120
121
122
|
# File 'lib/multimedia_paradise/video/prepare_video_lecture.rb', line 120
def work_on_these_urls?
@work_on_these_urls
end
|