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:
@@ -428,7 +428,7 @@
|
||||
"Description": "Control Playtube (YouTube / YouTube Music) from your Stream Dock",
|
||||
"Category": "Playtube",
|
||||
"CategoryIcon": "static/icon/[email protected]",
|
||||
"Version": "1.0.0",
|
||||
"Version": "1.1.0",
|
||||
"OS": [
|
||||
{
|
||||
"Platform": "windows",
|
||||
|
||||
@@ -4027,7 +4027,11 @@ var require_actions = __commonJS({
|
||||
tab: "toggle",
|
||||
// Aktion "Tab wechseln": "toggle" | "youtube" | "music"
|
||||
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 TABS = ["toggle", "youtube", "music"];
|
||||
@@ -4047,8 +4051,14 @@ var require_actions = __commonJS({
|
||||
settings.showTitle = show === true || show === "true";
|
||||
settings.playlistId = typeof settings.playlistId === "string" ? settings.playlistId.trim() : "";
|
||||
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;
|
||||
}
|
||||
function needsPlaylistCover(rawSettings) {
|
||||
const settings = normalizeSettings(rawSettings);
|
||||
return Boolean(settings.playlistId) && !settings.playlistCover;
|
||||
}
|
||||
function pickTab(state, target) {
|
||||
if (!state || !state.tabs) return null;
|
||||
const name = target === "auto" ? state.activeTab : target;
|
||||
@@ -4167,7 +4177,12 @@ var require_actions = __commonJS({
|
||||
},
|
||||
playlist: {
|
||||
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: {
|
||||
request: (s) => ({ cmd: "switch_tab", fields: { target: s.tab === "toggle" ? "auto" : s.tab } }),
|
||||
@@ -4200,6 +4215,7 @@ var require_actions = __commonJS({
|
||||
DEFAULTS,
|
||||
DEFINITIONS,
|
||||
normalizeSettings,
|
||||
needsPlaylistCover,
|
||||
pickTab,
|
||||
wrapTitle,
|
||||
actionIdFromUuid,
|
||||
@@ -4299,6 +4315,7 @@ var require_controller = __commonJS({
|
||||
DEFINITIONS,
|
||||
actionIdFromUuid,
|
||||
buildRequest,
|
||||
needsPlaylistCover,
|
||||
normalizeSettings,
|
||||
pickTab,
|
||||
renderAction
|
||||
@@ -4338,6 +4355,7 @@ var require_controller = __commonJS({
|
||||
this.state = null;
|
||||
this.covers = /* @__PURE__ */ new Map();
|
||||
this.coverLoading = /* @__PURE__ */ new Set();
|
||||
this.playlistCoverTried = /* @__PURE__ */ new Set();
|
||||
this.repeaters = /* @__PURE__ */ new Map();
|
||||
this.pollTimer = null;
|
||||
this.refreshTimer = null;
|
||||
@@ -4347,6 +4365,8 @@ var require_controller = __commonJS({
|
||||
this.host.on("event", (message) => this.handleEvent(message));
|
||||
this.client.on("connected", (name) => {
|
||||
this.logger.info(`Mit Playtube verbunden (${name})`);
|
||||
this.playlistCoverTried.clear();
|
||||
for (const context of this.keys.keys()) this.ensurePlaylistCover(context);
|
||||
this.poll();
|
||||
});
|
||||
this.client.on("disconnected", () => {
|
||||
@@ -4394,6 +4414,7 @@ var require_controller = __commonJS({
|
||||
this.logger.info(`willAppear ${actionId} controller=${payload.controller} info=${info}`);
|
||||
this.keys.set(message.context, { actionId, settings, info, last: null });
|
||||
this.renderKey(message.context);
|
||||
this.ensurePlaylistCover(message.context);
|
||||
if (this.client.connected && !this.state) this.poll();
|
||||
}
|
||||
onSettings(message) {
|
||||
@@ -4402,6 +4423,33 @@ var require_controller = __commonJS({
|
||||
key.settings = message.payload && message.payload.settings || {};
|
||||
key.last = null;
|
||||
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) {
|
||||
const key = this.keys.get(context);
|
||||
|
||||
Reference in New Issue
Block a user