royw-dvdprofiler2xbmc 0.0.12 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 12
2
+ :patch: 13
3
3
  :major: 0
4
4
  :minor: 0
@@ -7,6 +7,7 @@ require 'xmlsimple'
7
7
  require 'ftools'
8
8
  require 'imdb'
9
9
  require 'tmdb'
10
+ require 'dvdprofiler_collection'
10
11
  require 'mash'
11
12
  require 'log4r'
12
13
  require 'ruby-debug'
@@ -17,8 +18,6 @@ require 'dvdprofiler2xbmc/controllers/app'
17
18
  require 'dvdprofiler2xbmc/controllers/fanart_controller'
18
19
  require 'dvdprofiler2xbmc/controllers/nfo_controller'
19
20
  require 'dvdprofiler2xbmc/controllers/thumbnail_controller'
20
- require 'dvdprofiler2xbmc/models/collection'
21
- require 'dvdprofiler2xbmc/models/dvdprofiler_profile'
22
21
  require 'dvdprofiler2xbmc/models/media'
23
22
  require 'dvdprofiler2xbmc/models/media_files'
24
23
  require 'dvdprofiler2xbmc/models/xbmc_info'
@@ -39,6 +39,8 @@ class DvdProfiler2Xbmc
39
39
  def execute
40
40
  AppConfig[:logger].info { "Media Directories:\n #{AppConfig[:directories].join("\n ")}" }
41
41
 
42
+ DvdprofilerProfile.collection_filespec = AppConfig[:collection_filespec]
43
+
42
44
  @media_files = MediaFiles.new(AppConfig[:directories])
43
45
  if AppConfig[:do_update]
44
46
  @media_files.titles.each do |title, medias|
@@ -12,10 +12,14 @@ describe "NfoController" do
12
12
  logger.outputters = Log4r::StdoutOutputter.new(:console)
13
13
  Log4r::Outputter[:console].formatter = Log4r::PatternFormatter.new(:pattern => "%m")
14
14
  logger.level = Log4r::WARN
15
+
15
16
  AppConfig.default
16
17
  AppConfig[:logger] = logger
17
18
  AppConfig.load
19
+
20
+ DvdprofilerProfile.collection_filespec = AppConfig[:collection_filespec]
18
21
  File.mkdirs(TMPDIR)
22
+
19
23
  AppConfig[:logger].warn { "\nNfoController Specs" }
20
24
  end
21
25
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: royw-dvdprofiler2xbmc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roy Wright
@@ -115,8 +115,6 @@ files:
115
115
  - lib/dvdprofiler2xbmc/controllers/nfo_controller.rb
116
116
  - lib/dvdprofiler2xbmc/controllers/thumbnail_controller.rb
117
117
  - lib/dvdprofiler2xbmc/extensions.rb
118
- - lib/dvdprofiler2xbmc/models/collection.rb
119
- - lib/dvdprofiler2xbmc/models/dvdprofiler_profile.rb
120
118
  - lib/dvdprofiler2xbmc/models/media.rb
121
119
  - lib/dvdprofiler2xbmc/models/media_files.rb
122
120
  - lib/dvdprofiler2xbmc/models/xbmc_info.rb
@@ -127,7 +125,6 @@ files:
127
125
  - spec/cache_extensions.rb
128
126
  - spec/config_editor_spec.rb
129
127
  - spec/dvdprofiler2xbmc_spec.rb
130
- - spec/dvdprofiler_profile_spec.rb
131
128
  - spec/fanart_controller_spec.rb
132
129
  - spec/media_spec.rb
133
130
  - spec/nfo_controller_spec.rb
@@ -181,7 +178,6 @@ test_files:
181
178
  - spec/spec_helper.rb
182
179
  - spec/app_spec.rb
183
180
  - spec/config_editor_spec.rb
184
- - spec/dvdprofiler_profile_spec.rb
185
181
  - spec/fanart_controller_spec.rb
186
182
  - spec/media_spec.rb
