Class: XbmcSql::NfoFile

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

Constant Summary collapse

SIMPLE_ATTRIBUTES =
%w{
  id title originaltitle sorttitle year releasedate top250 rating
  votes mpaa certification studio outline plot runtime playcount
}
PLURAL_ATTRIBUTES =
{
  countries: 'country',
  genres:    'genre',
  directors: 'director',
  credits:   'credits',
  actors:    'actor',
  thumbs:    'thumb',
  fanart:    'fanart'
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_file) ⇒ NfoFile

Returns a new instance of NfoFile.



7
8
9
# File 'lib/xbmc_sql/nfo_file.rb', line 7

def initialize(raw_file)
  @raw_file = raw_file
end

Instance Attribute Details

#raw_fileObject

Returns the value of attribute raw_file.



5
6
7
# File 'lib/xbmc_sql/nfo_file.rb', line 5

def raw_file
  @raw_file
end

Instance Method Details

#audio_streamsObject



59
60
61
# File 'lib/xbmc_sql/nfo_file.rb', line 59

def audio_streams
  streams['audio']
end

#docObject



15
16
17
# File 'lib/xbmc_sql/nfo_file.rb', line 15

def doc
  @doc ||= XmlSimple.xml_in(File.read(@raw_file))
end

#new_docObject



19
20
21
22
23
24
25
# File 'lib/xbmc_sql/nfo_file.rb', line 19

def new_doc
  out = XmlSimple.xml_out doc,
    xmldeclaration: '<?xml version="1.0" encoding="utf-8"?>',
    rootname:       'movie',
    noescape:       true
  out.gsub /<([^>]+)>\s*<\/\1>/, '<\1 />'
end

#save!Object



11
12
13
# File 'lib/xbmc_sql/nfo_file.rb', line 11

def save!
  File.open(raw_file, 'w+') { |f| f.write new_doc }
end

#sub_streamsObject



63
64
65
# File 'lib/xbmc_sql/nfo_file.rb', line 63

def sub_streams
  streams['sub']
end

#video_streamObject



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

def video_stream
  video_streams[0]
end

#video_streamsObject

File info



55
56
57
# File 'lib/xbmc_sql/nfo_file.rb', line 55

def video_streams
  streams['video']
end