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:
@@ -24,7 +24,7 @@ class FakeHost extends EventEmitter {
|
||||
constructor() {
|
||||
super();
|
||||
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]);
|
||||
}
|
||||
}
|
||||
@@ -40,6 +40,7 @@ class FakeClient extends EventEmitter {
|
||||
this.state = STATE;
|
||||
this.failWith = null;
|
||||
this.playlists = [{ id: 'LM', title: 'Liked' }];
|
||||
this.playlistCover = null; // Antwort auf "playlist_cover"; Error = aeltere Playtube
|
||||
}
|
||||
|
||||
start() {}
|
||||
@@ -47,6 +48,10 @@ class FakeClient extends EventEmitter {
|
||||
async request(cmd, fields) {
|
||||
if (this.failWith) throw this.failWith;
|
||||
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 };
|
||||
}
|
||||
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');
|
||||
controller.handleEvent({ event: 'keyUp', context: 'p1' });
|
||||
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 () => {
|
||||
|
||||
Reference in New Issue
Block a user