Class: MultimediaParadise::Video::VideoInformation

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

Overview

MultimediaParadise::Video::VideoInformation.new

Constant Summary collapse

SHALL_WE_DEBUG =
#

SHALL_WE_DEBUG

#
false
VIDEO_STREAMS =
#

VIDEO_STREAMS

The registered videostreams come here.

#
%w(
  h264 mpeg1video msmpeg4v2 mpeg4
)
AUDIO_STREAMS =
#

AUDIO_STREAMS

#
%w( aac wmav2 mp2 mp3 )

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, #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 = nil, run_already = true) ⇒ VideoInformation

#

initialize

#


58
59
60
61
62
63
64
65
# File 'lib/multimedia_paradise/video/video_information.rb', line 58

def initialize(
    i           = nil,
    run_already = true
  )
  reset
  set_files(i)
  run if run_already
end

Instance Method Details

#audio?Boolean Also known as: audio

#

audio?

#

Returns:

  • (Boolean)


142
143
144
# File 'lib/multimedia_paradise/video/video_information.rb', line 142

def audio?
  @audio
end

#bitrate?Boolean

#

bitrate?

#

Returns:

  • (Boolean)


245
246
247
# File 'lib/multimedia_paradise/video/video_information.rb', line 245

def bitrate?
  @bitrate
end

#data?Boolean Also known as: data

#

data?

#

Returns:

  • (Boolean)


208
209
210
# File 'lib/multimedia_paradise/video/video_information.rb', line 208

def data?
  @data
end

#decompose(i) ⇒ Object

#

decompose

The input will hold all information.

#


368
369
370
371
372
373
374
375
376
377
378
379
380
381
# File 'lib/multimedia_paradise/video/video_information.rb', line 368

def decompose(i)
  i = i.split(N)
  if SHALL_WE_DEBUG
    opne 'The user wants to debug, so we will output the information'
    opne 'that is to be decomposed:'
    pp i
  end
  grab_all_streams = i.select {|entry|
    entry.strip.include? 'Stream #' # Grab all video and audio streams.
  }
  set_audio(grab_all_streams)
  set_video(grab_all_streams)
  set_resolution(grab_all_streams)
end

#determine_duration_of_the_fileObject

#

determine_duration_of_the_file

#


298
299
300
301
302
# File 'lib/multimedia_paradise/video/video_information.rb', line 298

def determine_duration_of_the_file
  use_this_regex = /Duration: (\d{1,2}:\d{1,2}:\d{1,2}.\d{1,2})/ # See: http://rubular.com/r/NYoZ9GMryH
  input_stream? =~ use_this_regex
  set_duration($1.to_s.dup)
end

#duration?Boolean

#

duration?

#

Returns:

  • (Boolean)


307
308
309
# File 'lib/multimedia_paradise/video/video_information.rb', line 307

def duration?
  @duration
end

#file?Boolean

#

files?

#

file?

Returns:

  • (Boolean)


114
115
116
# File 'lib/multimedia_paradise/video/video_information.rb', line 114

def files?
  @files
end

#files?Boolean

#

files?

#

Returns:

  • (Boolean)


111
112
113
# File 'lib/multimedia_paradise/video/video_information.rb', line 111

def files?
  @files
end

#input?Boolean

#

files?

#

input?

Returns:

  • (Boolean)


113
114
115
# File 'lib/multimedia_paradise/video/video_information.rb', line 113

def files?
  @files
end

#input_stream?Boolean

#

input_stream?

#

Returns:

  • (Boolean)


289
290
291
292
293
# File 'lib/multimedia_paradise/video/video_information.rb', line 289

def input_stream?
  inspect_this_file_via_ffmpeg(
    files?.first
  )
end

#inspect_this_file_via_ffmpeg(the_file = files?.first) ⇒ Object

#

inspect_this_file_via_ffmpeg

The argument given to this method should be an existing file.

#


181
182
183
184
185
# File 'lib/multimedia_paradise/video/video_information.rb', line 181

def inspect_this_file_via_ffmpeg(
    the_file = files?.first
  )
  `ffmpeg -i #{the_file} 2>&1` # The input-stream.
end

#name?Boolean

#

name?

