Class: NfoController
- Inherits:
-
Object
- Object
- NfoController
- Defined in:
- lib/dvdprofiler2xbmc/controllers/nfo_controller.rb
Overview
Synopsis
This is the heart and soul of the application. This is where the different media meta data are merged into the info (.nfo) format needed by XBMC.
TODO: This class is rather large and should be refactored.
the @info hash has keys that map directly to the .nfo file
Usage:
controller = NfoController.new(media)
controller.update
puts controller.isbn
puts controller.imdb_id
or
NfoController.update(media)
Instance Attribute Summary collapse
-
#info ⇒ Object
readonly
Returns the value of attribute info.
Class Method Summary collapse
-
.update(media) ⇒ Object
Synopsis.
Instance Method Summary collapse
-
#imdb_id ⇒ Object
Synopsis return the IMDB ID or nil.
-
#imdb_id=(ident) ⇒ Object
Synopsis set the IMDB ID.
-
#initialize(media) ⇒ NfoController
constructor
Synopsis.
-
#isbn ⇒ Object
Synopsis return the ISBN or nil.
-
#isbn=(n) ⇒ Object
Synopsis set the ISBN.
-
#update ⇒ Object
Synopsis merge meta-data from the DVD Profiler collection.xml and from IMDB into the @movie hash.
Constructor Details
#initialize(media) ⇒ NfoController
Synopsis
28 29 30 31 32 33 34 |
# File 'lib/dvdprofiler2xbmc/controllers/nfo_controller.rb', line 28 def initialize(media) @media = media @info = Hash.new @xbmc_info = XbmcInfo.new(@media.path_to(:nfo)) self.isbn = @xbmc_info.movie['isbn'] self.imdb_id = @xbmc_info.movie['id'] end |
Instance Attribute Details
#info ⇒ Object (readonly)
Returns the value of attribute info.
20 21 22 |
# File 'lib/dvdprofiler2xbmc/controllers/nfo_controller.rb', line 20 def info @info end |
Class Method Details
.update(media) ⇒ Object
Synopsis
23 24 25 |
# File 'lib/dvdprofiler2xbmc/controllers/nfo_controller.rb', line 23 def self.update(media) NfoController.new(media).update end |
Instance Method Details
#imdb_id ⇒ Object
Synopsis
return the IMDB ID or nil
103 104 105 106 107 108 109 110 111 112 |
# File 'lib/dvdprofiler2xbmc/controllers/nfo_controller.rb', line 103 def imdb_id unless @info['id'].blank? # make sure is not an array @media.imdb_id ||= [@info['id'].to_s].flatten.uniq.compact.first end unless @media.imdb_id.blank? || (@media.imdb_id.to_s =~ /^tt\d+$/)|| (@media.imdb_id.to_s =~ /^\d+$/) AppConfig[:logger].warn { "Attempting to return invalid IMDB ID: \"#{@media.imdb_id}\"" } end @media.imdb_id end |
#imdb_id=(ident) ⇒ Object
Synopsis
set the IMDB ID
116 117 118 119 120 121 122 123 124 125 |
# File 'lib/dvdprofiler2xbmc/controllers/nfo_controller.rb', line 116 def imdb_id=(ident) if ident.blank? @media.imdb_id = nil elsif (ident.to_s =~ /^tt\d+$/) || (ident.to_s =~ /^\d+$/) @media.imdb_id = ident.to_s else AppConfig[:logger].warn { "Attempting to set invalid IMDB ID: \"#{ident}\"" } end @media.imdb_id end |
#isbn ⇒ Object
Synopsis
return the ISBN or nil
87 88 89 90 91 92 |
# File 'lib/dvdprofiler2xbmc/controllers/nfo_controller.rb', line 87 def isbn unless @info['isbn'].blank? @media.isbn ||= [@info['isbn']].flatten.uniq.compact.first.to_s end @media.isbn end |
#isbn=(n) ⇒ Object
Synopsis
set the ISBN
96 97 98 99 |
# File 'lib/dvdprofiler2xbmc/controllers/nfo_controller.rb', line 96 def isbn=(n) @media.isbn = n.to_s unless n.blank? @media.isbn end |
#update ⇒ Object
Synopsis
merge meta-data from the DVD Profiler collection.xml and from IMDB into the @movie hash
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/dvdprofiler2xbmc/controllers/nfo_controller.rb', line 39 def update result = false begin AppConfig[:logger].info { "\n#{@media.title}" } @info.merge!(@xbmc_info.movie) # load any manually cached IDs self.isbn ||= load_isbn_id self.imdb_id ||= load_imdb_id extra_titles = [] production_years = [] released_years = [] dvdprofiler_info = load_dvdprofiler_info unless dvdprofiler_info.nil? original_titles = dvdprofiler_info.original_titles box_set_parent_titles = dvdprofiler_info.box_set_parent_titles extra_titles << dvdprofiler_info.title unless dvdprofiler_info.title.blank? extra_titles += original_titles unless original_titles.blank? extra_titles += box_set_parent_titles unless box_set_parent_titles.blank? production_years = dvdprofiler_info.production_years released_years = dvdprofiler_info.released_years end imdb_info = load_imdb_info(extra_titles, production_years, released_years) unless imdb_info.nil? self.imdb_id ||= imdb_info.imdb_id end tmdb_info = load_tmdb_info @info = merge(@info, dvdprofiler_info, imdb_info, tmdb_info) # map any genres @info['genre'] = remap_genres(@info['genre']) save result = true rescue Exception => e AppConfig[:logger].error { "Error updating \"#{@media.path_to(:nfo)}\" - " + e.to_s + "\n" + e.backtrace.join("\n") } raise e end result end |