mirror of
https://github.com/tcsenpai/swingmusic.git
synced 2025-06-06 03:05: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
|
||||
update_playlist = PL.update_playlist
|
||||
delete_playlist = PL.delete_playlist
|
||||
remove_image = PL.remove_banner
|
||||
|
||||
|
||||
def duplicate_images(images: list):
|
||||
@ -38,7 +39,7 @@ def duplicate_images(images: list):
|
||||
elif len(images) == 2:
|
||||
images += list(reversed(images))
|
||||
elif len(images) == 3:
|
||||
images = images + images[:]
|
||||
images = images + images[:1]
|
||||
|
||||
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"])
|
||||
def remove_playlist():
|
||||
"""
|
||||
@ -298,5 +323,6 @@ def remove_tracks_from_playlist(pid: int):
|
||||
|
||||
tracks = data["tracks"]
|
||||
PL.remove_tracks_from_playlist(pid, tracks)
|
||||
PL.update_last_updated(pid)
|
||||
|
||||
return {"msg": "Done"}, 200
|
||||
|
@ -177,6 +177,13 @@ class SQLitePlaylistMethods:
|
||||
with SQLiteManager(userdata_db=True) as cur:
|
||||
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
|
||||
def remove_tracks_from_playlist(playlistid: int, tracks: list[dict[str, int]]):
|
||||
"""
|
||||
|
@ -271,13 +271,19 @@ class FetchSimilarArtistsLastFM:
|
||||
def __init__(self) -> None:
|
||||
artists = ArtistStore.artists
|
||||
|
||||
with Pool(processes=cpu_count()) as pool:
|
||||
results = list(
|
||||
tqdm(
|
||||
pool.imap_unordered(save_similar_artists, artists),
|
||||
total=len(artists),
|
||||
desc="Fetching similar artists",
|
||||
try:
|
||||
with Pool(processes=cpu_count()) as pool:
|
||||
results = list(
|
||||
tqdm(
|
||||
pool.imap_unordered(save_similar_artists, artists),
|
||||
total=len(artists),
|
||||
desc="Fetching similar artists",
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
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.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:
|
||||
self.thumb = "thumb_" + self.image
|
||||
|
Loading…
x
Reference in New Issue
Block a user