yayimdbs 0.2.1 → 0.2.2
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.
- data/lib/yay_imdbs.rb +9 -11
- metadata +18 -5
data/lib/yay_imdbs.rb
CHANGED
@@ -31,7 +31,7 @@ class YayImdbs
|
|
31
31
|
class << self
|
32
32
|
|
33
33
|
def search_for_imdb_id(name, year=nil, type=nil)
|
34
|
-
search_results =
|
34
|
+
search_results = search_imdb(name)
|
35
35
|
|
36
36
|
search_results.each do |result|
|
37
37
|
# Ensure result is the correct video type
|
@@ -46,7 +46,7 @@ class YayImdbs
|
|
46
46
|
def search_imdb(search_term)
|
47
47
|
search_results = []
|
48
48
|
|
49
|
-
doc =
|
49
|
+
doc = get_search_page(search_term)
|
50
50
|
|
51
51
|
# If the search is an exact match imdb will redirect to the movie page not search results page
|
52
52
|
# we uses the title meta element to determine if we got an exact match
|
@@ -79,14 +79,14 @@ class YayImdbs
|
|
79
79
|
def scrap_movie_info(imdb_id)
|
80
80
|
info_hash = {:imdb_id => imdb_id}.with_indifferent_access
|
81
81
|
|
82
|
-
doc =
|
82
|
+
doc = get_movie_page(imdb_id)
|
83
83
|
title, year = get_title_and_year_from_meta(doc)
|
84
84
|
info_hash[:title], info_hash[:year] = title, year
|
85
85
|
if info_hash['title'].nil?
|
86
86
|
#If we cant get title and year something is wrong
|
87
87
|
raise "Unable to find title or year for imdb id #{imdb_id}"
|
88
88
|
end
|
89
|
-
info_hash[:video_type] =
|
89
|
+
info_hash[:video_type] = video_type_from_meta(doc)
|
90
90
|
|
91
91
|
info_hash[:plot] = doc.xpath("//td[@id='overview-top']/p[2]").inner_text.strip
|
92
92
|
info_hash[:rating] = doc.at_css('.rating-rating').content.gsub(/\/.*/, '').to_f rescue nil
|
@@ -99,7 +99,7 @@ class YayImdbs
|
|
99
99
|
info_hash[PROPERTY_ALIAS[key]] = info_hash[key] if PROPERTY_ALIAS[key]
|
100
100
|
end
|
101
101
|
|
102
|
-
|
102
|
+
unless found_info_divs
|
103
103
|
#If we don't find any info divs assume parsing failed
|
104
104
|
raise "No info divs found for imdb id #{imdb_id}"
|
105
105
|
end
|
@@ -107,12 +107,10 @@ class YayImdbs
|
|
107
107
|
# Hack: tv shows can have a year property, which is a list, fixing ...
|
108
108
|
info_hash[:year] = year
|
109
109
|
|
110
|
-
|
110
|
+
scrap_images(doc, info_hash)
|
111
111
|
|
112
112
|
#scrap episodes if tv series
|
113
|
-
if info_hash.has_key?('season')
|
114
|
-
self.scrap_episodes(info_hash)
|
115
|
-
end
|
113
|
+
scrap_episodes(info_hash) if info_hash.has_key?('season')
|
116
114
|
|
117
115
|
return info_hash
|
118
116
|
end
|
@@ -167,7 +165,7 @@ class YayImdbs
|
|
167
165
|
|
168
166
|
def scrap_episodes(info_hash)
|
169
167
|
episodes = []
|
170
|
-
doc =
|
168
|
+
doc = get_episodes_page(info_hash[:imdb_id])
|
171
169
|
|
172
170
|
doc.css(".filter-all").each do |e_div|
|
173
171
|
next unless e_div.at_css('h3').inner_text =~ /Season (\d+), Episode (\d+):/
|
@@ -204,7 +202,7 @@ class YayImdbs
|
|
204
202
|
title_text = doc.at_css("meta[name='title']").try(:[], 'content')
|
205
203
|
# Matches 'Movie Name (2010)' or 'Movie Name (2010/I)' or 'Lost (TV Series 2004–2010)'
|
206
204
|
if title_text && title_text =~ /(.*) \([^\)0-9]*(\d{4})((\/\w*)|(.\d{4}))?\)/
|
207
|
-
movie_title =
|
205
|
+
movie_title = clean_title($1)
|
208
206
|
movie_year = $2.to_i
|
209
207
|
end
|
210
208
|
return movie_title, movie_year
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 2
|
9
|
+
version: 0.2.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Sam Cavenagh
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-03-
|
17
|
+
date: 2011-03-07 00:00:00 +11:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -46,9 +46,22 @@ dependencies:
|
|
46
46
|
type: :runtime
|
47
47
|
version_requirements: *id002
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
|
-
name:
|
49
|
+
name: i18n
|
50
50
|
prerelease: false
|
51
51
|
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
segments:
|
57
|
+
- 0
|
58
|
+
version: "0"
|
59
|
+
type: :runtime
|
60
|
+
version_requirements: *id003
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rspec
|
63
|
+
prerelease: false
|
64
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
52
65
|
none: false
|
53
66
|
requirements:
|
54
67
|
- - ">="
|
@@ -59,7 +72,7 @@ dependencies:
|
|
59
72
|
- 0
|
60
73
|
version: 2.0.0
|
61
74
|
type: :development
|
62
|
-
version_requirements: *
|
75
|
+
version_requirements: *id004
|
63
76
|
description: A simple imdb scraper built on Nokogiri for ruby 1.9+
|
64
77
|
email: cavenaghweb@hotmail.com
|
65
78
|
executables: []
|