spotifywebapiPython 1.0.242__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. spotifywebapipython/__init__.py +35 -0
  2. spotifywebapipython/const.py +114 -0
  3. spotifywebapipython/docs/__init__.html +2156 -0
  4. spotifywebapipython/docs/codecopy.js +70 -0
  5. spotifywebapipython/docs/index.html +514 -0
  6. spotifywebapipython/docs/search.js +46 -0
  7. spotifywebapipython/docs/spotifywebapipython/const.html +636 -0
  8. spotifywebapipython/docs/spotifywebapipython/saappmessages.html +540 -0
  9. spotifywebapipython/docs/spotifywebapipython/sautils.html +620 -0
  10. spotifywebapipython/docs/spotifywebapipython/spotifyapierror.html +341 -0
  11. spotifywebapipython/docs/spotifywebapipython/spotifyapimessage.html +598 -0
  12. spotifywebapipython/docs/spotifywebapipython/spotifyauthtoken.html +612 -0
  13. spotifywebapipython/docs/spotifywebapipython/spotifyclient.html +16557 -0
  14. spotifywebapipython/docs/spotifywebapipython/spotifydiscovery.html +518 -0
  15. spotifywebapipython/docs/spotifywebapipython/spotifywebapiauthenticationerror.html +421 -0
  16. spotifywebapipython/docs/spotifywebapipython/spotifywebapierror.html +400 -0
  17. spotifywebapipython/docs/spotifywebapipython/spotifywebplayertoken.html +635 -0
  18. spotifywebapipython/docs/spotifywebapipython.ico +0 -0
  19. spotifywebapipython/docs/spotifywebapipython_OLD.ico +0 -0
  20. spotifywebapipython/models/__init__.py +121 -0
  21. spotifywebapipython/models/album.py +170 -0
  22. spotifywebapipython/models/albumpagesaved.py +85 -0
  23. spotifywebapipython/models/albumpagesimplified.py +88 -0
  24. spotifywebapipython/models/albumsaved.py +102 -0
  25. spotifywebapipython/models/albumsimplified.py +308 -0
  26. spotifywebapipython/models/artist.py +146 -0
  27. spotifywebapipython/models/artistinfo.py +282 -0
  28. spotifywebapipython/models/artistinfotourevent.py +127 -0
  29. spotifywebapipython/models/artistpage.py +70 -0
  30. spotifywebapipython/models/artistsimplified.py +163 -0
  31. spotifywebapipython/models/audiobook.py +87 -0
  32. spotifywebapipython/models/audiobookpagesimplified.py +88 -0
  33. spotifywebapipython/models/audiobooksimplified.py +362 -0
  34. spotifywebapipython/models/audiofeatures.py +333 -0
  35. spotifywebapipython/models/author.py +67 -0
  36. spotifywebapipython/models/category.py +168 -0
  37. spotifywebapipython/models/categorypage.py +70 -0
  38. spotifywebapipython/models/chapter.py +84 -0
  39. spotifywebapipython/models/chapterpagesimplified.py +88 -0
  40. spotifywebapipython/models/chaptersimplified.py +387 -0
  41. spotifywebapipython/models/context.py +113 -0
  42. spotifywebapipython/models/copyright.py +79 -0
  43. spotifywebapipython/models/device.py +301 -0
  44. spotifywebapipython/models/episode.py +84 -0
  45. spotifywebapipython/models/episodepagesaved.py +85 -0
  46. spotifywebapipython/models/episodepagesimplified.py +88 -0
  47. spotifywebapipython/models/episodesaved.py +99 -0
  48. spotifywebapipython/models/episodesimplified.py +370 -0
  49. spotifywebapipython/models/explicitcontent.py +80 -0
  50. spotifywebapipython/models/externalids.py +91 -0
  51. spotifywebapipython/models/externalurls.py +104 -0
  52. spotifywebapipython/models/followers.py +81 -0
  53. spotifywebapipython/models/imageobject.py +193 -0
  54. spotifywebapipython/models/imagevibrantcolors.py +182 -0
  55. spotifywebapipython/models/linkedfrom.py +165 -0
  56. spotifywebapipython/models/narrator.py +67 -0
  57. spotifywebapipython/models/owner.py +162 -0
  58. spotifywebapipython/models/pageobject.py +343 -0
  59. spotifywebapipython/models/playeractions.py +196 -0
  60. spotifywebapipython/models/playerlastplayedinfo.py +334 -0
  61. spotifywebapipython/models/playerplaystate.py +467 -0
  62. spotifywebapipython/models/playerqueueinfo.py +207 -0
  63. spotifywebapipython/models/playhistory.py +136 -0
  64. spotifywebapipython/models/playhistorypage.py +85 -0
  65. spotifywebapipython/models/playlist.py +125 -0
  66. spotifywebapipython/models/playlistpage.py +85 -0
  67. spotifywebapipython/models/playlistpagesimplified.py +107 -0
  68. spotifywebapipython/models/playlistsimplified.py +334 -0
  69. spotifywebapipython/models/playlisttrack.py +143 -0
  70. spotifywebapipython/models/playlisttracksummary.py +80 -0
  71. spotifywebapipython/models/recommendationseed.py +135 -0
  72. spotifywebapipython/models/restrictions.py +86 -0
  73. spotifywebapipython/models/resumepoint.py +79 -0
  74. spotifywebapipython/models/searchresponse.py +391 -0
  75. spotifywebapipython/models/searchresultbase.py +299 -0
  76. spotifywebapipython/models/show.py +87 -0
  77. spotifywebapipython/models/showpagesaved.py +85 -0
  78. spotifywebapipython/models/showpagesimplified.py +88 -0
  79. spotifywebapipython/models/showsaved.py +99 -0
  80. spotifywebapipython/models/showsimplified.py +320 -0
  81. spotifywebapipython/models/spotifyconnectdevice.py +321 -0
  82. spotifywebapipython/models/spotifyconnectdevices.py +441 -0
  83. spotifywebapipython/models/track.py +142 -0
  84. spotifywebapipython/models/trackpage.py +110 -0
  85. spotifywebapipython/models/trackpagesaved.py +85 -0
  86. spotifywebapipython/models/trackpagesimplified.py +88 -0
  87. spotifywebapipython/models/trackrecommendations.py +88 -0
  88. spotifywebapipython/models/tracksaved.py +99 -0
  89. spotifywebapipython/models/tracksimplified.py +398 -0
  90. spotifywebapipython/models/userprofile.py +184 -0
  91. spotifywebapipython/models/userprofilesimplified.py +206 -0
  92. spotifywebapipython/models/zeroconfdiscoveryresult.py +592 -0
  93. spotifywebapipython/models/zeroconfproperty.py +93 -0
  94. spotifywebapipython/oauthcli/__init__.py +7 -0
  95. spotifywebapipython/oauthcli/authclient.py +1229 -0
  96. spotifywebapipython/saappmessages.py +86 -0
  97. spotifywebapipython/sautils.py +285 -0
  98. spotifywebapipython/spotifyapierror.py +66 -0
  99. spotifywebapipython/spotifyapimessage.py +269 -0
  100. spotifywebapipython/spotifyauthtoken.py +264 -0
  101. spotifywebapipython/spotifyclient.py +17885 -0
  102. spotifywebapipython/spotifyconnect/__init__.py +19 -0
  103. spotifywebapipython/spotifyconnect/spotifyconnectdeviceeventargs.py +67 -0
  104. spotifywebapipython/spotifyconnect/spotifyconnectdirectorytask.py +2564 -0
  105. spotifywebapipython/spotifyconnect/spotifyconnectzeroconfcastapptask.py +467 -0
  106. spotifywebapipython/spotifyconnect/spotifyconnectzeroconfcastcontroller.py +701 -0
  107. spotifywebapipython/spotifyconnect/spotifyconnectzeroconfcastlistener.py +359 -0
  108. spotifywebapipython/spotifyconnect/spotifyconnectzeroconfcastmultizonelistener.py +212 -0
  109. spotifywebapipython/spotifyconnect/spotifyconnectzeroconfexceptions.py +20 -0
  110. spotifywebapipython/spotifyconnect/spotifyconnectzeroconflistener.py +335 -0
  111. spotifywebapipython/spotifydiscovery.py +473 -0
  112. spotifywebapipython/spotifymediatypes.py +53 -0
  113. spotifywebapipython/spotifywebapiauthenticationerror.py +122 -0
  114. spotifywebapipython/spotifywebapierror.py +106 -0
  115. spotifywebapipython/spotifywebplayertoken.py +743 -0
  116. spotifywebapipython/vibrant/__init__.py +17 -0
  117. spotifywebapipython/vibrant/generator.py +261 -0
  118. spotifywebapipython/vibrant/image.py +100 -0
  119. spotifywebapipython/vibrant/main.py +34 -0
  120. spotifywebapipython/vibrant/models.py +93 -0
  121. spotifywebapipython/vibrant/utils.py +56 -0
  122. spotifywebapipython/zeroconfapi/__init__.py +23 -0
  123. spotifywebapipython/zeroconfapi/authenticationtypes.py +38 -0
  124. spotifywebapipython/zeroconfapi/blobbuilder.py +370 -0
  125. spotifywebapipython/zeroconfapi/credentials.py +37 -0
  126. spotifywebapipython/zeroconfapi/cryptodiffiehellman.py +89 -0
  127. spotifywebapipython/zeroconfapi/helpers.py +64 -0
  128. spotifywebapipython/zeroconfapi/spotifyzeroconfapierror.py +108 -0
  129. spotifywebapipython/zeroconfapi/zeroconfconnect.py +1327 -0
  130. spotifywebapipython/zeroconfapi/zeroconfgetinfo.py +572 -0
  131. spotifywebapipython/zeroconfapi/zeroconfgetinfoalias.py +109 -0
  132. spotifywebapipython/zeroconfapi/zeroconfgetinfodrmmediaformat.py +90 -0
  133. spotifywebapipython/zeroconfapi/zeroconfresponse.py +195 -0
  134. spotifywebapipython-1.0.242.dist-info/LICENSE +22 -0
  135. spotifywebapipython-1.0.242.dist-info/METADATA +219 -0
  136. spotifywebapipython-1.0.242.dist-info/RECORD +138 -0
  137. spotifywebapipython-1.0.242.dist-info/WHEEL +5 -0
  138. spotifywebapipython-1.0.242.dist-info/top_level.txt +1 -0
