1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
from ._base import Field, PandoraModel
class SearchResultItem(PandoraModel):
score = Field("score")
token = Field("musicToken")
@property
def is_song(self):
return isinstance(self, SongSearchResultItem)
@property
def is_artist(self):
return isinstance(self, ArtistSearchResultItem) and \
self.token.startswith("R")
@property
def is_composer(self):
return isinstance(self, ArtistSearchResultItem) and \
self.token.startswith("C")
@property
def is_genre_station(self):
return isinstance(self, GenreStationSearchResultItem)
def create_station(self):
raise NotImplementedError
@classmethod
def from_json(cls, api_client, data):
if data["musicToken"].startswith("S"):
return SongSearchResultItem.from_json(api_client, data)
elif data["musicToken"].startswith(("R", "C")):
return ArtistSearchResultItem.from_json(api_client, data)
elif data["musicToken"].startswith("G"):
return GenreStationSearchResultItem.from_json(api_client, data)
else:
raise NotImplementedError("Unknown result token type '{}'"
.format(data["musicToken"]))
class ArtistSearchResultItem(SearchResultItem):
score = Field("score")
token = Field("musicToken")
artist = Field("artistName")
likely_match = Field("likelyMatch", default=False)
def create_station(self):
self._api_client.create_station(artist_token=self.token)
@classmethod
def from_json(cls, api_client, data):
return super(SearchResultItem, cls).from_json(api_client, data)
class SongSearchResultItem(SearchResultItem):
score = Field("score")
token = Field("musicToken")
artist = Field("artistName")
song_name = Field("songName")
def create_station(self):
self._api_client.create_station(track_token=self.token)
@classmethod
def from_json(cls, api_client, data):
return super(SearchResultItem, cls).from_json(api_client, data)
class GenreStationSearchResultItem(SearchResultItem):
score = Field("score")
token = Field("musicToken")
station_name = Field("stationName")
def create_station(self):
self._api_client.create_station(search_token=self.token)
@classmethod
def from_json(cls, api_client, data):
return super(SearchResultItem, cls).from_json(api_client, data)
class SearchResult(PandoraModel):
nearest_matches_available = Field("nearMatchesAvailable")
explanation = Field("explanation")
songs = Field("songs", model=SongSearchResultItem)
artists = Field("artists", model=ArtistSearchResultItem)
genre_stations = Field("genreStations", model=GenreStationSearchResultItem)
|