royw-dvdprofiler2xbmc 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. data/Rakefile +10 -0
  2. data/VERSION.yml +2 -2
  3. data/lib/dvdprofiler2xbmc/controllers/app.rb +4 -3
  4. data/lib/dvdprofiler2xbmc/models/dvdprofiler_info.rb +6 -2
  5. data/lib/dvdprofiler2xbmc/models/imdb_info.rb +6 -0
  6. data/lib/dvdprofiler2xbmc/models/media.rb +5 -6
  7. data/lib/dvdprofiler2xbmc/models/media_files.rb +11 -6
  8. data/lib/dvdprofiler2xbmc/models/tmdb_info.rb +4 -0
  9. data/spec/app_spec.rb +0 -1
  10. data/spec/config_editor_spec.rb +0 -1
  11. data/spec/dvdprofiler2xbmc_spec.rb +56 -56
  12. data/spec/dvdprofiler_info_spec.rb +85 -0
  13. data/spec/fanart_controller_spec.rb +96 -94
  14. data/spec/imdb_info_spec.rb +61 -0
  15. data/spec/media_files_spec.rb +103 -0
  16. data/spec/media_spec.rb +59 -56
  17. data/spec/nfo_controller_spec.rb +71 -72
  18. data/spec/samples/Collection.xml +645 -0
  19. data/spec/samples/api.themoviedb.org/2.0/Movie.imdbLookup?imdb_id=tt0120616&api_key=7a2f6eb9b6aa01651000f0a9324db835 +26 -0
  20. data/spec/samples/api.themoviedb.org/2.0/Movie.imdbLookup?imdb_id=tt0209163&api_key=7a2f6eb9b6aa01651000f0a9324db835 +26 -0
  21. data/spec/samples/api.themoviedb.org/2.0/Movie.imdbLookup?imdb_id=tt0277296&api_key=7a2f6eb9b6aa01651000f0a9324db835 +8 -0
  22. data/spec/samples/api.themoviedb.org/2.0/Movie.imdbLookup?imdb_id=tt0465234&api_key= +3 -0
  23. data/spec/samples/www.imdb.com/find?q=The+Mummy+Returns;s=tt +522 -0
  24. data/spec/samples/www.imdb.com/find?q=The+Mummy;s=tt +527 -0
  25. data/spec/samples/www.imdb.com/find?q=The+Scorpion+King;s=tt +526 -0
  26. data/spec/spec_helper.rb +2 -0
  27. data/spec/tmdb_info_spec.rb +47 -0
  28. data/spec/xbmc_info_spec.rb +31 -28
  29. metadata +17 -3
  30. data/lib/dvdprofiler2xbmc/open_cache_extension.rb +0 -39
