feat: prepare adding songs

This commit is contained in:
2026-09-01 09:33:05 +02:00
parent 72dada18eb
commit f3d9251eee
18 changed files with 186 additions and 7 deletions
+32
View File
@@ -16,6 +16,38 @@ export interface PlayerSourcePlugin {
*/
'id': string;
/**
* Font-Awesome icon name (without fa and needs to be of free icons
*/
'icon'?: string;
/**
* Describe how files are loaded here
*/
'loading': {
/**
* Set to true if the user needs to load files
*/
'requiresLocalFiles': true;
/**
* The allowed MIME types for loading associated files
*/
'MIMETypes': string;
/**
* Function used to associate the file to the songs of the playlist
* @param files - The files that were picked by the user
* @returns A promise resolving to an array of song identifiers (corresponding to Song.identifier, for association)
*/
'association': ( files: File[] ) => Promise<string[]>;
} | {
/**
* Set to true if the user needs to load files
*/
'requiresLocalFiles': false;
};
/**
* Implement any login flow here. Optional
*/
+7 -1
View File
@@ -22,6 +22,12 @@ export const useLocalPlayer: PlayerSourcePluginInitializer = async (): Promise<P
'pause': player.pause,
'stop': () => player.src = '',
// TODO: Implement
'addSongsFromThisSource': async () => []
'addSongsFromThisSource': async () => [],
'loading': {
'requiresLocalFiles': true,
'MIMETypes': 'audio/mp3,audio/wav',
// TODO: Implement
'association': async () => []
}
};
};
+7 -1
View File
@@ -3,6 +3,9 @@ import type {
PlayerSourcePlugin,
PlayerSourcePluginInitializer
} from '../interface';
import {
addFromAppleMusic
} from './search';
import {
musicKitPlayback
} from './playback';
@@ -49,7 +52,10 @@ export const useMusicKit: PlayerSourcePluginInitializer = ( storefront: string =
'seekTo': controls.seekTo,
'login': login,
// TODO: Implement
'addSongsFromThisSource': async () => []
'addSongsFromThisSource': async () => await addFromAppleMusic(),
'loading': {
'requiresLocalFiles': false
}
};
} else {
throw new Error( 'ERR_AUTH' );
@@ -0,0 +1,10 @@
import type {
MusicKitInstance
} from 'musickitjs-v3-types/MusicKitInstance';
export const searchAlbums = async ( instance: MusicKitInstance, term: string ) => {
const addSelected = ( idx: number ) => {
// TODO: Load album's songs and return them
Promise.resolve();
};
};
@@ -0,0 +1,10 @@
import type {
MusicKitInstance
} from 'musickitjs-v3-types/MusicKitInstance';
import type {
Song
} from '@/ts/dtype/playlist';
export const addFromAppleMusic = async ( instance: MusicKitInstance ): Promise<Song[]> => {
return [];
};
@@ -0,0 +1,10 @@
import type {
MusicKitInstance
} from 'musickitjs-v3-types/MusicKitInstance';
export const searchPlaylists = async ( instance: MusicKitInstance, userPlaylists: boolean = true ) => {
const addSelected = ( idx: number ) => {
// TODO: Load the playlist content and return songs
Promise.resolve();
};
};
@@ -0,0 +1,20 @@
import type {
MusicKitInstance
} from 'musickitjs-v3-types/MusicKitInstance';
export const seachSongs = async ( instance: MusicKitInstance ) => {
const search = async ( term: string ) => {
const params = {
'term': term,
'types': [ 'songs' ],
'l': 'en-us'
};
await instance.api.music( '/v1/catalog/{{storefrontId}}/search', params );
};
const addSelected = ( idx: number ) => {
// TODO: Need to only return the selected song
Promise.resolve();
};
};