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
data/Rakefile CHANGED
@@ -42,6 +42,16 @@ end
42
42
  Spec::Rake::SpecTask.new(:spec) do |spec|
43
43
  spec.libs << 'lib' << 'spec'
44
44
  spec.spec_files = FileList['spec/**/*_spec.rb']
45
+ spec.spec_opts = ["--color", "--format nested"]
46
+ end
47
+
48
+ # spec under development task
49
+ # NOTE, change the pathspec in the FileList to the spec you
50
+ # are currently developing
51
+ Spec::Rake::SpecTask.new('spec:ud') do |spec|
52
+ spec.libs << 'lib' << 'spec'
53
+ spec.spec_files = FileList['spec/dvdprofiler_info_spec.rb']
54
+ spec.spec_opts = ["--color", "--format nested"]
45
55
  end
46
56
 
47
57
  Spec::Rake::SpecTask.new(:rcov) do |spec|
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 2
3
- :major: 0
4
2
  :minor: 1
3
+ :patch: 4
4
+ :major: 0
@@ -14,6 +14,7 @@ class DvdProfiler2Xbmc
14
14
  # protected initializer because it is a Singleton class
15
15
  def initialize
16
16
  @media_files = nil
17
+ @duplicate_titles = []
17
18
  end
18
19
 
19
20
  public
@@ -69,6 +70,7 @@ class DvdProfiler2Xbmc
69
70
  end
70
71
  end
71
72
  end
73
+ @duplicate_titles = @media_files.duplicate_titles
72
74
 
73
75
  # set file and directory permissions
74
76
  AppConfig[:directories].each { |dir| set_permissions(dir) }
@@ -190,9 +192,8 @@ class DvdProfiler2Xbmc
190
192
  # duplicate media file report
191
193
  def duplicates_report
192
194
  buf = []
193
- duplicates = @media_files.duplicate_titles
194
- unless duplicates.empty?
195
- duplicates.each do |title, medias|
195
+ unless @duplicate_titles.empty?
196
+ @duplicate_titles.each do |title, medias|
196
197
  if medias.length > 1
197
198
  buf << title
198
199
  medias.each {|media| buf << " #{media.media_path}"}
@@ -1,9 +1,13 @@
1
1
  class DvdprofilerInfo
2
2
 
3
+ protected
4
+
3
5
  def initialize(profile)
4
6
  @profile = profile
5
7
  end
6
8
 
9
+ public
10
+
7
11
  # == Synopsis
8
12
  # see DvdprofilerProfile.all for options
9
13
  # really should include at least: :title, :year, :isbn, :filespec
@@ -101,11 +105,11 @@ class DvdprofilerInfo
101
105
  end
102
106
 
103
107
  def production_years
104
- @profile.dvd_hash[:productionyear] rescue []
108
+ @profile.dvd_hash[:productionyear].collect{|y| y =~ /(\d{4})/ ? $1 : nil}.compact rescue []
105
109
  end
106
110
 
107
111
  def released_years
108
- @profile.dvd_hash[:released] rescue []
112
+ @profile.dvd_hash[:released].collect{|y| y =~ /(\d{4})/ ? $1 : nil}.compact rescue []
109
113
  end
110
114
 
111
115
  def original_titles
@@ -1,9 +1,12 @@
1
1
  class ImdbInfo
2
2
 
3
+ protected
4
+ # only instantiate via ImdbInfo.find(...)
3
5
  def initialize(profile)
4
6
  @profile = profile
5
7
  end
6
8
 
9
+ public
7
10
  # == Synopsis
8
11
  # See ImdbProfile.all for options
9
12
  def self.find(options)
@@ -15,6 +18,7 @@ class ImdbInfo
15
18
  imdb_info
16
19
  end
17
20
 
21
+ protected
18
22
  # == Synopsis
19
23
  # maps the imdb.movie hash to the info hash
20
24
  IMDB_HASH_TO_INFO_MAP = {
@@ -33,6 +37,8 @@ class ImdbInfo
33
37
  # 'tiny_poster_url', 'also_known_as'
34
38
  }
35
39
 
40
+ public
41
+
36
42
  # == Synopsis
37
43
  # maps the imdb.movie hash to the info hash