@@ -0,0 +1,61 @@
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 "ImdbInfo" 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
+ File.mkdirs(TMPDIR)
19
+ end
20
+
21
+ # before(:each) do
22
+ # filespec = File.expand_path(File.join(File.dirname(__FILE__), 'samples/Die Hard - 1988.nfo'))
23
+ # @xbmc_info = XbmcInfo.new(filespec)
24
+ # end
25
+ #
26
+ # after(:all) do
27
+ # Dir.glob(File.join(TMPDIR,'xbmcinfo_*')).each { |filename| File.delete(filename) }
28
+ # end
29
+
30
+ describe "Finder" do
31
+ it "should find a profile" do
32
+ info = ImdbInfo.find(:imdb_id => 'tt0465234')
33
+ info.should_not be_nil
34
+ end
35
+
36
+ it "should return nil if profile not found" do
37
+ info = ImdbInfo.find(:title => 'should not find this title')
38
+ info.should be_nil
39
+ end
40
+ end
41
+
42
+ describe "Attributes" do
43
+ it "should generate xbmc_info" do
44
+ info = ImdbInfo.find(:imdb_id => 'tt0465234')
45
+ info.to_xbmc_info.length.should > 0
46
+ end
47
+
48
+ it "should generate valid xbmc_info" do
49
+ info = ImdbInfo.find(:imdb_id => 'tt0465234')
50
+ xbmc_info = info.to_xbmc_info
51
+ xbmc_info['title'].should == "National Treasure: Book of Secrets"
52
+ end
53
+
54
+ it "should return imdb id when profile has one" do
55
+ info = ImdbInfo.find(:imdb_id => 'tt0465234')
56
+ info.imdb_id.should == 'tt0465234'
57
+ end
58
+ end
59
+
60
+ end
61
+
@@ -0,0 +1,103 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ require 'tempfile'
4
+
5
+ describe "MediaFiles" do
6
+
7
+ before(:all) do
8
+ logger = Log4r::Logger.new('dvdprofiler2xbmc')
9
+ logger.outputters = Log4r::StdoutOutputter.new(:console)
10
+ Log4r::Outputter[:console].formatter = Log4r::PatternFormatter.new(:pattern => "%m")
11
+ logger.level = Log4r::WARN
12
+ AppConfig.default
13
+ AppConfig[:logger] = logger
14
+ # AppConfig.load
15
+ File.mkdirs(TMPDIR)
16
+ @titles = [
17
+ 'Alexander the Great',
18
+ 'Anastasia',
19
+ 'About a Boy',
20
+ 'Gung Ho',
21
+ 'Hot Shots',
22
+ 'Meltdown',
23
+ 'Oklahoma!',
24
+ 'The Man From Snowy River',
25
+ 'Rooster Cogburn (...and the Lady)',
26
+ 'Call Me The Rise And Fall of Heidi Fleiss',
27
+ 'batteries not included',
28
+ 'Flyboys',
29
+ "Captain Corelli's Mandolin",
30
+ ]
31
+ end
32
+
33
+ after(:each) do
34
+ dup_dir = File.join(TMPDIR, 'dups')
35
+ if File.exist?(dup_dir)
36
+ Dir.glob(File.join(dup_dir, "*.m4v")).each { |filename| File.delete(filename) }
37
+ Dir.delete(dup_dir)
38
+ end
39
+ Dir.glob(File.join(TMPDIR, "*.m4v")).each { |filename| File.delete(filename) }
40
+ end
41
+
42
+ describe "Finders" do
43
+ it "should find the correct number of titles using relative directory paths" do
44
+ @titles.each {|title| File.touch(File.join(TMPDIR, "#{title}.m4v"))}
45
+ media_files = MediaFiles.new([TMPDIR])
46
+ media_files.titles.length.should == @titles.length
47
+ end
48
+
49
+ it "should find the correct number of titles using absolute directory paths" do
50
+ @titles.each {|title| File.touch(File.join(TMPDIR, "#{title}.m4v"))}
51
+ media_files = MediaFiles.new([File.expand_path(TMPDIR)])
52
+ media_files.titles.length.should == @titles.length
53
+ end
54
+
55
+ it "should find the correct number of media files using relative directory paths" do
56
+ @titles.each {|title| File.touch(File.join(TMPDIR, "#{title}.m4v"))}
57
+ media_files = MediaFiles.new([TMPDIR])
58
+ media_files.medias.length.should == @titles.length
59
+ end
60
+
61
+ it "should find the correct number of media files using absolute directory paths" do
62
+ @titles.each {|title| File.touch(File.join(TMPDIR, "#{title}.m4v"))}
63
+ media_files = MediaFiles.new([File.expand_path(TMPDIR)])
64
+ media_files.medias.length.should == @titles.length
65
+ end
66
+
67
+ it "should find all of the titles according to the titles hash" do
68
+ @titles.each {|title| File.touch(File.join(TMPDIR, "#{title}.m4v"))}
69
+ media_files = MediaFiles.new([TMPDIR])
70
+ (media_files.titles.keys.sort - @titles.sort).empty?.should be_true
71
+ end
72
+
73
+ it "should find all of the media files according to the medias array" do
74
+ @titles.each {|title| File.touch(File.join(TMPDIR, "#{title}.m4v"))}
75
+ media_files = MediaFiles.new([TMPDIR])
76
+ (media_files.medias.collect{|media| media.title}.sort - @titles.sort).empty?.should be_true
77
+ end
78
+ end
79
+
80
+ describe "Duplicates" do
81
+ it "should not find any duplicate titles when there are none" do
82
+ @titles.each {|title| File.touch(File.join(TMPDIR, "#{title}.m4v"))}
83
+ media_files = MediaFiles.new([File.expand_path(TMPDIR)])
84
+ media_files.duplicate_titles.length.should == 0
85
+ end
86
+
87
+ # nfo_controller.execute has not been ran, so the only information
88
+ # in each media instance is what was gathered from the filename.
89
+ # So this means filenames with years will not match against identical
90
+ # titles but without years.
91
+ # So the only way we can test is against identical filenames in multiple
92
+ # directories.
93
+ it "should find duplicate titles when there are some" do
94
+ @titles.each {|title| File.touch(File.join(TMPDIR, "#{title}.m4v"))}
95
+ File.mkdirs(File.join(TMPDIR, 'dups'))
96
+ duplicate_titles = @titles[0..(@titles.length/3)]
97
+ duplicate_titles.each {|title| File.touch(File.join(TMPDIR, 'dups', "#{title}.m4v"))}
98
+ media_files = MediaFiles.new([File.expand_path(TMPDIR)])
99
+ media_files.duplicate_titles.length.should == duplicate_titles.length
100
+ end
101
+ end
102
+
103
+ end
data/spec/media_spec.rb CHANGED
@@ -13,9 +13,9 @@ describe "Media" do
13
13
  AppConfig[:logger] = logger
