Class: KodiDedup::MediaFile

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/kodi_dedup/media_file.rb

Constant Summary collapse

FORMATS =
['unknown', 'MPEG-4 Visual', 'AVC', 'HEVC']

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ MediaFile

Returns a new instance of MediaFile.



8
9
10
11
# File 'lib/kodi_dedup/media_file.rb', line 8

def initialize(filename)
  @filename  = filename
  @mediainfo = KodiDedup.config.mediainfo.new(filename: filename)
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



4
5
6
# File 'lib/kodi_dedup/media_file.rb', line 4

def filename
  @filename
end

#mediainfoObject (readonly)

Returns the value of attribute mediainfo.



4
5
6
# File 'lib/kodi_dedup/media_file.rb', line 4

def mediainfo
  @mediainfo
end

Instance Method Details

#<=>(other) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/kodi_dedup/media_file.rb', line 13

def <=>(other)
  if other.resolution != resolution
    other.resolution <=> resolution
  elsif other.format_index != format_index
    other.format_index <=> format_index
  elsif other.size != size
    size <=> other.size
  else
    0
  end
end

#==(other) ⇒ Object



25
26
27
# File 'lib/kodi_dedup/media_file.rb', line 25

def ==(other)
  width == other.width && height == other.height && format == other.format && size == other.size
end

#basenameObject



55
56
57
# File 'lib/kodi_dedup/media_file.rb', line 55

def basename
  File.basename(filename)
end

#formatObject



49
50
51
52
53
# File 'lib/kodi_dedup/media_file.rb', line 49

def format
  mediainfo.format
rescue ::Mediainfo::StreamProxy::NoStreamsForProxyError
  'unknown'
end

#format_indexObject



59
60
61
# File 'lib/kodi_dedup/media_file.rb', line 59

def format_index
  FORMATS.index(format)
end

#heightObject



43
44
45
46
47
# File 'lib/kodi_dedup/media_file.rb', line 43

def height
  mediainfo.height
rescue ::Mediainfo::StreamProxy::NoStreamsForProxyError
  0
end

#resolutionObject



33
34
35
# File 'lib/kodi_dedup/media_file.rb', line 33

def resolution
  width * height
end

#sizeObject



29
30
31
# File 'lib/kodi_dedup/media_file.rb', line 29

def size
  (mediainfo.size / (1024*1024.0)).to_i
end

#to_sObject



63
64
65
# File 'lib/kodi_dedup/media_file.rb', line 63

def to_s
  "#{basename} (#{format}@#{width}x#{height} #{size}MB)"
end

#widthObject



37
38
39
40
41
# File 'lib/kodi_dedup/media_file.rb', line 37

def width
  mediainfo.width
rescue ::Mediainfo::StreamProxy::NoStreamsForProxyError
  0
end