From 363c73b537d5965f2e1871bdfdc9df5a241759a3 Mon Sep 17 00:00:00 2001 From: Mike Crute Date: Mon, 30 Oct 2017 02:39:23 +0000 Subject: 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. --- pandora/models/pandora.py | 77 +++++++++++++++++++++++++++++++++++++++++++++++ setup.py | 1 + 2 files changed, 78 insertions(+) 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 @@ +from enum import Enum + from ..client import BaseAPIClient from ..errors import ParameterMissing from . import Field, DateField, SyntheticField from . import PandoraModel, PandoraListModel, PandoraDictListModel +class PandoraType(Enum): + + TRACK = "TR" + ARTIST = "AR" + GENRE = "GR" + + @staticmethod + def from_model(client, value): + return PandoraType.from_string(value) + + @staticmethod + def from_string(value): + return { + "TR": PandoraType.TRACK, + "AR": PandoraType.ARTIST, + }.get(value, PandoraType.GENRE) + + +class Icon(PandoraModel): + + dominant_color = Field("dominantColor") + art_url = Field("artUrl") + + +class StationSeed(PandoraModel): + + seed_id = Field("seedId") + music_token = Field("musicToken") + pandora_id = Field("pandoraId") + pandora_type = Field("pandoraType", formatter=PandoraType.from_model) + + genre_name = Field("genreName") + song_name = Field("songName") + artist_name = Field("artistName") + art_url = Field("artUrl") + icon = Field("icon", model=Icon) + + +class StationSeeds(PandoraModel): + + genres = Field("genres", model=StationSeed) + songs = Field("songs", model=StationSeed) + artists = Field("artists", model=StationSeed) + + +class SongFeedback(PandoraModel): + + feedback_id = Field("feedbackId") + song_identity = Field("songIdentity") + is_positive = Field("isPositive") + pandora_id = Field("pandoraId") + album_art_url = Field("albumArtUrl") + music_token = Field("musicToken") + song_name = Field("songName") + artist_name = Field("artistName") + pandora_type = Field("pandoraType", formatter=PandoraType.from_model) + date_created = DateField("dateCreated") + + +class StationFeedback(PandoraModel): + + total_thumbs_up = Field("totalThumbsUp") + total_thumbs_down = Field("totalThumbsDown") + thumbs_up = Field("thumbsUp", model=SongFeedback) + thumbs_down = Field("thumbsDown", model=SongFeedback) + + class Station(PandoraModel): can_add_music = Field("allowAddMusic") can_delete = Field("allowDelete") can_rename = Field("allowRename") + can_edit_description = Field("allowEditDescription") + process_skips = Field("processSkips") is_shared = Field("isShared") is_quickmix = Field("isQuickMix") + is_genre_station = Field("isGenreStation") + is_thumbprint_station = Field("isThumbprint") art_url = Field("artUrl") date_created = DateField("dateCreated") @@ -18,11 +91,15 @@ class Station(PandoraModel): id = Field("stationId") name = Field("stationName") sharing_url = Field("stationSharingUrl") + thumb_count = Field("thumbCount") token = Field("stationToken") genre = Field("genre", []) quickmix_stations = Field("quickMixStationIds", []) + seeds = Field("music", model=StationSeeds) + feedback = Field("feedback", model=StationFeedback) + def get_playlist(self): return iter(self._api_client.get_playlist(self.token)) diff --git a/setup.py b/setup.py index 2515870..4a36abd 100755 --- a/setup.py +++ b/setup.py @@ -58,6 +58,7 @@ if sys.version_info.major == 3 and sys.version_info.minor >= 4: requires["install_requires"].append("blowfish>=0.6.1,<1.0") else: requires["install_requires"].append("cryptography>=2,<3") + requires["install_requires"].append("enum34") setup( -- cgit v1.2.3