aboutsummaryrefslogtreecommitdiff
path: root/pandora
diff options
context:
space:
mode:
authorjcass <john.cass77@gmail.com>2015-10-28 15:50:43 +0200
committerMike Crute <mcrute@gmail.com>2015-12-05 18:51:30 -0800
commit1d09ea8698e30bd9d3c1a2193b7c0de4ed6ec3a9 (patch)
tree60f418f6661774ce2cfcbef45d3348c523c0a149 /pandora
parent120975c31e339050889be9aee3471998a40270ce (diff)
downloadpydora-1d09ea8698e30bd9d3c1a2193b7c0de4ed6ec3a9.tar.bz2
pydora-1d09ea8698e30bd9d3c1a2193b7c0de4ed6ec3a9.tar.xz
pydora-1d09ea8698e30bd9d3c1a2193b7c0de4ed6ec3a9.zip
Add PlaylistModel superclass to refactor common ad_item and playlist_item logic into.
Diffstat (limited to 'pandora')
-rw-r--r--pandora/client.py5
-rw-r--r--pandora/models/pandora.py121
2 files changed, 76 insertions, 50 deletions
diff --git a/pandora/client.py b/pandora/client.py
index ba2b86f..4d9671b 100644
--- a/pandora/client.py
+++ b/pandora/client.py
@@ -238,6 +238,11 @@ class APIClient(BaseAPIClient):
238 musicToken=music_token, 238 musicToken=music_token,
239 email=emails[0]) 239 email=emails[0])
240 240
241 def get_ad_item(self, ad_token):
242 from .models.pandora import AdItem
243
244 return AdItem.from_json(self, self.get_ad_metadata(ad_token))
245
241 def get_ad_metadata(self, ad_token): 246 def get_ad_metadata(self, ad_token):
242 return self("ad.getAdMetadata", 247 return self("ad.getAdMetadata",
243 adToken=ad_token, 248 adToken=ad_token,
diff --git a/pandora/models/pandora.py b/pandora/models/pandora.py
index 0505d9c..7c766c1 100644
--- a/pandora/models/pandora.py
+++ b/pandora/models/pandora.py
@@ -53,56 +53,7 @@ class StationList(PandoraListModel):
53 return checksum != self.checksum 53 return checksum != self.checksum
54 54
55 55
56class PlaylistItem(PandoraModel): 56class PlaylistModel(PandoraModel):
57
58 artist_name = Field("artistName")
59 album_name = Field("albumName")
60 song_name = Field("songName")
61 song_rating = Field("songRating")
62 track_gain = Field("trackGain")
63 track_length = Field("trackLength", 0)
64 track_token = Field("trackToken")
65 audio_url = Field("audioUrl")
66 bitrate = Field("bitrate")
67 album_art_url = Field("albumArtUrl")
68 allow_feedback = Field("allowFeedback", True)
69 station_id = Field("stationId")
70
71 ad_token = Field("adToken")
72
73 album_detail_url = Field("albumDetailUrl")
74 album_explore_url = Field("albumExplorerUrl")
75
76 amazon_album_asin = Field("amazonAlbumAsin")
77 amazon_album_digital_asin = Field("amazonAlbumDigitalAsin")
78 amazon_album_url = Field("amazonAlbumUrl")
79 amazon_song_digital_asin = Field("amazonSongDigitalAsin")
80
81 artist_detail_url = Field("artistDetailUrl")
82 artist_explore_url = Field("artistExplorerUrl")
83
84 itunes_song_url = Field("itunesSongUrl")
85
86 song_detail_url = Field("songDetailUrl")
87 song_explore_url = Field("songExplorerUrl")
88
89 def thumbs_up(self):
90 self._api_client.add_feedback(self.track_token, True)
91
92 def thumbs_down(self):
93 self._api_client.add_feedback(self.track_token, False)
94
95 def bookmark_song(self):
96 self._api_client.add_song_bookmark(self.track_token)
97
98 def bookmark_artist(self):
99 self._api_client.add_artist_bookmark(self.track_token)
100
101 def sleep(self):
102 self._api_client.sleep_song(self.track_token)
103
104 def get_is_playable(self):
105 return self._api_client.transport.test_url(self.audio_url)
106 57
107 @classmethod 58 @classmethod
108 def from_json(cls, api_client, data): 59 def from_json(cls, api_client, data):
@@ -181,6 +132,76 @@ class PlaylistItem(PandoraModel):
181 """ 132 """
182 return cls.get_audio_field(data, "bitrate", preferred_quality=preferred_quality) 133 return cls.get_audio_field(data, "bitrate", preferred_quality=preferred_quality)
183 134
135 def get_is_playable(self):
136 return self._api_client.transport.test_url(self.audio_url)
137
138
139class PlaylistItem(PlaylistModel):
140
141 artist_name = Field("artistName")
142 album_name = Field("albumName")
143 song_name = Field("songName")
144 song_rating = Field("songRating")
145 track_gain = Field("trackGain")
146 track_length = Field("trackLength", 0)
147 track_token = Field("trackToken")
148 audio_url = Field("audioUrl")
149 album_art_url = Field("albumArtUrl")
150 allow_feedback = Field("allowFeedback", True)
151 station_id = Field("stationId")
152
153 ad_token = Field("adToken")
154
155 album_detail_url = Field("albumDetailUrl")
156 album_explore_url = Field("albumExplorerUrl")
157
158 amazon_album_asin = Field("amazonAlbumAsin")
159 amazon_album_digital_asin = Field("amazonAlbumDigitalAsin")
160 amazon_album_url = Field("amazonAlbumUrl")
161 amazon_song_digital_asin = Field("amazonSongDigitalAsin")
162
163 artist_detail_url = Field("artistDetailUrl")
164 artist_explore_url = Field("artistExplorerUrl")
165
166 itunes_song_url = Field("itunesSongUrl")
167
168 song_detail_url = Field("songDetailUrl")
169 song_explore_url = Field("songExplorerUrl")
170
171 @property
172 def is_ad(self):
173 return self.ad_token is not None
174
175 def thumbs_up(self):
176 self._api_client.add_feedback(self.track_token, True)
177
178 def thumbs_down(self):
179 self._api_client.add_feedback(self.track_token, False)
180
181 def bookmark_song(self):
182 self._api_client.add_song_bookmark(self.track_token)
183
184 def bookmark_artist(self):
185 self._api_client.add_artist_bookmark(self.track_token)
186
187 def sleep(self):
188 self._api_client.sleep_song(self.track_token)
189
190
191class AdItem(PlaylistModel):
192
193 title = Field("title")
194 company_name = Field("companyName")
195 tracking_tokens = Field("adTrackingTokens")
196 audio_url = Field("audioUrl")
197
198 @property
199 def is_ad(self):
200 return True
201
202 def register_ad(self, station_id):
203 self._api_client.register_ad(station_id, self.tracking_tokens)
204
184 205
185class Playlist(PandoraListModel): 206class Playlist(PandoraListModel):
186 207