14
14
  AppConfig.load
15
15
  File.mkdirs(TMPDIR)
16
- AppConfig[:logger].warn { "\nMedia Specs" }
17
16
  end
18
17
 
18
+ describe "Media filename parsing" do
19
19
  # "movie title - yyyy.ext"
20
20
  # "movie title (yyyy).ext"
21
21
  # "movie title.ext"
@@ -23,64 +23,67 @@ describe "Media" do
23
23
  # "movie title (yyyy).partN.ext"
24
24
  # "movie title.partN.ext"
25
25
 
26
- it 'should parse "movie title.m4v"' do
27
- result = Media.parse('movie title.m4v')
28
- result.should == {:title => 'movie title', :extension => 'm4v'}
26
+ it 'should parse "movie title.m4v"' do
27
+ result = Media.parse('movie title.m4v')
28
+ result.should == {:title => 'movie title', :extension => 'm4v'}
29
+ end
30
+
31
+ it 'should parse "movie title - 1999.m4v"' do
32
+ result = Media.parse('movie title - 1999.m4v')
33
+ result.should == {:title => 'movie title', :year => '1999', :extension => 'm4v'}
34
+ end
35
+
36
+ it 'should parse "movie title-1999.m4v"' do
37
+ result = Media.parse('movie title-1999.m4v')
38
+ result.should == {:title => 'movie title', :year => '1999', :extension => 'm4v'}
39
+ end
40
+
41
+ it 'should parse "movie title (1999).m4v"' do
42
+ result = Media.parse('movie title (1999).m4v')
43
+ result.should == {:title => 'movie title', :year => '1999', :extension => 'm4v'}
44
+ end
45
+
46
+ it 'should parse "movie title ( 1999 ) .m4v"' do
47
+ result = Media.parse('movie title ( 1999 ) .m4v')
48
+ result.should == {:title => 'movie title', :year => '1999', :extension => 'm4v'}
49
+ end
50
+
51
+ it 'should parse "movie title.cd1.m4v"' do
52
+ result = Media.parse('movie title.cd1.m4v')
53
+ result.should == {:title => 'movie title', :part => 'cd1', :extension => 'm4v'}
54
+ end
55
+
56
+ it 'should parse "movie title - 1999.cd1.m4v"' do
57
+ result = Media.parse('movie title - 1999.cd1.m4v')
58
+ result.should == {:title => 'movie title', :year => '1999', :part => 'cd1', :extension => 'm4v'}
59
+ end
60
+
61
+ it 'should parse "movie title-1999.cd1.m4v"' do
62
+ result = Media.parse('movie title-1999.cd1.m4v')
63
+ result.should == {:title => 'movie title', :year => '1999', :part => 'cd1', :extension => 'm4v'}
64
+ end
65
+
66
+ it 'should parse "movie title (1999).cd1.m4v"' do
67
+ result = Media.parse('movie title (1999).cd1.m4v')
68
+ result.should == {:title => 'movie title', :year => '1999', :part => 'cd1', :extension => 'm4v'}
69
+ end
70
+
71
+ it 'should parse "movie title ( 1999 ) .cd1.m4v"' do
72
+ result = Media.parse('movie title ( 1999 ) .cd1.m4v')
73
+ result.should == {:title => 'movie title', :year => '1999', :part => 'cd1', :extension => 'm4v'}
74
+ end
29
75
  end
