feat: Playlist-Tasten zeigen das Cover der Playlist (1.1.0)
Das Plugin holt fuer jede Playlist-Taste einmal das Cover ueber den neuen Playtube-Befehl playlist_cover (ab Playtube 2.12.0) und speichert es in den Tasten-Einstellungen; das Cover gilt nur fuer die Playlist, fuer die es geholt wurde. Aeltere Playtube: Taste zeigt wie bisher den Namen. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -33,7 +33,7 @@ findest du in der Kategorie **Playtube**. Das Skript installiert auch das Icon-P
|
|||||||
| Stumm | Ton aus/ein, zeigt die Lautstärke |
|
| Stumm | Ton aus/ein, zeigt die Lautstärke |
|
||||||
| Aktueller Titel | Cover und Titel; auf dem Info-Display eine große Karte mit Interpret und Fortschritt |
|
| Aktueller Titel | Cover und Titel; auf dem Info-Display eine große Karte mit Interpret und Fortschritt |
|
||||||
| Gefällt mir, Zufall, Wiederholen | Umschalten, Symbol zeigt den Zustand |
|
| Gefällt mir, Zufall, Wiederholen | Umschalten, Symbol zeigt den Zustand |
|
||||||
| Playlist abspielen | Playlist aus YouTube Music wählen (Liste wird von Playtube geladen) |
|
| Playlist abspielen | Playlist aus YouTube Music wählen (Liste wird von Playtube geladen); die Taste zeigt das Cover der Playlist (ab Playtube 2.12.0, sonst den Namen) |
|
||||||
| Tab wechseln / Playtube anzeigen | YouTube ↔ YouTube Music, Fenster nach vorn |
|
| Tab wechseln / Playtube anzeigen | YouTube ↔ YouTube Music, Fenster nach vorn |
|
||||||
|
|
||||||
Pro Taste einstellbar: Ziel-Tab (automatisch = aktiver Tab, YouTube oder YouTube Music), je
|
Pro Taste einstellbar: Ziel-Tab (automatisch = aktiver Tab, YouTube oder YouTube Music), je
|
||||||
|
|||||||
@@ -428,7 +428,7 @@
|
|||||||
"Description": "Control Playtube (YouTube / YouTube Music) from your Stream Dock",
|
"Description": "Control Playtube (YouTube / YouTube Music) from your Stream Dock",
|
||||||
"Category": "Playtube",
|
"Category": "Playtube",
|
||||||
"CategoryIcon": "static/icon/[email protected]",
|
"CategoryIcon": "static/icon/[email protected]",
|
||||||
"Version": "1.0.0",
|
"Version": "1.1.0",
|
||||||
"OS": [
|
"OS": [
|
||||||
{
|
{
|
||||||
"Platform": "windows",
|
"Platform": "windows",
|
||||||
|
|||||||
@@ -4027,7 +4027,11 @@ var require_actions = __commonJS({
|
|||||||
tab: "toggle",
|
tab: "toggle",
|
||||||
// Aktion "Tab wechseln": "toggle" | "youtube" | "music"
|
// Aktion "Tab wechseln": "toggle" | "youtube" | "music"
|
||||||
playlistId: "",
|
playlistId: "",
|
||||||
playlistTitle: ""
|
playlistTitle: "",
|
||||||
|
playlistCover: "",
|
||||||
|
// Cover-Adresse, von Playtube geholt (Befehl "playlist_cover")
|
||||||
|
playlistCoverId: ""
|
||||||
|
// zu welcher Playlist das gespeicherte Cover gehoert
|
||||||
});
|
});
|
||||||
var TARGETS = ["auto", "youtube", "music"];
|
var TARGETS = ["auto", "youtube", "music"];
|
||||||
var TABS = ["toggle", "youtube", "music"];
|
var TABS = ["toggle", "youtube", "music"];
|
||||||
@@ -4047,8 +4051,14 @@ var require_actions = __commonJS({
|
|||||||
settings.showTitle = show === true || show === "true";
|
settings.showTitle = show === true || show === "true";
|
||||||
settings.playlistId = typeof settings.playlistId === "string" ? settings.playlistId.trim() : "";
|
settings.playlistId = typeof settings.playlistId === "string" ? settings.playlistId.trim() : "";
|
||||||
settings.playlistTitle = typeof settings.playlistTitle === "string" ? settings.playlistTitle : "";
|
settings.playlistTitle = typeof settings.playlistTitle === "string" ? settings.playlistTitle : "";
|
||||||
|
const cover = typeof settings.playlistCover === "string" ? settings.playlistCover : "";
|
||||||
|
settings.playlistCover = cover.startsWith("https://") && settings.playlistCoverId === settings.playlistId ? cover : "";
|
||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
|
function needsPlaylistCover(rawSettings) {
|
||||||
|
const settings = normalizeSettings(rawSettings);
|
||||||
|
return Boolean(settings.playlistId) && !settings.playlistCover;
|
||||||
|
}
|
||||||
function pickTab(state, target) {
|
function pickTab(state, target) {
|
||||||
if (!state || !state.tabs) return null;
|
if (!state || !state.tabs) return null;
|
||||||
const name = target === "auto" ? state.activeTab : target;
|
const name = target === "auto" ? state.activeTab : target;
|
||||||
@@ -4167,7 +4177,12 @@ var require_actions = __commonJS({
|
|||||||
},
|
},
|
||||||
playlist: {
|
playlist: {
|
||||||
request: (s) => s.playlistId ? { cmd: "play_playlist", fields: { playlist: s.playlistId } } : null,
|
request: (s) => s.playlistId ? { cmd: "play_playlist", fields: { playlist: s.playlistId } } : null,
|
||||||
render: (s) => ({ title: s.playlistTitle ? wrapTitle(s.playlistTitle) : "" })
|
// Mit Cover zeigt die Taste das Bild (Titel nur, wenn "Titel anzeigen" an ist); ohne Cover den
|
||||||
|
// Namen wie bisher.
|
||||||
|
render: (s) => ({
|
||||||
|
coverUrl: s.playlistCover || null,
|
||||||
|
title: s.playlistTitle && (!s.playlistCover || s.showTitle) ? wrapTitle(s.playlistTitle) : ""
|
||||||
|
})
|
||||||
},
|
},
|
||||||
switchtab: {
|
switchtab: {
|
||||||
request: (s) => ({ cmd: "switch_tab", fields: { target: s.tab === "toggle" ? "auto" : s.tab } }),
|
request: (s) => ({ cmd: "switch_tab", fields: { target: s.tab === "toggle" ? "auto" : s.tab } }),
|
||||||
@@ -4200,6 +4215,7 @@ var require_actions = __commonJS({
|
|||||||
DEFAULTS,
|
DEFAULTS,
|
||||||
DEFINITIONS,
|
DEFINITIONS,
|
||||||
normalizeSettings,
|
normalizeSettings,
|
||||||
|
needsPlaylistCover,
|
||||||
pickTab,
|
pickTab,
|
||||||
wrapTitle,
|
wrapTitle,
|
||||||
actionIdFromUuid,
|
actionIdFromUuid,
|
||||||
@@ -4299,6 +4315,7 @@ var require_controller = __commonJS({
|
|||||||
DEFINITIONS,
|
DEFINITIONS,
|
||||||
actionIdFromUuid,
|
actionIdFromUuid,
|
||||||
buildRequest,
|
buildRequest,
|
||||||
|
needsPlaylistCover,
|
||||||
normalizeSettings,
|
normalizeSettings,
|
||||||
pickTab,
|
pickTab,
|
||||||
renderAction
|
renderAction
|
||||||
@@ -4338,6 +4355,7 @@ var require_controller = __commonJS({
|
|||||||
this.state = null;
|
this.state = null;
|
||||||
this.covers = /* @__PURE__ */ new Map();
|
this.covers = /* @__PURE__ */ new Map();
|
||||||
this.coverLoading = /* @__PURE__ */ new Set();
|
this.coverLoading = /* @__PURE__ */ new Set();
|
||||||
|
this.playlistCoverTried = /* @__PURE__ */ new Set();
|
||||||
this.repeaters = /* @__PURE__ */ new Map();
|
this.repeaters = /* @__PURE__ */ new Map();
|
||||||
this.pollTimer = null;
|
this.pollTimer = null;
|
||||||
this.refreshTimer = null;
|
this.refreshTimer = null;
|
||||||
@@ -4347,6 +4365,8 @@ var require_controller = __commonJS({
|
|||||||
this.host.on("event", (message) => this.handleEvent(message));
|
this.host.on("event", (message) => this.handleEvent(message));
|
||||||
this.client.on("connected", (name) => {
|
this.client.on("connected", (name) => {
|
||||||
this.logger.info(`Mit Playtube verbunden (${name})`);
|
this.logger.info(`Mit Playtube verbunden (${name})`);
|
||||||
|
this.playlistCoverTried.clear();
|
||||||
|
for (const context of this.keys.keys()) this.ensurePlaylistCover(context);
|
||||||
this.poll();
|
this.poll();
|
||||||
});
|
});
|
||||||
this.client.on("disconnected", () => {
|
this.client.on("disconnected", () => {
|
||||||
@@ -4394,6 +4414,7 @@ var require_controller = __commonJS({
|
|||||||
this.logger.info(`willAppear ${actionId} controller=${payload.controller} info=${info}`);
|
this.logger.info(`willAppear ${actionId} controller=${payload.controller} info=${info}`);
|
||||||
this.keys.set(message.context, { actionId, settings, info, last: null });
|
this.keys.set(message.context, { actionId, settings, info, last: null });
|
||||||
this.renderKey(message.context);
|
this.renderKey(message.context);
|
||||||
|
this.ensurePlaylistCover(message.context);
|
||||||
if (this.client.connected && !this.state) this.poll();
|
if (this.client.connected && !this.state) this.poll();
|
||||||
}
|
}
|
||||||
onSettings(message) {
|
onSettings(message) {
|
||||||
@@ -4402,6 +4423,33 @@ var require_controller = __commonJS({
|
|||||||
key.settings = message.payload && message.payload.settings || {};
|
key.settings = message.payload && message.payload.settings || {};
|
||||||
key.last = null;
|
key.last = null;
|
||||||
this.renderKey(message.context);
|
this.renderKey(message.context);
|
||||||
|
this.ensurePlaylistCover(message.context);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Playlist-Tasten: Cover einmal bei Playtube holen (Befehl "playlist_cover", ab Playtube 2.12.0)
|
||||||
|
* und in den Tasten-Einstellungen speichern - beim naechsten Start ist es sofort da. Eine aeltere
|
||||||
|
* Playtube kennt den Befehl nicht; dann bleibt die Taste wie bisher beim Namen.
|
||||||
|
*/
|
||||||
|
async ensurePlaylistCover(context) {
|
||||||
|
const key = this.keys.get(context);
|
||||||
|
if (!key || key.actionId !== "playlist" || !this.client.connected) return;
|
||||||
|
if (!needsPlaylistCover(key.settings)) return;
|
||||||
|
const playlistId = normalizeSettings(key.settings).playlistId;
|
||||||
|
const attempt = `${context}:${playlistId}`;
|
||||||
|
if (this.playlistCoverTried.has(attempt)) return;
|
||||||
|
this.playlistCoverTried.add(attempt);
|
||||||
|
try {
|
||||||
|
const response = await this.client.request("playlist_cover", { playlist: playlistId });
|
||||||
|
const cover = response && typeof response.cover === "string" && response.cover.startsWith("https://") ? response.cover : "";
|
||||||
|
const current = this.keys.get(context);
|
||||||
|
if (!cover || !current || normalizeSettings(current.settings).playlistId !== playlistId) return;
|
||||||
|
current.settings = { ...current.settings, playlistCover: cover, playlistCoverId: playlistId };
|
||||||
|
current.last = null;
|
||||||
|
this.host.setSettings(context, current.settings);
|
||||||
|
this.renderKey(context);
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.warn(`Playlist-Cover nicht lesbar: ${error.message}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
onKeyDown(context) {
|
onKeyDown(context) {
|
||||||
const key = this.keys.get(context);
|
const key = this.keys.get(context);
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "playtube-streamdock-plugin",
|
"name": "playtube-streamdock-plugin",
|
||||||
"version": "1.0.0",
|
"version": "1.1.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "Stream Dock plugin (Ajazz AKP153E and other Stream Dock devices) to control Playtube",
|
"description": "Stream Dock plugin (Ajazz AKP153E and other Stream Dock devices) to control Playtube",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|||||||
+18
-1
@@ -17,6 +17,8 @@ const DEFAULTS = Object.freeze({
|
|||||||
tab: 'toggle', // Aktion "Tab wechseln": "toggle" | "youtube" | "music"
|
tab: 'toggle', // Aktion "Tab wechseln": "toggle" | "youtube" | "music"
|
||||||
playlistId: '',
|
playlistId: '',
|
||||||
playlistTitle: '',
|
playlistTitle: '',
|
||||||
|
playlistCover: '', // Cover-Adresse, von Playtube geholt (Befehl "playlist_cover")
|
||||||
|
playlistCoverId: '', // zu welcher Playlist das gespeicherte Cover gehoert
|
||||||
});
|
});
|
||||||
|
|
||||||
const TARGETS = ['auto', 'youtube', 'music'];
|
const TARGETS = ['auto', 'youtube', 'music'];
|
||||||
@@ -40,9 +42,18 @@ function normalizeSettings(raw, titleDefault = false) {
|
|||||||
settings.showTitle = show === true || show === 'true';
|
settings.showTitle = show === true || show === 'true';
|
||||||
settings.playlistId = typeof settings.playlistId === 'string' ? settings.playlistId.trim() : '';
|
settings.playlistId = typeof settings.playlistId === 'string' ? settings.playlistId.trim() : '';
|
||||||
settings.playlistTitle = typeof settings.playlistTitle === 'string' ? settings.playlistTitle : '';
|
settings.playlistTitle = typeof settings.playlistTitle === 'string' ? settings.playlistTitle : '';
|
||||||
|
// Ein gespeichertes Cover gilt nur fuer die Playlist, fuer die es geholt wurde.
|
||||||
|
const cover = typeof settings.playlistCover === 'string' ? settings.playlistCover : '';
|
||||||
|
settings.playlistCover = cover.startsWith('https://') && settings.playlistCoverId === settings.playlistId ? cover : '';
|
||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Braucht diese Playlist-Taste noch ein Cover von Playtube? */
|
||||||
|
function needsPlaylistCover(rawSettings) {
|
||||||
|
const settings = normalizeSettings(rawSettings);
|
||||||
|
return Boolean(settings.playlistId) && !settings.playlistCover;
|
||||||
|
}
|
||||||
|
|
||||||
/** Welcher Tab ist gemeint? "auto" = der Tab, den Playtube als aktiv meldet. */
|
/** Welcher Tab ist gemeint? "auto" = der Tab, den Playtube als aktiv meldet. */
|
||||||
function pickTab(state, target) {
|
function pickTab(state, target) {
|
||||||
if (!state || !state.tabs) return null;
|
if (!state || !state.tabs) return null;
|
||||||
@@ -173,7 +184,12 @@ const DEFINITIONS = {
|
|||||||
},
|
},
|
||||||
playlist: {
|
playlist: {
|
||||||
request: (s) => (s.playlistId ? { cmd: 'play_playlist', fields: { playlist: s.playlistId } } : null),
|
request: (s) => (s.playlistId ? { cmd: 'play_playlist', fields: { playlist: s.playlistId } } : null),
|
||||||
render: (s) => ({ title: s.playlistTitle ? wrapTitle(s.playlistTitle) : '' }),
|
// Mit Cover zeigt die Taste das Bild (Titel nur, wenn "Titel anzeigen" an ist); ohne Cover den
|
||||||
|
// Namen wie bisher.
|
||||||
|
render: (s) => ({
|
||||||
|
coverUrl: s.playlistCover || null,
|
||||||
|
title: s.playlistTitle && (!s.playlistCover || s.showTitle) ? wrapTitle(s.playlistTitle) : '',
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
switchtab: {
|
switchtab: {
|
||||||
request: (s) => ({ cmd: 'switch_tab', fields: { target: s.tab === 'toggle' ? 'auto' : s.tab } }),
|
request: (s) => ({ cmd: 'switch_tab', fields: { target: s.tab === 'toggle' ? 'auto' : s.tab } }),
|
||||||
@@ -212,6 +228,7 @@ module.exports = {
|
|||||||
DEFAULTS,
|
DEFAULTS,
|
||||||
DEFINITIONS,
|
DEFINITIONS,
|
||||||
normalizeSettings,
|
normalizeSettings,
|
||||||
|
needsPlaylistCover,
|
||||||
pickTab,
|
pickTab,
|
||||||
wrapTitle,
|
wrapTitle,
|
||||||
actionIdFromUuid,
|
actionIdFromUuid,
|
||||||
|
|||||||
+36
-2
@@ -5,11 +5,12 @@
|
|||||||
* - haelt fuer jede sichtbare Taste Aktion + Einstellungen,
|
* - haelt fuer jede sichtbare Taste Aktion + Einstellungen,
|
||||||
* - fuehrt Tastendruecke als Playtube-Befehle aus (Lautstaerke: Dauerdruck mit Wiederholung),
|
* - fuehrt Tastendruecke als Playtube-Befehle aus (Lautstaerke: Dauerdruck mit Wiederholung),
|
||||||
* - fragt den Status regelmaessig ab und aktualisiert Titel/Zustand/Cover der Tasten,
|
* - fragt den Status regelmaessig ab und aktualisiert Titel/Zustand/Cover der Tasten,
|
||||||
* - beantwortet die Playlist-Anfrage des Property Inspectors.
|
* - beantwortet die Playlist-Anfrage des Property Inspectors,
|
||||||
|
* - holt fuer Playlist-Tasten einmal das Cover bei Playtube und speichert es in den Einstellungen.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const {
|
const {
|
||||||
DEFINITIONS, actionIdFromUuid, buildRequest, normalizeSettings, pickTab, renderAction,
|
DEFINITIONS, actionIdFromUuid, buildRequest, needsPlaylistCover, normalizeSettings, pickTab, renderAction,
|
||||||
} = require('./actions');
|
} = require('./actions');
|
||||||
const { buildInfoSvg, svgToDataUri } = require('./infoPanel');
|
const { buildInfoSvg, svgToDataUri } = require('./infoPanel');
|
||||||
|
|
||||||
@@ -52,6 +53,7 @@ class Controller {
|
|||||||
this.state = null;
|
this.state = null;
|
||||||
this.covers = new Map(); // url -> dataUri (Einfuegereihenfolge = Alter)
|
this.covers = new Map(); // url -> dataUri (Einfuegereihenfolge = Alter)
|
||||||
this.coverLoading = new Set();
|
this.coverLoading = new Set();
|
||||||
|
this.playlistCoverTried = new Set(); // "context:playlistId" - pro Verbindung nur einmal fragen
|
||||||
this.repeaters = new Map(); // context -> {delayTimer, intervalTimer}
|
this.repeaters = new Map(); // context -> {delayTimer, intervalTimer}
|
||||||
this.pollTimer = null;
|
this.pollTimer = null;
|
||||||
this.refreshTimer = null;
|
this.refreshTimer = null;
|
||||||
@@ -62,6 +64,8 @@ class Controller {
|
|||||||
this.host.on('event', (message) => this.handleEvent(message));
|
this.host.on('event', (message) => this.handleEvent(message));
|
||||||
this.client.on('connected', (name) => {
|
this.client.on('connected', (name) => {
|
||||||
this.logger.info(`Mit Playtube verbunden (${name})`);
|
this.logger.info(`Mit Playtube verbunden (${name})`);
|
||||||
|
this.playlistCoverTried.clear();
|
||||||
|
for (const context of this.keys.keys()) this.ensurePlaylistCover(context);
|
||||||
this.poll();
|
this.poll();
|
||||||
});
|
});
|
||||||
this.client.on('disconnected', () => {
|
this.client.on('disconnected', () => {
|
||||||
@@ -113,6 +117,7 @@ class Controller {
|
|||||||
this.logger.info(`willAppear ${actionId} controller=${payload.controller} info=${info}`);
|
this.logger.info(`willAppear ${actionId} controller=${payload.controller} info=${info}`);
|
||||||
this.keys.set(message.context, { actionId, settings, info, last: null });
|
this.keys.set(message.context, { actionId, settings, info, last: null });
|
||||||
this.renderKey(message.context);
|
this.renderKey(message.context);
|
||||||
|
this.ensurePlaylistCover(message.context);
|
||||||
if (this.client.connected && !this.state) this.poll();
|
if (this.client.connected && !this.state) this.poll();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,6 +127,35 @@ class Controller {
|
|||||||
key.settings = (message.payload && message.payload.settings) || {};
|
key.settings = (message.payload && message.payload.settings) || {};
|
||||||
key.last = null;
|
key.last = null;
|
||||||
this.renderKey(message.context);
|
this.renderKey(message.context);
|
||||||
|
this.ensurePlaylistCover(message.context);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Playlist-Tasten: Cover einmal bei Playtube holen (Befehl "playlist_cover", ab Playtube 2.12.0)
|
||||||
|
* und in den Tasten-Einstellungen speichern - beim naechsten Start ist es sofort da. Eine aeltere
|
||||||
|
* Playtube kennt den Befehl nicht; dann bleibt die Taste wie bisher beim Namen.
|
||||||
|
*/
|
||||||
|
async ensurePlaylistCover(context) {
|
||||||
|
const key = this.keys.get(context);
|
||||||
|
if (!key || key.actionId !== 'playlist' || !this.client.connected) return;
|
||||||
|
if (!needsPlaylistCover(key.settings)) return;
|
||||||
|
const playlistId = normalizeSettings(key.settings).playlistId;
|
||||||
|
const attempt = `${context}:${playlistId}`;
|
||||||
|
if (this.playlistCoverTried.has(attempt)) return;
|
||||||
|
this.playlistCoverTried.add(attempt);
|
||||||
|
try {
|
||||||
|
const response = await this.client.request('playlist_cover', { playlist: playlistId });
|
||||||
|
const cover = response && typeof response.cover === 'string' && response.cover.startsWith('https://') ? response.cover : '';
|
||||||
|
const current = this.keys.get(context);
|
||||||
|
// Inzwischen eine andere Playlist gewaehlt oder Taste entfernt -> verwerfen.
|
||||||
|
if (!cover || !current || normalizeSettings(current.settings).playlistId !== playlistId) return;
|
||||||
|
current.settings = { ...current.settings, playlistCover: cover, playlistCoverId: playlistId };
|
||||||
|
current.last = null;
|
||||||
|
this.host.setSettings(context, current.settings);
|
||||||
|
this.renderKey(context);
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.warn(`Playlist-Cover nicht lesbar: ${error.message}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onKeyDown(context) {
|
onKeyDown(context) {
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ class FakeHost extends EventEmitter {
|
|||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.calls = [];
|
this.calls = [];
|
||||||
for (const name of ['setTitle', 'setImage', 'setState', 'showAlert', 'showOk', 'sendToPropertyInspector']) {
|
for (const name of ['setTitle', 'setImage', 'setState', 'setSettings', 'showAlert', 'showOk', 'sendToPropertyInspector']) {
|
||||||
this[name] = (...args) => this.calls.push([name, ...args]);
|
this[name] = (...args) => this.calls.push([name, ...args]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -40,6 +40,7 @@ class FakeClient extends EventEmitter {
|
|||||||
this.state = STATE;
|
this.state = STATE;
|
||||||
this.failWith = null;
|
this.failWith = null;
|
||||||
this.playlists = [{ id: 'LM', title: 'Liked' }];
|
this.playlists = [{ id: 'LM', title: 'Liked' }];
|
||||||
|
this.playlistCover = null; // Antwort auf "playlist_cover"; Error = aeltere Playtube
|
||||||
}
|
}
|
||||||
|
|
||||||
start() {}
|
start() {}
|
||||||
@@ -47,6 +48,10 @@ class FakeClient extends EventEmitter {
|
|||||||
async request(cmd, fields) {
|
async request(cmd, fields) {
|
||||||
if (this.failWith) throw this.failWith;
|
if (this.failWith) throw this.failWith;
|
||||||
this.requests.push({ cmd, ...fields });
|
this.requests.push({ cmd, ...fields });
|
||||||
|
if (cmd === 'playlist_cover') {
|
||||||
|
if (this.playlistCover instanceof Error) throw this.playlistCover;
|
||||||
|
return { ok: true, cover: this.playlistCover };
|
||||||
|
}
|
||||||
return { ok: true };
|
return { ok: true };
|
||||||
}
|
}
|
||||||
async status() { return this.state; }
|
async status() { return this.state; }
|
||||||
@@ -129,7 +134,48 @@ test('Playlist-Taste startet die gewaehlte Playlist und zeigt ihren Namen', asyn
|
|||||||
assert.equal(host.named('setTitle').at(-1)[2], 'Mein Mix');
|
assert.equal(host.named('setTitle').at(-1)[2], 'Mein Mix');
|
||||||
controller.handleEvent({ event: 'keyUp', context: 'p1' });
|
controller.handleEvent({ event: 'keyUp', context: 'p1' });
|
||||||
await tick();
|
await tick();
|
||||||
assert.deepEqual(client.requests, [{ cmd: 'play_playlist', playlist: 'PLabc' }]);
|
assert.deepEqual(client.requests.filter((r) => r.cmd !== 'playlist_cover'), [{ cmd: 'play_playlist', playlist: 'PLabc' }]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Playlist-Taste holt das Cover, speichert es und zeigt es als Bild', async () => {
|
||||||
|
const { host, client, controller, covers } = setup();
|
||||||
|
client.playlistCover = 'https://yt3.googleusercontent.com/c=w544-h544-l90-rj';
|
||||||
|
appear(controller, 'playlist', 'p1', { playlistId: 'PLabc', playlistTitle: 'Mein Mix' });
|
||||||
|
await tick(20);
|
||||||
|
assert.deepEqual(client.requests[0], { cmd: 'playlist_cover', playlist: 'PLabc' });
|
||||||
|
const [, context, saved] = host.named('setSettings').at(-1);
|
||||||
|
assert.equal(context, 'p1');
|
||||||
|
assert.equal(saved.playlistCover, 'https://yt3.googleusercontent.com/c=w544-h544-l90-rj');
|
||||||
|
assert.equal(saved.playlistCoverId, 'PLabc');
|
||||||
|
assert.deepEqual(covers, ['https://yt3.googleusercontent.com/c=w144-h144-l90-rj']);
|
||||||
|
assert.match(host.named('setImage').filter((c) => c[1] === 'p1').at(-1)[2], /^data:image\/jpeg;base64,/);
|
||||||
|
assert.equal(host.named('setTitle').filter((c) => c[1] === 'p1').at(-1)[2], '', 'mit Cover kein Name darueber');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Gespeichertes Cover wird ohne neue Anfrage benutzt, gilt aber nur fuer seine Playlist', async () => {
|
||||||
|
const { host, client, controller } = setup();
|
||||||
|
appear(controller, 'playlist', 'p1', { playlistId: 'PLabc', playlistTitle: 'Mix',
|
||||||
|
playlistCover: 'https://yt3.ggpht.com/a=s88', playlistCoverId: 'PLabc' });
|
||||||
|
await tick(20);
|
||||||
|
assert.equal(client.requests.length, 0);
|
||||||
|
// Andere Playlist gewaehlt: altes Cover verworfen, neues angefragt, solange der Name sichtbar.
|
||||||
|
controller.handleEvent({ event: 'didReceiveSettings', context: 'p1', payload: { settings: {
|
||||||
|
playlistId: 'PLother', playlistTitle: 'Anderer Mix', playlistCover: 'https://yt3.ggpht.com/a=s88', playlistCoverId: 'PLabc' } } });
|
||||||
|
assert.equal(host.named('setTitle').filter((c) => c[1] === 'p1').at(-1)[2], 'Anderer\nMix');
|
||||||
|
await tick(20);
|
||||||
|
assert.deepEqual(client.requests, [{ cmd: 'playlist_cover', playlist: 'PLother' }]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Aeltere Playtube ohne playlist_cover: Taste bleibt beim Namen, nur ein Versuch', async () => {
|
||||||
|
const { host, client, controller } = setup();
|
||||||
|
client.playlistCover = new PlaytubeError('remote', 'unbekannter Befehl: "playlist_cover"');
|
||||||
|
appear(controller, 'playlist', 'p1', { playlistId: 'PLabc', playlistTitle: 'Mix' });
|
||||||
|
await tick(20);
|
||||||
|
controller.handleEvent({ event: 'didReceiveSettings', context: 'p1', payload: { settings: { playlistId: 'PLabc', playlistTitle: 'Mix' } } });
|
||||||
|
await tick(20);
|
||||||
|
assert.equal(client.requests.filter((r) => r.cmd === 'playlist_cover').length, 1);
|
||||||
|
assert.equal(host.named('setSettings').length, 0);
|
||||||
|
assert.equal(host.named('setTitle').filter((c) => c[1] === 'p1').at(-1)[2], 'Mix');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Status aktualisiert Zustand und Lautstaerke-Anzeige, nur bei Aenderung', async () => {
|
test('Status aktualisiert Zustand und Lautstaerke-Anzeige, nur bei Aenderung', async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user