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.
- spotifywebapipython/__init__.py +35 -0
- spotifywebapipython/const.py +114 -0
- spotifywebapipython/docs/__init__.html +2156 -0
- spotifywebapipython/docs/codecopy.js +70 -0
- spotifywebapipython/docs/index.html +514 -0
- spotifywebapipython/docs/search.js +46 -0
- spotifywebapipython/docs/spotifywebapipython/const.html +636 -0
- spotifywebapipython/docs/spotifywebapipython/saappmessages.html +540 -0
- spotifywebapipython/docs/spotifywebapipython/sautils.html +620 -0
- spotifywebapipython/docs/spotifywebapipython/spotifyapierror.html +341 -0
- spotifywebapipython/docs/spotifywebapipython/spotifyapimessage.html +598 -0
- spotifywebapipython/docs/spotifywebapipython/spotifyauthtoken.html +612 -0
- spotifywebapipython/docs/spotifywebapipython/spotifyclient.html +16557 -0
- spotifywebapipython/docs/spotifywebapipython/spotifydiscovery.html +518 -0
- spotifywebapipython/docs/spotifywebapipython/spotifywebapiauthenticationerror.html +421 -0
- spotifywebapipython/docs/spotifywebapipython/spotifywebapierror.html +400 -0
- spotifywebapipython/docs/spotifywebapipython/spotifywebplayertoken.html +635 -0
- spotifywebapipython/docs/spotifywebapipython.ico +0 -0
- spotifywebapipython/docs/spotifywebapipython_OLD.ico +0 -0
- spotifywebapipython/models/__init__.py +121 -0
- spotifywebapipython/models/album.py +170 -0
- spotifywebapipython/models/albumpagesaved.py +85 -0
- spotifywebapipython/models/albumpagesimplified.py +88 -0
- spotifywebapipython/models/albumsaved.py +102 -0
- spotifywebapipython/models/albumsimplified.py +308 -0
- spotifywebapipython/models/artist.py +146 -0
- spotifywebapipython/models/artistinfo.py +282 -0
- spotifywebapipython/models/artistinfotourevent.py +127 -0
- spotifywebapipython/models/artistpage.py +70 -0
- spotifywebapipython/models/artistsimplified.py +163 -0
- spotifywebapipython/models/audiobook.py +87 -0
- spotifywebapipython/models/audiobookpagesimplified.py +88 -0
- spotifywebapipython/models/audiobooksimplified.py +362 -0
- spotifywebapipython/models/audiofeatures.py +333 -0
- spotifywebapipython/models/author.py +67 -0
- spotifywebapipython/models/category.py +168 -0
- spotifywebapipython/models/categorypage.py +70 -0
- spotifywebapipython/models/chapter.py +84 -0
- spotifywebapipython/models/chapterpagesimplified.py +88 -0
- spotifywebapipython/models/chaptersimplified.py +387 -0
- spotifywebapipython/models/context.py +113 -0
- spotifywebapipython/models/copyright.py +79 -0
- spotifywebapipython/models/device.py +301 -0
- spotifywebapipython/models/episode.py +84 -0
- spotifywebapipython/models/episodepagesaved.py +85 -0
- spotifywebapipython/models/episodepagesimplified.py +88 -0
- spotifywebapipython/models/episodesaved.py +99 -0
- spotifywebapipython/models/episodesimplified.py +370 -0
- spotifywebapipython/models/explicitcontent.py +80 -0
- spotifywebapipython/models/externalids.py +91 -0
- spotifywebapipython/models/externalurls.py +104 -0
- spotifywebapipython/models/followers.py +81 -0
- spotifywebapipython/models/imageobject.py +193 -0
- spotifywebapipython/models/imagevibrantcolors.py +182 -0
- spotifywebapipython/models/linkedfrom.py +165 -0
- spotifywebapipython/models/narrator.py +67 -0
- spotifywebapipython/models/owner.py +162 -0
- spotifywebapipython/models/pageobject.py +343 -0
- spotifywebapipython/models/playeractions.py +196 -0
- spotifywebapipython/models/playerlastplayedinfo.py +334 -0
- spotifywebapipython/models/playerplaystate.py +467 -0
- spotifywebapipython/models/playerqueueinfo.py +207 -0
- spotifywebapipython/models/playhistory.py +136 -0
- spotifywebapipython/models/playhistorypage.py +85 -0
- spotifywebapipython/models/playlist.py +125 -0
- spotifywebapipython/models/playlistpage.py +85 -0
- spotifywebapipython/models/playlistpagesimplified.py +107 -0
- spotifywebapipython/models/playlistsimplified.py +334 -0
- spotifywebapipython/models/playlisttrack.py +143 -0
- spotifywebapipython/models/playlisttracksummary.py +80 -0
- spotifywebapipython/models/recommendationseed.py +135 -0
- spotifywebapipython/models/restrictions.py +86 -0
- spotifywebapipython/models/resumepoint.py +79 -0
- spotifywebapipython/models/searchresponse.py +391 -0
- spotifywebapipython/models/searchresultbase.py +299 -0
- spotifywebapipython/models/show.py +87 -0
- spotifywebapipython/models/showpagesaved.py +85 -0
- spotifywebapipython/models/showpagesimplified.py +88 -0
- spotifywebapipython/models/showsaved.py +99 -0
- spotifywebapipython/models/showsimplified.py +320 -0
- spotifywebapipython/models/spotifyconnectdevice.py +321 -0
- spotifywebapipython/models/spotifyconnectdevices.py +441 -0
- spotifywebapipython/models/track.py +142 -0
- spotifywebapipython/models/trackpage.py +110 -0
- spotifywebapipython/models/trackpagesaved.py +85 -0
- spotifywebapipython/models/trackpagesimplified.py +88 -0
- spotifywebapipython/models/trackrecommendations.py +88 -0
- spotifywebapipython/models/tracksaved.py +99 -0
- spotifywebapipython/models/tracksimplified.py +398 -0
- spotifywebapipython/models/userprofile.py +184 -0
- spotifywebapipython/models/userprofilesimplified.py +206 -0
- spotifywebapipython/models/zeroconfdiscoveryresult.py +592 -0
- spotifywebapipython/models/zeroconfproperty.py +93 -0
- spotifywebapipython/oauthcli/__init__.py +7 -0
- spotifywebapipython/oauthcli/authclient.py +1229 -0
- spotifywebapipython/saappmessages.py +86 -0
- spotifywebapipython/sautils.py +285 -0
- spotifywebapipython/spotifyapierror.py +66 -0
- spotifywebapipython/spotifyapimessage.py +269 -0
- spotifywebapipython/spotifyauthtoken.py +264 -0
- spotifywebapipython/spotifyclient.py +17885 -0
- spotifywebapipython/spotifyconnect/__init__.py +19 -0
- spotifywebapipython/spotifyconnect/spotifyconnectdeviceeventargs.py +67 -0
- spotifywebapipython/spotifyconnect/spotifyconnectdirectorytask.py +2564 -0
- spotifywebapipython/spotifyconnect/spotifyconnectzeroconfcastapptask.py +467 -0
- spotifywebapipython/spotifyconnect/spotifyconnectzeroconfcastcontroller.py +701 -0
- spotifywebapipython/spotifyconnect/spotifyconnectzeroconfcastlistener.py +359 -0
- spotifywebapipython/spotifyconnect/spotifyconnectzeroconfcastmultizonelistener.py +212 -0
- spotifywebapipython/spotifyconnect/spotifyconnectzeroconfexceptions.py +20 -0
- spotifywebapipython/spotifyconnect/spotifyconnectzeroconflistener.py +335 -0
- spotifywebapipython/spotifydiscovery.py +473 -0
- spotifywebapipython/spotifymediatypes.py +53 -0
- spotifywebapipython/spotifywebapiauthenticationerror.py +122 -0
- spotifywebapipython/spotifywebapierror.py +106 -0
- spotifywebapipython/spotifywebplayertoken.py +743 -0
- spotifywebapipython/vibrant/__init__.py +17 -0
- spotifywebapipython/vibrant/generator.py +261 -0
- spotifywebapipython/vibrant/image.py +100 -0
- spotifywebapipython/vibrant/main.py +34 -0
- spotifywebapipython/vibrant/models.py +93 -0
- spotifywebapipython/vibrant/utils.py +56 -0
- spotifywebapipython/zeroconfapi/__init__.py +23 -0
- spotifywebapipython/zeroconfapi/authenticationtypes.py +38 -0
- spotifywebapipython/zeroconfapi/blobbuilder.py +370 -0
- spotifywebapipython/zeroconfapi/credentials.py +37 -0
- spotifywebapipython/zeroconfapi/cryptodiffiehellman.py +89 -0
- spotifywebapipython/zeroconfapi/helpers.py +64 -0
- spotifywebapipython/zeroconfapi/spotifyzeroconfapierror.py +108 -0
- spotifywebapipython/zeroconfapi/zeroconfconnect.py +1327 -0
- spotifywebapipython/zeroconfapi/zeroconfgetinfo.py +572 -0
- spotifywebapipython/zeroconfapi/zeroconfgetinfoalias.py +109 -0
- spotifywebapipython/zeroconfapi/zeroconfgetinfodrmmediaformat.py +90 -0
- spotifywebapipython/zeroconfapi/zeroconfresponse.py +195 -0
- spotifywebapipython-1.0.242.dist-info/LICENSE +22 -0
- spotifywebapipython-1.0.242.dist-info/METADATA +219 -0
- spotifywebapipython-1.0.242.dist-info/RECORD +138 -0
- spotifywebapipython-1.0.242.dist-info/WHEEL +5 -0
- spotifywebapipython-1.0.242.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# external package imports.
|
|
2
|
+
from datetime import datetime
|
|
3
|
+
|
|
4
|
+
# our package imports.
|
|
5
|
+
from ..sautils import export
|
|
6
|
+
from .context import Context
|
|
7
|
+
from .track import Track
|
|
8
|
+
|
|
9
|
+
@export
|
|
10
|
+
class PlayHistory:
|
|
11
|
+
"""
|
|
12
|
+
Spotify Web API PlayHistory object.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
def __init__(self, root:dict=None) -> None:
|
|
16
|
+
"""
|
|
17
|
+
Initializes a new instance of the class.
|
|
18
|
+
|
|
19
|
+
Args:
|
|
20
|
+
root (dict):
|
|
21
|
+
Spotify Web API JSON response in dictionary format, used to load object
|
|
22
|
+
attributes; otherwise, None to not load attributes.
|
|
23
|
+
"""
|
|
24
|
+
self._Context:Context = None
|
|
25
|
+
self._PlayedAt:str = None
|
|
26
|
+
self._PlayedAtMS:int = None
|
|
27
|
+
self._Track:Track = None
|
|
28
|
+
|
|
29
|
+
if (root is None):
|
|
30
|
+
|
|
31
|
+
pass
|
|
32
|
+
|
|
33
|
+
else:
|
|
34
|
+
|
|
35
|
+
self._PlayedAt = root.get('played_at', None)
|
|
36
|
+
|
|
37
|
+
# process all collections and objects.
|
|
38
|
+
item:dict = root.get('context',None)
|
|
39
|
+
if item is not None:
|
|
40
|
+
self._Context = Context(root=item)
|
|
41
|
+
|
|
42
|
+
item:dict = root.get('track',None)
|
|
43
|
+
if item is not None:
|
|
44
|
+
self._Track = Track(root=item)
|
|
45
|
+
|
|
46
|
+
# convert played at local datetime to unix milliseconds timestamp.
|
|
47
|
+
if self._PlayedAt is not None:
|
|
48
|
+
dtLocalIso:str = self._PlayedAt.replace('Z','+00:00')
|
|
49
|
+
dtLocal:str = datetime.fromisoformat(dtLocalIso)
|
|
50
|
+
dtLocalUnixTS:float = dtLocal.timestamp()
|
|
51
|
+
self._PlayedAtMS = int(dtLocalUnixTS * 1000)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def __repr__(self) -> str:
|
|
55
|
+
return self.ToString()
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def __str__(self) -> str:
|
|
59
|
+
return self.ToString()
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
@property
|
|
63
|
+
def PlayedAt(self) -> str:
|
|
64
|
+
"""
|
|
65
|
+
The date and time the track was played (in local time).
|
|
66
|
+
|
|
67
|
+
Example: `2024-01-25T15:33:17.136Z`
|
|
68
|
+
"""
|
|
69
|
+
return self._PlayedAt
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
@property
|
|
73
|
+
def PlayedAtMS(self) -> int:
|
|
74
|
+
"""
|
|
75
|
+
The `PlayedAt` value in Unix millisecond timestamp format, or null if the `PlayedAt` value is null.
|
|
76
|
+
|
|
77
|
+
Example: `1706213826000`
|
|
78
|
+
"""
|
|
79
|
+
return self._PlayedAtMS
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
@property
|
|
83
|
+
def Context(self) -> Context:
|
|
84
|
+
"""
|
|
85
|
+
The context the track was played from.
|
|
86
|
+
"""
|
|
87
|
+
return self._Context
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
@property
|
|
91
|
+
def Track(self) -> Track:
|
|
92
|
+
"""
|
|
93
|
+
The track the user listened to.
|
|
94
|
+
"""
|
|
95
|
+
return self._Track
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def ToDictionary(self) -> dict:
|
|
99
|
+
"""
|
|
100
|
+
Returns a dictionary representation of the class.
|
|
101
|
+
"""
|
|
102
|
+
context:dict = {}
|
|
103
|
+
if self._Context is not None:
|
|
104
|
+
context = self._Context.ToDictionary()
|
|
105
|
+
|
|
106
|
+
track:dict = {}
|
|
107
|
+
if self._Track is not None:
|
|
108
|
+
track = self._Track.ToDictionary()
|
|
109
|
+
|
|
110
|
+
result:dict = \
|
|
111
|
+
{
|
|
112
|
+
'context': context,
|
|
113
|
+
'played_at': self._PlayedAt,
|
|
114
|
+
'played_at_ms': self._PlayedAtMS,
|
|
115
|
+
'track': track,
|
|
116
|
+
}
|
|
117
|
+
return result
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def ToString(self, includeItems:bool=False) -> str:
|
|
121
|
+
"""
|
|
122
|
+
Returns a displayable string representation of the class.
|
|
123
|
+
|
|
124
|
+
Args:
|
|
125
|
+
includeItems (bool):
|
|
126
|
+
True to include the Items collection of objects; otherwise, False
|
|
127
|
+
to only return base properties.
|
|
128
|
+
"""
|
|
129
|
+
msg:str = 'PlayHistory:'
|
|
130
|
+
if self._PlayedAt is not None: msg = '%s\n PlayedAt="%s"' % (msg, str(self._PlayedAt))
|
|
131
|
+
if self._Context is not None: msg = '%s\n Context="%s"' % (msg, str(self._Context.Uri))
|
|
132
|
+
|
|
133
|
+
if (includeItems):
|
|
134
|
+
if self._Track is not None: msg = '%s\n %s' % (msg, str(self._Track))
|
|
135
|
+
|
|
136
|
+
return msg
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# external package imports.
|
|
2
|
+
|
|
3
|
+
# our package imports.
|
|
4
|
+
from ..sautils import export
|
|
5
|
+
from .pageobject import PageObject
|
|
6
|
+
from .playhistory import PlayHistory
|
|
7
|
+
from .track import Track
|
|
8
|
+
|
|
9
|
+
@export
|
|
10
|
+
class PlayHistoryPage(PageObject):
|
|
11
|
+
"""
|
|
12
|
+
Spotify Web API PlayHistoryPage object.
|
|
13
|
+
|
|
14
|
+
This allows for multiple pages of `PlayHistory` objects to be navigated.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
def __init__(self, root:dict=None) -> None:
|
|
18
|
+
"""
|
|
19
|
+
Initializes a new instance of the class.
|
|
20
|
+
|
|
21
|
+
Args:
|
|
22
|
+
root (dict):
|
|
23
|
+
Spotify Web API JSON response in dictionary format, used to load object
|
|
24
|
+
attributes; otherwise, None to not load attributes.
|
|
25
|
+
"""
|
|
26
|
+
# initialize base class.
|
|
27
|
+
super().__init__(root=root)
|
|
28
|
+
|
|
29
|
+
# initialize storage.
|
|
30
|
+
self._Items:list[PlayHistory] = []
|
|
31
|
+
|
|
32
|
+
if (root is None):
|
|
33
|
+
|
|
34
|
+
pass
|
|
35
|
+
|
|
36
|
+
else:
|
|
37
|
+
|
|
38
|
+
# process all collections and objects.
|
|
39
|
+
items:list = root.get('items',None)
|
|
40
|
+
if items is not None:
|
|
41
|
+
for item in items:
|
|
42
|
+
if item is not None:
|
|
43
|
+
self._Items.append(PlayHistory(root=item))
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def __repr__(self) -> str:
|
|
47
|
+
return self.ToString()
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def __str__(self) -> str:
|
|
51
|
+
return self.ToString()
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
@property
|
|
55
|
+
def Items(self) -> list[PlayHistory]:
|
|
56
|
+
"""
|
|
57
|
+
Array of `PlayHistory` objects.
|
|
58
|
+
"""
|
|
59
|
+
return self._Items
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def GetTracks(self) -> list[Track]:
|
|
63
|
+
"""
|
|
64
|
+
Gets a list of all tracks contained in the underlying `Items` list.
|
|
65
|
+
|
|
66
|
+
This is a convenience method so one does not have to loop through the `Items`
|
|
67
|
+
array of PlayHistory objects to get the list of tracks.
|
|
68
|
+
"""
|
|
69
|
+
result:list[Track] = []
|
|
70
|
+
item:PlayHistory
|
|
71
|
+
for item in self._Items:
|
|
72
|
+
result.append(item.Track)
|
|
73
|
+
return result
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def ToString(self, includeItems:bool=False) -> str:
|
|
77
|
+
"""
|
|
78
|
+
Returns a displayable string representation of the class.
|
|
79
|
+
|
|
80
|
+
Args:
|
|
81
|
+
includeItems (bool):
|
|
82
|
+
True to include the Items collection of objects; otherwise, False
|
|
83
|
+
to only return base properties.
|
|
84
|
+
"""
|
|
85
|
+
return 'PlayHistoryPage: %s' % super().ToString(includeItems)
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# external package imports.
|
|
2
|
+
|
|
3
|
+
# our package imports.
|
|
4
|
+
from ..sautils import export
|
|
5
|
+
from .followers import Followers
|
|
6
|
+
from .playlistpage import PlaylistPage
|
|
7
|
+
from .playlistsimplified import PlaylistSimplified
|
|
8
|
+
from .track import Track
|
|
9
|
+
|
|
10
|
+
@export
|
|
11
|
+
class Playlist(PlaylistSimplified):
|
|
12
|
+
"""
|
|
13
|
+
Spotify Web API Playlist 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
|
+
# initialize base class.
|
|
26
|
+
super().__init__(root)
|
|
27
|
+
|
|
28
|
+
# initialize storage.
|
|
29
|
+
self._Followers:Followers = None
|
|
30
|
+
self._Tracks:PlaylistPage = None
|
|
31
|
+
|
|
32
|
+
if (root is None):
|
|
33
|
+
|
|
34
|
+
# if not building the class from json response, then initialize various properties as
|
|
35
|
+
# the playlist is probably being built manually.
|
|
36
|
+
self._Followers = Followers()
|
|
37
|
+
self._Tracks = PlaylistPage()
|
|
38
|
+
|
|
39
|
+
else:
|
|
40
|
+
|
|
41
|
+
# process all collections and objects.
|
|
42
|
+
item:dict = root.get('followers',None)
|
|
43
|
+
if item is not None:
|
|
44
|
+
self._Followers = Followers(root=item)
|
|
45
|
+
|
|
46
|
+
item:dict = root.get('tracks',None)
|
|
47
|
+
if item is not None:
|
|
48
|
+
self._Tracks = PlaylistPage(root=item)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def __repr__(self) -> str:
|
|
52
|
+
return self.ToString()
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def __str__(self) -> str:
|
|
56
|
+
return self.ToString()
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
@property
|
|
60
|
+
def Followers(self) -> Followers:
|
|
61
|
+
"""
|
|
62
|
+
Information about the followers of the playlist.
|
|
63
|
+
"""
|
|
64
|
+
return self._Followers
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
@property
|
|
68
|
+
def Tracks(self) -> PlaylistPage:
|
|
69
|
+
"""
|
|
70
|
+
The tracks of the playlist.
|
|
71
|
+
|
|
72
|
+
This is a `PlaylistPage` object, meaning only 50 tracks max are listed per request.
|
|
73
|
+
"""
|
|
74
|
+
return self._Tracks
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def GetTracks(self) -> list[Track]:
|
|
78
|
+
"""
|
|
79
|
+
Gets a list of all tracks contained in the underlying `Tracks.Items` list.
|
|
80
|
+
|
|
81
|
+
This is a convenience method so one does not have to loop through the `Tracks.Items`
|
|
82
|
+
array of PlaylistPage objects to get the list of tracks.
|
|
83
|
+
"""
|
|
84
|
+
result:list[Track] = []
|
|
85
|
+
if self._Tracks is not None:
|
|
86
|
+
result = self._Tracks.GetTracks()
|
|
87
|
+
return result
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def ToDictionary(self) -> dict:
|
|
91
|
+
"""
|
|
92
|
+
Returns a dictionary representation of the class.
|
|
93
|
+
"""
|
|
94
|
+
# get base class result.
|
|
95
|
+
resultBase:dict = super().ToDictionary()
|
|
96
|
+
|
|
97
|
+
followers:dict = {}
|
|
98
|
+
if self._Followers is not None:
|
|
99
|
+
followers = self._Followers.ToDictionary()
|
|
100
|
+
|
|
101
|
+
tracks:dict = {}
|
|
102
|
+
if self._Tracks is not None:
|
|
103
|
+
tracks = self._Tracks.ToDictionary()
|
|
104
|
+
|
|
105
|
+
result:dict = \
|
|
106
|
+
{
|
|
107
|
+
'tracks': tracks,
|
|
108
|
+
'followers': followers
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
# combine base class results with these results.
|
|
112
|
+
resultBase.update(result)
|
|
113
|
+
|
|
114
|
+
# return an unsorted dictionary.
|
|
115
|
+
return resultBase
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def ToString(self) -> str:
|
|
119
|
+
"""
|
|
120
|
+
Returns a displayable string representation of the class.
|
|
121
|
+
"""
|
|
122
|
+
msg:str = 'Playlist: %s' % super().ToString(False)
|
|
123
|
+
#if self._Followers is not None: msg = '%s\n %s' % (msg, str(self._Followers))
|
|
124
|
+
if self._Tracks is not None: msg = '%s\n Tracks Count=%s' % (msg, str(self._Tracks.Total))
|
|
125
|
+
return msg
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# external package imports.
|
|
2
|
+
|
|
3
|
+
# our package imports.
|
|
4
|
+
from ..sautils import export
|
|
5
|
+
from .pageobject import PageObject
|
|
6
|
+
from .playlisttrack import PlaylistTrack
|
|
7
|
+
from .track import Track
|
|
8
|
+
|
|
9
|
+
@export
|
|
10
|
+
class PlaylistPage(PageObject):
|
|
11
|
+
"""
|
|
12
|
+
Spotify Web API PlaylistPage object.
|
|
13
|
+
|
|
14
|
+
This allows for multiple pages of `PlaylistTrack` objects to be navigated.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
def __init__(self, root:dict=None) -> None:
|
|
18
|
+
"""
|
|
19
|
+
Initializes a new instance of the class.
|
|
20
|
+
|
|
21
|
+
Args:
|
|
22
|
+
root (dict):
|
|
23
|
+
Spotify Web API JSON response in dictionary format, used to load object
|
|
24
|
+
attributes; otherwise, None to not load attributes.
|
|
25
|
+
"""
|
|
26
|
+
# initialize base class.
|
|
27
|
+
super().__init__(root=root)
|
|
28
|
+
|
|
29
|
+
# initialize storage.
|
|
30
|
+
self._Items:list[PlaylistTrack] = []
|
|
31
|
+
|
|
32
|
+
if (root is None):
|
|
33
|
+
|
|
34
|
+
pass
|
|
35
|
+
|
|
36
|
+
else:
|
|
37
|
+
|
|
38
|
+
# process all collections and objects.
|
|
39
|
+
items:list = root.get('items',None)
|
|
40
|
+
if items is not None:
|
|
41
|
+
for item in items:
|
|
42
|
+
if item is not None:
|
|
43
|
+
self._Items.append(PlaylistTrack(root=item))
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def __repr__(self) -> str:
|
|
47
|
+
return self.ToString()
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def __str__(self) -> str:
|
|
51
|
+
return self.ToString()
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
@property
|
|
55
|
+
def Items(self) -> list[PlaylistTrack]:
|
|
56
|
+
"""
|
|
57
|
+
Array of `PlaylistTrack` objects.
|
|
58
|
+
"""
|
|
59
|
+
return self._Items
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def GetTracks(self) -> list[Track]:
|
|
63
|
+
"""
|
|
64
|
+
Gets a list of all tracks contained in the underlying `Items` list.
|
|
65
|
+
|
|
66
|
+
This is a convenience method so one does not have to loop through the `Items`
|
|
67
|
+
array of PlaylistTrack objects to get the list of tracks.
|
|
68
|
+
"""
|
|
69
|
+
result:list[Track] = []
|
|
70
|
+
item:PlaylistTrack
|
|
71
|
+
for item in self._Items:
|
|
72
|
+
result.append(item.Track)
|
|
73
|
+
return result
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def ToString(self, includeItems:bool=False) -> str:
|
|
77
|
+
"""
|
|
78
|
+
Returns a displayable string representation of the class.
|
|
79
|
+
|
|
80
|
+
Args:
|
|
81
|
+
includeItems (bool):
|
|
82
|
+
True to include the Items collection of objects; otherwise, False
|
|
83
|
+
to only return base properties.
|
|
84
|
+
"""
|
|
85
|
+
return 'PlaylistPage: %s' % super().ToString(includeItems)
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# external package imports.
|
|
2
|
+
|
|
3
|
+
# our package imports.
|
|
4
|
+
from ..sautils import export
|
|
5
|
+
from .pageobject import PageObject
|
|
6
|
+
from .playlistsimplified import PlaylistSimplified
|
|
7
|
+
|
|
8
|
+
@export
|
|
9
|
+
class PlaylistPageSimplified(PageObject):
|
|
10
|
+
"""
|
|
11
|
+
Spotify Web API PlaylistPageSimplified object.
|
|
12
|
+
|
|
13
|
+
This allows for multiple pages of `PlaylistSimplified` objects to be navigated.
|
|
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
|
+
# initialize base class.
|
|
26
|
+
super().__init__(root=root)
|
|
27
|
+
|
|
28
|
+
# initialize storage.
|
|
29
|
+
self._Items:list[PlaylistSimplified] = []
|
|
30
|
+
|
|
31
|
+
if (root is None):
|
|
32
|
+
|
|
33
|
+
pass
|
|
34
|
+
|
|
35
|
+
else:
|
|
36
|
+
|
|
37
|
+
# process all collections and objects.
|
|
38
|
+
items:list = root.get('items',None)
|
|
39
|
+
if items is not None:
|
|
40
|
+
for item in items:
|
|
41
|
+
if item is not None:
|
|
42
|
+
self._Items.append(PlaylistSimplified(root=item))
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def __repr__(self) -> str:
|
|
46
|
+
return self.ToString()
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def __str__(self) -> str:
|
|
50
|
+
return self.ToString()
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
@property
|
|
54
|
+
def Items(self) -> list[PlaylistSimplified]:
|
|
55
|
+
"""
|
|
56
|
+
Array of `PlaylistSimplified` objects.
|
|
57
|
+
"""
|
|
58
|
+
return self._Items
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def ContainsId(self, itemId:str=False) -> bool:
|
|
62
|
+
"""
|
|
63
|
+
Checks the `Items` collection to see if an item already exists with the
|
|
64
|
+
specified Id value.
|
|
65
|
+
|
|
66
|
+
Returns True if the itemId exists in the collection; otherwise, False.
|
|
67
|
+
"""
|
|
68
|
+
result:bool = False
|
|
69
|
+
|
|
70
|
+
item:PlaylistSimplified
|
|
71
|
+
for item in self._Items:
|
|
72
|
+
if item.Id == itemId:
|
|
73
|
+
result = True
|
|
74
|
+
break
|
|
75
|
+
|
|
76
|
+
return result
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def GetSpotifyOwnedItems(self) -> list[PlaylistSimplified]:
|
|
80
|
+
"""
|
|
81
|
+
Gets a list of all items contained in the `Items` list that are owned
|
|
82
|
+
by `spotify:user:spotify`.
|
|
83
|
+
"""
|
|
84
|
+
result:list[PlaylistSimplified] = []
|
|
85
|
+
item:PlaylistSimplified
|
|
86
|
+
for item in self._Items:
|
|
87
|
+
if item.Owner is not None:
|
|
88
|
+
if item.Owner.Uri == "spotify:user:spotify":
|
|
89
|
+
result.append(item)
|
|
90
|
+
|
|
91
|
+
# sort items on Name property, ascending order.
|
|
92
|
+
if len(result) > 0:
|
|
93
|
+
result.sort(key=lambda x: (x.Name or "").lower(), reverse=False)
|
|
94
|
+
|
|
95
|
+
return result
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def ToString(self, includeItems:bool=False) -> str:
|
|
99
|
+
"""
|
|
100
|
+
Returns a displayable string representation of the class.
|
|
101
|
+
|
|
102
|
+
Args:
|
|
103
|
+
includeItems (bool):
|
|
104
|
+
True to include the Items collection of objects; otherwise, False
|
|
105
|
+
to only return base properties.
|
|
106
|
+
"""
|
|
107
|
+
return 'PlaylistPageSimplified: %s' % super().ToString(includeItems)
|