30
76
 
31
- it 'should parse "movie title - 1999.m4v"' do
32
- result = Media.parse('movie title - 1999.m4v')
33
- result.should == {:title => 'movie title', :year => '1999', :extension => 'm4v'}
34
- end
35
-
36
- it 'should parse "movie title-1999.m4v"' do
37
- result = Media.parse('movie title-1999.m4v')
38
- result.should == {:title => 'movie title', :year => '1999', :extension => 'm4v'}
39
- end
40
-
41
- it 'should parse "movie title (1999).m4v"' do
42
- result = Media.parse('movie title (1999).m4v')
43
- result.should == {:title => 'movie title', :year => '1999', :extension => 'm4v'}
44
- end
45
-
46
- it 'should parse "movie title ( 1999 ) .m4v"' do
47
- result = Media.parse('movie title ( 1999 ) .m4v')
48
- result.should == {:title => 'movie title', :year => '1999', :extension => 'm4v'}
49
- end
50
-
51
- it 'should parse "movie title.cd1.m4v"' do
52
- result = Media.parse('movie title.cd1.m4v')
53
- result.should == {:title => 'movie title', :part => 'cd1', :extension => 'm4v'}
54
- end
55
-
56
- it 'should parse "movie title - 1999.cd1.m4v"' do
57
- result = Media.parse('movie title - 1999.cd1.m4v')
58
- result.should == {:title => 'movie title', :year => '1999', :part => 'cd1', :extension => 'm4v'}
59
- end
60
-
61
- it 'should parse "movie title-1999.cd1.m4v"' do
62
- result = Media.parse('movie title-1999.cd1.m4v')
63
- result.should == {:title => 'movie title', :year => '1999', :part => 'cd1', :extension => 'm4v'}
64
- end
65
-
66
- it 'should parse "movie title (1999).cd1.m4v"' do
67
- result = Media.parse('movie title (1999).cd1.m4v')
68
- result.should == {:title => 'movie title', :year => '1999', :part => 'cd1', :extension => 'm4v'}
69
- end
70
-
71
- it 'should parse "movie title ( 1999 ) .cd1.m4v"' do
72
- result = Media.parse('movie title ( 1999 ) .cd1.m4v')
73
- result.should == {:title => 'movie title', :year => '1999', :part => 'cd1', :extension => 'm4v'}
74
- end
75
-
76
- it 'should generate path_to(:nfo)' do
77
- media = Media.new(File.join(File.dirname(__FILE__), 'samples'), 'The Egg and I.dummy')
78
- media.path_to(:nfo).should == File.expand_path('spec/samples/The Egg and I.nfo')
79
- end
77
+ describe "NFO filename generation" do
78
+ it 'should generate path_to(:nfo)' do
79
+ media = Media.new(File.join(File.dirname(__FILE__), 'samples'), 'The Egg and I.dummy')
80
+ media.path_to(:nfo).should == File.expand_path('spec/samples/The Egg and I.nfo')
81
+ end
80
82
 
81
- it 'should generate path_to(:nfo) for multipart media' do
82
- media = Media.new(File.join(File.dirname(__FILE__), 'samples'), 'Ma and Pa Kettle.cd1.dummy')
83
- media.path_to(:nfo).should == File.expand_path('spec/samples/Ma and Pa Kettle.nfo')
83
+ it 'should generate path_to(:nfo) for multipart media' do
84
+ media = Media.new(File.join(File.dirname(__FILE__), 'samples'), 'Ma and Pa Kettle.cd1.dummy')
85
+ media.path_to(:nfo).should == File.expand_path('spec/samples/Ma and Pa Kettle.nfo')
86
+ end
84
87
  end