38
44
  def to_xbmc_info
@@ -59,12 +59,11 @@ class Media
59
59
  @media_subdirs = File.dirname(media_file)
60
60
  @media_path = File.expand_path(File.join(directory, media_file))
61
61
 
62
- cwd = File.expand_path(Dir.getwd)
63
- Dir.chdir(File.dirname(@media_path))
64
- @nfo_files = Dir.glob("*.{#{AppConfig[:extensions][:nfo]}}")
65
- @image_files = Dir.glob("*.{#{AppConfig[:extensions][:thumbnail]}}")
66
- @fanart_files = Dir.glob("*#{AppConfig[:extensions][:fanart]}*}")
67
- Dir.chdir(cwd)
62
+ Dir.chdir(File.dirname(@media_path)) do
63
+ @nfo_files = Dir.glob("*.{#{AppConfig[:extensions][:nfo]}}")
64
+ @image_files = Dir.glob("*.{#{AppConfig[:extensions][:thumbnail]}}")
65
+ @fanart_files = Dir.glob("*#{AppConfig[:extensions][:fanart]}*}")
66
+ end
68
67
 
69
68
  components = Media.parse(@media_path)
70
69
  unless components.nil?
@@ -1,14 +1,18 @@
1
1
  # == Synopsis
2
2
  # encapsulation of all media files
3
3
  class MediaFiles
4
- attr_reader :medias, :titles, :duplicate_titles
4
+ attr_reader :medias, :titles
5
5
 
6
6
  # == Synopsis
7
7
  # directories => Array of String directory pathspecs
8
8
  def initialize(directories)
9
9
  @medias = find_medias(directories)
10
10
  @titles = find_titles(@medias)
11
- @duplicate_titles = find_duplicate_titles(@titles)
11
+ end
12
+
13
+ # should be ran after nfo_controller.update
14
+ def duplicate_titles
15
+ find_duplicate_titles(@titles)
12
16
  end
13
17
 
14
18
  protected
@@ -17,10 +21,11 @@ class MediaFiles
17
21
  # find all the media files in the given set of directories
18
22
  def find_medias(directories)
19
23
  medias = []
20
- directories.each do |dir|
21
- Dir.chdir(dir)
22
- medias += Dir.glob("**/*.{#{AppConfig[:media_extensions].join(',')}}").collect do |filename|
23
- Media.new(dir, filename)
24
+ directories.collect{|d| File.expand_path(d)}.each do |dir|
25
+ Dir.chdir(dir) do
26
+ medias += Dir.glob("**/*.{#{AppConfig[:media_extensions].join(',')}}").collect do |filename|
27
+ Media.new(dir, filename)
28
+ end
24
29
  end
25
30
  end
26
31
  medias
@@ -1,9 +1,13 @@
1
1
  class TmdbInfo
2
2
 
3
+ protected
4
+
3
5
  def initialize(profile)
4
6
  @profile = profile
5
7
  end
6
8
 
9
+ public
10
+
7
11
  # == Synopsis
8
12
  # load data from themovieDb.com
9
13
  # see TmdbProfile.all for options
data/spec/app_spec.rb CHANGED
@@ -13,7 +13,6 @@ describe "App" do
13
13
  AppConfig[:logger] = logger
14
14
  AppConfig.load
15
15
  File.mkdirs(TMPDIR)
16
- AppConfig[:logger].warn { "\nApp Specs" }
17
16
  end
18
17
 
19
18
  after(:all) do
@@ -14,7 +14,6 @@ describe "ConfigEditor" do
14
14
  AppConfig[:logger] = logger
15
15
  AppConfig.load
16
16
  File.mkdirs(TMPDIR)
17
- AppConfig[:logger].warn { "\nConfigEditor Specs" }
18
17
  end
19
18
 
20
19
  before(:each) do
@@ -19,7 +19,6 @@ describe "Dvdprofiler2xbmc" do
19
19
  AppConfig.load
20
20
  DvdprofilerProfile.collection_filespec = File.join(SAMPLES_DIR, 'Collection.xml')
21
21
  File.mkdirs(TMPDIR)
22
- AppConfig[:logger].warn { "\nDvdprofiler2xbmc Specs" }
23
22
 
24
23
  # the ignore_isbns array contain ISBNs for titles that can not be looked up on IMDB,
25
24
  # i.e., sets ands really low volume/special interest titles.
@@ -35,70 +34,71 @@ describe "Dvdprofiler2xbmc" do
35
34
  ]
36
35
  end
37
36
 
38
- unless FULL_REGRESSION
39
- it "should find some titles (quick regression)" do
40
- titles = [
41
- 'Alexander the Great',
42
- 'Anastasia',
43
- 'About a Boy',
44
- 'Gung Ho',
45
- 'Hot Shots',
46
- 'Meltdown',
47
- 'Oklahoma!',
48
- 'The Man From Snowy River',
49
- 'Rooster Cogburn (...and the Lady)',
50
- 'Call Me The Rise And Fall of Heidi Fleiss',
51
- 'batteries not included',
52
- 'Flyboys',
53
- "Captain Corelli's Mandolin",
54
- ].collect{|title| Collection.title_pattern(title)}
55
- buf = regression(titles)
56
- buf.should be_empty
37
+ describe "Regression" do
38
+ unless FULL_REGRESSION
39
+ it "should find some titles (quick regression)" do
40
+ titles = [
41
+ 'Alexander the Great',
42
+ 'Anastasia',
43
+ 'About a Boy',
44
+ 'Gung Ho',
45
+ 'Hot Shots',
46
+ 'Meltdown',
47
+ 'Oklahoma!',
48
+ 'The Man From Snowy River',
49
+ 'Rooster Cogburn (...and the Lady)',
50
+ 'Call Me The Rise And Fall of Heidi Fleiss',
51
+ 'batteries not included',
52
+ 'Flyboys',
53
+ "Captain Corelli's Mandolin",
54
+ ].collect{|title| Collection.title_pattern(title)}
55
+ buf = regression(titles)
56
+ buf.should be_empty
57
+ end
57
58
  end
58
- end
59
59
 
60
- if FULL_REGRESSION
61
- DvdprofilerProfile.collection_filespec = File.join(SAMPLES_DIR, 'Collection.xml')
62
- profiles = DvdprofilerProfile.all
63
- titles = profiles.collect{|profile| profile.title}
64
- titles.sort.each do |title|
65
- it "should find all Collection titles (full regression) title=>#{title}" do
66
- regression([title]).should == []
60
+ if FULL_REGRESSION
61
+ DvdprofilerProfile.collection_filespec = File.join(SAMPLES_DIR, 'Collection.xml')
62
+ profiles = DvdprofilerProfile.all
63
+ titles = profiles.collect{|profile| profile.title}
64
+ titles.sort.each do |title|
65
+ it "should find all Collection titles (full regression) title=>#{title}" do
66
+ regression([title]).should == []
67
+ end
67
68
  end
68
69
  end
69
- end
70
70
 
71
- def regression(titles)
72
- buf = []
73
- count = 0
74
- titles.each do |title|
75
- AppConfig[:logger].debug "title => #{title}"
76
- dvdprofiler_profiles = DvdprofilerProfile.all(:title => title)
77
- if dvdprofiler_profiles.blank?
78
- buf << "Can not find profile for #{title}"
79
- else
80
- dvdprofiler_profile = dvdprofiler_profiles.first
81
- isbn = dvdprofiler_profile.isbn
82
- AppConfig[:logger].debug "ISBN => #{isbn}"
83
- unless @ignore_isbns.include?(isbn.to_s)
84
- dvd_hash = dvdprofiler_profile.dvd_hash
85
- unless dvd_hash[:genres].include?('Television')
86
- count += 1
87
- imdb_profile = ImdbProfile.first(:titles => [dvd_hash[:title], title, dvd_hash[:originaltitle]].uniq.compact,
88
- :production_years => dvd_hash[:productionyear],
89
- :released_years => dvd_hash[:released],
90
- :logger => AppConfig[:logger])
91
- if imdb_profile.blank?
92
- buf << "Can not find IMDB ID for #{isbn} #{title}"
93
- else
94
- AppConfig[:logger].debug "IMDB ID => #{imdb_profile.imdb_id}"
71
+ def regression(titles)
72
+ buf = []
73
+ count = 0
74
+ titles.each do |title|
75
+ AppConfig[:logger].debug "title => #{title}"
76
+ dvdprofiler_profiles = DvdprofilerProfile.all(:title => title)
77
+ if dvdprofiler_profiles.blank?
78
+ buf << "Can not find profile for #{title}"
79
+ else
80
+ dvdprofiler_profile = dvdprofiler_profiles.first
81
+ isbn = dvdprofiler_profile.isbn
82
+ AppConfig[:logger].debug "ISBN => #{isbn}"
83
+ unless @ignore_isbns.include?(isbn.to_s)
84
+ dvd_hash = dvdprofiler_profile.dvd_hash
85
+ unless dvd_hash[:genres].include?('Television')
86
+ count += 1
87
+ imdb_profile = ImdbProfile.first(:titles => [dvd_hash[:title], title, dvd_hash[:originaltitle]].uniq.compact,
88
+ :production_years => dvd_hash[:productionyear],
89
+ :released_years => dvd_hash[:released],
90
+ :logger => AppConfig[:logger])
91
+ if imdb_profile.blank?
92
+ buf << "Can not find IMDB ID for #{isbn} #{title}"
93
+ else
94
+ AppConfig[:logger].debug "IMDB ID => #{imdb_profile.imdb_id}"
95
+ end
95
96
  end
96
97
  end
97
98
  end
98
99
  end
100
+ AppConfig[:logger].debug buf.join("\n") + "\n\m# movies: #{count}\n# missing IMDB ID: #{buf.size}"
101
+ buf
99
102
  end
100
- AppConfig[:logger].debug buf.join("\n") + "\n\m# movies: #{count}\n# missing IMDB ID: #{buf.size}"
101
- buf
102
103
  end
103
-
104
104
  end
@@ -0,0 +1,85 @@
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 "DvdprofilerInfo" 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
+ DvdprofilerProfile.collection_filespec = File.join(SAMPLES_DIR, 'Collection.xml')
20
+ end
21
+
22
+ describe "Finder" do
23
+ it "should find a profile" do
24
+
25
+ info = DvdprofilerInfo.find(:isbn => '786936735390')
26
+ info.should_not be_nil
27
+ end
28
+
29
+ it "should return nil if profile not found" do
30
+ info = DvdprofilerInfo.find(:title => 'should not find this title')
31
+ info.should be_nil
32
+ end
33
+ end
34
+
35
+ describe "Attributes" do
36
+ it "should generate xbmc_info" do
37
+ info = DvdprofilerInfo.find(:isbn => '786936735390')
38
+ info.to_xbmc_info.length.should > 0
39
+ end
40
+
41
+ it "should generate valid xbmc_info" do
42
+ info = DvdprofilerInfo.find(:isbn => '786936735390')
43
+ xbmc_info = info.to_xbmc_info
44
+ xbmc_info['title'].should == "National Treasure 2: Book of Secrets"
45
+ end
46
+
47
+ it "should return ISBN when profile has one" do
48
+ info = DvdprofilerInfo.find(:isbn => '786936735390')
49
+ info.isbn.should == '786936735390'
50
+ end
51
+
52
+ it "should return lowest production year for the media" do
53
+ info = DvdprofilerInfo.find(:isbn => '786936735390')
54
+ info.year.should == '2007'
55
+ end
56
+
57
+ it "should return box_set_parent_titles" do
58
+ info = DvdprofilerInfo.find(:title => ' The Scorpion King')
59
+ info.box_set_parent_titles.should == ["The Mummy Collector's Set"]
60
+ end
61
+
62
+ it "should return production_years" do
63
+ info = DvdprofilerInfo.find(:isbn => '786936735390')
64
+ info.production_years.should == ['2007']
65
+ end
66
+
67
+ it "should return released_years" do
68
+ info = DvdprofilerInfo.find(:isbn => '786936735390')
69
+ info.released_years.should == ['2008']
70
+ end
71
+
72
+ it "should return original_titles" do
73
+ info = DvdprofilerInfo.find(:isbn => '786936735390')
74
+ info.original_titles.should == ["National Treasure: Book of Secrets"]
75
+ end
76
+
77
+ it "should return title" do
78
+ info = DvdprofilerInfo.find(:isbn => '786936735390')
79
+ info.title.should == "National Treasure 2: Book of Secrets"
80
+ end
81
+
82
+ end
83
+
84
+ end
85
+
@@ -14,7 +14,6 @@ describe "FanartController" do
14
14
  AppConfig[:logger] = logger
