Class: WmaInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/wmainfo.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, opts = {}) ⇒ WmaInfo

Returns a new instance of WmaInfo.



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/wmainfo.rb', line 33

def initialize(file, opts = {})
  @drm = nil
  @tags = {}
  @header_object = {}
  @info = {}
  @ext_info = {}
  @stream = {}
  @file = file
  @debug = opts[:debug]
  @encoding = opts[:encoding] || "ASCII"
  @ic = Iconv.new(@encoding, "UTF-16LE") if RUBY_VERSION.to_f < 1.9
  parse_wma_header
end

Instance Attribute Details

#ext_infoObject (readonly)

WmaInfo.tags and WmaInfo.info are hashes of NAME=VALUE pairs WmaInfo.header_object is a hash of arrays



32
33
34
# File 'lib/wmainfo.rb', line 32

def ext_info
  @ext_info
end

#header_objectObject (readonly)

WmaInfo.tags and WmaInfo.info are hashes of NAME=VALUE pairs WmaInfo.header_object is a hash of arrays



32
33
34
# File 'lib/wmainfo.rb', line 32

def header_object
  @header_object
end

#infoObject (readonly)

WmaInfo.tags and WmaInfo.info are hashes of NAME=VALUE pairs WmaInfo.header_object is a hash of arrays



32
33
34
# File 'lib/wmainfo.rb', line 32

def info
  @info
end

#streamObject (readonly)

WmaInfo.tags and WmaInfo.info are hashes of NAME=VALUE pairs WmaInfo.header_object is a hash of arrays



32
33
34
# File 'lib/wmainfo.rb', line 32

def stream
  @stream
end

#tagsObject (readonly)

WmaInfo.tags and WmaInfo.info are hashes of NAME=VALUE pairs WmaInfo.header_object is a hash of arrays



32
33
34
# File 'lib/wmainfo.rb', line 32

def tags
  @tags
end

Instance Method Details

#hasdrm?Boolean

returns true if the file has DRM ie: if a “*Content_Encryption_Object” is found

Returns:

  • (Boolean)


57
58
59
# File 'lib/wmainfo.rb', line 57

def hasdrm?
  @drm ? true : false
end

#hasinfo?(field) ⇒ Boolean

returns true if info has a value

Returns:

  • (Boolean)


72
73
74
# File 'lib/wmainfo.rb', line 72

def hasinfo?(field)
  @info[field] ? true : false
end

#hastag?(tag) ⇒ Boolean

returns true if tags has a value

Returns:

  • (Boolean)


62
63
64
# File 'lib/wmainfo.rb', line 62

def hastag?(tag)
  @tags[tag] ? true : false
end

#inspectObject

This cleans up the output when using WmaInfo in irb


94
95
96
97
98
99
100
# File 'lib/wmainfo.rb', line 94

def inspect #:nodoc:
  s = "#<#{self.class}:0x#{(self.object_id*2).to_s(16)} "
  @header_object.each_pair do |k,v|
    s += "(#{k.upcase} size=#{v[1]} offset=#{v[2]}) " unless k == "ASF_Header_Object"
  end
  s += "\b>"
end

prettyprint WmaInfo.info hash



77
78
79
# File 'lib/wmainfo.rb', line 77

def print_info
  @info.each_pair { |key,val| puts "#{key}: #{val}" }
end

for ASF_Header_Object prints: “name: GUID size num_objects” for others, prints: “name: GUID size offset”



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

def print_objects
  @header_object.each_pair do |key,val|
    puts "#{key}: #{val[0]} #{val[1]} #{val[2]}"
  end
end

prettyprint WmaInfo.stream hash



82
83
84
# File 'lib/wmainfo.rb', line 82

def print_stream
  @stream.each_pair { |key,val| puts "#{key}: #{val}" }
end

prettyprint WmaInfo.tags hash



67
68
69
# File 'lib/wmainfo.rb', line 67

def print_tags
  @tags.each_pair { |key,val| puts "#{key}: #{val}" }
end

#to_sObject

returns: “filename.wma
Size: N bytes
Bitrate: N kbps

Duration: N seconds“

this is useless



88
89
90
# File 'lib/wmainfo.rb', line 88

def to_s
  "#{File.basename(@file)} :: Size: #{@size} bytes :: Bitrate: #{@info['bitrate']} kbps :: Duration: #{@info['playtime_seconds']} seconds"
end