google-play 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/google-play-class.rb +219 -0
- data/lib/google-play.rb +33 -0
- metadata +57 -0
@@ -0,0 +1,219 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'nokogiri'
|
3
|
+
|
4
|
+
class PlayResult
|
5
|
+
attr_accessor :id, :type, :title, :price, :rating, :description, :thumbnail, :actors, :lengthtime, :contentrating, :genre, :related
|
6
|
+
|
7
|
+
def initialize(id,type,title)
|
8
|
+
@id=id
|
9
|
+
@type=type
|
10
|
+
@title=title
|
11
|
+
@price=""
|
12
|
+
@rating=""
|
13
|
+
@description=""
|
14
|
+
@thumbnail=""
|
15
|
+
@actors=Array.new
|
16
|
+
@lengthtime=""
|
17
|
+
@contentrating=""
|
18
|
+
@genre=""
|
19
|
+
@related=Array.new
|
20
|
+
fillPlayData(id,type,title)
|
21
|
+
end
|
22
|
+
|
23
|
+
def fillPlayData(id,type,title)
|
24
|
+
doc = Nokogiri::HTML(open("https://play.google.com/store/#{type}/details?id=#{id}"))
|
25
|
+
get_price(doc)
|
26
|
+
get_rating(doc)
|
27
|
+
get_description(doc)
|
28
|
+
get_thumbnail(doc)
|
29
|
+
get_actors(doc)
|
30
|
+
get_lengthtime(doc)
|
31
|
+
get_contentrating(doc)
|
32
|
+
get_genre(doc)
|
33
|
+
get_related(doc)
|
34
|
+
end
|
35
|
+
def get_title(doc)
|
36
|
+
if @title == ""
|
37
|
+
@title = doc.css('div.doc-header-content h1.doc-header-title').text
|
38
|
+
end
|
39
|
+
end
|
40
|
+
def get_price(doc)
|
41
|
+
if doc.css('.buy-wrapper .buy-border a.buy-link .buy-button-price').length != 0
|
42
|
+
@price = doc.css('.buy-wrapper .buy-border a.buy-link .buy-button-price')[0].text
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def get_rating(doc)
|
47
|
+
if doc.css('.doc-details-ratings-price div div.ratings').length != 0
|
48
|
+
@rating = doc.css('.doc-details-ratings-price div div.ratings')[0]['title']
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def get_description(doc)
|
53
|
+
if doc.css('div#doc-original-text').length != 0
|
54
|
+
@description = doc.css('div#doc-original-text').text
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def get_thumbnail(doc)
|
59
|
+
if doc.css('div.doc-banner-icon img').length != 0
|
60
|
+
@thumbnail = doc.css('div.doc-banner-icon img')[0]['src']
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def get_actors(doc)
|
65
|
+
if doc.css('td.credit-cell span[itemprop=actors] a span').length != 0
|
66
|
+
doc.css('td.credit-cell span[itemprop=actors] a span').each{ |value|
|
67
|
+
@actors << value.text.to_s
|
68
|
+
}
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def get_lengthtime(doc)
|
73
|
+
if doc.css('dl.doc-metadata-list dd').length != 0
|
74
|
+
doc.css('dl.doc-metadata-list dd').each{ |value|
|
75
|
+
if value.text.to_s =~ /minutes/
|
76
|
+
@lengthtime = value.text.to_s
|
77
|
+
end
|
78
|
+
}
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def get_contentrating(doc)
|
83
|
+
if doc.css('dd[itemprop=contentRating]').length != 0
|
84
|
+
@contentrating = doc.css('dd[itemprop=contentRating]').text
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def get_genre(doc)
|
89
|
+
if doc.css('ul.doc-genres .doc-genre-link a:first-child').length != 0
|
90
|
+
@genre = doc.css('ul.doc-genres .doc-genre-link a:first-child').text
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def get_related(doc)
|
95
|
+
if doc.css('div#related-list ul.snippet-list li div div.details a.title').length != 0
|
96
|
+
doc.css('div#related-list ul.snippet-list li div div.details a.title').each{ |value|
|
97
|
+
@related << value.text.to_s
|
98
|
+
}
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
class SearchResult
|
104
|
+
attr_accessor :id, :type, :title, :price, :rating, :description, :thumbnail
|
105
|
+
|
106
|
+
def initialize(query,type,list)
|
107
|
+
@id=""
|
108
|
+
@type=type
|
109
|
+
@title=""
|
110
|
+
@price=""
|
111
|
+
@rating=""
|
112
|
+
@description=""
|
113
|
+
@thumbnail=""
|
114
|
+
fillSearchData(query,type,list)
|
115
|
+
end
|
116
|
+
|
117
|
+
def fillSearchData(id,type,list)
|
118
|
+
get_id(list)
|
119
|
+
get_title(list)
|
120
|
+
get_price(list)
|
121
|
+
get_rating(list)
|
122
|
+
get_description(list)
|
123
|
+
get_thumbnail(list)
|
124
|
+
end
|
125
|
+
|
126
|
+
def get_id(doc)
|
127
|
+
@id = doc['data-docid']
|
128
|
+
end
|
129
|
+
|
130
|
+
def get_title(doc)
|
131
|
+
if doc.css('a.title').length != 0
|
132
|
+
@title = doc.css('a.title').text
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def get_price(doc)
|
137
|
+
if doc.css('span.buy-button-price').length != 0
|
138
|
+
@price = doc.css('span.buy-button-price').text
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def get_rating(doc)
|
143
|
+
if doc.css('div.ratings-wrapper .ratings').length != 0
|
144
|
+
@rating = doc.css('div.ratings-wrapper .ratings')[0]['title']
|
145
|
+
else
|
146
|
+
@rating = "None"
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
def get_description(doc)
|
151
|
+
if doc.css('div.description').length != 0
|
152
|
+
@description = doc.css('div.description').text
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
def get_thumbnail(doc)
|
157
|
+
if doc.css('.thumbnail-wrapper .thumbnail img').length != 0
|
158
|
+
@thumbnail = doc.css('.thumbnail-wrapper .thumbnail img')[0]['src']
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
class TopResult
|
164
|
+
attr_accessor :id, :type, :title, :price, :artist, :explicit, :thumbnail
|
165
|
+
|
166
|
+
def initialize(type,list)
|
167
|
+
@id=""
|
168
|
+
@type=type
|
169
|
+
@title=""
|
170
|
+
@price=""
|
171
|
+
if type == "music" then @artist="" end
|
172
|
+
@explicit=""
|
173
|
+
@thumbnail=""
|
174
|
+
fillSearchData(type,list)
|
175
|
+
end
|
176
|
+
|
177
|
+
def fillSearchData(type,list)
|
178
|
+
get_id(list)
|
179
|
+
get_title(list)
|
180
|
+
get_price(list)
|
181
|
+
get_artist(list)
|
182
|
+
get_explicit(list)
|
183
|
+
get_thumbnail(list)
|
184
|
+
end
|
185
|
+
|
186
|
+
def get_id(doc)
|
187
|
+
@id = doc['data-docid']
|
188
|
+
end
|
189
|
+
|
190
|
+
def get_title(doc)
|
191
|
+
if doc.css('a.title').length != 0
|
192
|
+
@title = doc.css('a.title')[0]['title']
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
def get_price(doc)
|
197
|
+
if doc.css('span.buy-button-price').length != 0
|
198
|
+
@price = doc.css('span.buy-button-price').text
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
def get_artist(doc)
|
203
|
+
if doc.css('span.attribution div a').length != 0
|
204
|
+
@artist = doc.css('span.attribution div a').text
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
def get_explicit(doc)
|
209
|
+
if doc.css('.explicit').length != 0
|
210
|
+
@explicit = 1
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
def get_thumbnail(doc)
|
215
|
+
if doc.css('.thumbnail-wrapper .thumbnail img').length != 0
|
216
|
+
@thumbnail = doc.css('.thumbnail-wrapper .thumbnail img')[0]['src']
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
data/lib/google-play.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'uri'
|
3
|
+
require 'nokogiri'
|
4
|
+
require './google-play-class.rb'
|
5
|
+
|
6
|
+
# TODO: Build whitelist of types to search for and check type on submit. Also add pagination
|
7
|
+
module GooglePlay
|
8
|
+
def self.search(query,type,page)
|
9
|
+
results = Array.new
|
10
|
+
doc = Nokogiri::HTML(open("https://play.google.com/store/search?q=#{URI.escape(query)}&c=#{URI.escape(type)}"))
|
11
|
+
doc.css('ul.search-results-list li.search-results-item').each{ |list|
|
12
|
+
results << SearchResult.new(query,type,list)
|
13
|
+
}
|
14
|
+
return results
|
15
|
+
end
|
16
|
+
def self.info(id,type)
|
17
|
+
doc = Nokogiri::HTML(open("https://play.google.com/store/#{URI.escape(type)}/details?id=#{URI.escape(id)}"))
|
18
|
+
return PlayResult.new(id,type,doc.css('h1.doc-banner-title').text)
|
19
|
+
end
|
20
|
+
def self.top(type)
|
21
|
+
results = Array.new
|
22
|
+
if type == "music"
|
23
|
+
url = "https://play.google.com/store/music/collection/topselling_paid_album"
|
24
|
+
else type == "movie"
|
25
|
+
url = "https://play.google.com/store/movies/collection/topselling_paid"
|
26
|
+
end
|
27
|
+
doc = Nokogiri::HTML(open(url))
|
28
|
+
doc.css('ul.container-snippet-list li').each{ |list|
|
29
|
+
results << TopResult.new(type,list)
|
30
|
+
}
|
31
|
+
return results
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: google-play
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.5
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Tom Doyle
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-03-06 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: nokogiri
|
16
|
+
requirement: &70315623457760 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.5.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70315623457760
|
25
|
+
description: A simple gem for grabbing Google Play data
|
26
|
+
email: me@tdoyle.me
|
27
|
+
executables: []
|
28
|
+
extensions: []
|
29
|
+
extra_rdoc_files: []
|
30
|
+
files:
|
31
|
+
- lib/google-play-class.rb
|
32
|
+
- lib/google-play.rb
|
33
|
+
homepage: https://github.com/tdoyle/Google-Play-Unofficial-Gem/
|
34
|
+
licenses: []
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options: []
|
37
|
+
require_paths:
|
38
|
+
- lib
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
|
+
none: false
|
47
|
+
requirements:
|
48
|
+
- - ! '>='
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
requirements: []
|
52
|
+
rubyforge_project:
|
53
|
+
rubygems_version: 1.8.15
|
54
|
+
signing_key:
|
55
|
+
specification_version: 3
|
56
|
+
summary: Grab data from Google Play
|
57
|
+
test_files: []
|