Class: MultimediaParadise::Video::CorrectVideoNumbers

Inherits:
Base
  • Object
show all
Defined in:
lib/multimedia_paradise/video/correct_video_numbers.rb

Overview

MultimediaParadise::CorrectVideoNumbers.new

Constant Summary

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

Methods included from CommandlineArgumentsModule

#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(i = dir?, , run_already = true) ⇒ CorrectVideoNumbers

#

initialize

#


38
39
40
41
42
43
44
45
46
# File 'lib/multimedia_paradise/video/correct_video_numbers.rb', line 38

def initialize(
    i           = dir?,
    run_already = true
  )
  register_sigint
  reset
  set_input(i)
  run if run_already
end

Instance Method Details

#all_files?Boolean

#

all_files?

#

Returns:

  • (Boolean)


80
81
82
# File 'lib/multimedia_paradise/video/correct_video_numbers.rb', line 80

def all_files?
  @all_files
end

#check_if_there_were_any_wrong_video_filesObject

#

check_if_there_were_any_wrong_video_files

#


101
102
103
104
105
106
107
# File 'lib/multimedia_paradise/video/correct_video_numbers.rb', line 101

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) ⇒ Object

#

colourize_real_title

#


112
113
114
115
116
117
118
# File 'lib/multimedia_paradise/video/correct_video_numbers.rb', line 112

def colourize_real_title(i = @real_title)
  if Object.const_defined? :Colours
    COLOURS.seagreen(i)
  else
    sfancy(i)
  end
end

#dir?Boolean

#

dir?

#

Returns:

  • (Boolean)


73
74
75
# File 'lib/multimedia_paradise/video/correct_video_numbers.rb', line 73

def dir?
  (Dir.pwd+'/').squeeze '/'
end

#obtain_all_videofilesObject

#

obtain_all_videofiles

#


123
124
125
126
127
128
129
130
# File 'lib/multimedia_paradise/video/correct_video_numbers.rb', line 123

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

#output(i) ⇒ Object

#

output

This will output something, by combining opn() with e().

#


137
138
139
# File 'lib/multimedia_paradise/video/correct_video_numbers.rb', line 137

def output(i)
  opnn; e i
end

#process_these_videofiles(i = all_files?) ) ⇒ Object

#

process_these_videofiles

#


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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/multimedia_paradise/video/correct_video_numbers.rb', line 144

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?Boolean

#

real_title?

#

Returns:

  • (Boolean)


87
88
89
# File 'lib/multimedia_paradise/video/correct_video_numbers.rb', line 87

def real_title?
  colourize_real_title(@real_title)
end

#resetObject

#

reset (reset tag)

#


51
52
53
54
55
56
57
58
# File 'lib/multimedia_paradise/video/correct_video_numbers.rb', line 51

def reset
  super()
  infer_the_namespace
  # ======================================================================= #
  # === @n_wrong_videos
  # ======================================================================= #
  @n_wrong_videos = 0
end

#runObject

#

run (run tag)

#


243
244
245
246
247
248
# File 'lib/multimedia_paradise/video/correct_video_numbers.rb', line 243

def run
  reset
  obtain_all_videofiles
  process_these_videofiles
  check_if_there_were_any_wrong_video_files
end

#set_input(i = dir?) ) ⇒ Object

#

set_input

#


63
64
65
66
67
68
# File 'lib/multimedia_paradise/video/correct_video_numbers.rb', line 63

def set_input(i = dir?)
  i = i.first if i.is_a? Array
  i = dir? if i.nil?
  i = i.to_s.dup if i
  @input = i
end

#set_real_title(i) ⇒ Object

#

set_real_title

#


94
95
96
# File 'lib/multimedia_paradise/video/correct_video_numbers.rb', line 94

def set_real_title(i)
  @real_title = i
end