Class: Pandata::Parser
- Inherits:
-
Object
- Object
- Pandata::Parser
- Defined in:
- lib/pandata/parser.rb
Overview
Parses HTML/XML pages from Pandora for relevant data.
Instance Method Summary collapse
-
#get_bookmarked_artists(xml) ⇒ Object
Returns an array of artist names.
-
#get_bookmarked_tracks(xml) ⇒ Object
Returns an array of hashes with :artist and :track keys.
-
#get_followers(html) ⇒ Object
Returns an array of hashes with :name, :webname and :href keys.
-
#get_following(html) ⇒ Object
Returns an array of hashes with :name, :webname and :href keys.
-
#get_liked_albums(html) ⇒ Object
Returns an array of hashes with :artist and :album keys.
-
#get_liked_artists(html) ⇒ Object
Returns an array of artist names.
-
#get_liked_stations(html) ⇒ Object
Returns an array of station names.
-
#get_liked_tracks(html) ⇒ Object
Returns an array of hashes with :artist and :track keys.
-
#get_next_data_indices(html) ⇒ Hash, False
Get the query parameters necessary to get the next page of data from Pandora.
- #get_playing_station(xml) ⇒ String
-
#get_recent_activity(xml) ⇒ Object
Returns an array of recent activity names.
-
#get_stations(xml) ⇒ Object
Returns an array of station names.
-
#get_webnames_from_search(html) ⇒ Array
Get the webnames from a user ID search.
Instance Method Details
#get_bookmarked_artists(xml) ⇒ Object
Returns an array of artist names.
95 96 97 98 99 100 101 102 103 |
# File 'lib/pandata/parser.rb', line 95 def get_bookmarked_artists(xml) artists = [] xml_each_item(xml) do |title| artists << title end artists end |
#get_bookmarked_tracks(xml) ⇒ Object
Returns an array of hashes with :artist and :track keys.
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/pandata/parser.rb', line 82 def get_bookmarked_tracks(xml) tracks = [] xml_each_item(xml) do |title| track, artist = title.split(' by ') tracks << { artist: artist, track: track } end tracks end |
#get_followers(html) ⇒ Object
Returns an array of hashes with :name, :webname and :href keys.
150 151 152 |
# File 'lib/pandata/parser.rb', line 150 def get_followers(html) get_followx_users(html) end |
#get_following(html) ⇒ Object
Returns an array of hashes with :name, :webname and :href keys.
144 145 146 |
# File 'lib/pandata/parser.rb', line 144 def get_following(html) get_followx_users(html) end |
#get_liked_albums(html) ⇒ Object
Returns an array of hashes with :artist and :album keys.
132 133 134 135 136 137 138 139 140 |
# File 'lib/pandata/parser.rb', line 132 def get_liked_albums(html) albums = [] infobox_each_link(html) do |title, subtitle| albums << { album: title, artist: subtitle } end albums end |
#get_liked_artists(html) ⇒ Object
Returns an array of artist names.
120 121 122 |
# File 'lib/pandata/parser.rb', line 120 def get_liked_artists(html) get_infobox_titles(html) end |
#get_liked_stations(html) ⇒ Object
Returns an array of station names.
126 127 128 |
# File 'lib/pandata/parser.rb', line 126 def get_liked_stations(html) get_infobox_titles(html) end |
#get_liked_tracks(html) ⇒ Object
Returns an array of hashes with :artist and :track keys.
107 108 109 110 111 112 113 114 115 116 |
# File 'lib/pandata/parser.rb', line 107 def get_liked_tracks(html) tracks = [] doublelink_each_link(html) do |title, subtitle| artist = subtitle.sub(/^by\s/i, '') tracks << { track: title, artist: artist } end tracks end |
#get_next_data_indices(html) ⇒ Hash, False
Get the query parameters necessary to get the next page of data from Pandora.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/pandata/parser.rb', line 25 def get_next_data_indices(html) # .js-more-link is found on mobile pages. show_more = Nokogiri::HTML(html).css('.show_more, .js-more-link')[0] if show_more next_indices = {} data_attributes = ['nextStartIndex', 'nextLikeStartIndex', 'nextThumbStartIndex'] data_attributes.each do |attr_name| attr = show_more.attributes['data-' + attr_name.downcase] next_indices[attr_name.to_sym] = attr.value.to_i if attr end next_indices else false end end |
#get_playing_station(xml) ⇒ String
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/pandata/parser.rb', line 69 def (xml) station = '' xml_each_item(xml) do |title| station = title # First title is the station name. break end station end |
#get_recent_activity(xml) ⇒ Object
Returns an array of recent activity names.
45 46 47 48 49 50 51 52 53 |
# File 'lib/pandata/parser.rb', line 45 def get_recent_activity(xml) activity_names = [] xml_each_item(xml) do |title| activity_names << title end activity_names end |
#get_stations(xml) ⇒ Object
Returns an array of station names.
57 58 59 60 61 62 63 64 65 |
# File 'lib/pandata/parser.rb', line 57 def get_stations(xml) stations = [] xml_each_item(xml) do |title| stations << title end stations end |
#get_webnames_from_search(html) ⇒ Array
Get the webnames from a user ID search.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/pandata/parser.rb', line 11 def get_webnames_from_search(html) user_links = Nokogiri::HTML(html).css('.user_name a') webnames = [] user_links.each do |link| webnames << link['webname'] end webnames end |