15
15
  AppConfig.load
16
16
  File.mkdirs(TMPDIR)
17
- AppConfig[:logger].warn { "\nFanartController Specs" }
18
17
  end
19
18
 
20
19
  before(:each) do
@@ -34,121 +33,124 @@ describe "FanartController" do
34
33
  Dir.glob(File.join(TMPDIR,'*.tmdb.xml')).each { |filename| File.delete(filename) }
35
34
  end
36
35
 
37
- it 'should generate "original.0" size destination filespec' do
38
- indexes = {}
39
- filespec = @controller.send('get_destination_filespec', '/tmp/movie title.m4v', 'original', indexes)
40
- filespec.should == "/tmp/movie title-fanart.original.0"
41
- end
36
+ describe "Filespec generation" do
37
+ it 'should generate "original.0" size destination filespec' do
38
+ indexes = {}
39
+ filespec = @controller.send('get_destination_filespec', '/tmp/movie title.m4v', 'original', indexes)
40
+ filespec.should == "/tmp/movie title-fanart.original.0"
41
+ end
42
42
 
43
- it 'should generate "mid.0" size destination filespec' do
44
- indexes = {}
45
- filespec = @controller.send('get_destination_filespec', '/tmp/movie title.m4v', 'mid', indexes)
46
- filespec.should == "/tmp/movie title-fanart.mid.0"
47
- end
43
+ it 'should generate "mid.0" size destination filespec' do
44
+ indexes = {}
45
+ filespec = @controller.send('get_destination_filespec', '/tmp/movie title.m4v', 'mid', indexes)
46
+ filespec.should == "/tmp/movie title-fanart.mid.0"
47
+ end
48
48
 
49
- it 'should generate "thumb.0" size destination filespec' do
50
- indexes = {}
51
- filespec = @controller.send('get_destination_filespec', '/tmp/movie title.m4v', 'thumb', indexes)
52
- filespec.should == "/tmp/movie title-fanart.thumb.0"
53
- end
49
+ it 'should generate "thumb.0" size destination filespec' do
50
+ indexes = {}
51
+ filespec = @controller.send('get_destination_filespec', '/tmp/movie title.m4v', 'thumb', indexes)
52
+ filespec.should == "/tmp/movie title-fanart.thumb.0"
53
+ end
54
54
 
55
- it 'should generate "cover.0" size destination filespec' do
56
- indexes = {}
57
- filespec = @controller.send('get_destination_filespec', '/tmp/movie title.m4v', 'cover', indexes)
58
- filespec.should == "/tmp/movie title-fanart.cover.0"
59
- end
55
+ it 'should generate "cover.0" size destination filespec' do
56
+ indexes = {}
57
+ filespec = @controller.send('get_destination_filespec', '/tmp/movie title.m4v', 'cover', indexes)
58
+ filespec.should == "/tmp/movie title-fanart.cover.0"
59
+ end
60
60
 
61
- it 'should generate "original.1" size destination filespec' do
62
- indexes = {'original' => 0}
63
- filespec = @controller.send('get_destination_filespec', '/tmp/movie title.m4v', 'original', indexes)
64
- filespec.should == "/tmp/movie title-fanart.original.1"
65
- end
61
+ it 'should generate "original.1" size destination filespec' do
62
+ indexes = {'original' => 0}
63
+ filespec = @controller.send('get_destination_filespec', '/tmp/movie title.m4v', 'original', indexes)
64
+ filespec.should == "/tmp/movie title-fanart.original.1"
65
+ end
66
66
 
