Class: DvdprofilerInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/dvdprofiler2xbmc/models/dvdprofiler_info.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find(options) ⇒ Object

Synopsis

see DvdprofilerProfile.all for options really should include at least: :title, :year, :isbn, :filespec


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/dvdprofiler2xbmc/models/dvdprofiler_info.rb', line 14

def self.find(options)
  dvdprofiler_info = nil
  # replace options[:year] => 0 with nil
  options[:year] = (options[:year].to_i > 0 ? options[:year] : nil) unless options[:year].blank?
  # find ISBN for each title and assign to the media
  profiles = DvdprofilerProfile.all(options)
  if profiles.length > 1
    media_title = "#{options[:title]}#{options[:year].blank? ? '' : ' (' + options[:year] + ')'}"
    DvdProfiler2Xbmc.multiple_profiles << "#{media_title} #{profiles.collect{|prof| prof.isbn}.join(", ")}"
    AppConfig[:logger].warn { "Multiple profiles found for #{media_title}" }
  else
    profile = profiles.first
    unless profile.nil?
      AppConfig[:logger].info { "ISBN => #{options[:isbn]}" } unless options[:isbn].nil?
      profile.save(options[:filespec])
      dvdprofiler_info = DvdprofilerInfo.new(profile)
    end
  end
  dvdprofiler_info
end

Instance Method Details

#box_set_parent_titlesObject

Synopsis

try to find box set parent's title


87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/dvdprofiler2xbmc/models/dvdprofiler_info.rb', line 87

def box_set_parent_titles
  titles = []
  unless @profile.dvd_hash[:boxset].blank?
    begin
      AppConfig[:logger].debug { "Need to find box set parent's title" }
      parent_isbn = @profile.dvd_hash[:boxset].first['parent'].first
      unless parent_isbn.blank?
        parent_profile = DvdprofilerProfile.first(:isbn => parent_isbn)
        unless parent_profile.blank?
          titles << parent_profile.title
          titles += get_parent_titles(parent_profile.dvd_hash)
        end
      end
    rescue
    end
  end
  AppConfig[:logger].debug { "parent titles => #{titles.pretty_inspect}" } unless titles.empty?
  titles
end

#isbnObject


75
76
77
# File 'lib/dvdprofiler2xbmc/models/dvdprofiler_info.rb', line 75

def isbn
  @profile.isbn rescue nil
end

#original_titlesObject


115
116
117
118
119
120
121
# File 'lib/dvdprofiler2xbmc/models/dvdprofiler_info.rb', line 115

def original_titles
  titles = []
  originaltitle = @profile.dvd_hash[:originaltitle]
  titles = [originaltitle].flatten.uniq.compact unless originaltitle.blank?
  titles = titles.collect{|t| t.blank? ? nil : t}.compact
  titles
end

#production_yearsObject


107
108
109
# File 'lib/dvdprofiler2xbmc/models/dvdprofiler_info.rb', line 107

def production_years
  @profile.dvd_hash[:productionyear].collect{|y| y =~ /(\d{4})/ ? $1 : nil}.compact rescue []
end

#released_yearsObject


111
112
113
# File 'lib/dvdprofiler2xbmc/models/dvdprofiler_info.rb', line 111

def released_years
  @profile.dvd_hash[:released].collect{|y| y =~ /(\d{4})/ ? $1 : nil}.compact rescue []
end

#titleObject


123
124
125
# File 'lib/dvdprofiler2xbmc/models/dvdprofiler_info.rb', line 123

def title
  @profile.dvd_hash[:title] rescue nil
end

#to_xbmc_infoObject

Synopsis

map the given dvd_hash into a @movie hash


61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/dvdprofiler2xbmc/models/dvdprofiler_info.rb', line 61

def to_xbmc_info
  info = Hash.new
  unless @profile.dvd_hash.nil?
    @profile.dvd_hash[:genres] ||= []
    info['genre'] = @profile.dvd_hash[:genres] unless @profile.dvd_hash[:genres].blank?
    info['title'] = @profile.dvd_hash[:title]
    info['year']  = [@profile.dvd_hash[:productionyear], @profile.dvd_hash[:released]].flatten.uniq.collect{|s| ((s =~ /(\d{4})/) ? $1 : nil)}.uniq.compact.first
    DVD_HASH_TO_INFO_MAP.each do |key, value|
      info[value] = @profile.dvd_hash[key] unless @profile.dvd_hash[key].blank?
    end
  end
  info
end

#yearObject

Synopsis

return the lowest production year as the year


81
82
83
# File 'lib/dvdprofiler2xbmc/models/dvdprofiler_info.rb', line 81

def year
  [@profile.dvd_hash[:productionyear]].flatten.uniq.compact.sort.first rescue nil
end