mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-05 04:53:01 +00:00
check if album colors have contrast
- remove albumid field from album class - set accent color to $red
This commit is contained in:
committed by
Mungai Geoffrey
parent
a23b6200eb
commit
5acb8cb84d
+10
-2
@@ -41,20 +41,28 @@ def get_album():
|
||||
"""Returns all the tracks in the given album."""
|
||||
data = request.get_json()
|
||||
albumhash = data["hash"]
|
||||
error_msg = {"error": "Album not created yet."}
|
||||
|
||||
tracks = instances.tracks_instance.find_tracks_by_hash(albumhash)
|
||||
|
||||
if len(tracks) == 0:
|
||||
return error_msg, 204
|
||||
|
||||
tracks = [models.Track(t) for t in tracks]
|
||||
tracks = helpers.RemoveDuplicates(tracks)()
|
||||
|
||||
album = instances.album_instance.find_album_by_hash(albumhash)
|
||||
|
||||
if not album:
|
||||
return {"error": "Album not created yet."}, 204
|
||||
return error_msg, 204
|
||||
|
||||
album = models.Album(album)
|
||||
|
||||
album.count = len(tracks)
|
||||
album.duration = albumslib.get_album_duration(tracks)
|
||||
try:
|
||||
album.duration = albumslib.get_album_duration(tracks)
|
||||
except AttributeError:
|
||||
album.duration = 0
|
||||
|
||||
if (
|
||||
album.count == 1
|
||||
|
||||
@@ -61,11 +61,11 @@ class Albums(MongoAlbums):
|
||||
album = self.collection.find_one({"hash": hash})
|
||||
return convert_one(album)
|
||||
|
||||
def set_album_colors(self, colors: List[str], album_id: str) -> None:
|
||||
def set_album_colors(self, colors: List[str], hash: str) -> None:
|
||||
"""
|
||||
Sets the colors for an album.
|
||||
"""
|
||||
self.collection.update_one(
|
||||
{"_id": ObjectId(album_id)},
|
||||
{"hash": hash},
|
||||
{"$set": {"colors": colors}},
|
||||
)
|
||||
|
||||
@@ -45,6 +45,6 @@ class ProcessAlbumColors:
|
||||
colors = get_image_colors(img)
|
||||
|
||||
if len(colors) > 0:
|
||||
instances.album_instance.set_album_colors(colors, album.albumid)
|
||||
instances.album_instance.set_album_colors(colors, album.hash)
|
||||
|
||||
return colors
|
||||
|
||||
@@ -82,7 +82,6 @@ class Album:
|
||||
Creates an album object
|
||||
"""
|
||||
|
||||
albumid: str
|
||||
title: str
|
||||
artist: str
|
||||
hash: str
|
||||
@@ -96,7 +95,6 @@ class Album:
|
||||
colors: List[str] = field(default_factory=list)
|
||||
|
||||
def __init__(self, tags):
|
||||
self.albumid = tags["_id"]["$oid"]
|
||||
self.title = tags["title"]
|
||||
self.artist = tags["artist"]
|
||||
self.date = tags["date"]
|
||||
|
||||
Reference in New Issue
Block a user