187
183
  - spec/nfo_controller_spec.rb
@@ -1,186 +0,0 @@
1
- # == Synopsis
2
- # This model encapsulates the DVDProfiler Collection.xml
3
- class Collection
4
- # various regexes used to clean up a title for matching purposes.
5
- # used in TITLE_REPLACEMENTS hash below
6
- PUNCTUATION = /[\?\:\!\"\'\,\.\-\/\*]/
7
- HTML_ESCAPES = /\&[a-zA-Z]+\;/
8
- SQUARE_BRACKET_ENCLOSURES = /\[.*?\]/
9
- PARENTHESIS_ENCLOSURES = /\(.*?\)/
10
- MULTIPLE_WHITESPACES= /\s+/
11
- STANDALONE_AMPERSAND = /\s\&\s/
12
- WIDESCREEN = /widescreen/i
13
- SPECIAL_EDITION = /special edition/i
14
-
15
- # array of hashes is intentional as the order is critical
16
- # the enclosures [...] & (...) must be removed first,
17
- # then " & " must be replaced by " and ",
18
- # then html escapes &...; must be replaced by a space,
19
- # then remaining punctuation is replacesed by a space,
20
- # finally multiple whitespaces are reduced to single whitespace
21
- TITLE_REPLACEMENTS = [
22
- { SQUARE_BRACKET_ENCLOSURES => '' },
23
- { PARENTHESIS_ENCLOSURES => '' },
24
- { STANDALONE_AMPERSAND => ' and ' },
25
- { HTML_ESCAPES => ' ' },
26
- { WIDESCREEN => ' ' },
27
- { SPECIAL_EDITION => ' ' },
28
- { PUNCTUATION => ' ' },
29
- { MULTIPLE_WHITESPACES => ' ' },
30
- ]
31
-
32
- attr_reader :isbn_dvd_hash, :title_isbn_hash, :isbn_title_hash
33
-
34
- @filespec = nil
35
-
36
- def initialize(filename = 'Collection.xml')
37
- @title_isbn_hash = Hash.new
38
- @isbn_dvd_hash = Hash.new
39
- @isbn_title_hash = Hash.new
40
- @filespec = filename
41
- reload
42
- save
43
- end
44
-
45
- # save as a collection.yaml file unless the existing
46
- # collection.yaml is newer than the collection.xml
47
- def save
48
- unless @filespec.nil?
49
- yaml_filespec = @filespec.ext('.yaml')
50
- if !File.exist?(yaml_filespec) || (File.mtime(@filespec) > File.mtime(yaml_filespec))
51
- AppConfig[:logger].info { "saving: #{yaml_filespec}" }
52
- File.open(yaml_filespec, "w") do |f|
53
- YAML.dump(
54
- {
55
- :title_isbn_hash => @title_isbn_hash,
56
- :isbn_title_hash => @isbn_title_hash,
57
- :isbn_dvd_hash => @isbn_dvd_hash,
58
- }, f)
59
- end
60
- else
61
- AppConfig[:logger].info { "not saving, yaml file is newer than xml file" }
62
- end
63
- else
64
- AppConfig[:logger].error { "can not save, the filespec is nil" }
65
- end
66
- end
67
-
68
- # load the collection from the collection.yaml if it exists,
69
- # otherwise from the collection.xml
70
- def reload
71
- @title_isbn_hash.clear
72
- @isbn_dvd_hash.clear
73
- @isbn_title_hash.clear
74
- collection = Hash.new
75
- yaml_filespec = @filespec.ext('.yaml')
76
- if File.exist?(yaml_filespec) && (File.mtime(yaml_filespec) > File.mtime(@filespec))
77
- AppConfig[:logger].info { "Loading #{yaml_filespec}" }
78
- data = YAML.load_file(yaml_filespec)
79
- @title_isbn_hash = data[:title_isbn_hash]
80
- @isbn_dvd_hash = data[:isbn_dvd_hash]
81
- @isbn_title_hash = data[:isbn_title_hash]
82
- else
83
- elapsed_time = timer do
84
- AppConfig[:logger].info { "Loading #{@filespec}" }
85
- collection = XmlSimple.xml_in(@filespec, { 'KeyToSymbol' => true})
86
- end
87
- AppConfig[:logger].info { "XmlSimple.xml_in elapse time: #{elapsed_time.elapsed_time_s}" }
88
- collection[:dvd].each do |dvd|
89
- isbn = dvd[:id][0]
90
- original_title = dvd[:title][0]
91
- title = Collection.title_pattern(dvd[:title][0])
92
- unless isbn.blank? || title.blank?
93
- @title_isbn_hash[title] ||= []
94
- @title_isbn_hash[title] << isbn
95
- @isbn_title_hash[isbn] = original_title
96
- dvd_hash = Hash.new
97
- dvd_hash[:isbn] = isbn
98
- dvd_hash[:title] = original_title
99
- unless dvd[:actors].blank?
100
- dvd_hash[:actors] = dvd[:actors].compact.collect {|a| a[:actor]}.flatten.compact.collect do |a|
101
- name = []
102
- name << a['FirstName'] unless a['FirstName'].blank?
103
- name << a['MiddleName'] unless a['MiddleName'].blank?
104
- name << a['LastName'] unless a['LastName'].blank?
105
- info = Hash.new
106
- info['name'] = name.join(' ')
107
- info['role'] = a['Role']
108
- info
109
- end
110
- end
111
- dvd_hash[:genres] = dvd[:genres].collect{|a| a[:genre]}.flatten unless dvd[:genres].blank?
112
- dvd_hash[:studios] = dvd[:studios].collect{|a| a[:studio]}.flatten unless dvd[:studios].blank?
113
- dvd_hash[:productionyear] = [dvd[:productionyear].join(',')] unless dvd[:productionyear].blank?
114
- dvd_hash[:rating] = [dvd[:rating].join(',')] unless dvd[:rating].blank?
115
- dvd_hash[:runningtime] = [dvd[:runningtime].join(',')] unless dvd[:runningtime].blank?
116
- dvd_hash[:released] = [dvd[:released].join(',')] unless dvd[:released].blank?
117
- dvd_hash[:overview] = [dvd[:overview].join(',')] unless dvd[:overview].blank?
118
- dvd_hash[:lastedited] = dvd[:lastedited][0] unless dvd[:lastedited].blank?
119
- directors = find_directors(dvd[:credits])
120
- dvd_hash[:directors] = directors unless directors.blank?
121
- dvd_hash[:boxset] = dvd[:boxset] unless dvd[:boxset].blank?
122
- dvd_hash[:mediatypes] = dvd[:mediatypes] unless dvd[:mediatypes].blank?
123
- dvd_hash[:format] = dvd[:format] unless dvd[:format].blank?
124
- @isbn_dvd_hash[isbn] = dvd_hash
125
- end
126
- end
127
- end
128
- end
129
-
130
- def find_directors(dvd_credits)
131
- directors = nil
132
- begin
133
- dvd[:credits].each do |credits_hash|
134
- credits_hash[:credit].each do |credit_hash|
135
- if((credit_hash['CreditType'] == 'Direction') || (credit_hash['CreditSubtype'] == 'Director'))
136
- name = []
137
- name << credit_hash['FirstName'] unless credit_hash['FirstName'].blank?
138
- name << credit_hash['MiddleName'] unless credit_hash['MiddleName'].blank?
139
- name << credit_hash['LastName'] unless credit_hash['LastName'].blank?
140
- directors ||= []
141
- directors << name.join(' ')
142
- end
143
- end
144
- end
145
- rescue
146
- end
147
- directors
148
- end
149
-
150
- # == Synopsis
151
- # The titles found between LMCE's Amazon lookup and DVDProfiler sometimes differ in
152
- # whether or not a prefix of "The", "A", or "An" is included in the title. Here we
153
- # create an Array of possible titles with and without these prefix words.
154
- def Collection.title_permutations(base_title)
155
- titles = []
156
- unless base_title.nil? || base_title.empty?
157
- titles << base_title
158
- ['the', 'a', 'an'].each do |prefix|
159
- titles << "#{prefix} " + base_title unless base_title =~ /^#{prefix}\s/
160
- titles << $1 if base_title =~ /^#{prefix}\s(.*)$/
161
- end
162
- end
163
- titles
164
- end
165
-
166
- # == Synopsis
167
- # the titles found between LMCE's Amazon lookup and DVDProfiler quite often differ in the
168
- # inclusion of punctuation and capitalization. So we create a pattern of lower case words
169
- # without punctuation and with single spaces between words.
170
- def Collection.title_pattern(src_title)
171
- title = nil
172
- unless src_title.nil?
173
- title = src_title.dup
174
- title.downcase!
175
- TITLE_REPLACEMENTS.each do |replacement|
176
- replacement.each do |regex, value|
177
- title.gsub!(regex, value)
178
- end
179
- end
180
- title.strip!
181
- end
182
- title
183
- end
184
-
185
- end
186
-
@@ -1,119 +0,0 @@
1
- # This is the model for the DVD Profiler profile which is used
2
- # to find meta data from DVD Profiler's exported Collection.xml
3
- #
4
- # Usage:
5
- #
6
- # profiles = DvdprofilerProfile.all(:titles => ['The Alamo'])
7
- #
8
- # profile = DvdprofilerProfile.first(:isbn => '012345678901')
9
- # or
10
- # profile = DvdprofilerProfile.first(:title => 'movie title')
11
- #
12
- # puts profile.dvd_hash[:key]
13
- # puts profile.to_xml
14
- # puts profile.isbn
15
- # puts profile.title
16
- # profile.save(media.path_to(:dvdprofiler_xml))
17
- #
18
- class DvdprofilerProfile
19
-
20
- # options:
21
- # :isbn => String
22
- # :title => String
23
- # returns: Array of DvdprofilerProfile instances
24
- def self.all(options={})
25
- # :isbn_dvd_hash, :title_isbn_hash, :isbn_title_hash
26
- result = []
27
-
28
- # try finding by isbn first
29
- if options.has_key?(:isbn) && !options[:isbn].blank?
30
- dvd_hash = collection.isbn_dvd_hash[options[:isbn]]
31
- unless dvd_hash.blank?
32
- result << DvdprofilerProfile.new(dvd_hash, options[:isbn])
33
- end
34
- end
35
-
36
- # if unable to find by isbn, then try finding by title
37
- if result.empty? && options.has_key?(:title)
38
- isbns = self.find_isbns(options)
39
- unless isbns.blank?
40
- isbns.each do |isbn|
41
- dvd_hash = collection.isbn_dvd_hash[isbn]
42
- unless dvd_hash.blank?
43
- unless options[:year].blank?
44
- if dvd_hash[:productionyear].include? options[:year]
45
- result << DvdprofilerProfile.new(dvd_hash, isbn, options[:title])
46
- end
47
- else
48
- result << DvdprofilerProfile.new(dvd_hash, isbn, options[:title])
49
- end
50
- end
51
- end
52
- end
53
- end
54
-
55
- # return all profiles if neither :isbn nor :title are given
56
- if result.empty? && !options.has_key?(:isbn) && !options.has_key?(:title)
57
- collection.isbn_dvd_hash.each do |isbn, dvd_hash|
58
- result << DvdprofilerProfile.new(dvd_hash, isbn)
59
- end
60
- end
61
-
62
- result
63
- end
64
-
65
- # options:
66
- # :isbn => String
67
- # :title => String
68
- # returns: DvdprofilerProfile instance or nil
69
- def self.first(options={})
70
- all(options).first
71
- end
72
-
73
- # look up ISBN by title
74
- # expects a :title option
75
- # returns Array of ISBN Strings
76
- def self.find_isbns(options={})
77
- result = []
78
- if options.has_key?(:title)
79
- result = [collection.title_isbn_hash[Collection.title_pattern(options[:title])]].flatten.uniq.compact
80
- end
81
- result
82
- end
83
-
84
- protected
85
-
86
- def self.collection
87
- @collection ||= Collection.new(File.expand_path(AppConfig[:collection_filespec]))
88
- end
89
-
90
- def initialize(dvd_hash, isbn, title=nil)
91
- @dvd_hash = dvd_hash
92
- @isbn = isbn
93
- @title = title
94
- @title ||= @dvd_hash[:title]
95
- end
96
-
97
- public
98
-
99
- attr_reader :isbn, :title, :dvd_hash
100
-
101
- def to_xml
102
- data = @dvd_hash.stringify_keys
103
- data.delete_if { |key, value| value.nil? }
104
- xml = XmlSimple.xml_out(data, 'NoAttr' => true, 'RootName' => 'movie')
105
- end
106
-
107
- def save(filespec)
108
- begin
109
- xml = self.to_xml
110
- unless xml.blank?
111
- AppConfig[:logger].debug { "saving #{filespec}" }
112
- DvdProfiler2Xbmc.save_to_file(filespec, xml)
113
- end
114
- rescue Exception => e
115
- AppConfig[:logger].error { "Unable to save dvdprofiler profile to #{filespec} - #{e.to_s}" }
116
- end
117
- end
118
-
119
- end
@@ -1,66 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper.rb'
2
-
3
- require 'tempfile'
4
-
5
- # Time to add your specs!
6
- # http://rspec.info/
7
-
8
- describe "DvdprofilerProfile" do
9
-
10
- before(:all) do
11
- logger = Log4r::Logger.new('dvdprofiler2xbmc')
12
- logger.outputters = Log4r::StdoutOutputter.new(:console)
13
- Log4r::Outputter[:console].formatter = Log4r::PatternFormatter.new(:pattern => "%m")
14
- logger.level = Log4r::WARN
15
- AppConfig.default
16
- AppConfig[:logger] = logger
17
- AppConfig.load
18
- AppConfig[:collection_filespec] = 'spec/samples/Collection.xml'
19
- File.mkdirs(TMPDIR)
20
- AppConfig[:logger].warn { "\nDvdprofilerProfile Specs" }
21
- end
22
-
23
- before(:each) do
24
- @profile = DvdprofilerProfile.first(:isbn => '786936735390')
25
- end
26
-
27
- after(:all) do
28
- Dir.glob(File.join(TMPDIR, "dvdprofiler_profile_spec*")).each { |filename| File.delete(filename) }
29
- end
30
-
31
- it "should find by imdb_id" do
32
- @profile.should_not == nil
33
- end
34
-
35
- it "should find by title" do
36
- profile = DvdprofilerProfile.first(:title => 'National Treasure 2: Book of Secrets')
37
- profile.should_not == nil
38
- end
39
-
40
- it "should be able to convert to xml and then from xml" do
41
- hash = nil
42
- begin
43
- xml = @profile.to_xml
44
- hash = XmlSimple.xml_in(xml)
45
- rescue
46
- hash = nil
47
- end
48
- hash.should_not be_nil
49
- end
50
-
51
- it "should find multiple movies with the same title" do
52
- profiles = DvdprofilerProfile.all(:title => 'Sabrina')
53
- profiles.length.should == 2
54
- end
55
-
56
- it "should find a single movie using the year when multiple movies have the same title" do
57
- profiles = DvdprofilerProfile.all(:title => 'Sabrina', :year => '1995')
58
- (profiles.length.should == 1) && (profiles.first.isbn.should == '097363304340')
59
- end
60
-
61
- it "should find the other single movie using the year when multiple movies have the same title" do
62
- profiles = DvdprofilerProfile.all(:title => 'Sabrina', :year => '1954')
63
- (profiles.length.should == 1) && (profiles.first.isbn.should == '097360540246')
64
- end
65
-
66
- end