85
88
 
86
89
  end
@@ -19,8 +19,6 @@ describe "NfoController" do
19
19
 
20
20
  DvdprofilerProfile.collection_filespec = File.join(SAMPLES_DIR, 'Collection.xml')
21
21
  File.mkdirs(TMPDIR)
22
-
23
- AppConfig[:logger].warn { "\nNfoController Specs" }
24
22
  end
25
23
 
26
24
  before(:each) do
@@ -29,7 +27,6 @@ describe "NfoController" do
29
27
  filespec = @media.path_to(extension)
30
28
  File.delete(filespec) if File.exist?(filespec)
31
29
  end
32
- # AppConfig[:logger].info { "media path => " + @media.media_path }
33
30
  end
34
31
 
35
32
  after(:each) do
@@ -44,83 +41,85 @@ describe "NfoController" do
44
41
  end
45
42
  end
46
43
 
44
+ describe "Update" do
45
+ it "should update" do
46
+ NfoController.update(@media).should be_true
47
+ end
47
48
 
48
- it "should use certifications if mpaa not available" do
49
- NfoController.update(@media)
50
- filespec = @media.path_to(:nfo)
51
- xml = open(filespec).read
52
- hash = XmlSimple.xml_in(xml)
53
- hash['mpaa'].should == ['Approved']
54
- end
55
-
56
- it "should update" do
57
- NfoController.update(@media).should be_true
58
- end
49
+ it "should use certifications if mpaa not available" do
50
+ NfoController.update(@media)
51
+ filespec = @media.path_to(:nfo)
52
+ xml = open(filespec).read
53
+ hash = XmlSimple.xml_in(xml)
54
+ hash['mpaa'].should == ['Approved']
55
+ end
59
56
 
60
- it "should generate populated nfo file on update" do
61
- NfoController.update(@media)
62
- filespec = @media.path_to(:nfo)
63
- xml = open(filespec).read
64
- hash = XmlSimple.xml_in(xml)
65
- hash['runtime'].should == ['108 min']
66
- end
57
+ it "should generate populated nfo file on update" do
58
+ NfoController.update(@media)
59
+ filespec = @media.path_to(:nfo)
60
+ xml = open(filespec).read
61
+ hash = XmlSimple.xml_in(xml)
62
+ hash['runtime'].should == ['108 min']
63
+ end
67
64
 
68
- it "should generate populated imdb.xml file on update" do
69
- NfoController.update(@media)
70
- filespec = @media.path_to(:imdb_xml)
71
- xml = open(filespec).read
72
- hash = XmlSimple.xml_in(xml)
73
- hash['length'].should == ['108 min']
74
- end
65
+ it "should generate populated imdb.xml file on update" do
66
+ NfoController.update(@media)
67
+ filespec = @media.path_to(:imdb_xml)
68
+ xml = open(filespec).read
69
+ hash = XmlSimple.xml_in(xml)
70
+ hash['length'].should == ['108 min']
71
+ end
75
72
 
76
- it "should generate populated tmdb.xml file on update" do
77
- NfoController.update(@media)
78
- filespec = @media.path_to(:tmdb_xml)
79
- xml = open(filespec).read
80
- hash = XmlSimple.xml_in(xml)
81
- hash.should be_empty
82
- end
73
+ it "should generate populated tmdb.xml file on update" do
74
+ NfoController.update(@media)
75
+ filespec = @media.path_to(:tmdb_xml)
76
+ xml = open(filespec).read
77
+ hash = XmlSimple.xml_in(xml)
78
+ hash.should be_empty
79
+ end
83
80
 