67
- it 'should increment indexes' do
68
- indexes = {}
69
- filespec = @controller.send('get_destination_filespec', '/tmp/movie title.m4v', 'original', indexes) # indexex['original'] => 0
70
- filespec = @controller.send('get_destination_filespec', '/tmp/movie title.m4v', 'original', indexes) # indexex['original'] => 1
71
- filespec = @controller.send('get_destination_filespec', '/tmp/movie title.m4v', 'original', indexes) # indexex['original'] => 2
72
- indexes['original'].should == 2 && filespec.should == "/tmp/movie title-fanart.original.2"
67
+ it 'should increment indexes' do
68
+ indexes = {}
69
+ filespec = @controller.send('get_destination_filespec', '/tmp/movie title.m4v', 'original', indexes) # indexex['original'] => 0
70
+ filespec = @controller.send('get_destination_filespec', '/tmp/movie title.m4v', 'original', indexes) # indexex['original'] => 1
71
+ filespec = @controller.send('get_destination_filespec', '/tmp/movie title.m4v', 'original', indexes) # indexex['original'] => 2
72
+ indexes['original'].should == 2 && filespec.should == "/tmp/movie title-fanart.original.2"
73
+ end
73
74
  end
74
75
 
75
- it 'should link to a fanart file' do
76
- dest_filespec = "#{TMPDIR}/foo-fanart"
77
- link_filespec = "#{dest_filespec}.jpg"
78
- touch("#{dest_filespec}.original.0.jpg")
79
- @controller.send('link_fanart', dest_filespec)
80
- File.exist?(link_filespec).should be_true
81
- end
76
+ describe "Linking" do
77
+ it 'should link to a fanart file' do
78
+ dest_filespec = "#{TMPDIR}/foo-fanart"
79
+ link_filespec = "#{dest_filespec}.jpg"
80
+ FileUtils.touch("#{dest_filespec}.original.0.jpg")
81
+ @controller.send('link_fanart', dest_filespec)
82
+ File.exist?(link_filespec).should be_true
83
+ end
82
84
 
83
- it 'should link to the first, largest (original) fanart file' do
84
- dest_filespec = "#{TMPDIR}/foo-fanart"
85
- link_filespec = "#{dest_filespec}.jpg"
86
- ['original', 'mid', 'thumb'].each do |size|
87
- 0.upto(2) do |index|
88
- touch("#{dest_filespec}.#{size}.#{index}.jpg")
85
+ it 'should link to the first, largest (original) fanart file' do
86
+ dest_filespec = "#{TMPDIR}/foo-fanart"
87
+ link_filespec = "#{dest_filespec}.jpg"
88
+ ['original', 'mid', 'thumb'].each do |size|
89
+ 0.upto(2) do |index|
90
+ FileUtils.touch("#{dest_filespec}.#{size}.#{index}.jpg")
91
+ end
89
92
  end
93
+ @controller.send('link_fanart', dest_filespec)
94
+ File.exist?(link_filespec).should be_true
90
95
  end
91
- @controller.send('link_fanart', dest_filespec)
92
- (File.exist?(link_filespec).should be_true) && (open(link_filespec).read.should == "#{dest_filespec}.original.0.jpg\n")
93
- end
94
96
 
95
- it 'should link to the first, largest (mid) fanart file' do
96
- dest_filespec = "#{TMPDIR}/foo-fanart"
97
- link_filespec = "#{dest_filespec}.jpg"
98
- ['mid', 'thumb'].each do |size|
99
- 0.upto(2) do |index|
100
- touch("#{dest_filespec}.#{size}.#{index}.jpg")
97
+ it 'should link to the first, largest (mid) fanart file' do
98
+ dest_filespec = "#{TMPDIR}/foo-fanart"
99
+ link_filespec = "#{dest_filespec}.jpg"
100
+ ['mid', 'thumb'].each do |size|
101
+ 0.upto(2) do |index|
102
+ FileUtils.touch("#{dest_filespec}.#{size}.#{index}.jpg")
103
+ end
101
104
  end
105
+ @controller.send('link_fanart', dest_filespec)
106
+ File.exist?(link_filespec).should be_true
102
107
  end
103
- @controller.send('link_fanart', dest_filespec)
104
- (File.exist?(link_filespec).should be_true) && (open(link_filespec).read.should == "#{dest_filespec}.mid.0.jpg\n")
105
- end
106
108
 
