diff options
author | Mike Crute <mcrute@gmail.com> | 2015-12-06 19:29:42 -0800 |
---|---|---|
committer | Mike Crute <mcrute@gmail.com> | 2015-12-06 19:29:42 -0800 |
commit | d55320aded3c1639dca4d077e14866fce30cab6d (patch) | |
tree | 318d450d371915a2558c9d906ed65db3cb05fdf5 | |
parent | 9563f26dce80baa96c89ffa4eb54fc980a303b7f (diff) | |
download | pydora-d55320aded3c1639dca4d077e14866fce30cab6d.tar.bz2 pydora-d55320aded3c1639dca4d077e14866fce30cab6d.tar.xz pydora-d55320aded3c1639dca4d077e14866fce30cab6d.zip |
Style cleanup
-rw-r--r-- | pandora/client.py | 47 | ||||
-rw-r--r-- | pandora/models/pandora.py | 15 |
2 files changed, 25 insertions, 37 deletions
diff --git a/pandora/client.py b/pandora/client.py index c8a5f00..be107d2 100644 --- a/pandora/client.py +++ b/pandora/client.py | |||
@@ -52,11 +52,6 @@ class BaseAPIClient(object): | |||
52 | from .clientbuilder import PydoraConfigFileBuilder | 52 | from .clientbuilder import PydoraConfigFileBuilder |
53 | return PydoraConfigFileBuilder(path, authenticate).build() | 53 | return PydoraConfigFileBuilder(path, authenticate).build() |
54 | 54 | ||
55 | def get_params_dict(self, reg_params, ad_params): | ||
56 | params = reg_params.copy() | ||
57 | params.update(ad_params) | ||
58 | return params | ||
59 | |||
60 | def _partner_login(self): | 55 | def _partner_login(self): |
61 | partner = self.transport("auth.partnerLogin", | 56 | partner = self.transport("auth.partnerLogin", |
62 | username=self.partner_user, | 57 | username=self.partner_user, |
@@ -76,19 +71,16 @@ class BaseAPIClient(object): | |||
76 | def _authenticate(self): | 71 | def _authenticate(self): |
77 | self._partner_login() | 72 | self._partner_login() |
78 | 73 | ||
79 | reg_params = dict(loginType="user", | ||
80 | username=self.username, | ||
81 | password=self.password, | ||
82 | includePandoraOneInfo=True, | ||
83 | includeSubscriptionExpiration=True, | ||
84 | returnCapped=True) | ||
85 | |||
86 | ad_params = dict(includeAdAttributes=True, | ||
87 | includeAdvertiserAttributes=True, | ||
88 | xplatformAdCapable=True) | ||
89 | |||
90 | user = self.transport("auth.userLogin", | 74 | user = self.transport("auth.userLogin", |
91 | **self.get_params_dict(reg_params, ad_params)) | 75 | loginType="user", |
76 | username=self.username, | ||
77 | password=self.password, | ||
78 | includePandoraOneInfo=True, | ||
79 | includeSubscriptionExpiration=True, | ||
80 | returnCapped=True, | ||
81 | includeAdAttributes=True, | ||
82 | includeAdvertiserAttributes=True, | ||
83 | xplatformAdCapable=True) | ||
92 | 84 | ||
93 | self.transport.set_user(user) | 85 | self.transport.set_user(user) |
94 | 86 | ||
@@ -122,19 +114,17 @@ class APIClient(BaseAPIClient): | |||
122 | def get_playlist(self, station_token): | 114 | def get_playlist(self, station_token): |
123 | from .models.pandora import Playlist | 115 | from .models.pandora import Playlist |
124 | 116 | ||
125 | reg_params = dict(stationToken=station_token, includeTrackLength=True) | 117 | raw_playlist = Playlist.from_json(self, |
126 | ad_params = dict(xplatformAdCapable=True, audioAdPodCapable=True,) | 118 | self("station.getPlaylist", |
127 | 119 | stationToken=station_token, | |
128 | params = self.get_params_dict(reg_params, ad_params) | 120 | includeTrackLength=True, |
129 | raw_playlist = Playlist.from_json( | 121 | xplatformAdCapable=True, |
130 | self, self("station.getPlaylist", **params)) | 122 | audioAdPodCapable=True)) |
131 | 123 | ||
132 | playlist = [] | 124 | playlist = [] |
133 | |||
134 | for track in raw_playlist: | 125 | for track in raw_playlist: |
135 | if track.is_ad: | 126 | if track.is_ad: |
136 | track = self.get_ad_item(station_token, track.ad_token) | 127 | track = self.get_ad_item(station_token, track.ad_token) |
137 | |||
138 | playlist.append(track) | 128 | playlist.append(track) |
139 | 129 | ||
140 | return playlist | 130 | return playlist |
@@ -259,9 +249,10 @@ class APIClient(BaseAPIClient): | |||
259 | def get_ad_item(self, station_id, ad_token): | 249 | def get_ad_item(self, station_id, ad_token): |
260 | from .models.pandora import AdItem | 250 | from .models.pandora import AdItem |
261 | 251 | ||
262 | ad_item = AdItem.from_json(self, self.get_ad_metadata(ad_token)) | 252 | ad_metadata = self.get_ad_metadata(ad_token) |
263 | ad_item.station_id = station_id | 253 | ad_metadata["station_id"] = station_id |
264 | return ad_item | 254 | |
255 | return AdItem.from_json(self, ad_metadata) | ||
265 | 256 | ||
266 | def get_ad_metadata(self, ad_token): | 257 | def get_ad_metadata(self, ad_token): |
267 | return self("ad.getAdMetadata", | 258 | return self("ad.getAdMetadata", |
diff --git a/pandora/models/pandora.py b/pandora/models/pandora.py index a1e3781..e3a3c1c 100644 --- a/pandora/models/pandora.py +++ b/pandora/models/pandora.py | |||
@@ -33,11 +33,8 @@ class GenreStation(PandoraModel): | |||
33 | category = Field("categoryName") | 33 | category = Field("categoryName") |
34 | 34 | ||
35 | def get_playlist(self): | 35 | def get_playlist(self): |
36 | # Not possible to retrieve playlist for genre stations directly. | 36 | raise NotImplementedError("Genre stations do not have playlists. " |
37 | # Need to 'create' an actual Station object first using | 37 | "Create a real station using the token.") |
38 | # APIClient.create_station | ||
39 | raise NotImplementedError(("Cannot retrieve playlist for genre " | ||
40 | "stations.")) | ||
41 | 38 | ||
42 | 39 | ||
43 | class StationList(PandoraListModel): | 40 | class StationList(PandoraListModel): |
@@ -264,8 +261,8 @@ class Bookmark(PandoraModel): | |||
264 | 261 | ||
265 | class BookmarkList(PandoraModel): | 262 | class BookmarkList(PandoraModel): |
266 | 263 | ||
267 | songs = Field("songs", formatter=Bookmark.from_json_list) | 264 | songs = Field("songs", formatter=PandoraModel.from_json_list) |
268 | artists = Field("artists", formatter=Bookmark.from_json_list) | 265 | artists = Field("artists", formatter=PandoraModel.from_json_list) |
269 | 266 | ||
270 | 267 | ||
271 | class SearchResultItem(PandoraModel): | 268 | class SearchResultItem(PandoraModel): |
@@ -291,8 +288,8 @@ class SearchResult(PandoraModel): | |||
291 | 288 | ||
292 | nearest_matches_available = Field("nearMatchesAvailable") | 289 | nearest_matches_available = Field("nearMatchesAvailable") |
293 | explanation = Field("explanation") | 290 | explanation = Field("explanation") |
294 | songs = Field("songs", formatter=SearchResultItem.from_json_list) | 291 | songs = Field("songs", formatter=PandoraModel.from_json_list) |
295 | artists = Field("artists", formatter=SearchResultItem.from_json_list) | 292 | artists = Field("artists", formatter=PandoraModel.from_json_list) |
296 | 293 | ||
297 | 294 | ||
298 | class GenreStationList(PandoraDictListModel): | 295 | class GenreStationList(PandoraDictListModel): |