#

Returns:

  • (Boolean)


119
120
121
122
123
# File 'lib/multimedia_paradise/video/video_information.rb', line 119

def name?
  _ = file?
  _ = _.first if _.is_a? Array
  _
end

#opnnObject

#

opnn

#


259
260
261
# File 'lib/multimedia_paradise/video/video_information.rb', line 259

def opnn
  super(NAMESPACE) if @report_the_namespace
end

#populate_main_dataObject

#

populate_main_data

#


165
166
167
# File 'lib/multimedia_paradise/video/video_information.rb', line 165

def populate_main_data
  @data = [video?, audio?] # Build up @data.
end

#report_audio_bitrateObject

#

report_audio_bitrate

#


231
232
233
234
235
236
237
238
239
240
# File 'lib/multimedia_paradise/video/video_information.rb', line 231

def report_audio_bitrate
  regex = /bitrate: (\d+ kb\/s)/
  _ = inspect_this_file_via_ffmpeg
  _ =~ regex
  if $1
    set_bitrate($1)
    opne "#{rev}The audio bitrate is:"
    opne "  #{simp(bitrate?)}"
  end
end

#report_audio_streamObject

#

report_audio_stream

We try to report which audio stream we have, e. g. “.mp3”.

#


217
218
219
220
221
222
223
224
225
226
# File 'lib/multimedia_paradise/video/video_information.rb', line 217

def report_audio_stream
  if audio?
    opne 'The audio stream is `'+sfancy(audio?)+'`.'
    if audio?.end_with? 'mp3' # Ok we have a .mp3 file. Report the audio-bitrate next.
      report_audio_bitrate
    end
  else
    opne 'No audio stream could be found.'
  end
end

#report_the_durationObject

#

report_the_duration

This method will report the duration of that particular multimedia file.

#


352
353
354
355
356
357
358
359
360
361
# File 'lib/multimedia_paradise/video/video_information.rb', line 352

def report_the_duration
  duration = duration?
  opne rev+'The duration of this file is `'+
        sfancy(duration.to_s)+
        rev+
        '` seconds. '\
        '('+seagreen(
          to_hh_mm_ss(duration)
        )+"#{rev})"
end

#report_the_name_of_the_fileObject

#

report_the_name_of_the_file

#


266
267
268
269
270
271
# File 'lib/multimedia_paradise/video/video_information.rb', line 266

def report_the_name_of_the_file
  _ = name?
  if File.exist? _
    opne "#{rev}The name of the video file is `#{simp(_)}#{rev}`."
  end
end

#report_the_resolutionObject

#

report_the_resolution

#


341
342
343
344
# File 'lib/multimedia_paradise/video/video_information.rb', line 341

def report_the_resolution
  print rev+' The video-resolution is '+
        sfancy(resolution?)+rev+'.'
end

#report_video_streamObject

#

report_video_stream

#


276
277
278
279
280
281
282
283
284
# File 'lib/multimedia_paradise/video/video_information.rb', line 276

def report_video_stream
  if File.exist? name?
    opnn; print "#{rev}The video stream is `#{sfancy(video?)}#{rev}`."
    if resolution?
      report_the_resolution
    end
    e
  end
end

#resetObject

#

reset (reset tag)

#


70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/multimedia_paradise/video/video_information.rb', line 70

def reset
  super()
  infer_the_namespace
  set_be_verbose
  set_audio # Set it to empty first.
  # ======================================================================= #
  # === @video
  # ======================================================================= #
  @video = nil
  # ======================================================================= #
  # === @data
  #
  # This Array will hold video and audio.
  # ======================================================================= #
  @data = []
  # ======================================================================= #
  # === @report_the_namespace
  # ======================================================================= #
  @report_the_namespace = true
  # ======================================================================= #
  # === :resolution
  #
  # This will carry the video result, such as: 1280x720
  # ======================================================================= #
  @internal_hash[:resolution] = nil
  set_duration nil # Initialize it to nil specifically.
end

#resolution?Boolean

#

resolution?

#

Returns:

  • (Boolean)


405
406
407
# File 'lib/multimedia_paradise/video/video_information.rb', line 405

def resolution?
  @internal_hash[:resolution]
