fix playing from album bug when there's inconsistent discs

~ eg. when there's no disc 1, but there's disc 2, or 3
This commit is contained in:
geoffrey45
2022-12-24 17:26:03 +03:00
committed by Mungai Njoroge
parent 7f0fe88c43
commit c52390117e
6 changed files with 17 additions and 49 deletions
-1
View File
@@ -26,7 +26,6 @@ const getAlbumData = async (hash: string, ToastStore: typeof useNotifStore) => {
if (status == 204) { if (status == 204) {
ToastStore().showNotification("Album not created yet!", NotifType.Error); ToastStore().showNotification("Album not created yet!", NotifType.Error);
} }
return data as AlbumData; return data as AlbumData;
}; };
+4 -2
View File
@@ -16,15 +16,17 @@ export interface Track extends AlbumDisc {
filepath?: string; filepath?: string;
duration?: number; duration?: number;
bitrate: number; bitrate: number;
genre?: string;
image: string; image: string;
track: number; track: number;
disc: number; disc: number;
index: number; index: number;
trackhash: string; trackhash: string;
copyright?: string;
filetype: string; filetype: string;
is_favorite: boolean; is_favorite: boolean;
genre?: string;
copyright?: string;
master_index?: number;
} }
export interface Folder { export interface Folder {
+11 -17
View File
@@ -9,7 +9,6 @@ import { maxAbumCards } from "@/stores/content-width";
import { getAlbum, getAlbumsFromArtist } from "../../composables/fetch/album"; import { getAlbum, getAlbumsFromArtist } from "../../composables/fetch/album";
import { Album, FuseResult, Track } from "../../interfaces"; import { Album, FuseResult, Track } from "../../interfaces";
import { useNotifStore } from "../notification"; import { useNotifStore } from "../notification";
import router from "@/router";
interface Disc { interface Disc {
[key: string]: Track[]; [key: string]: Track[];
@@ -25,12 +24,6 @@ function sortByTrackNumber(tracks: Track[]) {
}); });
} }
// function albumHasNoDiscs(album: Album) {
// if (album.is_single) return true;
// return false;
// }
/** /**
* *
* @param tracks The raw tracklist from the server * @param tracks The raw tracklist from the server
@@ -39,8 +32,10 @@ function sortByTrackNumber(tracks: Track[]) {
function createDiscs(tracks: Track[]) { function createDiscs(tracks: Track[]) {
return tracks.reduce((group, track) => { return tracks.reduce((group, track) => {
const { disc } = track; const { disc } = track;
group[disc] = group[disc] ?? []; group[disc] = group[disc] ?? [];
group[disc].push(track); group[disc].push(track);
return group; return group;
}, {} as Disc); }, {} as Disc);
} }
@@ -49,7 +44,7 @@ export default defineStore("album", {
state: () => ({ state: () => ({
query: "", query: "",
info: <Album>{}, info: <Album>{},
rawTracks: <Track[]>[], srcTracks: <Track[]>[],
albumArtists: <{ artisthash: string; albums: Album[] }[]>[], albumArtists: <{ artisthash: string; albums: Album[] }[]>[],
bio: null, bio: null,
}), }),
@@ -62,8 +57,14 @@ export default defineStore("album", {
async fetchTracksAndArtists(hash: string) { async fetchTracksAndArtists(hash: string) {
const album = await getAlbum(hash, useNotifStore); const album = await getAlbum(hash, useNotifStore);
this.rawTracks = album.tracks; this.srcTracks = album.tracks;
this.info = album.info; this.info = album.info;
this.srcTracks = sortByTrackNumber(this.srcTracks);
this.srcTracks.forEach((t, index) => {
t.master_index = index;
});
}, },
async fetchArtistAlbums() { async fetchArtistAlbums() {
const albumartists = this.info.albumartists; const albumartists = this.info.albumartists;
@@ -85,14 +86,7 @@ export default defineStore("album", {
}, },
getters: { getters: {
discs(): Disc { discs(): Disc {
return createDiscs(sortByTrackNumber(this.rawTracks)); return createDiscs(this.srcTracks);
},
allTracks(): Track[] {
return Object.keys(this.discs).reduce((tracks: Track[], disc) => {
const disc_tracks = this.discs[disc];
return [...tracks, ...disc_tracks];
}, []);
}, },
filteredTracks(): ComputedRef<FuseResult[]> { filteredTracks(): ComputedRef<FuseResult[]> {
const discs = this.discs; const discs = this.discs;
-1
View File
@@ -46,7 +46,6 @@ export default defineStore("Queue", {
play(index: number = 0) { play(index: number = 0) {
if (this.tracklist.length === 0) return; if (this.tracklist.length === 0) return;
this.currentindex = index; this.currentindex = index;
console.log(this.tracklist.length);
if (!this.mousover) { if (!this.mousover) {
this.queueScrollFunction(this.currentindex - 1); this.queueScrollFunction(this.currentindex - 1);
-24
View File
@@ -1,24 +0,0 @@
<template>
<div class="bottom-content">
<FeaturedArtists :artists="artists" />
<AlbumBio
:bio="bio"
:images="{ album: image, artist: artists[0]?.image }"
/>
</div>
</template>
<script setup lang="ts">
import { Artist } from "@/interfaces";
import FeaturedArtists from "@/components/PlaylistView/FeaturedArtists.vue";
import AlbumBio from "@/components/AlbumView/AlbumBio.vue";
defineProps<{
artists: Artist[];
bio: string | null;
image: string;
}>();
</script>
<style lang="scss"></style>
+2 -4
View File
@@ -11,9 +11,7 @@
<component <component
:is="item.component" :is="item.component"
v-bind="item.props" v-bind="item.props"
@playThis=" @playThis="playFromAlbum(item.props.track.master_index)"
playFromAlbum(item.props.track.index - item.props.track.disc)
"
/> />
</div> </div>
</RecycleScroller> </RecycleScroller>
@@ -122,7 +120,7 @@ const scrollerItems = computed(() => {
function playFromAlbum(index: number) { function playFromAlbum(index: number) {
const { title, albumartists, albumhash } = album.info; const { title, albumartists, albumhash } = album.info;
queue.playFromAlbum(title, albumhash, album.allTracks); queue.playFromAlbum(title, albumhash, album.srcTracks);
queue.play(index); queue.play(index);
} }