lib/dvdprofiler2xbmc/nfo.rb in royw-dvdprofiler2xbmc-0.0.2 vs lib/dvdprofiler2xbmc/nfo.rb in royw-dvdprofiler2xbmc-0.0.3
- old
+ new
@@ -4,60 +4,64 @@
def initialize(media, dvd_hash)
@media = media
@dvd_hash = dvd_hash
load
end
-
+
# save as a .nfo file, creating a backup if the .nfo already exists
def save
begin
- nfo_filespec = @media.media_path.ext(".#{AppConfig[:nfo_extension]}")
- nfo_backup_filespec = @media.media_path.ext(".#{AppConfig[:nfo_backup_extension]}")
+ nfo_filespec = @media.path_to(:nfo_extension)
+ nfo_backup_filespec = @media.path_to(:nfo_backup_extension)
File.delete(nfo_backup_filespec) if File.exist?(nfo_backup_filespec)
File.rename(nfo_filespec, nfo_backup_filespec) if File.exist?(nfo_filespec)
File.open(nfo_filespec, "w") do |file|
file.puts(to_nfo(@dvd_hash))
end
rescue Exception => e
AppConfig[:logger].error { "Error saving nfo file - " + e.to_s }
end
end
-
+
def load
begin
- nfo_filespec = @media.media_path.ext(".#{AppConfig[:nfo_extension]}")
+ nfo_filespec = @media.path_to(:nfo_extension)
@movie = XmlSimple.xml_in(nfo_filespec) if File.exist? nfo_filespec
rescue Exception => e
AppConfig[:logger].error { "Error loading \"#{nfo_filespec}\" - " + e.to_s }
end
end
-
+
# return a nfo xml String from the given dvd_hash (from Collection)
def to_nfo(dvd_hash)
@movie ||= {}
imdb_id = @movie['id']
- imdb_id = imdb_lookup(dvd_hash) if AppConfig[:imdb_query] && imdb_id.blank?
+ if AppConfig[:imdb_query] && imdb_id.blank?
+ unless File.exist?(@media.path_to(:no_imdb_extension))
+ imdb_id = imdb_lookup(dvd_hash)
+ end
+ end
@movie['title'] = dvd_hash[:title]
@movie['mpaa'] = dvd_hash[:rating]
@movie['year'] = dvd_hash[:productionyear]
@movie['outline'] = dvd_hash[:overview]
# @movie['plot'] = dvd_hash[:overview]
@movie['runtime'] = dvd_hash[:runningtime]
@movie['genre'] = map_genres((dvd_hash[:genres] + @media.media_subdirs.split('/')).uniq)
@movie['actor'] = dvd_hash[:actors]
@movie['id'] = imdb_id unless imdb_id.nil?
@movie['isbn'] = dvd_hash[:isbn]
-
+
begin
XmlSimple.xml_out(@movie, 'NoAttr' => true, 'RootName' => 'movie')
rescue Exception => e
AppConfig[:logger].error { "Error creating nfo file - " + e.to_s }
end
end
-
+
protected
-
+
def map_genres(genres)
new_genres = []
genres.each do |genre|
new_genres << (AppConfig[:genre_maps][genre].nil? ? genre : AppConfig[:genre_maps][genre])
end
@@ -69,15 +73,15 @@
id = nil
AppConfig[:logger].info { "Searching IMDB for \"#{dvd_hash[:title]}\"" }
unless dvd_hash[:title].blank?
years = released_years(dvd_hash)
begin
- imdb_search = ImdbSearch.new(dvd_hash[:title])
- id = imdb_search.find_id(:years => years, :media_path => @media.media_path)
+ imdb_search = ImdbSearch.new(dvd_hash[:title])
+ id = imdb_search.find_id(:years => years, :media_path => @media.media_path)
rescue Exception => e
- AppConfig[:logger].error { "Error searching IMDB - " + e.to_s }
- AppConfig[:logger].error { e.backtrace.join("\n") }
+ AppConfig[:logger].error { "Error searching IMDB - " + e.to_s }
+ AppConfig[:logger].error { e.backtrace.join("\n") }
end
end
AppConfig[:logger].info { "IMDB id => #{id}" } unless id.nil?
id
end
@@ -96,8 +100,8 @@
y
end
end
years.flatten.uniq.compact.sort
end
-
+
end