mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-05 13:03:02 +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
@@ -41,20 +41,28 @@ def get_album():
|
|||||||
"""Returns all the tracks in the given album."""
|
"""Returns all the tracks in the given album."""
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
albumhash = data["hash"]
|
albumhash = data["hash"]
|
||||||
|
error_msg = {"error": "Album not created yet."}
|
||||||
|
|
||||||
tracks = instances.tracks_instance.find_tracks_by_hash(albumhash)
|
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 = [models.Track(t) for t in tracks]
|
||||||
tracks = helpers.RemoveDuplicates(tracks)()
|
tracks = helpers.RemoveDuplicates(tracks)()
|
||||||
|
|
||||||
album = instances.album_instance.find_album_by_hash(albumhash)
|
album = instances.album_instance.find_album_by_hash(albumhash)
|
||||||
|
|
||||||
if not album:
|
if not album:
|
||||||
return {"error": "Album not created yet."}, 204
|
return error_msg, 204
|
||||||
|
|
||||||
album = models.Album(album)
|
album = models.Album(album)
|
||||||
|
|
||||||
album.count = len(tracks)
|
album.count = len(tracks)
|
||||||
|
try:
|
||||||
album.duration = albumslib.get_album_duration(tracks)
|
album.duration = albumslib.get_album_duration(tracks)
|
||||||
|
except AttributeError:
|
||||||
|
album.duration = 0
|
||||||
|
|
||||||
if (
|
if (
|
||||||
album.count == 1
|
album.count == 1
|
||||||
|
|||||||
@@ -61,11 +61,11 @@ class Albums(MongoAlbums):
|
|||||||
album = self.collection.find_one({"hash": hash})
|
album = self.collection.find_one({"hash": hash})
|
||||||
return convert_one(album)
|
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.
|
Sets the colors for an album.
|
||||||
"""
|
"""
|
||||||
self.collection.update_one(
|
self.collection.update_one(
|
||||||
{"_id": ObjectId(album_id)},
|
{"hash": hash},
|
||||||
{"$set": {"colors": colors}},
|
{"$set": {"colors": colors}},
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -45,6 +45,6 @@ class ProcessAlbumColors:
|
|||||||
colors = get_image_colors(img)
|
colors = get_image_colors(img)
|
||||||
|
|
||||||
if len(colors) > 0:
|
if len(colors) > 0:
|
||||||
instances.album_instance.set_album_colors(colors, album.albumid)
|
instances.album_instance.set_album_colors(colors, album.hash)
|
||||||
|
|
||||||
return colors
|
return colors
|
||||||
|
|||||||
@@ -82,7 +82,6 @@ class Album:
|
|||||||
Creates an album object
|
Creates an album object
|
||||||
"""
|
"""
|
||||||
|
|
||||||
albumid: str
|
|
||||||
title: str
|
title: str
|
||||||
artist: str
|
artist: str
|
||||||
hash: str
|
hash: str
|
||||||
@@ -96,7 +95,6 @@ class Album:
|
|||||||
colors: List[str] = field(default_factory=list)
|
colors: List[str] = field(default_factory=list)
|
||||||
|
|
||||||
def __init__(self, tags):
|
def __init__(self, tags):
|
||||||
self.albumid = tags["_id"]["$oid"]
|
|
||||||
self.title = tags["title"]
|
self.title = tags["title"]
|
||||||
self.artist = tags["artist"]
|
self.artist = tags["artist"]
|
||||||
self.date = tags["date"]
|
self.date = tags["date"]
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ $teal: rgb(64, 200, 224);
|
|||||||
|
|
||||||
|
|
||||||
$primary: $gray4;
|
$primary: $gray4;
|
||||||
$accent: $darkblue;
|
$accent: $red;
|
||||||
$secondary: $gray5;
|
$secondary: $gray5;
|
||||||
$cta: $blue;
|
$cta: $blue;
|
||||||
$danger: $red;
|
$danger: $red;
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
class="a-header rounded"
|
class="a-header rounded"
|
||||||
:style="{
|
:style="{
|
||||||
backgroundImage: `linear-gradient(
|
backgroundImage: `linear-gradient(
|
||||||
37deg, ${album.colors[0]}, ${album.colors[3]}
|
37deg, ${props.album.colors[0]}, ${props.album.colors[3]}
|
||||||
)`,
|
)`,
|
||||||
}"
|
}"
|
||||||
>
|
>
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
v-motion-slide-from-left
|
v-motion-slide-from-left
|
||||||
></div>
|
></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="info">
|
<div class="info" :class="{ nocontrast: isLight() }">
|
||||||
<div class="top" v-motion-slide-from-top>
|
<div class="top" v-motion-slide-from-top>
|
||||||
<div class="h">
|
<div class="h">
|
||||||
<span v-if="album.is_soundtrack">Soundtrack</span>
|
<span v-if="album.is_soundtrack">Soundtrack</span>
|
||||||
@@ -46,14 +46,14 @@
|
|||||||
import useVisibility from "@/composables/useVisibility";
|
import useVisibility from "@/composables/useVisibility";
|
||||||
import useNavStore from "@/stores/nav";
|
import useNavStore from "@/stores/nav";
|
||||||
import useAlbumStore from "@/stores/pages/album";
|
import useAlbumStore from "@/stores/pages/album";
|
||||||
import { ref } from "vue";
|
import { reactive, ref } from "vue";
|
||||||
import { playSources } from "../../composables/enums";
|
import { playSources } from "../../composables/enums";
|
||||||
import { formatSeconds } from "../../composables/perks";
|
import { formatSeconds } from "../../composables/perks";
|
||||||
import { paths } from "../../config";
|
import { paths } from "../../config";
|
||||||
import { AlbumInfo } from "../../interfaces";
|
import { AlbumInfo } from "../../interfaces";
|
||||||
import PlayBtnRect from "../shared/PlayBtnRect.vue";
|
import PlayBtnRect from "../shared/PlayBtnRect.vue";
|
||||||
|
|
||||||
defineProps<{
|
const props = defineProps<{
|
||||||
album: AlbumInfo;
|
album: AlbumInfo;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
@@ -61,7 +61,22 @@ const albumheaderthing = ref<HTMLElement>(null);
|
|||||||
const imguri = paths.images.thumb;
|
const imguri = paths.images.thumb;
|
||||||
const nav = useNavStore();
|
const nav = useNavStore();
|
||||||
|
|
||||||
|
const colors = reactive({
|
||||||
|
color1: props.album.colors[0],
|
||||||
|
color2: props.album.colors[3],
|
||||||
|
});
|
||||||
|
|
||||||
useVisibility(albumheaderthing, nav.toggleShowPlay);
|
useVisibility(albumheaderthing, nav.toggleShowPlay);
|
||||||
|
|
||||||
|
function isLight(rgb: string = props.album.colors[0]) {
|
||||||
|
if (rgb == null || undefined) return false;
|
||||||
|
|
||||||
|
const [r, g, b] = rgb.match(/\d+/g)!.map(Number);
|
||||||
|
const brightness = (r * 299 + g * 587 + b * 114) / 1000;
|
||||||
|
console.log(brightness);
|
||||||
|
|
||||||
|
return brightness > 150;
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
@@ -91,6 +106,10 @@ useVisibility(albumheaderthing, nav.toggleShowPlay);
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.nocontrast {
|
||||||
|
color: $black;
|
||||||
|
}
|
||||||
|
|
||||||
.info {
|
.info {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
display: flex;
|
display: flex;
|
||||||
@@ -98,20 +117,14 @@ useVisibility(albumheaderthing, nav.toggleShowPlay);
|
|||||||
justify-content: flex-end;
|
justify-content: flex-end;
|
||||||
|
|
||||||
.top {
|
.top {
|
||||||
.h {
|
|
||||||
color: #ffffffcb;
|
|
||||||
}
|
|
||||||
|
|
||||||
.title {
|
.title {
|
||||||
font-size: 2.5rem;
|
font-size: 2.5rem;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
color: white;
|
|
||||||
text-transform: capitalize;
|
text-transform: capitalize;
|
||||||
}
|
}
|
||||||
|
|
||||||
.artist {
|
.artist {
|
||||||
font-size: 1.15rem;
|
font-size: 1.15rem;
|
||||||
color: #ffffffe0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,23 +141,6 @@ useVisibility(albumheaderthing, nav.toggleShowPlay);
|
|||||||
font-size: 0.8rem;
|
font-size: 0.8rem;
|
||||||
margin-bottom: 0.75rem;
|
margin-bottom: 0.75rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.play {
|
|
||||||
height: 2.5rem;
|
|
||||||
width: 6rem;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
background: $blue;
|
|
||||||
padding: $small;
|
|
||||||
cursor: pointer;
|
|
||||||
|
|
||||||
.icon {
|
|
||||||
height: 1.5rem;
|
|
||||||
width: 1.5rem;
|
|
||||||
margin-right: $small;
|
|
||||||
background: url(../../assets/icons/play.svg) no-repeat center/cover;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ const menus = [
|
|||||||
}
|
}
|
||||||
|
|
||||||
svg > path {
|
svg > path {
|
||||||
fill: $side-nav-svg;
|
fill: $accent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { playSources } from "@/composables/enums";
|
import { playSources } from "@/composables/enums";
|
||||||
import usePlayFrom from "@/composables/usePlayFrom";
|
import usePlayFrom from "@/composables/usePlayFrom";
|
||||||
import useFStore from "@/stores/folder";
|
import useFStore from "@/stores/pages/folder";
|
||||||
import useAStore from "@/stores/pages/album";
|
import useAStore from "@/stores/pages/album";
|
||||||
import usePStore from "@/stores/pages/playlist";
|
import usePStore from "@/stores/pages/playlist";
|
||||||
import useQStore from "@/stores/queue";
|
import useQStore from "@/stores/queue";
|
||||||
@@ -34,8 +34,9 @@ defineProps<{
|
|||||||
height: 2.5rem;
|
height: 2.5rem;
|
||||||
padding-left: 0.75rem;
|
padding-left: 0.75rem;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
background: linear-gradient(34deg, $accent, $red);
|
background-color: $accent;
|
||||||
user-select: none;
|
user-select: none;
|
||||||
|
color: $white;
|
||||||
transition: all 0.5s ease-in-out;
|
transition: all 0.5s ease-in-out;
|
||||||
|
|
||||||
.icon {
|
.icon {
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ const getAlbumData = async (hash: string, ToastStore: typeof useNotifStore) => {
|
|||||||
info: {
|
info: {
|
||||||
album: "",
|
album: "",
|
||||||
artist: "",
|
artist: "",
|
||||||
|
colors: []
|
||||||
},
|
},
|
||||||
tracks: [],
|
tracks: [],
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user