@@ -0,0 +1,398 @@
1
+ # external package imports.
2
+
3
+ # our package imports.
4
+ from ..sautils import export
5
+ from .artistsimplified import ArtistSimplified
6
+ from .externalurls import ExternalUrls
7
+ from .linkedfrom import LinkedFrom
8
+ from .restrictions import Restrictions
9
+
10
+ @export
11
+ class TrackSimplified:
12
+ """
13
+ Spotify Web API SimplifiedTrack object.
14
+ """
15
+
16
+ def __init__(self, root:dict=None) -> None:
17
+ """
18
+ Initializes a new instance of the class.
19
+
20
+ Args:
21
+ root (dict):
22
+ Spotify Web API JSON response in dictionary format, used to load object
23
+ attributes; otherwise, None to not load attributes.
24
+ """
25
+ self._Artists:list[ArtistSimplified] = []
26
+ self._AvailableMarkets:list[str] = []
27
+ self._DiscNumber:int = None
28
+ self._DurationMS:int = None
29
+ self._Explicit:bool = None
30
+ self._ExternalUrls:ExternalUrls = None
31
+ self._Href:str = None
32
+ self._Id:int = None
33
+ self._IsLocal:bool = None
34
+ self._IsPlayable:bool = None
35
+ self._LinkedFrom:LinkedFrom = None
36
+ self._Name:str = None
37
+ self._PreviewUrl:str = None
38
+ self._Restrictions:Restrictions = None
39
+ self._TrackNumber:int = None
40
+ self._Type:str = None
41
+ self._Uri:str = None
42
+
43
+ if (root is None):
44
+
45
+ pass
46
+
47
+ else:
48
+
49
+ self._AvailableMarkets = root.get('available_markets', None) or []
50
+ self._DiscNumber = root.get('disc_number', None)
51
+ self._DurationMS = root.get('duration_ms', None)
52
+ self._Explicit = root.get('explicit', None)
53
+ self._Href = root.get('href', None)
54
+ self._Id = root.get('id', None)
55
+ self._IsPlayable = root.get('is_playable', None)
56
+ self._IsLocal = root.get('is_local', None)
57
+ self._Name = root.get('name', None)
58
+ self._PreviewUrl = root.get('preview_url', None)
59
+ self._TrackNumber = root.get('track_number', None)
60
+ self._Type = root.get('type', None)
61
+ self._Uri = root.get('uri', None)
62
+
63
+ # process all collections and objects.
64
+ items:list = root.get('artists',None)
65
+ if items is not None:
66
+ for item in items:
67
+ self._Artists.append(ArtistSimplified(root=item))
68
+
69
+ item:dict = root.get('external_urls',None)
70
+ if item is not None:
71
+ self._ExternalUrls = ExternalUrls(root=item)
72
+
73
+ item:dict = root.get('linked_from',None)
74
+ if item is not None:
75
+ self._LinkedFrom = LinkedFrom(root=item)
76
+
77
+ item:dict = root.get('restrictions',None)
78
+ if item is not None:
79
+ self._Restrictions = Restrictions(root=item)
80
+
81
+
82
+ def __repr__(self) -> str:
83
+ return self.ToString()
84
+
85
+
86
+ def __str__(self) -> str:
87
+ return self.ToString()
88
+
89
+
90
+ # implement sorting support.
91
+ def __eq__(self, other):
92
+ try:
93
+ return self.Name == other.Name
94
+ except Exception:
95
+ if (isinstance(self, TrackSimplified )) and (isinstance(other, TrackSimplified )):
96
+ return self.Name == other.Name
97
+ return False
98
+
99
+ def __lt__(self, other):
100
+ try:
101
+ return self.Name < other.Name
102
+ except Exception:
103
+ if (isinstance(self, TrackSimplified )) and (isinstance(other, TrackSimplified )):
104
+ return self.Name < other.Name
105
+ return False
106
+
107
+
108
+ @property
109
+ def Artists(self) -> list[ArtistSimplified]:
110
+ """
111
+ A list of artists who performed the track.
112
+ """
113
+ return self._Artists
114
+
115
+
116
+ @property
117
+ def AvailableMarkets(self) -> list[str]:
118
+ """
119
+ A list of the countries in which the track can be played, identified by their ISO 3166-1 alpha-2 code.
120
+ """
121
+ return self._AvailableMarkets
122
+
123
+
124
+ @property
125
+ def DiscNumber(self) -> int:
126
+ """
127
+ The disc number (usually 1 unless the album consists of more than one disc).
128
+ """
129
+ return self._DiscNumber
130
+
131
+
132
+ @property
133
+ def DurationMS(self) -> int:
134
+ """
135
+ The track length in milliseconds.
136
+ """
137
+ return self._DurationMS
138
+
139
+
140
+ @property
141
+ def Explicit(self) -> bool:
142
+ """
143
+ Whether or not the track has explicit content (true = yes it does; false = no it does not OR unknown).
144
+ """
145
+ return self._Explicit
146
+
147
+
148
+ @property
149
+ def ExternalUrls(self) -> ExternalUrls:
150
+ """
151
+ Known external URLs for the track.
152
+ """
153
+ return self._ExternalUrls
154
+
155
+
156
+ @property
157
+ def Href(self) -> str:
158
+ """
159
+ A link to the Web API endpoint providing full details of the track.
160
+ """
161
+ return self._Href
162
+
163
+
164
+ @property
165
+ def Id(self) -> str:
166
+ """
167
+ The Spotify ID for the track.
168
+ """
169
+ return self._Id
170
+
171
+
172
+ @property
173
+ def IdOrigin(self) -> str:
174
+ """
175
+ The origin Spotify ID for the track.
176
+ The `LinkedFrom.Id` value is returned if present;
177
+ otherwise, the `Id` value is returned.
178
+
179
+ This is a helper property, and is not part of the Spotify Web API specification.
180
+ """
181
+ if (self.IsLinkedFrom):
182
+ return self._LinkedFrom.Id
183
+ return self._Id
184
+
185
+
186
+ @property
187
+ def ImageUrl(self) -> str:
188
+ """
189
+ Always returns null, as tracks currently do not support images.
190
+
191
+ Added for compatibility with other objects.
192
+ """
193
+ return None
194
+
195
+
196
+ @property
197
+ def IsLinkedFrom(self) -> bool:
198
+ """
199
+ Whether or not the track is linked from another track.
200
+
201
+ If True, the `LinkedFrom` property contains track origin data;
202
+ If False, the `LinkedFrom` property is an empty dictionary.
203
+
204
+ This is a helper property, and is not part of the Spotify Web API specification.
205
+ """
206
+ if (self._LinkedFrom is not None) and (self._LinkedFrom.Id is not None):
207
+ return True
208
+ return False
209
+
210
+
211
+ @property
212
+ def IsLocal(self) -> bool:
213
+ """
214
+ Whether or not the track is from a local file.
215
+ """
216
+ return self._IsLocal
217
+
218
+
219
+ @property
220
+ def IsPlayable(self) -> bool:
221
+ """
222
+ Part of the response when Track Relinking is applied.
223
+ If true, the track is playable in the given market. Otherwise false.
224
+ """
225
+ return self._IsPlayable
226
+
227
+
228
+ @property
229
+ def LinkedFrom(self) -> LinkedFrom:
230
+ """
231
+ Part of the response when Track Relinking is applied, and the requested track has been replaced
232
+ with a different track. The track in the LinkedFrom object contains information about the originally
233
+ requested track.
234
+ """
235
+ return self._LinkedFrom
236
+
237
+
238
+ @property
239
+ def Name(self) -> str:
240
+ """
241
+ The name of the track.
242
+ """
243
+ return self._Name
244
+
245
+
246
+ @property
247
+ def Name(self) -> str:
248
+ """
249
+ The name of the track.
250
+ """
251
+ return self._Name
252
+
253
+
254
+ @property
255
+ def PreviewUrl(self) -> str:
256
+ """
257
+ <span class="deprecated">
258
+ DEPRECATED - property no longer supported by Spotify as of 2024/11/27.
259
+ More information about the deprecated functionality can be found on the
260
+ <a href="https://developer.spotify.com/blog/2024-11-27-changes-to-the-web-api" target="_blank">Spotify Developer Forum Blog</a>
261
+ page.
262
+ </span>
263
+
264
+ A link to a 30 second preview (MP3 format) of the track. Can be null.
265
+
266
+ Important policy note:
267
+ - Spotify Audio preview clips can not be a standalone service.
268
+ """
269
+ return self._PreviewUrl
270
+
271
+
272
+ @property
273
+ def Restrictions(self) -> Restrictions:
274
+ """
275
+ Included in the response when a content restriction is applied.
276
+ """
277
+ return self._Restrictions
278
+
279
+
280
+ @property
281
+ def TrackNumber(self) -> int:
282
+ """
283
+ The number of the track.
284
+
285
+ If an album has several discs, the track number is the number on the specified disc.
286
+ """
287
+ return self._TrackNumber
288
+
289
+
290
+ @property
291
+ def Type(self) -> str:
292
+ """
293
+ The object type: `track`.
294
+ """
295
+ return self._Type
296
+
297
+
298
+ @property
299
+ def Uri(self) -> str:
300
+ """
301
+ The Spotify URI for the track.
302
+ """
303
+ return self._Uri
304
+
305
+
306
+ @property
307
+ def UriOrigin(self) -> str:
308
+ """
309
+ The origin Spotify URI for the track.
310
+ The `LinkedFrom.Uri` value is returned if present;
311
+ otherwise, the `Uri` value is returned.
312
+
313
+ This is a helper property, and is not part of the Spotify Web API specification.
314
+ """
315
+ if (self.IsLinkedFrom):
316
+ return self._LinkedFrom.Uri
317
+ return self._Uri
318
+
319
+
320
+ def ToDictionary(self) -> dict:
321
+ """
322
+ Returns a dictionary representation of the class.
323
+ """
324
+ externalUrls:dict = {}
325
+ if self._ExternalUrls is not None:
326
+ externalUrls = self._ExternalUrls.ToDictionary()
327
+
328
+ restrictions:dict = {}
329
+ if self._Restrictions is not None:
330
+ restrictions = self._Restrictions.ToDictionary()
331
+
332
+ linked_from:dict = {}
333
+ if self._LinkedFrom is not None:
334
+ linked_from = self._LinkedFrom.ToDictionary()
335
+
336
+ result:dict = \
337
+ {
338
+ 'artists': [ item.ToDictionary() for item in self._Artists ],
339
+ 'available_markets': [ item for item in self._AvailableMarkets ],
340
+ 'disc_number': self._DiscNumber,
341
+ 'duration_ms': self._DurationMS,
342
+ 'explicit': self._Explicit,
343
+ 'external_urls': externalUrls,
344
+ 'href': self._Href,
345
+ 'id': self._Id,
346
+ 'is_linked_from': self.IsLinkedFrom,
347
+ 'is_local': self._IsLocal,
348
+ 'is_playable': self._IsPlayable,
349
+ 'name': self._Name,
350
+ 'preview_url': self._PreviewUrl,
351
+ 'restrictions': restrictions,
352
+ 'track_number': self._TrackNumber,
353
+ 'type': self._Type,
354
+ 'uri': self._Uri,
355
+ 'linked_from': linked_from,
356
+ 'id_origin': self.IdOrigin,
357
+ 'uri_origin': self.UriOrigin,
358
+ }
359
+ return result
360
+
361
+
362
+ def ToString(self, includeTitle:bool=True) -> str:
363
+ """
364
+ Returns a displayable string representation of the class.
365
+
366
+ Args:
367
+ includeTitle (str):
368
+ True to include the class name title prefix.
369
+ """
370
+ msg:str = ''
371
+ if includeTitle:
372
+ msg = 'TrackSimplified:'
373
+
374
+ if self._Name is not None: msg = '%s\n Name="%s"' % (msg, str(self._Name))
375
+ if self._Uri is not None: msg = '%s\n Uri="%s"' % (msg, str(self._Uri))
376
+ if self._Artists is not None:
377
+ cnt:int = len(self._Artists)
378
+ if cnt > 0:
379
+ msg = '%s\n Artist="%s" (%s)' % (msg, str(self._Artists[0].Name), str(self._Artists[0].Id))
380
+ msg = '%s\n Artists Count=%s' % (msg, str(cnt))
381
+ if self._AvailableMarkets is not None: msg = '%s\n AvailableMarkets Count=%s' % (msg, str(len(self._AvailableMarkets)))
382
+ if self._DiscNumber is not None: msg = '%s\n DiscNumber="%s"' % (msg, str(self._DiscNumber))
383
+ if self._DurationMS is not None: msg = '%s\n DurationMS="%s"' % (msg, str(self._DurationMS))
384
+ if self._Explicit is not None: msg = '%s\n Explicit="%s"' % (msg, str(self._Explicit))
385
+ if self._Href is not None: msg = '%s\n Href="%s"' % (msg, str(self._Href))
386
+ if self._Id is not None: msg = '%s\n Id="%s"' % (msg, str(self._Id))
387
+ if self.IdOrigin is not None: msg = '%s\n IdOrigin="%s"' % (msg, str(self.IdOrigin))
388
+ if self._IsLocal is not None: msg = '%s\n IsLocal="%s"' % (msg, str(self._IsLocal))
389
+ if self._IsPlayable is not None: msg = '%s\n IsPlayable="%s"' % (msg, str(self._IsPlayable))
390
+ if self._PreviewUrl is not None: msg = '%s\n PreviewUrl="%s"' % (msg, str(self._PreviewUrl))
391
+ if self._TrackNumber is not None: msg = '%s\n TrackNumber="%s"' % (msg, str(self._TrackNumber))
392
+ if self._Type is not None: msg = '%s\n Type="%s"' % (msg, str(self._Type))
393
+ if self._Uri is not None: msg = '%s\n Uri="%s"' % (msg, str(self._Uri))
394
+ if self.UriOrigin is not None: msg = '%s\n UriOrigin="%s"' % (msg, str(self.UriOrigin))
395
+ if self._LinkedFrom is not None: msg = '%s\n LinkedFrom: %s' % (msg, self._LinkedFrom.ToString(False))
396
+ #if self._Restrictions is not None: msg = '%s\n %s' % (msg, str(self._Restrictions))
397
+ #if self._ExternalUrls is not None: msg = '%s\n %s' % (msg, str(self._ExternalUrls))
398
+ return msg
@@ -0,0 +1,184 @@
1
+ # external package imports.
2
+
3
+ # our package imports.
4
+ from ..sautils import export
5
+ from .explicitcontent import ExplicitContent
6
+ from .externalurls import ExternalUrls
7
+ from .followers import Followers
8
+ from .imageobject import ImageObject
9
+ from .userprofilesimplified import UserProfileSimplified
10
+
11
+ @export
12
+ class UserProfile(UserProfileSimplified):
13
+ """
14
+ Spotify Web API User Profile object.
15
+
16
+ Information about the user from their account profile.
17
+ """
18
+
19
+ def __init__(self, root:dict=None) -> None:
20
+ """
21
+ Initializes a new instance of the class.
22
+
23
+ Args:
24
+ root (dict):
25
+ Spotify Web API JSON response in dictionary format, used to load object
26
+ attributes; otherwise, None to not load attributes.
27
+ """
28
+ # initialize base class.
29
+ super().__init__(root=root)
30
+
31
+ # initialize storage.
32
+ self._Country:str = None
33
+ self._EMail:str = None
34
+ self._ExplicitContent:ExplicitContent = None
35
+ self._Product:str = None
36
+
37
+ if (root is None):
38
+
39
+ pass
40
+
41
+ else:
42
+
43
+ self._Country = root.get('country', None)
44
+ self._EMail = root.get('email', None)
45
+ self._Product = root.get('product', None)
46
+
47
+ # process all collections and objects.
48
+ item:dict = root.get('explicit_content',None)
49
+ if item is not None:
50
+ self._ExplicitContent = ExplicitContent(root=item)
51
+
52
+ UNKNOWN:str = 'unknown'
53
+
54
+ # post validations.
55
+ # this is done, as some authorization levels will not return some of these details;
56
+ # in this case, we will default the values to 'unknown'.
57
+ if self._EMail is None:
58
+ self._EMail = UNKNOWN
59
+ if self._Product is None:
60
+ self._Product = UNKNOWN
61
+
62
+
63
+ def __repr__(self) -> str:
64
+ return self.ToString()
65
+
66
+
67
+ def __str__(self) -> str:
68
+ return self.ToString()
69
+
70
+
71
+ @property
72
+ def Country(self) -> str:
73
+ """
74
+ The country of the user, as set in the user's account profile.
75
+
76
+ An ISO 3166-1 alpha-2 country code.
77
+
78
+ This field is only available when the current user has granted access to
79
+ the `user-read-private` scope.
80
+
81
+ Example: `US`
82
+ """
83
+ return self._Country
84
+
85
+
86
+ @property
87
+ def EMail(self) -> str:
88
+ """
89
+ The user's email address, as entered by the user when creating their account.
90
+ Important! This email address is unverified; there is no proof that it actually
91
+ belongs to the user.
92
+
93
+ This field is only available when the current user has granted access to
94
+ the `user-read-email` scope.
95
+
96
+ Example: `johnsmith@example.com`
97
+ """
98
+ return self._EMail
99
+
100
+
101
+ @property
102
+ def ExplicitContent(self) -> ExternalUrls:
103
+ """
104
+ The user's explicit content settings.
105
+
106
+ This field is only available when the current user has granted access to
107
+ the `user-read-private` scope.
108
+ """
109
+ return self._ExplicitContent
110
+
111
+
112
+ @property
113
+ def IsProductFree(self) -> str:
114
+ """
115
+ Returns true if the user's Spotify subscription level is `free` or `open`;
116
+ otherwise, False.
117
+
118
+ This field is only valid when the current user has granted access to
119
+ the `user-read-private` scope; otherwise, it is set to `unknown`.
120
+ """
121
+ return (self._Product == 'free') or (self._Product == 'opem')
122
+
123
+
124
+ @property
125
+ def IsProductPremium(self) -> bool:
126
+ """
127
+ Returns true if the user's Spotify subscription level is `premium`;
128
+ otherwise, False.
129
+
130
+ This field is only valid when the current user has granted access to
131
+ the `user-read-private` scope; otherwise, it is set to `unknown`.
132
+ """
133
+ return (self._Product == 'premium')
134
+
135
+
136
+ @property
137
+ def Product(self) -> bool:
138
+ """
139
+ The user's Spotify subscription level: `premium`, `free`, etc.
140
+
141
+ The subscription level `open` can be considered the same as `free`.
142
+
143
+ This field is only valid when the current user has granted access to
144
+ the `user-read-private` scope; otherwise, it is set to `unknown`.
145
+ """
146
+ return self._Product
147
+
148
+
149
+ def ToDictionary(self) -> dict:
150
+ """
151
+ Returns a dictionary representation of the class.
152
+ """
153
+ # get base class result.
154
+ resultBase:dict = super().ToDictionary()
155
+
156
+ explicitContent:dict = {}
157
+ if self._ExplicitContent is not None:
158
+ explicitContent = self._ExplicitContent.ToDictionary()
159
+
160
+ result:dict = \
161
+ {
162
+ 'country': self._Country,
163
+ 'email': self._EMail,
164
+ 'explicitContent': explicitContent,
165
+ 'product': self._Product,
166
+ }
167
+
168
+ # combine base class results with these results.
169
+ resultBase.update(result)
170
+
171
+ # return a sorted dictionary.
172
+ return dict(sorted(resultBase.items()))
173
+
174
+
175
+ def ToString(self) -> str:
176
+ """
177
+ Returns a displayable string representation of the class.
178
+ """
179
+ msg:str = 'UserProfile: %s' % super().ToString(False)
180
+ if self._Country is not None: msg = '%s\n Country="%s"' % (msg, str(self._Country))
181
+ if self._EMail is not None: msg = '%s\n EMail="%s"' % (msg, str(self._EMail))
182
+ #if self._ExplicitContent is not None: msg = '%s\n %s' % (msg, str(self._ExplicitContent))
183
+ if self._Product is not None: msg = '%s\n Product="%s"' % (msg, str(self._Product))
184
+ return msg