Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
tehkillerbee committed Sep 30, 2024
1 parent 7c9b0d3 commit b619bc4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 32 deletions.
54 changes: 25 additions & 29 deletions tidalapi/playlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,18 +233,18 @@ def wide_image(self, width: int = 1080, height: int = 720) -> str:

class UserPlaylist(Playlist):
def _reparse(self) -> None:
# Re-Read Playlist to get ETag
"""Re-Read Playlist to get ETag."""
request = self.request.request("GET", self._base_url % self.id)
self._etag = request.headers["etag"]
self.request.map_json(request.json(), parse=self.parse)

def edit(
self, title: Optional[str] = None, description: Optional[str] = None
) -> None:
"""
Edit UserPlaylist title & description
"""Edit UserPlaylist title & description.
:param title: Playlist title
:param description: Playlist title
:param description: Playlist title.
"""
if not title:
title = self.name
Expand All @@ -255,19 +255,19 @@ def edit(
self.request.request("POST", self._base_url % self.id, data=data)

def delete(self, media_ids: List[str]) -> None:
"""
Delete one or more items from the UserPlaylist
:param media_ids: Lists of Media IDs to remove
"""Delete one or more items from the UserPlaylist.
:param media_ids: Lists of Media IDs to remove.
"""
# Generate list of track indices of tracks found in the list of media_ids.
track_ids = [str(track.id) for track in self.tracks()]
matching_indices = [i for i, item in enumerate(track_ids) if item in media_ids]
self.remove_by_indices(matching_indices)

def add(self, media_ids: List[str]) -> None:
"""
Add one or more items to the UserPlaylist
:param media_ids: List of Media IDs to add
"""Add one or more items to the UserPlaylist.
:param media_ids: List of Media IDs to add.
"""
data = {
"onArtifactNotFound": "SKIP",
Expand All @@ -286,9 +286,9 @@ def add(self, media_ids: List[str]) -> None:
self._reparse()

def remove_by_id(self, media_id: str) -> None:
"""
Remove a single item from the playlist, using the media ID
:param media_id: Media ID to remove
"""Remove a single item from the playlist, using the media ID :param media_id:
Media ID to remove.
"""
track_ids = [str(track.id) for track in self.tracks()]
try:
Expand All @@ -299,8 +299,8 @@ def remove_by_id(self, media_id: str) -> None:
pass

def remove_by_index(self, index: int) -> None:
"""
Remove a single item from the UserPlaylist, using item index.
"""Remove a single item from the UserPlaylist, using item index.
:param index: Media index to remove
"""
headers = {"If-None-Match": self._etag} if self._etag else None
Expand All @@ -309,9 +309,9 @@ def remove_by_index(self, index: int) -> None:
)

def remove_by_indices(self, indices: Sequence[int]) -> None:
"""
Remove one or more items from the UserPlaylist, using list of indices
:param indices: List containing indices to remove
"""Remove one or more items from the UserPlaylist, using list of indices.
:param indices: List containing indices to remove.
"""
headers = {"If-None-Match": self._etag} if self._etag else None
track_index_string = ",".join([str(x) for x in indices])
Expand All @@ -323,8 +323,8 @@ def remove_by_indices(self, indices: Sequence[int]) -> None:
self._reparse()

def clear(self, chunk_size: int = 50):
"""
Clear UserPlaylist
"""Clear UserPlaylist.
:param chunk_size: Number of items to remove per request
:return:
"""
Expand All @@ -333,9 +333,7 @@ def clear(self, chunk_size: int = 50):
self.remove_by_indices(indices)

def set_playlist_public(self):
"""
Set UserPlaylist as Public
"""
"""Set UserPlaylist as Public."""
self.request.request(
"PUT",
base_url=self.session.config.api_v2_location,
Expand All @@ -345,9 +343,7 @@ def set_playlist_public(self):
self._reparse()

def set_playlist_private(self):
"""
Set UserPlaylist as Private
"""
"""Set UserPlaylist as Private."""
self.request.request(
"PUT",
base_url=self.session.config.api_v2_location,
Expand All @@ -357,8 +353,8 @@ def set_playlist_private(self):
self._reparse()

def delete_playlist(self):
"""
Delete UserPlaylist
:return: True, if successful
"""Delete UserPlaylist.
:return: True, if successful.
"""
return self.request.request("DELETE", path="playlists/%s" % self.id).ok
6 changes: 3 additions & 3 deletions tidalapi/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ def playlists(self) -> List[Union["Playlist", "UserPlaylist"]]:
)

def get_public_playlists(self, offset=0) -> List[Union["Playlist", "UserPlaylist"]]:
"""
Get the (public) playlists created by the user
:return: List of public playlists
"""Get the (public) playlists created by the user.
:return: List of public playlists.
"""
params = {"limit": 50, "offset": offset}
endpoint = "user-playlists/%s/public" % self.id
Expand Down

0 comments on commit b619bc4

Please sign in to comment.