Class: MultimediaParadise::Video::CopyMissingVideoFiles
- Inherits:
-
Base
- Object
- Base
- MultimediaParadise::Video::CopyMissingVideoFiles
show all
- Defined in:
- lib/multimedia_paradise/video/copy_missing_video_files.rb
Overview
CopyMissingVideoFiles.new
Constant Summary
collapse
- NAMESPACE =
inspect
- LJUST =
28
- SUBDIR =
#
DEFAULT_TARGET_DIRECTORY
#
'/Video/Realvids/'
- DEFAULT_TARGET_DIRECTORY =
#
DEFAULT_TARGET_DIRECTORY
#
ENV['USB1'].to_s+SUBDIR
Constants inherited
from Base
Base::ERROR, Base::ERROR_LINE, 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(target_directory = DEFAULT_TARGET_DIRECTORY, run_already = true) ⇒ CopyMissingVideoFiles
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/multimedia_paradise/video/copy_missing_video_files.rb', line 54
def initialize(
target_directory = DEFAULT_TARGET_DIRECTORY,
run_already = true
)
register_sigint
reset
set_start_directory
set_target_directory(
target_directory
)
run if run_already
end
|
Instance Method Details
#compare_the_two_directories ⇒ Object
#
compare_the_two_directories
#
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
|
# File 'lib/multimedia_paradise/video/copy_missing_video_files.rb', line 186
def compare_the_two_directories
@files_from_target_directory.each {|entry|
result = @files_from_start_directory.map {|e|
File.basename(e)
}.include? File.basename(entry)
if result else
opnn { :no_colon }
e
e
e swarn('The following video file is NOT '+
'included: '+sfile(File.basename(entry)))
opnn
erev 'It will thus be copied to the current directory, from the'
opne "#{rev}location `#{sfile(entry)}#{rev}`."
copy_video_file(entry)
end
}
end
|
#copy_video_file(i) ⇒ Object
209
210
211
212
213
214
215
216
|
# File 'lib/multimedia_paradise/video/copy_missing_video_files.rb', line 209
def copy_video_file(i)
@array_copied_these_files << i
if File.exist? i
FileUtils.cp(i, Dir.pwd)
else
opne rev+'Can not copy '+sfile(i)+rev+' as it does not exist.'
end
end
|
#find_alternative_to(i) ⇒ Object
117
118
119
120
121
122
123
124
|
# File 'lib/multimedia_paradise/video/copy_missing_video_files.rb', line 117
def find_alternative_to(i)
if i.include? 'USB2'
i = i.gsub(/USB2/, 'USB1')
elsif i.include? 'USB1'
i = i.gsub(/USB1/, 'USB2')
end
return i
end
|
#from? ⇒ Boolean
169
170
171
|
# File 'lib/multimedia_paradise/video/copy_missing_video_files.rb', line 169
def from?
@start_directory
end
|
#get_available_video_files ⇒ Object
#
get_available_video_files
#
255
256
257
258
259
260
261
262
263
264
265
266
267
268
|
# File 'lib/multimedia_paradise/video/copy_missing_video_files.rb', line 255
def get_available_video_files
cliner
opne 'Now obtaining available video files.'
opne 'We will use these two locations:'
e
e ' - '+sfancy(from?.ljust(LJUST))+' # Start Location.'
e ' - '+sfancy(target?.ljust(LJUST))+' # Target Location.'
e
opne "#{rev}Note that we will simply copy missing files from <- -> to."
cliner
@files_from_start_directory = Dir["#{from?}*"].sort.select {|entry| File.file?(entry) }
@files_from_target_directory = Dir["#{target?}*"].sort.select {|entry| File.file?(entry) }
reject_non_videos
end
|
#
This is the commandline-menu interface for this class.
#
131
132
133
134
135
136
137
138
139
140
141
142
143
|
# File 'lib/multimedia_paradise/video/copy_missing_video_files.rb', line 131
def (i)
if i.is_a? Array
i.each {|entry| (entry) }
else
case i
when /^-?-?help$/i
show_help(:then_exit)
end
end
end
|
#obtain_target_directory ⇒ Object
#
obtain_target_directory
#
148
149
150
151
152
153
154
155
156
157
|
# File 'lib/multimedia_paradise/video/copy_missing_video_files.rb', line 148
def obtain_target_directory
if Object.const_defined? :Mountpoints
mounted_devices = Mountpoints[].map {|entry| entry + SUBDIR }
mounted_devices.select! {|entry| Dir.exist? entry }
result = mounted_devices.first else
result = DEFAULT_TARGET_DIRECTORY
end
result
end
|
#reject_non_videos ⇒ Object
#
reject_non_videos
Here we will get rid of .srt files.
#
178
179
180
181
|
# File 'lib/multimedia_paradise/video/copy_missing_video_files.rb', line 178
def reject_non_videos
@files_from_start_directory.reject! {|entry| entry.include? '.srt'}
@files_from_target_directory.reject! {|entry| entry.include? '.srt'}
end
|
#report_finished_tasks ⇒ Object
#
report_finished_tasks
#
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
|
# File 'lib/multimedia_paradise/video/copy_missing_video_files.rb', line 221
def report_finished_tasks
if @array_copied_these_files.empty?
opne 'No file was copied. This could mean that everything is '
opne 'already existing on the target directory. '+
steelblue('\o/')
else
opne 'Finished!'
e
opne 'The following files were copied:'
e
@array_copied_these_files.sort.each {|file|
e " #{sfile(File.basename(file))}"
}
e
end
end
|
#reset ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/multimedia_paradise/video/copy_missing_video_files.rb', line 70
def reset
super()
@namespace = NAMESPACE
@array_copied_these_files = []
end
|
#run ⇒ Object
273
274
275
276
277
|
# File 'lib/multimedia_paradise/video/copy_missing_video_files.rb', line 273
def run
get_available_video_files
compare_the_two_directories
report_finished_tasks
end
|
#set_start_directory(i = return_pwd) ⇒ Object
#
set_start_directory
Our starting directory.
#
87
88
89
90
|
# File 'lib/multimedia_paradise/video/copy_missing_video_files.rb', line 87
def set_start_directory(i = return_pwd) i << '/' unless i.end_with? '/'
@start_directory = rds(i)
end
|
#set_target_directory(i = obtain_target_directory) ⇒ Object
#
set_target_directory
We will copy the video files to this target directory.
#
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
# File 'lib/multimedia_paradise/video/copy_missing_video_files.rb', line 97
def set_target_directory(
i = obtain_target_directory
)
i = i.first if i.is_a? Array
i = DEFAULT_TARGET_DIRECTORY if i.nil?
i = rds(i)
i = find_alternative_to(@start_directory) if i == @start_directory
@target_directory = rds(i)
if i.start_with? '--'
(i)
end
end
|
#show_help(optional_argument = :do_nothing) ⇒ Object
241
242
243
244
245
246
247
248
249
250
|
# File 'lib/multimedia_paradise/video/copy_missing_video_files.rb', line 241
def show_help(optional_argument = :do_nothing)
e
e 'This class can copy video files from another directory to the'
e 'target directory.'
e
case optional_argument
when :then_exit
exit
end
end
|
#target? ⇒ Boolean
162
163
164
|
# File 'lib/multimedia_paradise/video/copy_missing_video_files.rb', line 162
def target?
@target_directory
end
|