cyp/app/js/mpd-mock.js

77 lines
1.6 KiB
JavaScript
Raw Normal View History

2020-03-09 01:06:54 +08:00
import * as mpd from "./mpd.js";
export const escape = mpd.escape;
export function command(cmd) {
2020-03-11 05:11:36 +08:00
console.warn(`mpd-mock does not know "${cmd}"`);
2020-03-09 01:06:54 +08:00
}
export function commandAndStatus(cmd) {
command(cmd);
return status();
}
export function status() {
return {
volume: 50,
elapsed: 10,
duration: 70,
file: "name.mp3",
Title: "Title of song",
Artist: "Artist of song",
Album: "Album of song",
Track: 6,
state: "play",
Id: 2
}
}
export function listQueue() {
return [
2020-03-10 05:24:31 +08:00
{Id:1, Track:5, Title:"Title 1", Artist:"AAA", Album:"BBB", duration:30},
2020-03-09 01:06:54 +08:00
status(),
2020-03-10 05:24:31 +08:00
{Id:3, Track:7, Title:"Title 3", Artist:"CCC", Album:"DDD", duration:230},
2020-03-09 01:06:54 +08:00
];
}
export async function listPlaylists() {
2020-03-10 05:24:31 +08:00
return [
"Playlist 1",
"Playlist 2",
"Playlist 3"
];
2020-03-09 01:06:54 +08:00
}
export async function enqueueByFilter(filter, sort = null) {
let tokens = ["findadd"];
tokens.push(serializeFilter(filter));
// sort && tokens.push("sort", sort); FIXME not implemented in MPD
return command(tokens.join(" "));
}
export async function listPath(path) {
let lines = await command(`lsinfo "${escape(path)}"`);
return parser.pathContents(lines);
}
export async function listTags(tag, filter = null) {
2020-03-12 05:46:28 +08:00
switch (tag) {
case "AlbumArtist": return ["Artist 1", "Artist 2", "Artist 3"];
case "Album": return ["Album 1", "Album 2", "Album 3"];
2020-03-09 01:06:54 +08:00
}
}
export async function listSongs(filter, window = null) {
let tokens = ["find"];
tokens.push(serializeFilter(filter));
if (window) { tokens.push("window", window.join(":")); }
let lines = await command(tokens.join(" "));
return parser.songList(lines);
}
export async function albumArt(songUrl) {
return null;
}
export function init() {}