From 327207f1ab8967ac72371d7941a95039504073e0 Mon Sep 17 00:00:00 2001 From: geoffrey45 Date: Wed, 3 Aug 2022 14:47:29 +0300 Subject: [PATCH] implement show copyright info on album page + rewrite server track and album models to use destructuring --- server/app/api/folder.py | 2 -- server/app/lib/albumslib.py | 1 + server/app/models.py | 47 +++++++++++++++++++------- src/components/FolderView/SongList.vue | 11 ++++++ src/interfaces.ts | 4 +-- src/views/album/Content.vue | 23 +++++++++++-- src/views/album/index.vue | 2 +- 7 files changed, 70 insertions(+), 20 deletions(-) diff --git a/server/app/api/folder.py b/server/app/api/folder.py index 6d1e99d..1cbb057 100644 --- a/server/app/api/folder.py +++ b/server/app/api/folder.py @@ -1,8 +1,6 @@ """ Contains all the folder routes. """ -from app import api -from app import helpers from app import settings from app.lib.folderslib import getFnF from flask import Blueprint diff --git a/server/app/lib/albumslib.py b/server/app/lib/albumslib.py index 6e19652..efb3944 100644 --- a/server/app/lib/albumslib.py +++ b/server/app/lib/albumslib.py @@ -143,6 +143,7 @@ def create_album(track: models.Track) -> dict: "title": track.album, "artist": track.albumartist, "hash": track.albumhash, + "copyright": track.copyright, } album["date"] = track.date diff --git a/server/app/models.py b/server/app/models.py index 432306b..07d1f07 100644 --- a/server/app/models.py +++ b/server/app/models.py @@ -3,6 +3,7 @@ Contains all the models for objects generation and typing. """ from dataclasses import dataclass from dataclasses import field +from operator import itemgetter from typing import List from app import helpers @@ -30,21 +31,37 @@ class Track: date: str image: str uniq_hash: str + copyright: str 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.title = tags["title"] 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.length = int(tags["length"]) self.discnumber = int(tags["discnumber"]) - self.albumhash = tags["albumhash"] - self.date = tags["date"] self.image = tags["albumhash"] + ".webp" self.tracknumber = int(tags["tracknumber"]) @@ -85,17 +102,21 @@ class Album: image: str count: int = 0 duration: int = 0 + copyright: str = field(default="") is_soundtrack: bool = False is_compilation: bool = False is_single: bool = False colors: List[str] = field(default_factory=list) def __init__(self, tags): - self.title = tags["title"] - self.artist = tags["artist"] - self.date = tags["date"] - self.image = tags["image"] - self.hash = tags["hash"] + ( + self.title, + self.artist, + self.date, + self.image, + self.hash, + self.copyright, + ) = itemgetter("title", "artist", "date", "image", "hash", "copyright")(tags) try: self.colors = tags["colors"] diff --git a/src/components/FolderView/SongList.vue b/src/components/FolderView/SongList.vue index 383d13c..29dc07e 100644 --- a/src/components/FolderView/SongList.vue +++ b/src/components/FolderView/SongList.vue @@ -22,6 +22,9 @@
No tracks here
+ @@ -46,6 +49,7 @@ const props = defineProps<{ playlistid?: string; on_album_page?: boolean; disc?: string | number; + copyright?: () => string; }>(); const route = useRoute(); @@ -140,6 +144,13 @@ function getTrackList() { padding: 1rem; } +.copyright { + font-size: 0.8rem; + margin-top: 1rem; + text-align: center; + opacity: 0.5; +} + .table { height: 100%; overflow-y: hidden; diff --git a/src/interfaces.ts b/src/interfaces.ts index a807a2a..41e8075 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -17,6 +17,7 @@ export interface Track { discnumber?: number; index?: number; uniq_hash: string; + copyright?: string; } export interface Folder { @@ -40,6 +41,7 @@ export interface AlbumInfo { is_single: boolean; hash: string; colors: string[]; + copyright?: string; } export interface Artist { @@ -108,5 +110,3 @@ export interface FetchProps { put?: boolean; headers?: {}; } - - diff --git a/src/views/album/Content.vue b/src/views/album/Content.vue index 693b2fb..7847baf 100644 --- a/src/views/album/Content.vue +++ b/src/views/album/Content.vue @@ -1,7 +1,19 @@ @@ -10,11 +22,18 @@ import { Track } from "@/interfaces"; import SongList from "@/components/FolderView/SongList.vue"; -defineProps<{ +const props = defineProps<{ discs: { [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; +};