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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 76f5e17f3dad6ffb6f02acba86f723335fbb97d4
4
- data.tar.gz: 6b828d02d74c2fa63c8c3a109539d81631c670a7
3
+ metadata.gz: fb5a92a63800d0ff36db81a216df6e872088e325
4
+ data.tar.gz: e4d9e93ceb1cfd76135af22bec7c17d96db2b787
5
5
  SHA512:
6
- metadata.gz: 754af5befcfe4bfc58dd1fbf0d24600d43a215188c5b58f3194d49d9c3d0d6ea99af07b0dc700c45f0738f3c73474dda06f476ffadcbea7423b2a98efacce347
7
- data.tar.gz: 39ec74d7091a081601f9f3fd193d6c947c75f93a1dbe4bcb50ceeacb0389e528ecedea30affc2eb52a0cc68d6ad25ce221964623e58f145f9925f5211df7a399
6
+ metadata.gz: 33172828630f417b6ab84a6de9e589af8390d9630a052a597ebfa72a475f68028ae2912d3e38a0bae378c21ab5b338c1c94a2ed418d005d4da077d3e8f722719
7
+ data.tar.gz: f63b4be008fdcac395c56c4a27a44a26dcd52bf717b38b763b9214842cdfd9bae2c6294a6a020bc9980b52c062d229a744faeaf0310db1733d50b017c969f077
data/lib/pandata.rb CHANGED
@@ -11,7 +11,7 @@ module Pandata
11
11
  module Version
12
12
  MAJOR = 0
13
13
  MINOR = 3
14
- PATCH = 0
14
+ PATCH = 1
15
15
  BUILD = nil
16
16
 
17
17
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
@@ -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/tracklikes?likeStartIndex=%{nextLikeStartIndex}&thumbStartIndex=%{nextThumbStartIndex}&webname=%{webname}',
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}',
@@ -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 cookie.
14
- @@cookie = nil
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, get_cookie).read
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.get_cookie
40
- @@cookie ||= download_cookie
45
+ def self.get_config
46
+ @@config ||= download_config
41
47
  end
42
48
 
43
- def self.download_cookie
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['cookie']
56
+ config
51
57
  end
52
58
 
53
59
  end
@@ -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
- show_more = Nokogiri::HTML(html).css('.show_more')[0]
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
- infobox_each_link(html) do |title, subtitle|
110
- tracks << { track: title, artist: subtitle }
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)
@@ -172,6 +172,8 @@ module Pandata
172
172
  } if next_data_indices.empty?
173
173
 
174
174
  next_data_indices[:webname] = @webname
175
+ next_data_indices[:pat] = Downloader.get_pat
176
+
175
177
  DATA_FEED_URLS[data_name] % next_data_indices
176
178
  end
177
179
 
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.0
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-02 00:00:00.000000000 Z
11
+ date: 2014-09-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri