class MultimediaParadise::Video::CorrectVideoNumbers
Constants
- NAMESPACE
#¶ ↑
NAMESPACE
¶ ↑#¶ ↑
Public Class Methods
Public Instance Methods
all_files?()
click to toggle source
check_if_there_were_any_wrong_video_files()
click to toggle source
#¶ ↑
check_if_there_were_any_wrong_video_files
¶ ↑
#¶ ↑
# File lib/multimedia_paradise/video/correct_video_numbers.rb, line 109 def check_if_there_were_any_wrong_video_files cliner if @n_wrong_videos == 0 output 'All those '+sfancy(@all_files.size.to_s)+' video '+ 'files seem to be correct! \o/' end end
colourize_real_title(i = @real_title)
click to toggle source
dir?()
click to toggle source
obtain_all_videofiles()
click to toggle source
#¶ ↑
obtain_all_videofiles
¶ ↑
#¶ ↑
# File lib/multimedia_paradise/video/correct_video_numbers.rb, line 131 def obtain_all_videofiles @all_files = Dir['*'].sort @all_files.select! {|entry| is_video_file?(entry) # We only select video files. } output 'We found '+sfancy(@all_files.size.to_s)+' video '+ 'files in `'+sdir(dir?)+'`.' end
opne(i)
click to toggle source
output(i)
click to toggle source
process_these_videofiles(i = all_files?)
click to toggle source
#¶ ↑
process_these_videofiles
¶ ↑
#¶ ↑
# File lib/multimedia_paradise/video/correct_video_numbers.rb, line 152 def process_these_videofiles(i = all_files?) i.each {|entry| splitted = entry.split('_') number = splitted.first title = File.basename(splitted[1]).gsub(/#{File.extname(splitted[1])}/,'') @real_title = ::MultimediaParadise.obtain_title_at_position(number) if @real_title # Defined in shared/shared.rb @real_title.delete!(' ') else opnn; e 'There may be a problem for number '+sfancy(number.to_s)+'.' opnn; e 'It probably is not registered in the video-files .yml file.' if number.to_i > max_entries_registered? file = MultimediaParadise.location_of_yaml_file_with_registered_videofiles opne 'The max entry registered in the '+sfile(file)+' file '\ 'is '+sfancy(max_entries_registered?.to_s)+'.' opne 'Since the number is higher than that, this can not '\ 'possibly be correct.' opne 'We will next attempt to correct this problem.' end results = Dir[number.to_s+'*'].select {|inner_entry| is_video_file?(inner_entry) } first = results.first first =~ /\d+_(.+)\./ try_to_find_this_title = $1.to_s.dup # =================================================================== # # Chop at '_' if this is included, to avoid problems such as: # No match for `startrekiii_thesearchforspock` found. # =================================================================== # if try_to_find_this_title.include? '_' try_to_find_this_title = try_to_find_this_title[0, try_to_find_this_title.index('_')] end e try_to_find_this_title result = FindVideo[try_to_find_this_title] # =================================================================== # # Next, we try to find the shortest match here if we have more than # one result. # =================================================================== # if result.size > 1 result = result.sort {|key, value| key.size } result = result.first end result.flatten! # We care here only about the first two results. opne 'We will attempt to perform a rename action next:' extname = File.extname(entry) pp result new_name = result[1]+'_'+result[0].delete(' ')+extname e entry+sfancy(' -> ')+new_name opne 'Press y to apply the above operation next:' user_input = $stdin.gets.chomp if user_input.start_with? 'y' rename entry, new_name end end if @real_title.include? title.delete(' ') cliner output 'The videofile `'+sfile(entry)+'` is ok.' else # Must be a wrong name. @n_wrong_videos += 1 output 'Incorrect name: `'+sfancy(title)+'` versus `'+ real_title?+'` does not match.' use_this_extension = File.extname(entry) # =================================================================== # # In this case, these are the same videos, so we can attempt a # rename action. # =================================================================== # if title.downcase == @real_title.downcase output 'These two files seem to be the same, and the number '\ 'seems to match,' output 'so we will attempt to rename the faulty name next.' rename(entry, return_full_name_for_video_at_this_position( number, use_this_extension ) ) # =================================================================== # # Next, we handle the case of strings such as `OnceUponATimeInChina` # versus `OnceUponatimeinChina1`. The logic we use here is simple: # if size is larger than 5 (so we don't include CTHD), and if the # compared downcase of both files is to 80% identical, then we # assume that it may be a worthy rename-action. # =================================================================== # elsif title.size > 5 and (Roebe::Identical[title.downcase, @real_title.downcase] > 79) opnn; e 'Attempting a slightly different rename action.' rename(entry, return_full_name_for_video_at_this_position(number, use_this_extension) ) end output 'The position of the latter ('+real_title?+') should '+ 'have been -> '+simp(number)+' <- but it is instead.' end } end
real_title?()
click to toggle source
reset()
click to toggle source
#¶ ↑
reset¶ ↑
#¶ ↑
Calls superclass method
MultimediaParadise::Base#reset
# File lib/multimedia_paradise/video/correct_video_numbers.rb, line 56 def reset # (reset tag) super() # ======================================================================= # # === @n_wrong_videos # ======================================================================= # @n_wrong_videos = 0 # ======================================================================= # # === @namespace # ======================================================================= # @namespace = NAMESPACE end
run()
click to toggle source
set_input(i = dir?)
click to toggle source