pandata 0.3.0 → 0.3.1
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.
- checksums.yaml +4 -4
- data/lib/pandata.rb +1 -1
- data/lib/pandata/data_urls.rb +1 -1
- data/lib/pandata/downloader.rb +13 -7
- data/lib/pandata/parser.rb +18 -3
- data/lib/pandata/scraper.rb +2 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb5a92a63800d0ff36db81a216df6e872088e325
|
4
|
+
data.tar.gz: e4d9e93ceb1cfd76135af22bec7c17d96db2b787
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 33172828630f417b6ab84a6de9e589af8390d9630a052a597ebfa72a475f68028ae2912d3e38a0bae378c21ab5b338c1c94a2ed418d005d4da077d3e8f722719
|
7
|
+
data.tar.gz: f63b4be008fdcac395c56c4a27a44a26dcd52bf717b38b763b9214842cdfd9bae2c6294a6a020bc9980b52c062d229a744faeaf0310db1733d50b017c969f077
|
data/lib/pandata.rb
CHANGED
data/lib/pandata/data_urls.rb
CHANGED
@@ -10,7 +10,7 @@ module Pandata
|
|
10
10
|
stations: "http://feeds.pandora.com/feeds/people/%{webname}/stations.xml?max=#{MAX_RESULTS}",
|
11
11
|
bookmarked_tracks: "http://feeds.pandora.com/feeds/people/%{webname}/favorites.xml?max=#{MAX_RESULTS}",
|
12
12
|
bookmarked_artists: "http://feeds.pandora.com/feeds/people/%{webname}/favoriteartists.xml?max=#{MAX_RESULTS}",
|
13
|
-
liked_tracks: 'http://www.pandora.com/content/
|
13
|
+
liked_tracks: 'http://www.pandora.com/content/mobile/profile_likes_track.vm?likeStartIndex=%{nextLikeStartIndex}&thumbStartIndex=%{nextThumbStartIndex}&webname=%{webname}&pat=%{pat}',
|
14
14
|
liked_artists: 'http://www.pandora.com/content/artistlikes?artistStartIndex=%{nextStartIndex}&webname=%{webname}',
|
15
15
|
liked_stations: 'http://www.pandora.com/content/stationlikes?stationStartIndex=%{nextStartIndex}&webname=%{webname}',
|
16
16
|
liked_albums: 'http://www.pandora.com/content/albumlikes?albumStartIndex=%{nextStartIndex}&webname=%{webname}',
|
data/lib/pandata/downloader.rb
CHANGED
@@ -10,14 +10,20 @@ module Pandata
|
|
10
10
|
# A GitHub Gist that contains an updated cookie allowing access to 'login-only' visible data.
|
11
11
|
CONFIG_URL = 'https://gist.github.com/ustasb/596f1ee96d03463fde77/raw/pandata_config.json'
|
12
12
|
|
13
|
-
# The cached
|
14
|
-
@@
|
13
|
+
# The cached config hash.
|
14
|
+
@@config = nil
|
15
15
|
|
16
16
|
# Downloads and reads a page from a URL.
|
17
17
|
# @param url [String]
|
18
18
|
# @return [String] contents of page
|
19
19
|
def self.read_page(url)
|
20
|
-
download(url,
|
20
|
+
download(url, get_config['cookie']).read
|
21
|
+
end
|
22
|
+
|
23
|
+
# Returns a pat token needed for mobile requests.
|
24
|
+
# @return [String]
|
25
|
+
def self.get_pat
|
26
|
+
get_config['pat']
|
21
27
|
end
|
22
28
|
|
23
29
|
private
|
@@ -36,18 +42,18 @@ module Pandata
|
|
36
42
|
raise PandataError
|
37
43
|
end
|
38
44
|
|
39
|
-
def self.
|
40
|
-
@@
|
45
|
+
def self.get_config
|
46
|
+
@@config ||= download_config
|
41
47
|
end
|
42
48
|
|
43
|
-
def self.
|
49
|
+
def self.download_config
|
44
50
|
config = JSON.parse download(CONFIG_URL).read
|
45
51
|
|
46
52
|
if Gem::Version.new(Pandata::Version::STRING) <= Gem::Version.new(config['required_update_for'])
|
47
53
|
raise PandataError, 'Pandora.com has changed something and you need to update Pandata!'
|
48
54
|
end
|
49
55
|
|
50
|
-
config
|
56
|
+
config
|
51
57
|
end
|
52
58
|
|
53
59
|
end
|
data/lib/pandata/parser.rb
CHANGED
@@ -23,7 +23,8 @@ module Pandata
|
|
23
23
|
# @param html [String]
|
24
24
|
# @return [Hash, False]
|
25
25
|
def get_next_data_indices(html)
|
26
|
-
|
26
|
+
# .js-more-link is found on mobile pages.
|
27
|
+
show_more = Nokogiri::HTML(html).css('.show_more, .js-more-link')[0]
|
27
28
|
|
28
29
|
if show_more
|
29
30
|
next_indices = {}
|
@@ -106,8 +107,9 @@ module Pandata
|
|
106
107
|
def get_liked_tracks(html)
|
107
108
|
tracks = []
|
108
109
|
|
109
|
-
|
110
|
-
|
110
|
+
doublelink_each_link(html) do |title, subtitle|
|
111
|
+
artist = subtitle.sub(/^by\s/i, '')
|
112
|
+
tracks << { track: title, artist: artist }
|
111
113
|
end
|
112
114
|
|
113
115
|
tracks
|
@@ -175,6 +177,19 @@ module Pandata
|
|
175
177
|
end
|
176
178
|
end
|
177
179
|
|
180
|
+
# Loops over each .double-link container and yields the title and subtitle.
|
181
|
+
# Encountered on mobile pages.
|
182
|
+
# @param html [String]
|
183
|
+
def doublelink_each_link(html)
|
184
|
+
Nokogiri::HTML(html).css('.double-link').each do |doublelink|
|
185
|
+
title_link = doublelink.css('h3 strong').text.strip
|
186
|
+
subtitle_link = doublelink.css('.media--backstageMusic__text div').text.strip
|
187
|
+
|
188
|
+
yield(title_link, subtitle_link)
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
|
178
193
|
# @param html [String]
|
179
194
|
# Returns an array of titles from #infobox_each_link.
|
180
195
|
def get_infobox_titles(html)
|
data/lib/pandata/scraper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pandata
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Ustas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|