107
- it 'should link to the first, largest (thumb) fanart file' do
108
- dest_filespec = "#{TMPDIR}/foo-fanart"
109
- link_filespec = "#{dest_filespec}.jpg"
110
- ['thumb'].each do |size|
111
- 0.upto(2) do |index|
112
- touch("#{dest_filespec}.#{size}.#{index}.jpg")
109
+ it 'should link to the first, largest (thumb) fanart file' do
110
+ dest_filespec = "#{TMPDIR}/foo-fanart"
111
+ link_filespec = "#{dest_filespec}.jpg"
112
+ ['thumb'].each do |size|
113
+ 0.upto(2) do |index|
114
+ FileUtils.touch("#{dest_filespec}.#{size}.#{index}.jpg")
115
+ end
113
116
  end
117
+ @controller.send('link_fanart', dest_filespec)
118
+ File.exist?(link_filespec).should be_true
114
119
  end
115
- @controller.send('link_fanart', dest_filespec)
116
- (File.exist?(link_filespec).should be_true) && (open(link_filespec).read.should == "#{dest_filespec}.thumb.0.jpg\n")
117
120
  end
118
121
 
119
- it 'should fetch fanart' do
120
- @controller.send('fetch_fanart', 'tt0095016')
121
- buf = []
122
- %w(mid original thumb).each do |size|
123
- filespec = File.join(TMPDIR, "Die Hard - 1988-fanart.#{size}.0.jpg")
124
- buf << "Missing: \"#{filespec}\"" unless File.exist?(filespec) && (File.size(filespec) > 0)
122
+ describe "Fetching" do
123
+ it 'should fetch fanart' do
124
+ @controller.send('fetch_fanart', 'tt0095016')
125
+ buf = []
126
+ %w(mid original thumb).each do |size|
127
+ filespec = File.join(TMPDIR, "Die Hard - 1988-fanart.#{size}.0.jpg")
128
+ buf << "Missing: \"#{filespec}\"" unless File.exist?(filespec) && (File.size(filespec) > 0)
129
+ end
130
+ puts buf.join("\n") unless buf.empty?
131
+ buf.empty?.should be_true
125
132
  end
126
- puts buf.join("\n") unless buf.empty?
127
- buf.empty?.should be_true
128
- end
129
133
 
130
- it 'should fetch fanart with unicode characters in the URL' do
131
- buf = []
132
- titles = {'While You Were Sleeping' => 'tt0114924',
133
- 'Sniper' => 'tt0108171',
134
- 'Leon The Professional' => 'tt0110413'
135
- }
136
- titles.each do |title, imdb_id|
137
- FileUtils.touch(File.join(TMPDIR, "#{title}.dummy"))
138
- media = Media.new(TMPDIR, "#{title}.dummy")
139
- media.imdb_id = 'tt0095016'
140
- controller = FanartController.new(media)
141
- controller.send('fetch_fanart', imdb_id)
142
- %w(mid original thumb).each do |size|
143
- filespec = File.join(TMPDIR, "#{title}-fanart.#{size}.0.jpg")
144
- buf << filespec unless File.exist?(filespec) && (File.size(filespec) > 0)
134
+ it 'should fetch fanart with unicode characters in the URL' do
135
+ buf = []
136
+ titles = {'While You Were Sleeping' => 'tt0114924',
137
+ 'Sniper' => 'tt0108171',
138
+ 'Leon The Professional' => 'tt0110413'
139
+ }
140
+ titles.each do |title, imdb_id|
141
+ FileUtils.touch(File.join(TMPDIR, "#{title}.dummy"))
142
+ media = Media.new(TMPDIR, "#{title}.dummy")
143
+ media.imdb_id = 'tt0095016'
144
+ controller = FanartController.new(media)
145
+ controller.send('fetch_fanart', imdb_id)
146
+ %w(mid original thumb).each do |size|
147
+ filespec = File.join(TMPDIR, "#{title}-fanart.#{size}.0.jpg")
148
+ buf << filespec unless File.exist?(filespec) && (File.size(filespec) > 0)
149
+ end
145
150
  end
151
+ puts buf.join("\n") unless buf.empty?
152
+ buf.empty?.should be_true
146
153
  end
147
- puts buf.join("\n") unless buf.empty?
148
- buf.empty?.should be_true
149
154
  end
150
155
 
151
- def touch(filespec)
152
- File.open(filespec, 'w') { |f| f.puts(filespec)}
153
- end
154
156
  end