end

#runObject

#

run (run tag)

#


430
431
432
433
434
# File 'lib/multimedia_paradise/video/video_information.rb', line 430

def run
  files?.each {|the_file|
    work_on_this_file(the_file)
  }
end

#set_audio(i = nil) ⇒ Object

#

set_audio (audio tag)

#


149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/multimedia_paradise/video/video_information.rb', line 149

def set_audio(i = nil)
  if i.is_a? Array
    i = i.select {|entry| entry.include? 'Audio:' }
    set_hertz(i) if i.include? ' Hz'
    i = i.first unless i.empty?
  end
  if i
    i = AUDIO_STREAMS.find { |s| i.include?(s.to_s) }
    i = nil if i.is_a? Array # Then it must be empty.
  end
  @audio = i
end

#set_bitrate(i) ⇒ Object

#

set_bitrate

#


252
253
254
# File 'lib/multimedia_paradise/video/video_information.rb', line 252

def set_bitrate(i)
  @bitrate = i.to_s
end

#set_duration(i = nil) ⇒ Object

#

set_duration

#


331
332
333
334
335
336
# File 'lib/multimedia_paradise/video/video_information.rb', line 331

def set_duration(i = nil)
  if i and i.is_a?(String) and i.include?(':')
    i = MultimediaParadise.long_format_to_milliseconds(i).to_f / 1000.0
  end
  @duration = i
end

#set_files(i = '') ⇒ Object

#

set_files

#


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

def set_files(i = '')
  if i.is_a? String
    i = rds(i)
  end
  @files = i
end

#set_hertz(i) ⇒ Object

#

set_hertz

#


135
136
137
# File 'lib/multimedia_paradise/video/video_information.rb', line 135

def set_hertz(i)
  @hertz = i.scan(/(\d+) Hz/).flatten.first if i.include? ' Hz'
end

#set_resolution(i) ⇒ Object

#

set_resolution

#


386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
# File 'lib/multimedia_paradise/video/video_information.rb', line 386

def set_resolution(i)
  if i
    if i.is_a? Array
      selection = i.select {|entry|
        entry.include?('Video: ')
      }.first
      if selection.include? 'x'
        i = selection.scan(
              /\d{2,4}x\d{2,4}/
            ).flatten.first.to_s.strip
      end
    end
    @internal_hash[:resolution] = i
  end
end

#set_video(i) ⇒ Object

#

set_video (video tag)

#


190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/multimedia_paradise/video/video_information.rb', line 190

def set_video(i)
  if i.is_a? Array
    i = i.select {|entry| entry.include? 'Video:' }
    i = i.first unless i.empty?
  end
  result = VIDEO_STREAMS.find { |s| i.include?(s) }
  # ======================================================================= #
  # Handle XVID next:
  # ======================================================================= #
  if result == 'mpeg4' and i.include?('XVID')
    result << ' (XVID)'
  end
  @video = result
end

#verbose_report(report_the_namespace = true) ⇒ Object Also known as: report

#

verbose_report

This method will report the name, the video stream and the audio stream.

#


317
318
319
320
321
322
323
324
325
326
# File 'lib/multimedia_paradise/video/video_information.rb', line 317

def verbose_report(report_the_namespace = true)
  case report_the_namespace
  when :do_not_report_the_namespace
    @report_the_namespace = false
  end
  report_the_name_of_the_file
  report_video_stream
  report_audio_stream
  report_the_duration if @duration
end

#video?Boolean

#

video?

#

Returns:

  • (Boolean)


128
129
130
# File 'lib/multimedia_paradise/video/video_information.rb', line 128

def video?
  @video
end

#work_on_this_file(the_file) ⇒ Object

#

work_on_this_file

This method can only work on an individual file.

#


414
415
416
417
418
419
420
421
422
423
424
425
# File 'lib/multimedia_paradise/video/video_information.rb', line 414

def work_on_this_file(the_file)
  if File.exist? the_file
    _ = inspect_this_file_via_ffmpeg(the_file)
    decompose(_)
    populate_main_data
    determine_duration_of_the_file
  else
    if be_verbose?
      opnn; no_file_exists_at(the_file)
    end
  end
end