diff options
author | Mike Crute <mike@crute.us> | 2017-10-30 02:39:23 +0000 |
---|---|---|
committer | Mike Crute <mike@crute.us> | 2017-10-30 02:39:23 +0000 |
commit | 363c73b537d5965f2e1871bdfdc9df5a241759a3 (patch) | |
tree | 594e9f7bf6bc578134d8fedf941512e60344f794 | |
parent | 474e3068d62ba60e2656c54a01e42787dc618a03 (diff) | |
download | pydora-363c73b537d5965f2e1871bdfdc9df5a241759a3.tar.bz2 pydora-363c73b537d5965f2e1871bdfdc9df5a241759a3.tar.xz pydora-363c73b537d5965f2e1871bdfdc9df5a241759a3.zip |
Update Station model
Stations contain feedback and seeds that can be manipulated later
through the API. Construct these model classes when building a Station
object.
-rw-r--r-- | pandora/models/pandora.py | 77 | ||||
-rwxr-xr-x | setup.py | 1 |
2 files changed, 78 insertions, 0 deletions
diff --git a/pandora/models/pandora.py b/pandora/models/pandora.py index e6a37ff..cc57eac 100644 --- a/pandora/models/pandora.py +++ b/pandora/models/pandora.py | |||
@@ -1,16 +1,89 @@ | |||
1 | from enum import Enum | ||
2 | |||
1 | from ..client import BaseAPIClient | 3 | from ..client import BaseAPIClient |
2 | from ..errors import ParameterMissing | 4 | from ..errors import ParameterMissing |
3 | from . import Field, DateField, SyntheticField | 5 | from . import Field, DateField, SyntheticField |
4 | from . import PandoraModel, PandoraListModel, PandoraDictListModel | 6 | from . import PandoraModel, PandoraListModel, PandoraDictListModel |
5 | 7 | ||
6 | 8 | ||
9 | class PandoraType(Enum): | ||
10 | |||
11 | TRACK = "TR" | ||
12 | ARTIST = "AR" | ||
13 | GENRE = "GR" | ||
14 | |||
15 | @staticmethod | ||
16 | def from_model(client, value): | ||
17 | return PandoraType.from_string(value) | ||
18 | |||
19 | @staticmethod | ||
20 | def from_string(value): | ||
21 | return { | ||
22 | "TR": PandoraType.TRACK, | ||
23 | "AR": PandoraType.ARTIST, | ||
24 | }.get(value, PandoraType.GENRE) | ||
25 | |||
26 | |||
27 | class Icon(PandoraModel): | ||
28 | |||
29 | dominant_color = Field("dominantColor") | ||
30 | art_url = Field("artUrl") | ||
31 | |||
32 | |||
33 | class StationSeed(PandoraModel): | ||
34 | |||
35 | seed_id = Field("seedId") | ||
36 | music_token = Field("musicToken") | ||
37 | pandora_id = Field("pandoraId") | ||
38 | pandora_type = Field("pandoraType", formatter=PandoraType.from_model) | ||
39 | |||
40 | genre_name = Field("genreName") | ||
41 | song_name = Field("songName") | ||
42 | artist_name = Field("artistName") | ||
43 | art_url = Field("artUrl") | ||
44 | icon = Field("icon", model=Icon) | ||
45 | |||
46 | |||
47 | class StationSeeds(PandoraModel): | ||
48 | |||
49 | genres = Field("genres", model=StationSeed) | ||
50 | songs = Field("songs", model=StationSeed) | ||
51 | artists = Field("artists", model=StationSeed) | ||
52 | |||
53 | |||
54 | class SongFeedback(PandoraModel): | ||
55 | |||
56 | feedback_id = Field("feedbackId") | ||
57 | song_identity = Field("songIdentity") | ||
58 | is_positive = Field("isPositive") | ||
59 | pandora_id = Field("pandoraId") | ||
60 | album_art_url = Field("albumArtUrl") | ||
61 | music_token = Field("musicToken") | ||
62 | song_name = Field("songName") | ||
63 | artist_name = Field("artistName") | ||
64 | pandora_type = Field("pandoraType", formatter=PandoraType.from_model) | ||
65 | date_created = DateField("dateCreated") | ||
66 | |||
67 | |||
68 | class StationFeedback(PandoraModel): | ||
69 | |||
70 | total_thumbs_up = Field("totalThumbsUp") | ||
71 | total_thumbs_down = Field("totalThumbsDown") | ||
72 | thumbs_up = Field("thumbsUp", model=SongFeedback) | ||
73 | thumbs_down = Field("thumbsDown", model=SongFeedback) | ||
74 | |||
75 | |||
7 | class Station(PandoraModel): | 76 | class Station(PandoraModel): |
8 | 77 | ||
9 | can_add_music = Field("allowAddMusic") | 78 | can_add_music = Field("allowAddMusic") |
10 | can_delete = Field("allowDelete") | 79 | can_delete = Field("allowDelete") |
11 | can_rename = Field("allowRename") | 80 | can_rename = Field("allowRename") |
81 | can_edit_description = Field("allowEditDescription") | ||
82 | process_skips = Field("processSkips") | ||
12 | is_shared = Field("isShared") | 83 | is_shared = Field("isShared") |
13 | is_quickmix = Field("isQuickMix") | 84 | is_quickmix = Field("isQuickMix") |
85 | is_genre_station = Field("isGenreStation") | ||
86 | is_thumbprint_station = Field("isThumbprint") | ||
14 | 87 | ||
15 | art_url = Field("artUrl") | 88 | art_url = Field("artUrl") |
16 | date_created = DateField("dateCreated") | 89 | date_created = DateField("dateCreated") |
@@ -18,11 +91,15 @@ class Station(PandoraModel): | |||
18 | id = Field("stationId") | 91 | id = Field("stationId") |
19 | name = Field("stationName") | 92 | name = Field("stationName") |
20 | sharing_url = Field("stationSharingUrl") | 93 | sharing_url = Field("stationSharingUrl") |
94 | thumb_count = Field("thumbCount") | ||
21 | token = Field("stationToken") | 95 | token = Field("stationToken") |
22 | 96 | ||
23 | genre = Field("genre", []) | 97 | genre = Field("genre", []) |
24 | quickmix_stations = Field("quickMixStationIds", []) | 98 | quickmix_stations = Field("quickMixStationIds", []) |
25 | 99 | ||
100 | seeds = Field("music", model=StationSeeds) | ||
101 | feedback = Field("feedback", model=StationFeedback) | ||
102 | |||
26 | def get_playlist(self): | 103 | def get_playlist(self): |
27 | return iter(self._api_client.get_playlist(self.token)) | 104 | return iter(self._api_client.get_playlist(self.token)) |
28 | 105 | ||
@@ -58,6 +58,7 @@ if sys.version_info.major == 3 and sys.version_info.minor >= 4: | |||
58 | requires["install_requires"].append("blowfish>=0.6.1,<1.0") | 58 | requires["install_requires"].append("blowfish>=0.6.1,<1.0") |
59 | else: | 59 | else: |
60 | requires["install_requires"].append("cryptography>=2,<3") | 60 | requires["install_requires"].append("cryptography>=2,<3") |
61 | requires["install_requires"].append("enum34") | ||
61 | 62 | ||
62 | 63 | ||
63 | setup( | 64 | setup( |