diff options
Diffstat (limited to 'pandora/models')
-rw-r--r-- | pandora/models/_base.py | 12 | ||||
-rw-r--r-- | pandora/models/ad.py | 5 | ||||
-rw-r--r-- | pandora/models/playlist.py | 36 | ||||
-rw-r--r-- | pandora/models/search.py | 15 | ||||
-rw-r--r-- | pandora/models/station.py | 9 |
5 files changed, 42 insertions, 35 deletions
diff --git a/pandora/models/_base.py b/pandora/models/_base.py index 6975d0a..8904be1 100644 --- a/pandora/models/_base.py +++ b/pandora/models/_base.py | |||
@@ -71,7 +71,6 @@ class DateField(SyntheticField): | |||
71 | 71 | ||
72 | 72 | ||
73 | class ModelMetaClass(type): | 73 | class ModelMetaClass(type): |
74 | |||
75 | def __new__(cls, name, parents, dct): | 74 | def __new__(cls, name, parents, dct): |
76 | dct["_fields"] = fields = {} | 75 | dct["_fields"] = fields = {} |
77 | new_dct = dct.copy() | 76 | new_dct = dct.copy() |
@@ -159,7 +158,8 @@ class PandoraModel(metaclass=ModelMetaClass): | |||
159 | """ | 158 | """ |
160 | items = [ | 159 | items = [ |
161 | "=".join((key, repr(getattr(self, key)))) | 160 | "=".join((key, repr(getattr(self, key)))) |
162 | for key in sorted(self._fields.keys())] | 161 | for key in sorted(self._fields.keys()) |
162 | ] | ||
163 | 163 | ||
164 | if items: | 164 | if items: |
165 | output = ", ".join(items) | 165 | output = ", ".join(items) |
@@ -167,8 +167,9 @@ class PandoraModel(metaclass=ModelMetaClass): | |||
167 | output = None | 167 | output = None |
168 | 168 | ||
169 | if and_also: | 169 | if and_also: |
170 | return "{}({}, {})".format(self.__class__.__name__, | 170 | return "{}({}, {})".format( |
171 | output, and_also) | 171 | self.__class__.__name__, output, and_also |
172 | ) | ||
172 | else: | 173 | else: |
173 | return "{}({})".format(self.__class__.__name__, output) | 174 | return "{}({})".format(self.__class__.__name__, output) |
174 | 175 | ||
@@ -301,7 +302,8 @@ class PandoraDictListModel(PandoraModel, dict): | |||
301 | 302 | ||
302 | for part in item[self.__list_key__]: | 303 | for part in item[self.__list_key__]: |
303 | self[key].append( | 304 | self[key].append( |
304 | cls.__list_model__.from_json(api_client, part)) | 305 | cls.__list_model__.from_json(api_client, part) |
306 | ) | ||
305 | 307 | ||
306 | return self | 308 | return self |
307 | 309 | ||
diff --git a/pandora/models/ad.py b/pandora/models/ad.py index ad4b7b0..48cd302 100644 --- a/pandora/models/ad.py +++ b/pandora/models/ad.py | |||
@@ -24,8 +24,9 @@ class AdItem(PlaylistModel): | |||
24 | if self.tracking_tokens: | 24 | if self.tracking_tokens: |
25 | self._api_client.register_ad(station_id, self.tracking_tokens) | 25 | self._api_client.register_ad(station_id, self.tracking_tokens) |
26 | else: | 26 | else: |
27 | raise ParameterMissing('No ad tracking tokens provided for ' | 27 | raise ParameterMissing( |
28 | 'registration.') | 28 | "No ad tracking tokens provided for registration." |
29 | ) | ||
29 | 30 | ||
30 | def prepare_playback(self): | 31 | def prepare_playback(self): |
31 | try: | 32 | try: |
diff --git a/pandora/models/playlist.py b/pandora/models/playlist.py index 38afb00..8e0d22e 100644 --- a/pandora/models/playlist.py +++ b/pandora/models/playlist.py | |||
@@ -5,15 +5,15 @@ from ._base import Field, SyntheticField, PandoraModel, PandoraListModel | |||
5 | 5 | ||
6 | 6 | ||
7 | class AdditionalAudioUrl(Enum): | 7 | class AdditionalAudioUrl(Enum): |
8 | HTTP_40_AAC_MONO = 'HTTP_40_AAC_MONO' | 8 | HTTP_40_AAC_MONO = "HTTP_40_AAC_MONO" |
9 | HTTP_64_AAC = 'HTTP_64_AAC' | 9 | HTTP_64_AAC = "HTTP_64_AAC" |
10 | HTTP_32_AACPLUS = 'HTTP_32_AACPLUS' | 10 | HTTP_32_AACPLUS = "HTTP_32_AACPLUS" |
11 | HTTP_64_AACPLUS = 'HTTP_64_AACPLUS' | 11 | HTTP_64_AACPLUS = "HTTP_64_AACPLUS" |
12 | HTTP_24_AACPLUS_ADTS = 'HTTP_24_AACPLUS_ADTS' | 12 | HTTP_24_AACPLUS_ADTS = "HTTP_24_AACPLUS_ADTS" |
13 | HTTP_32_AACPLUS_ADTS = 'HTTP_32_AACPLUS_ADTS' | 13 | HTTP_32_AACPLUS_ADTS = "HTTP_32_AACPLUS_ADTS" |
14 | HTTP_64_AACPLUS_ADTS = 'HTTP_64_AACPLUS_ADTS' | 14 | HTTP_64_AACPLUS_ADTS = "HTTP_64_AACPLUS_ADTS" |
15 | HTTP_128_MP3 = 'HTTP_128_MP3' | 15 | HTTP_128_MP3 = "HTTP_128_MP3" |
16 | HTTP_32_WMA = 'HTTP_32_WMA' | 16 | HTTP_32_WMA = "HTTP_32_WMA" |
17 | 17 | ||
18 | 18 | ||
19 | class PandoraType(Enum): | 19 | class PandoraType(Enum): |
@@ -28,14 +28,14 @@ class PandoraType(Enum): | |||
28 | 28 | ||
29 | @staticmethod | 29 | @staticmethod |
30 | def from_string(value): | 30 | def from_string(value): |
31 | return { | 31 | types = { |
32 | "TR": PandoraType.TRACK, | 32 | "TR": PandoraType.TRACK, |
33 | "AR": PandoraType.ARTIST, | 33 | "AR": PandoraType.ARTIST, |
34 | }.get(value, PandoraType.GENRE) | 34 | } |
35 | return types.get(value, PandoraType.GENRE) | ||
35 | 36 | ||
36 | 37 | ||
37 | class AudioField(SyntheticField): | 38 | class AudioField(SyntheticField): |
38 | |||
39 | def formatter(self, api_client, data, newval): | 39 | def formatter(self, api_client, data, newval): |
40 | """Get audio-related fields | 40 | """Get audio-related fields |
41 | 41 | ||
@@ -61,9 +61,11 @@ class AudioField(SyntheticField): | |||
61 | elif not url_map: # No audio url available (e.g. ad tokens) | 61 | elif not url_map: # No audio url available (e.g. ad tokens) |
62 | return None | 62 | return None |
63 | 63 | ||
64 | valid_audio_formats = [BaseAPIClient.HIGH_AUDIO_QUALITY, | 64 | valid_audio_formats = [ |
65 | BaseAPIClient.MED_AUDIO_QUALITY, | 65 | BaseAPIClient.HIGH_AUDIO_QUALITY, |
66 | BaseAPIClient.LOW_AUDIO_QUALITY] | 66 | BaseAPIClient.MED_AUDIO_QUALITY, |
67 | BaseAPIClient.LOW_AUDIO_QUALITY, | ||
68 | ] | ||
67 | 69 | ||
68 | # Only iterate over sublist, starting at preferred audio quality, or | 70 | # Only iterate over sublist, starting at preferred audio quality, or |
69 | # from the beginning of the list if nothing is found. Ensures that the | 71 | # from the beginning of the list if nothing is found. Ensures that the |
@@ -84,7 +86,6 @@ class AudioField(SyntheticField): | |||
84 | 86 | ||
85 | 87 | ||
86 | class AdditionalUrlField(SyntheticField): | 88 | class AdditionalUrlField(SyntheticField): |
87 | |||
88 | def formatter(self, api_client, data, newval): | 89 | def formatter(self, api_client, data, newval): |
89 | """Parse additional url fields and map them to inputs | 90 | """Parse additional url fields and map them to inputs |
90 | 91 | ||
@@ -94,7 +95,7 @@ class AdditionalUrlField(SyntheticField): | |||
94 | if newval is None: | 95 | if newval is None: |
95 | return None | 96 | return None |
96 | 97 | ||
97 | user_param = data['_paramAdditionalUrls'] | 98 | user_param = data["_paramAdditionalUrls"] |
98 | urls = {} | 99 | urls = {} |
99 | if isinstance(newval, str): | 100 | if isinstance(newval, str): |
100 | urls[user_param[0]] = newval | 101 | urls[user_param[0]] = newval |
@@ -105,7 +106,6 @@ class AdditionalUrlField(SyntheticField): | |||
105 | 106 | ||
106 | 107 | ||
107 | class PlaylistModel(PandoraModel): | 108 | class PlaylistModel(PandoraModel): |
108 | |||
109 | def get_is_playable(self): | 109 | def get_is_playable(self): |
110 | if not self.audio_url: | 110 | if not self.audio_url: |
111 | return False | 111 | return False |
diff --git a/pandora/models/search.py b/pandora/models/search.py index 94e6ee6..fe31561 100644 --- a/pandora/models/search.py +++ b/pandora/models/search.py | |||
@@ -12,13 +12,15 @@ class SearchResultItem(PandoraModel): | |||
12 | 12 | ||
13 | @property | 13 | @property |
14 | def is_artist(self): | 14 | def is_artist(self): |
15 | return isinstance(self, ArtistSearchResultItem) and \ | 15 | return isinstance( |
16 | self.token.startswith("R") | 16 | self, ArtistSearchResultItem |
17 | ) and self.token.startswith("R") | ||
17 | 18 | ||
18 | @property | 19 | @property |
19 | def is_composer(self): | 20 | def is_composer(self): |
20 | return isinstance(self, ArtistSearchResultItem) and \ | 21 | return isinstance( |
21 | self.token.startswith("C") | 22 | self, ArtistSearchResultItem |
23 | ) and self.token.startswith("C") | ||
22 | 24 | ||
23 | @property | 25 | @property |
24 | def is_genre_station(self): | 26 | def is_genre_station(self): |
@@ -36,8 +38,9 @@ class SearchResultItem(PandoraModel): | |||
36 | elif data["musicToken"].startswith("G"): | 38 | elif data["musicToken"].startswith("G"): |
37 | return GenreStationSearchResultItem.from_json(api_client, data) | 39 | return GenreStationSearchResultItem.from_json(api_client, data) |
38 | else: | 40 | else: |
39 | raise NotImplementedError("Unknown result token type '{}'" | 41 | raise NotImplementedError( |
40 | .format(data["musicToken"])) | 42 | "Unknown result token type '{}'".format(data["musicToken"]) |
43 | ) | ||
41 | 44 | ||
42 | 45 | ||
43 | class ArtistSearchResultItem(SearchResultItem): | 46 | class ArtistSearchResultItem(SearchResultItem): |
diff --git a/pandora/models/station.py b/pandora/models/station.py index a1880ec..d3f6552 100644 --- a/pandora/models/station.py +++ b/pandora/models/station.py | |||
@@ -80,8 +80,7 @@ class Station(PandoraModel): | |||
80 | feedback = Field("feedback", model=StationFeedback) | 80 | feedback = Field("feedback", model=StationFeedback) |
81 | 81 | ||
82 | def get_playlist(self, additional_urls=None): | 82 | def get_playlist(self, additional_urls=None): |
83 | return iter(self._api_client.get_playlist(self.token, | 83 | return iter(self._api_client.get_playlist(self.token, additional_urls)) |
84 | additional_urls)) | ||
85 | 84 | ||
86 | 85 | ||
87 | class StationList(PandoraListModel): | 86 | class StationList(PandoraListModel): |
@@ -105,8 +104,10 @@ class GenreStation(PandoraModel): | |||
105 | category = Field("categoryName") | 104 | category = Field("categoryName") |
106 | 105 | ||
107 | def get_playlist(self): | 106 | def get_playlist(self): |
108 | raise NotImplementedError("Genre stations do not have playlists. " | 107 | raise NotImplementedError( |
109 | "Create a real station using the token.") | 108 | "Genre stations do not have playlists. " |
109 | "Create a real station using the token." | ||
110 | ) | ||
110 | 111 | ||
111 | 112 | ||
112 | class GenreStationList(PandoraDictListModel): | 113 | class GenreStationList(PandoraDictListModel): |