84
- it "should handle different movies with the same title" do
85
- FileUtils.touch(File.join(TMPDIR, 'Sabrina - 1954.dummy'))
86
- media1 = Media.new(TMPDIR, 'Sabrina - 1954.dummy')
87
- controller1 = NfoController.new(media1)
88
- controller1.update
89
- FileUtils.touch(File.join(TMPDIR, 'Sabrina - 1995.dummy'))
90
- media2 = Media.new(TMPDIR, 'Sabrina - 1995.dummy')
91
- controller2 = NfoController.new(media2)
92
- controller2.update
93
- controller1.imdb_id.should_not == controller2.imdb_id
81
+ it "should handle different movies with the same title" do
82
+ FileUtils.touch(File.join(TMPDIR, 'Sabrina - 1954.dummy'))
83
+ media1 = Media.new(TMPDIR, 'Sabrina - 1954.dummy')
84
+ controller1 = NfoController.new(media1)
85
+ controller1.update
86
+ FileUtils.touch(File.join(TMPDIR, 'Sabrina - 1995.dummy'))
87
+ media2 = Media.new(TMPDIR, 'Sabrina - 1995.dummy')
88
+ controller2 = NfoController.new(media2)
89
+ controller2.update
90
+ controller1.imdb_id.should_not == controller2.imdb_id
91
+ end
94
92
  end
95
93
 
96
- it "should handle all movies in Collection.xml" do
97
- imdb_exceptions = [
98
- 'Pearl Harbor Payback Appointment in Tokyo',
99
- 'Rodeo Racketeers John Wayne Young Duke Series',
100
- 'The Adventures of Indiana Jones The Complete DVD Movie Collection',
101
- 'The Great American Western Volume 6',
102
- 'The Mummy Collector s Set',
103
- 'Mexico Whitetails'
104
- ]
105
- profiles = DvdprofilerProfile.all
106
- titles = profiles.collect do |profile|
107
- info = DvdprofilerInfo.new(profile)
108
- "#{profile.title.remove_punctuation} - #{info.year}"
109
- end
110
- buf = []
111
- titles.sort.each do |title|
112
- filename = "#{title}.m4v"
113
- FileUtils.touch(File.join(TMPDIR, filename))
114
- media = Media.new(TMPDIR, filename)
115
- controller = NfoController.new(media)
116
- # debugger if title =~ /Mexico/
117
- controller.update
118
- buf << "Missing ISBN for #{title}" if controller.isbn.blank?
119
- buf << "Missing IMDB ID for #{controller.info['title']}" if controller.imdb_id.blank? && !imdb_exceptions.include?(media.title)
120
- buf << "Unexpected IMDB ID for #{controller.info['title']}" if !controller.imdb_id.blank? && imdb_exceptions.include?(media.title)
94
+ describe "Problem media titles" do
95
+ it "should handle all movies in Collection.xml" do
96
+ imdb_exceptions = [
97
+ 'Pearl Harbor Payback Appointment in Tokyo',
98
+ 'Rodeo Racketeers John Wayne Young Duke Series',
99
+ 'The Adventures of Indiana Jones The Complete DVD Movie Collection',
100
+ 'The Great American Western Volume 6',
101
+ 'The Mummy Collector s Set',
102
+ 'Mexico Whitetails'
103
+ ]
104
+ profiles = DvdprofilerProfile.all
105
+ titles = profiles.collect do |profile|
106
+ info = DvdprofilerInfo.new(profile)
107
+ "#{profile.title.remove_punctuation} - #{info.year}"
108
+ end
109
+ buf = []
110
+ titles.sort.each do |title|
111
+ filename = "#{title}.m4v"
112
+ FileUtils.touch(File.join(TMPDIR, filename))
113
+ media = Media.new(TMPDIR, filename)
114
+ controller = NfoController.new(media)
115
+ controller.update
116
+ buf << "Missing ISBN for #{title}" if controller.isbn.blank?
117
+ buf << "Missing IMDB ID for #{controller.info['title']}" if controller.imdb_id.blank? && !imdb_exceptions.include?(media.title)
118
+ buf << "Unexpected IMDB ID for #{controller.info['title']}" if !controller.imdb_id.blank? && imdb_exceptions.include?(media.title)
119
+ end
120
+ puts buf.join("\n") unless buf.empty?
121
+ buf.empty?.should be_true
121
122
  end
122
- puts buf.join("\n") unless buf.empty?
123
- buf.empty?.should be_true
124
123
  end
125
124
 
126
125
  end