mirror of
https://github.com/tcsenpai/swingmusic.git
synced 2025-06-07 11:45:35 +00:00
add route to remove playlist banner
This commit is contained in:
parent
6439b512e9
commit
728c6c2def
@ -30,6 +30,7 @@ tracks_to_playlist = PL.add_tracks_to_playlist
|
|||||||
add_artist_to_playlist = PL.add_artist_to_playlist
|
add_artist_to_playlist = PL.add_artist_to_playlist
|
||||||
update_playlist = PL.update_playlist
|
update_playlist = PL.update_playlist
|
||||||
delete_playlist = PL.delete_playlist
|
delete_playlist = PL.delete_playlist
|
||||||
|
remove_image = PL.remove_banner
|
||||||
|
|
||||||
|
|
||||||
def duplicate_images(images: list):
|
def duplicate_images(images: list):
|
||||||
@ -38,7 +39,7 @@ def duplicate_images(images: list):
|
|||||||
elif len(images) == 2:
|
elif len(images) == 2:
|
||||||
images += list(reversed(images))
|
images += list(reversed(images))
|
||||||
elif len(images) == 3:
|
elif len(images) == 3:
|
||||||
images = images + images[:]
|
images = images + images[:1]
|
||||||
|
|
||||||
return images
|
return images
|
||||||
|
|
||||||
@ -245,6 +246,30 @@ def update_playlist_info(playlistid: str):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@api.route("/playlist/<playlistid>/remove-img", methods=["GET"])
|
||||||
|
def remove_playlist_image(playlistid: str):
|
||||||
|
"""
|
||||||
|
Removes the playlist image.
|
||||||
|
"""
|
||||||
|
pid = int(playlistid)
|
||||||
|
playlist = get_playlist_by_id(pid)
|
||||||
|
|
||||||
|
if playlist is None:
|
||||||
|
return {"error": "Playlist not found"}, 404
|
||||||
|
|
||||||
|
remove_image(pid)
|
||||||
|
|
||||||
|
playlist.image = None
|
||||||
|
playlist.has_gif = False
|
||||||
|
playlist.has_image = False
|
||||||
|
|
||||||
|
playlist.images = get_first_4_images(trackhashes=playlist.trackhashes)
|
||||||
|
playlist.last_updated = date_string_to_time_passed(playlist.last_updated)
|
||||||
|
PL.update_last_updated(pid)
|
||||||
|
|
||||||
|
return {"playlist": playlist}, 200
|
||||||
|
|
||||||
|
|
||||||
@api.route("/playlist/delete", methods=["POST"])
|
@api.route("/playlist/delete", methods=["POST"])
|
||||||
def remove_playlist():
|
def remove_playlist():
|
||||||
"""
|
"""
|
||||||
@ -298,5 +323,6 @@ def remove_tracks_from_playlist(pid: int):
|
|||||||
|
|
||||||
tracks = data["tracks"]
|
tracks = data["tracks"]
|
||||||
PL.remove_tracks_from_playlist(pid, tracks)
|
PL.remove_tracks_from_playlist(pid, tracks)
|
||||||
|
PL.update_last_updated(pid)
|
||||||
|
|
||||||
return {"msg": "Done"}, 200
|
return {"msg": "Done"}, 200
|
||||||
|
@ -177,6 +177,13 @@ class SQLitePlaylistMethods:
|
|||||||
with SQLiteManager(userdata_db=True) as cur:
|
with SQLiteManager(userdata_db=True) as cur:
|
||||||
cur.execute(sql, (pos, playlistid))
|
cur.execute(sql, (pos, playlistid))
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def remove_banner(playlistid: int):
|
||||||
|
sql = """UPDATE playlists SET image = NULL WHERE id = ?"""
|
||||||
|
|
||||||
|
with SQLiteManager(userdata_db=True) as cur:
|
||||||
|
cur.execute(sql, (playlistid,))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def remove_tracks_from_playlist(playlistid: int, tracks: list[dict[str, int]]):
|
def remove_tracks_from_playlist(playlistid: int, tracks: list[dict[str, int]]):
|
||||||
"""
|
"""
|
||||||
|
@ -271,6 +271,7 @@ class FetchSimilarArtistsLastFM:
|
|||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
artists = ArtistStore.artists
|
artists = ArtistStore.artists
|
||||||
|
|
||||||
|
try:
|
||||||
with Pool(processes=cpu_count()) as pool:
|
with Pool(processes=cpu_count()) as pool:
|
||||||
results = list(
|
results = list(
|
||||||
tqdm(
|
tqdm(
|
||||||
@ -281,3 +282,8 @@ class FetchSimilarArtistsLastFM:
|
|||||||
)
|
)
|
||||||
|
|
||||||
list(results)
|
list(results)
|
||||||
|
except TypeError:
|
||||||
|
print("TypeError: Handled!!")
|
||||||
|
# 🤷
|
||||||
|
# TypeError: JSONDecodeError.__init__() missing 2 required positional arguments: 'doc' and 'pos'
|
||||||
|
pass
|
@ -33,7 +33,9 @@ class Playlist:
|
|||||||
|
|
||||||
self.count = len(self.trackhashes)
|
self.count = len(self.trackhashes)
|
||||||
self.has_gif = bool(int(self.has_gif))
|
self.has_gif = bool(int(self.has_gif))
|
||||||
self.has_image = (Path(settings.Paths.get_playlist_img_path()) / str(self.image)).exists()
|
self.has_image = (
|
||||||
|
Path(settings.Paths.get_playlist_img_path()) / str(self.image)
|
||||||
|
).exists()
|
||||||
|
|
||||||
if self.image is not None:
|
if self.image is not None:
|
||||||
self.thumb = "thumb_" + self.image
|
self.thumb = "thumb_" + self.image
|
||||||
|
Loading…
x
Reference in New Issue
Block a user