From 7a418c4e8aaff3c6654ba064d59729e09e37d0f2 Mon Sep 17 00:00:00 2001 From: Ondrej Zara Date: Sun, 8 Mar 2020 18:06:54 +0100 Subject: [PATCH] wip --- app/js/app.js | 6 +++ app/js/component.js | 3 ++ app/js/lib/mpd-mock.js | 83 ++++++++++++++++++++++++++++++++++++++++++ app/js/player.js | 10 ++++- app/js/queue.js | 3 +- 5 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 app/js/component.js create mode 100644 app/js/lib/mpd-mock.js diff --git a/app/js/app.js b/app/js/app.js index 0b56910..5e38ed5 100644 --- a/app/js/app.js +++ b/app/js/app.js @@ -65,3 +65,9 @@ async function init() { init(); + +class App extends HTMLElement { + get mpd() { return mpd; } +} + +customElements.define("cyp-app", App); diff --git a/app/js/component.js b/app/js/component.js new file mode 100644 index 0000000..91b9424 --- /dev/null +++ b/app/js/component.js @@ -0,0 +1,3 @@ +export default class Component extends HTMLElement { + get _app() { return this.closest("cyp-app"); } +} diff --git a/app/js/lib/mpd-mock.js b/app/js/lib/mpd-mock.js new file mode 100644 index 0000000..bb2409b --- /dev/null +++ b/app/js/lib/mpd-mock.js @@ -0,0 +1,83 @@ +import * as mpd from "./mpd.js"; + +export const escape = mpd.escape; + +export function command(cmd) { + console.warn(`MOCK does not know "${cmd}"`); +} + +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 [ + {id:1, Track:5, Title:"Title 1", Artist:"AAA", Album:"BBB", duration:30}, + status(), + {id:3, Track:7, Title:"Title 3", Artist:"CCC", Album:"DDD", duration:230}, + ]; +} + +export async function listPlaylists() { + let lines = await command("listplaylists"); + let parsed = parser.linesToStruct(lines); + + let list = parsed["playlist"]; + if (!list) { return []; } + return (list instanceof Array ? list : [list]); +} + +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) { + let tokens = ["list", tag]; + if (filter) { + tokens.push(serializeFilter(filter)); + + let fakeGroup = Object.keys(filter)[0]; // FIXME hack for MPD < 0.21.6 + tokens.push("group", fakeGroup); + } + let lines = await command(tokens.join(" ")); + let parsed = parser.linesToStruct(lines); + return [].concat(tag in parsed ? parsed[tag] : []); +} + +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() {} diff --git a/app/js/player.js b/app/js/player.js index 77df796..d7338c7 100644 --- a/app/js/player.js +++ b/app/js/player.js @@ -1,8 +1,10 @@ -import * as mpd from "./lib/mpd.js"; +//import * as mpd from "./lib/mpd.js"; +import * as mpd from "./lib/mpd-mock.js"; import * as art from "./lib/art.js"; import * as html from "./lib/html.js"; import * as format from "./lib/format.js"; import * as pubsub from "./lib/pubsub.js"; +import Component from "./component.js"; const DELAY = 1000; const DOM = {}; @@ -130,3 +132,9 @@ export function init(n) { update(); } + +class Player extends Component { + +} + +customElements.define("cyp-player", Player); \ No newline at end of file diff --git a/app/js/queue.js b/app/js/queue.js index f005676..e000b0c 100644 --- a/app/js/queue.js +++ b/app/js/queue.js @@ -1,4 +1,5 @@ -import * as mpd from "./lib/mpd.js"; +// import * as mpd from "./lib/mpd.js"; +import * as mpd from "./lib/mpd-mock.js"; import * as html from "./lib/html.js"; import * as pubsub from "./lib/pubsub.js"; import * as ui from "./lib/ui.js";