mirror of
https://github.com/tcsenpai/swingmusic.git
synced 2025-06-09 12:37:22 +00:00
[client] add playlists and playlist page
This commit is contained in:
parent
e4640d9985
commit
69b691284d
@ -50,7 +50,7 @@ def create_playlist():
|
|||||||
|
|
||||||
|
|
||||||
@playlist_bp.route("/playlist/<playlist_id>/add", methods=["POST"])
|
@playlist_bp.route("/playlist/<playlist_id>/add", methods=["POST"])
|
||||||
def add_track_to_playlist(playlist_id):
|
def add_track_to_playlist(playlist_id: str):
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
|
|
||||||
trackid = data["track"]
|
trackid = data["track"]
|
||||||
@ -61,3 +61,16 @@ def add_track_to_playlist(playlist_id):
|
|||||||
return {"error": str(e)}, 409
|
return {"error": str(e)}, 409
|
||||||
|
|
||||||
return {"msg": "I think It's done"}, 200
|
return {"msg": "I think It's done"}, 200
|
||||||
|
|
||||||
|
|
||||||
|
@playlist_bp.route("/playlist/<playlist_id>")
|
||||||
|
def get_single_p_info(playlist_id: str):
|
||||||
|
for p in api.PLAYLISTS:
|
||||||
|
if p.playlistid == playlist_id:
|
||||||
|
return {"data": p}
|
||||||
|
|
||||||
|
|
||||||
|
# @playlist_bp.route("/playlist/<playlist_id>/info")
|
||||||
|
# def get_playlist_track(playlist_id: str):
|
||||||
|
# tracks = playlistlib.get_playlist_tracks(playlist_id)
|
||||||
|
# return {"data": tracks}
|
||||||
|
@ -49,11 +49,13 @@ def get_album_image(album: list) -> str:
|
|||||||
|
|
||||||
|
|
||||||
def get_album_tracks(album: str, artist: str) -> List:
|
def get_album_tracks(album: str, artist: str) -> List:
|
||||||
return [
|
tracks = []
|
||||||
track
|
|
||||||
for track in api.PRE_TRACKS
|
for track in api.PRE_TRACKS:
|
||||||
if track["album"] == album and track["albumartist"] == artist
|
if track["album"] == album and track["albumartist"] == artist:
|
||||||
]
|
tracks.append(track)
|
||||||
|
|
||||||
|
return tracks
|
||||||
|
|
||||||
|
|
||||||
def create_album(track) -> models.Album:
|
def create_album(track) -> models.Album:
|
||||||
@ -70,6 +72,7 @@ def create_album(track) -> models.Album:
|
|||||||
album["count"] = len(album_tracks)
|
album["count"] = len(album_tracks)
|
||||||
album["duration"] = get_album_duration(album_tracks)
|
album["duration"] = get_album_duration(album_tracks)
|
||||||
album["date"] = album_tracks[0]["date"]
|
album["date"] = album_tracks[0]["date"]
|
||||||
|
|
||||||
album["artistimage"] = urllib.parse.quote_plus(
|
album["artistimage"] = urllib.parse.quote_plus(
|
||||||
album_tracks[0]["albumartist"] + ".webp"
|
album_tracks[0]["albumartist"] + ".webp"
|
||||||
)
|
)
|
||||||
|
@ -25,6 +25,13 @@ def add_track(playlistid: str, trackid: str):
|
|||||||
raise TrackExistsInPlaylist("Track already in playlist.")
|
raise TrackExistsInPlaylist("Track already in playlist.")
|
||||||
|
|
||||||
|
|
||||||
|
def get_playlist_tracks(pid: str):
|
||||||
|
for p in api.PLAYLISTS:
|
||||||
|
if p.playlistid == pid:
|
||||||
|
return p.tracks
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def create_all_playlists():
|
def create_all_playlists():
|
||||||
"""
|
"""
|
||||||
Gets all playlists from the database.
|
Gets all playlists from the database.
|
||||||
|
@ -31,7 +31,7 @@ const menus = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "playlists",
|
name: "playlists",
|
||||||
route_name: "PlaylistView",
|
route_name: "Playlists",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "folders",
|
name: "folders",
|
||||||
|
@ -2,8 +2,10 @@
|
|||||||
<div class="p-header">
|
<div class="p-header">
|
||||||
<div class="info">
|
<div class="info">
|
||||||
<div>
|
<div>
|
||||||
<div class="title">Makaveli Radio</div>
|
<div class="title">{{ props.info.name }}</div>
|
||||||
<div class="metrics rounded border">45 Tracks • 3 Hours 4 Minutes</div>
|
<div class="metrics rounded border">
|
||||||
|
{{ props.info.count }} Tracks • {{ props.info.duration }}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="buttons">
|
<div class="buttons">
|
||||||
<button class="play">
|
<button class="play">
|
||||||
@ -16,12 +18,23 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="last-updated">
|
<div class="last-updated">
|
||||||
<span class="status">Last updated yesterday | </span>
|
<span class="status">Last updated {{props.info.lastUpdated}} | </span>
|
||||||
<span class="edit">Edit</span>
|
<span class="edit">Edit</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
const props = defineProps<{
|
||||||
|
info: {
|
||||||
|
name: string;
|
||||||
|
count: number;
|
||||||
|
duration: string;
|
||||||
|
lastUpdated: string;
|
||||||
|
};
|
||||||
|
}>();
|
||||||
|
</script>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
.p-header {
|
.p-header {
|
||||||
display: grid;
|
display: grid;
|
||||||
@ -30,7 +43,7 @@
|
|||||||
background-image: url("../../assets/images/eggs.jpg");
|
background-image: url("../../assets/images/eggs.jpg");
|
||||||
position: relative;
|
position: relative;
|
||||||
margin-top: $small;
|
margin-top: $small;
|
||||||
border-radius: .75rem;
|
border-radius: 0.75rem;
|
||||||
|
|
||||||
.last-updated {
|
.last-updated {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
@ -69,7 +82,7 @@
|
|||||||
align-items: flex-end;
|
align-items: flex-end;
|
||||||
padding: 1rem 1rem 4rem 1rem;
|
padding: 1rem 1rem 4rem 1rem;
|
||||||
box-shadow: 0 0 1.5rem rgba(0, 0, 0, 0.658);
|
box-shadow: 0 0 1.5rem rgba(0, 0, 0, 0.658);
|
||||||
border-radius: .75rem;
|
border-radius: 0.75rem;
|
||||||
background-color: $body;
|
background-color: $body;
|
||||||
|
|
||||||
@include phone-only {
|
@include phone-only {
|
||||||
@ -90,8 +103,8 @@
|
|||||||
|
|
||||||
.buttons {
|
.buttons {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
bottom:1rem;
|
bottom: 1rem;
|
||||||
left:1rem;
|
left: 1rem;
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: $small;
|
gap: $small;
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<PlayBtn />
|
<PlayBtn />
|
||||||
</div>
|
</div>
|
||||||
<div class="info">
|
<div class="info">
|
||||||
<div class="title">Legends never die</div>
|
<div class="title">Playlists</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="center rounded"></div>
|
<div class="center rounded"></div>
|
||||||
|
44
src/components/playlists/PlaylistCard.vue
Normal file
44
src/components/playlists/PlaylistCard.vue
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
<template>
|
||||||
|
<router-link
|
||||||
|
:to="{ name: 'PlaylistView', params: { pid: props.playlist.playlistid } }"
|
||||||
|
:playlist="props.playlist"
|
||||||
|
class="p-card rounded shadow-sm"
|
||||||
|
>
|
||||||
|
<div class="image rounded"></div>
|
||||||
|
<div class="bottom">
|
||||||
|
<div class="name ellip">{{ props.playlist.name }}</div>
|
||||||
|
<div class="count">N Tracks</div>
|
||||||
|
</div>
|
||||||
|
</router-link>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { Playlist } from "../../interfaces";
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
playlist: Playlist;
|
||||||
|
}>();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
.p-card {
|
||||||
|
width: 100%;
|
||||||
|
background-color: $gray;
|
||||||
|
padding: $small;
|
||||||
|
|
||||||
|
.image {
|
||||||
|
min-width: 100%;
|
||||||
|
height: 8.5rem;
|
||||||
|
background-image: url("../../assets/images/eggs.jpg");
|
||||||
|
}
|
||||||
|
|
||||||
|
.bottom {
|
||||||
|
margin-top: $small;
|
||||||
|
|
||||||
|
.count {
|
||||||
|
font-size: $medium;
|
||||||
|
color: $red;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
@ -74,4 +74,40 @@ async function addTrackToPlaylist(playlist: Playlist, track: Track) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export { createNewPlaylist, getAllPlaylists, addTrackToPlaylist };
|
async function getPTracks(playlistid: string) {
|
||||||
|
const uri = state.settings.uri + "/playlist/" + playlistid;
|
||||||
|
|
||||||
|
let tracks: Track[] = [];
|
||||||
|
|
||||||
|
await axios
|
||||||
|
.get(uri)
|
||||||
|
.then((res) => {
|
||||||
|
tracks = res.data.data;
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
new Notification("Something funny happened!", NotifType.Error);
|
||||||
|
throw new Error(err);
|
||||||
|
});
|
||||||
|
|
||||||
|
return tracks;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getPlaylist(pid: string) {
|
||||||
|
const uri = state.settings.uri + "/playlist/" + pid;
|
||||||
|
|
||||||
|
let playlist: Playlist;
|
||||||
|
|
||||||
|
await axios
|
||||||
|
.get(uri)
|
||||||
|
.then((res) => {
|
||||||
|
playlist = res.data.data;
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
new Notification("Something funny happened!", NotifType.Error);
|
||||||
|
throw new Error(err);
|
||||||
|
});
|
||||||
|
|
||||||
|
return playlist;
|
||||||
|
}
|
||||||
|
|
||||||
|
export { createNewPlaylist, getAllPlaylists, addTrackToPlaylist, getPTracks, getPlaylist };
|
||||||
|
@ -52,6 +52,7 @@ interface Playlist {
|
|||||||
name: string;
|
name: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
image?: string;
|
image?: string;
|
||||||
|
tracks?: Track[];
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Notif {
|
interface Notif {
|
||||||
|
@ -8,6 +8,6 @@ import { createPinia } from 'pinia'
|
|||||||
import "../src/assets/css/global.scss";
|
import "../src/assets/css/global.scss";
|
||||||
|
|
||||||
const app = createApp(App);
|
const app = createApp(App);
|
||||||
app.use(router);
|
|
||||||
app.use(createPinia())
|
app.use(createPinia())
|
||||||
|
app.use(router);
|
||||||
app.mount('#app');
|
app.mount('#app');
|
@ -2,6 +2,7 @@ import { createRouter, createWebHistory } from "vue-router";
|
|||||||
import Home from "../views/Home.vue";
|
import Home from "../views/Home.vue";
|
||||||
import FolderView from "../views/FolderView.vue";
|
import FolderView from "../views/FolderView.vue";
|
||||||
import PlaylistView from "../views/PlaylistView.vue";
|
import PlaylistView from "../views/PlaylistView.vue";
|
||||||
|
import Playlists from "../views/Playlists.vue";
|
||||||
|
|
||||||
import AlbumsExplorer from "../views/AlbumsExplorer.vue";
|
import AlbumsExplorer from "../views/AlbumsExplorer.vue";
|
||||||
import AlbumView from "../views/AlbumView.vue";
|
import AlbumView from "../views/AlbumView.vue";
|
||||||
@ -9,6 +10,9 @@ import AlbumView from "../views/AlbumView.vue";
|
|||||||
import ArtistsExplorer from "../views/ArtistsExplorer.vue";
|
import ArtistsExplorer from "../views/ArtistsExplorer.vue";
|
||||||
import SettingsView from "../views/SettingsView.vue";
|
import SettingsView from "../views/SettingsView.vue";
|
||||||
|
|
||||||
|
import usePStore from "../stores/playlists";
|
||||||
|
import usePTrackStore from "../stores/p.ptracks";
|
||||||
|
|
||||||
const routes = [
|
const routes = [
|
||||||
{
|
{
|
||||||
path: "/",
|
path: "/",
|
||||||
@ -25,9 +29,20 @@ const routes = [
|
|||||||
redirect: "/folder/home",
|
redirect: "/folder/home",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: "/playlist",
|
path: "/playlists",
|
||||||
|
name: "Playlists",
|
||||||
|
component: Playlists,
|
||||||
|
beforeEnter: async () => {
|
||||||
|
await usePStore().fetchAll();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "/playlist/:pid",
|
||||||
name: "PlaylistView",
|
name: "PlaylistView",
|
||||||
component: PlaylistView,
|
component: PlaylistView,
|
||||||
|
beforeEnter: async (to) => {
|
||||||
|
await usePTrackStore().fetchAll(to.params.pid);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: "/albums",
|
path: "/albums",
|
||||||
@ -53,7 +68,7 @@ const routes = [
|
|||||||
path: "/:pathMatch(.*)",
|
path: "/:pathMatch(.*)",
|
||||||
// alias: "*",
|
// alias: "*",
|
||||||
component: () => import("../views/NotFound.vue"),
|
component: () => import("../views/NotFound.vue"),
|
||||||
}
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const router = createRouter({
|
const router = createRouter({
|
||||||
|
15
src/stores/p.ptracks.ts
Normal file
15
src/stores/p.ptracks.ts
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import { defineStore } from "pinia";
|
||||||
|
import { getPlaylist, getPTracks } from "../composables/playlists";
|
||||||
|
import { Track, Playlist } from "../interfaces";
|
||||||
|
|
||||||
|
export default defineStore("playlist-tracks", {
|
||||||
|
state: () => ({
|
||||||
|
playlist: <Playlist>{},
|
||||||
|
}),
|
||||||
|
actions: {
|
||||||
|
async fetchAll(playlistid: string) {
|
||||||
|
const playlist = await getPlaylist(playlistid);
|
||||||
|
this.playlist = playlist;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
@ -7,8 +7,10 @@ export default defineStore("playlists", {
|
|||||||
playlists: <Playlist[]>[],
|
playlists: <Playlist[]>[],
|
||||||
}),
|
}),
|
||||||
actions: {
|
actions: {
|
||||||
fetchAll() {
|
async fetchAll() {
|
||||||
|
const playlists = await getAllPlaylists();
|
||||||
|
|
||||||
|
this.playlists = playlists;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -1,40 +1,29 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="playlist-view">
|
<div class="playlist-view">
|
||||||
<Header :playlist_info="playlist_info" />
|
<Header :info="info" />
|
||||||
<div class="separator no-border"></div>
|
<div class="separator no-border"></div>
|
||||||
|
|
||||||
<div class="songlist rounded">
|
<div class="songlist rounded">
|
||||||
<SongList :songs="songs" />
|
<SongList :songs="playlist.tracks" />
|
||||||
</div>
|
</div>
|
||||||
<div class="separator no-border"></div>
|
<div class="separator no-border"></div>
|
||||||
<FeaturedArtists />
|
<FeaturedArtists />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script setup lang="ts">
|
||||||
import Header from "@/components/PlaylistView/Header.vue";
|
import Header from "../components/PlaylistView/Header.vue";
|
||||||
import SongList from "@/components/FolderView/SongList.vue";
|
import SongList from "../components/FolderView/SongList.vue";
|
||||||
import FeaturedArtists from "@/components/PlaylistView/FeaturedArtists.vue";
|
import FeaturedArtists from "../components/PlaylistView/FeaturedArtists.vue";
|
||||||
import state from "@/composables/state";
|
import usePTrackStore from "../stores/p.ptracks";
|
||||||
export default {
|
|
||||||
components: {
|
const playlist = usePTrackStore().playlist;
|
||||||
Header,
|
|
||||||
SongList,
|
const info = {
|
||||||
FeaturedArtists,
|
name: playlist.name,
|
||||||
},
|
count: playlist.tracks.length,
|
||||||
setup() {
|
duration: "3 hours, 4 minutes",
|
||||||
return {
|
lastUpdated: "yesterday",
|
||||||
songs: state.queue,
|
|
||||||
playlist_info: {
|
|
||||||
name: "Dax Radio",
|
|
||||||
count: state.folder_song_list.value.length,
|
|
||||||
duration: "0:00",
|
|
||||||
image: "../../assets/images/null.webp",
|
|
||||||
artist: "",
|
|
||||||
artist_image: "",
|
|
||||||
},
|
|
||||||
};
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
32
src/views/Playlists.vue
Normal file
32
src/views/Playlists.vue
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<template>
|
||||||
|
<div id="p-view">
|
||||||
|
<div class="grid">
|
||||||
|
<PlaylistCard
|
||||||
|
v-for="p in pStore.playlists"
|
||||||
|
:key="p.playlistid"
|
||||||
|
:playlist="p"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import PlaylistCard from "../components/playlists/PlaylistCard.vue";
|
||||||
|
|
||||||
|
import usePStore from "../stores/playlists";
|
||||||
|
const pStore = usePStore();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
#p-view {
|
||||||
|
margin: $small;
|
||||||
|
padding: $small;
|
||||||
|
overflow: auto;
|
||||||
|
|
||||||
|
.grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr));
|
||||||
|
gap: 1rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
Loading…
x
Reference in New Issue
Block a user