unified_db 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,9 +1,10 @@
1
+ require 'imdb'
1
2
  require 'imdb_party'
2
3
 
3
4
  module UnifiedDB
4
5
  module Backend
5
6
  class IMDB < Base
6
-
7
+
7
8
  def find_by_id(id)
8
9
  movie = handler.find_movie_by_id(id)
9
10
  @result = Result::ID.new(
@@ -22,25 +23,29 @@ module UnifiedDB
22
23
  rescue
23
24
  raise ApiError, 'not found'
24
25
  end
25
-
26
+
26
27
  def find_by_title(title)
27
- movies = handler.find_by_title(title)
28
+ # movies = handler.find_by_title(title)
29
+ movies = Imdb::Search.new(title).movies
28
30
  movies.each do |movie|
31
+ id = "tt#{movie.id}"
32
+ title1, year, title2 = movie.title.match(/(.*) \(([0-9]{4})\)(.*)/)[1..3] rescue next
29
33
  @result << Result::Title.new(
30
- :id => movie[:imdb_id],
31
- :title => movie[:title],
32
- :year => movie[:year])
34
+ :id => id,
35
+ :title => [title1.to_s.strip, title2.to_s.strip].join(" ").strip,
36
+ :year => year)
33
37
  end
38
+ result
34
39
  end
35
-
40
+
36
41
  private
37
-
42
+
38
43
  def service; 'imdb'; end
39
-
44
+
40
45
  def handler
41
46
  @handler ||= ImdbParty::Imdb.new(:anonymize => true)
42
47
  end
43
-
48
+
44
49
  end
45
50
  end
46
51
  end
@@ -3,11 +3,11 @@ require 'tvdb_party'
3
3
  module UnifiedDB
4
4
  module Backend
5
5
  class TVDB < Base
6
-
6
+
7
7
  def find_by_id(id)
8
8
  movie = handler.get_series_by_id(id)
9
9
  raise if movie.nil?
10
-
10
+
11
11
  @result = Result::ID.new(
12
12
  :id => movie.id,
13
13
  :title => movie.name,
@@ -24,7 +24,7 @@ module UnifiedDB
24
24
  rescue
25
25
  raise ApiError, 'not found'
26
26
  end
27
-
27
+
28
28
  def find_by_title(title)
29
29
  movies = handler.search(title)
30
30
  movies.each do |movie|
@@ -33,22 +33,23 @@ module UnifiedDB
33
33
  :title => movie['SeriesName'],
34
34
  :year => movie['FirstAired'].to_s.split('-')[0])
35
35
  end
36
+ result
36
37
  end
37
-
38
+
38
39
  private
39
-
40
+
40
41
  def service; 'tvdb'; end
41
-
42
+
42
43
  def handler
43
- raise ApiError, 'no TVDB secret provided' if UnifiedDB.tvdb_secret.nil?
44
+ raise ApiError, 'no TVDB secret provided' if UnifiedDB.tvdb_secret.nil?
44
45
  @handler ||= TvdbParty::Search.new(UnifiedDB.tvdb_secret)
45
46
  end
46
-
47
+
47
48
  def format_posters(posters)
48
49
  list = posters.select { |poster| ['season', 'poster'].include? poster.banner_type }
49
50
  list.sort { |a,b| b.banner_type <=> a.banner_type }.collect(&:url)
50
51
  end
51
-
52
+
52
53
  end
53
54
  end
54
55
  end
@@ -1,5 +1,5 @@
1
1
  module UnifiedDB
2
-
3
- VERSION = '0.1.1'
4
-
2
+
3
+ VERSION = '0.2.0'
4
+
5
5
  end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe UnifiedDB::Backend::TVDB do
4
4
  subject { described_class.new }
5
-
5
+
6
6
  it "should return valid find by title" do
7
7
  result = subject.find(:title => 'StarGate SG-1')
8
8
  result.class.should eql(Hash)
@@ -11,30 +11,30 @@ describe UnifiedDB::Backend::TVDB do
11
11
  result[:service].should eql('tvdb')
12
12
  result[:result].class.should eql(Array)
13
13
  result[:result].size.should eql 1
14
-
14
+
15
15
  first_result = result[:result].first
16
16
  first_result.class.should eql(UnifiedDB::Result::Title)
17
17
  first_result.id.should eql('72449')
18
18
  first_result.title.should eql('Stargate SG-1')
19
19
  first_result.year.should eql('1997')
20
-
20
+
21
21
  encoded = Yajl::Encoder.new.encode result
22
22
  decoded = Yajl::Parser.new.parse encoded
23
-
23
+
24
24
  decoded.class.should eql(Hash)
