implement show copyright info on album page

+ rewrite server track and album models to use destructuring
This commit is contained in:
geoffrey45 2022-08-03 14:47:29 +03:00
parent 7b2e162ed4
commit 327207f1ab
7 changed files with 70 additions and 20 deletions

View File

@ -1,8 +1,6 @@
""" """
Contains all the folder routes. Contains all the folder routes.
""" """
from app import api
from app import helpers
from app import settings from app import settings
from app.lib.folderslib import getFnF from app.lib.folderslib import getFnF
from flask import Blueprint from flask import Blueprint

View File

@ -143,6 +143,7 @@ def create_album(track: models.Track) -> dict:
"title": track.album, "title": track.album,
"artist": track.albumartist, "artist": track.albumartist,
"hash": track.albumhash, "hash": track.albumhash,
"copyright": track.copyright,
} }
album["date"] = track.date album["date"] = track.date

View File

@ -3,6 +3,7 @@ Contains all the models for objects generation and typing.
""" """
from dataclasses import dataclass from dataclasses import dataclass
from dataclasses import field from dataclasses import field
from operator import itemgetter
from typing import List from typing import List
from app import helpers from app import helpers
@ -30,21 +31,37 @@ class Track:
date: str date: str
image: str image: str
uniq_hash: str uniq_hash: str
copyright: str
def __init__(self, tags): def __init__(self, tags):
(
self.title,
self.album,
self.albumartist,
self.genre,
self.albumhash,
self.date,
self.folder,
self.filepath,
self.copyright,
) = itemgetter(
"title",
"album",
"albumartist",
"genre",
"albumhash",
"date",
"folder",
"filepath",
"copyright",
)(
tags
)
self.trackid = tags["_id"]["$oid"] self.trackid = tags["_id"]["$oid"]
self.title = tags["title"]
self.artists = tags["artists"].split(", ") self.artists = tags["artists"].split(", ")
self.albumartist = tags["albumartist"]
self.album = tags["album"]
self.folder = tags["folder"]
self.filepath = tags["filepath"]
self.genre = tags["genre"]
self.bitrate = int(tags["bitrate"]) self.bitrate = int(tags["bitrate"])
self.length = int(tags["length"]) self.length = int(tags["length"])
self.discnumber = int(tags["discnumber"]) self.discnumber = int(tags["discnumber"])
self.albumhash = tags["albumhash"]
self.date = tags["date"]
self.image = tags["albumhash"] + ".webp" self.image = tags["albumhash"] + ".webp"
self.tracknumber = int(tags["tracknumber"]) self.tracknumber = int(tags["tracknumber"])
@ -85,17 +102,21 @@ class Album:
image: str image: str
count: int = 0 count: int = 0
duration: int = 0 duration: int = 0
copyright: str = field(default="")
is_soundtrack: bool = False is_soundtrack: bool = False
is_compilation: bool = False is_compilation: bool = False
is_single: bool = False is_single: bool = False
colors: List[str] = field(default_factory=list) colors: List[str] = field(default_factory=list)
def __init__(self, tags): def __init__(self, tags):
self.title = tags["title"] (
self.artist = tags["artist"] self.title,
self.date = tags["date"] self.artist,
self.image = tags["image"] self.date,
self.hash = tags["hash"] self.image,
self.hash,
self.copyright,
) = itemgetter("title", "artist", "date", "image", "hash", "copyright")(tags)
try: try:
self.colors = tags["colors"] self.colors = tags["colors"]

View File

@ -22,6 +22,9 @@
<div class="text">No tracks here</div> <div class="text">No tracks here</div>
</div> </div>
</div> </div>
<div class="copyright" v-if="copyright">
{{ copyright() }}
</div>
</div> </div>
</template> </template>
@ -46,6 +49,7 @@ const props = defineProps<{
playlistid?: string; playlistid?: string;
on_album_page?: boolean; on_album_page?: boolean;
disc?: string | number; disc?: string | number;
copyright?: () => string;
}>(); }>();
const route = useRoute(); const route = useRoute();
@ -140,6 +144,13 @@ function getTrackList() {
padding: 1rem; padding: 1rem;
} }
.copyright {
font-size: 0.8rem;
margin-top: 1rem;
text-align: center;
opacity: 0.5;
}
.table { .table {
height: 100%; height: 100%;
overflow-y: hidden; overflow-y: hidden;

View File

@ -17,6 +17,7 @@ export interface Track {
discnumber?: number; discnumber?: number;
index?: number; index?: number;
uniq_hash: string; uniq_hash: string;
copyright?: string;
} }
export interface Folder { export interface Folder {
@ -40,6 +41,7 @@ export interface AlbumInfo {
is_single: boolean; is_single: boolean;
hash: string; hash: string;
colors: string[]; colors: string[];
copyright?: string;
} }
export interface Artist { export interface Artist {
@ -108,5 +110,3 @@ export interface FetchProps {
put?: boolean; put?: boolean;
headers?: {}; headers?: {};
} }

View File

@ -1,7 +1,19 @@
<template> <template>
<div class="album-tracks rounded"> <div class="album-tracks rounded">
<div v-for="(disc, key) in discs" class="album-disc"> <div v-for="(disc, key) in discs" class="album-disc">
<SongList :key="key" :tracks="disc" :on_album_page="true" :disc="key" /> <SongList
:key="key"
:tracks="disc"
:on_album_page="true"
:disc="key"
:copyright="
() => {
if (isLastDisc(key)) {
return copyright;
}
}
"
/>
</div> </div>
</div> </div>
</template> </template>
@ -10,11 +22,18 @@
import { Track } from "@/interfaces"; import { Track } from "@/interfaces";
import SongList from "@/components/FolderView/SongList.vue"; import SongList from "@/components/FolderView/SongList.vue";
defineProps<{ const props = defineProps<{
discs: { discs: {
[key: string]: Track[]; [key: string]: Track[];
}; };
copyright: string;
}>(); }>();
// check if the disc is the last disc
const isLastDisc = (disc: string | number) => {
const discs = Object.keys(props.discs);
return discs[discs.length - 1] === disc;
};
</script> </script>
<style lang="scss"> <style lang="scss">

View File

@ -4,7 +4,7 @@
<Header :album="album.info" /> <Header :album="album.info" />
</template> </template>
<template #content> <template #content>
<Content :discs="album.discs" /> <Content :discs="album.discs" :copyright="album.info.copyright" />
</template> </template>
<template #bottom> <template #bottom>
<Bottom <Bottom