25
25
  do_sort(decoded.keys).should eql(['result', 'service', 'status'])
26
26
  decoded['status'].should eql('success')
27
27
  decoded['service'].should eql('tvdb')
28
28
  decoded['result'].class.should eql(Array)
29
29
  decoded['result'].size.should eql 1
30
-
30
+
31
31
  first_result = decoded['result'].first
32
32
  first_result.class.should eql(Hash)
33
33
  first_result['id'].should eql('72449')
34
34
  first_result['title'].should eql('Stargate SG-1')
35
35
  first_result['year'].should eql('1997')
36
36
  end
37
-
37
+
38
38
  it "should return empty array if invalid find by title specified" do
39
39
  result = subject.find(:title => "qwertyuiopasdfghjkllzxcvbnm")
40
40
  result.class.should eql(Hash)
@@ -44,15 +44,15 @@ describe UnifiedDB::Backend::TVDB do
44
44
  result[:result].class.should eql(Array)
45
45
  result[:result].size.should eql(0)
46
46
  end
47
-
48
-
47
+
48
+
49
49
  it "should return valid find by id" do
50
50
  result = subject.find(:id => '72449')
51
51
  result.class.should eql(Hash)
52
52
  do_sort(result.keys).should eql([:result, :service, :status])
53
53
  result[:status].should eql('success')
54
54
  result[:service].should eql('tvdb')
55
-
55
+
56
56
  result[:result].class.should eql(UnifiedDB::Result::ID)
57
57
  result[:result].id.should eql('72449')
58
58
  result[:result].title.should eql('Stargate SG-1')
@@ -65,13 +65,13 @@ describe UnifiedDB::Backend::TVDB do
65
65
  result[:result].rating.should be < 10
66
66
  result[:result].runtime.should eql(60)
67
67
  result[:result].actors.class.should eql(Array)
68
- result[:result].actors.first.should eql({"Richard Dean Anderson"=>"Col./Gen. Jack O'Neill"})
68
+ result[:result].actors.first.should eql({"Christopher Judge"=>"Teal'c"})
69
69
  result[:result].directors.should eql([])
70
70
  result[:result].writers.should eql([])
71
71
  result[:result].posters.class.should eql(Array)
72
72
  result[:result].posters.size.should be > 0
73
73
  end
74
-
74
+
75
75
  it "should return error if id was not found" do
76
76
  result = subject.find(:id => '72449123')
77
77
  result.class.should eql(Hash)
@@ -79,5 +79,5 @@ describe UnifiedDB::Backend::TVDB do
79
79
  result[:status].should eql('error')
80
80
  result[:reason].should eql('not found')
81
81
  end
82
-
82
+
83
83
  end
data/unified_db.gemspec CHANGED
@@ -11,10 +11,12 @@ Gem::Specification.new do |s|
11
11
  s.homepage = "http://github.com/imanel/unifieddb"
12
12
  s.summary = %q{Scrapper for multiple Movie Databases}
13
13
  s.description = %q{Scrapper for multiple Movie Databases}
14
-
14
+
15
15
  s.add_dependency 'yajl-ruby'
16
- s.add_dependency 'imdb_party', '~> 0.6.0'
17
- s.add_dependency 'tvdb_party', '~> 0.6.0'
16
+ s.add_dependency 'imdb', '~> 0.6.8'
17
+ s.add_dependency 'httparty', '0.8.1'
18
+ s.add_dependency 'imdb_party', '0.6.1'
19
+ s.add_dependency 'tvdb_party', '0.6.2'
18
20
  s.add_development_dependency 'rspec', '~> 2.0'
19
21
 
20
22
  s.files = `git ls-files`.split("\n")
metadata CHANGED
@@ -1,68 +1,125 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: unified_db
3
- version: !ruby/object:Gem::Version
4
- version: 0.1.1
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Bernard Potocki
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2011-10-16 00:00:00.000000000 +02:00
13
- default_executable:
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
17
+
18
+ date: 2012-06-21 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
16
21
  name: yajl-ruby
17
- requirement: &70329097056220 !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
18
24
  none: false
19
- requirements:
20
- - - ! '>='
21
- - !ruby/object:Gem::Version
22
- version: '0'
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
23
32
  type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: imdb
24
36
  prerelease: false
25
- version_requirements: *70329097056220
26
- - !ruby/object:Gem::Dependency
27
- name: imdb_party
28
- requirement: &70329097055680 !ruby/object:Gem::Requirement
37
+ requirement: &id002 !ruby/object:Gem::Requirement
29
38
  none: false
30
- requirements:
39
+ requirements:
31
40
  - - ~>
32
- - !ruby/object:Gem::Version
33
- version: 0.6.0
41
+ - !ruby/object:Gem::Version
42
+ hash: 23
43
+ segments:
44
+ - 0
45
+ - 6
46
+ - 8
47
+ version: 0.6.8
34
48
  type: :runtime
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: httparty
35
52
  prerelease: false
36
- version_requirements: *70329097055680
37
- - !ruby/object:Gem::Dependency
38
- name: tvdb_party
39
- requirement: &70329097055120 !ruby/object:Gem::Requirement
53
+ requirement: &id003 !ruby/object:Gem::Requirement
40
54
  none: false
41
- requirements:
42
- - - ~>
43
- - !ruby/object:Gem::Version
44
- version: 0.6.0
55
+ requirements:
56
+ - - "="
57
+ - !ruby/object:Gem::Version
58
+ hash: 61
59
+ segments:
60
+ - 0
61
+ - 8
62
+ - 1
63
+ version: 0.8.1
45
64
  type: :runtime
65
+ version_requirements: *id003
66
+ - !ruby/object:Gem::Dependency
67
+ name: imdb_party
46
68
  prerelease: false
47
- version_requirements: *70329097055120
48
- - !ruby/object:Gem::Dependency
69
+ requirement: &id004 !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - "="
73
+ - !ruby/object:Gem::Version
74
+ hash: 5
75
+ segments:
76
+ - 0
77
+ - 6
78
+ - 1
79
+ version: 0.6.1
80
+ type: :runtime
81
+ version_requirements: *id004
82
+ - !ruby/object:Gem::Dependency
83
+ name: tvdb_party
84
+ prerelease: false
85
+ requirement: &id005 !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - "="
89
+ - !ruby/object:Gem::Version
90
+ hash: 3
91
+ segments:
92
+ - 0
93
+ - 6
94
+ - 2
95
+ version: 0.6.2
96
+ type: :runtime
97
+ version_requirements: *id005
98
+ - !ruby/object:Gem::Dependency
49
99
  name: rspec
50
- requirement: &70329097054580 !ruby/object:Gem::Requirement
100
+ prerelease: false
101
+ requirement: &id006 !ruby/object:Gem::Requirement
51
102
  none: false
52
- requirements:
103
+ requirements:
53
104
  - - ~>
54
- - !ruby/object:Gem::Version
55
- version: '2.0'
105
+ - !ruby/object:Gem::Version
106
+ hash: 3
107
+ segments:
108
+ - 2
109
+ - 0
110
+ version: "2.0"
56
111
  type: :development
57
- prerelease: false
58
- version_requirements: *70329097054580
112
+ version_requirements: *id006
59
113
  description: Scrapper for multiple Movie Databases
60
- email:
114
+ email:
61
115
  - bernard.potocki@imanel.org
62
116
  executables: []
117
+
63
118
  extensions: []
119
+
64
120
  extra_rdoc_files: []
65
- files:
121
+
122
+ files:
66
123
  - .gitignore
67
124
  - .travis.yml
68
125
  - Gemfile
@@ -84,32 +141,40 @@ files:
84
141
  - spec/unified_db/backend/imdb_spec.rb
85
142
  - spec/unified_db/backend/tvdb_spec.rb
86
143
  - unified_db.gemspec
87
- has_rdoc: true
88
144
  homepage: http://github.com/imanel/unifieddb
89
145
  licenses: []
146
+
90
147
  post_install_message:
91
148
  rdoc_options: []
92
- require_paths:
149
+
150
+ require_paths:
93
151
  - lib
94
- required_ruby_version: !ruby/object:Gem::Requirement
152
+ required_ruby_version: !ruby/object:Gem::Requirement
95
153
  none: false
96
- requirements:
97
- - - ! '>='
98
- - !ruby/object:Gem::Version
99
- version: '0'
100
- required_rubygems_version: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - ">="
156
+ - !ruby/object:Gem::Version
157
+ hash: 3
158
+ segments:
159
+ - 0
160
+ version: "0"
161
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
162
  none: false
102
- requirements:
103
- - - ! '>='
104
- - !ruby/object:Gem::Version
105
- version: '0'
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ hash: 3
167
+ segments:
168
+ - 0
169
+ version: "0"
106
170
  requirements: []
171
+
107
172
  rubyforge_project:
108
- rubygems_version: 1.6.2
173
+ rubygems_version: 1.8.22
109
174
  signing_key:
110
175
  specification_version: 3
111
176
  summary: Scrapper for multiple Movie Databases
112
- test_files:
177
+ test_files:
113
178
  - spec/spec_helper.rb
114
179
  - spec/support/do_sort.rb
115
180
  - spec/unified_db/backend/imdb_spec.rb