@doitian/dsh-music 0.1.6 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -6
- package/lib/dj.js +151 -16
- package/lib/index.js +45 -1
- package/lib/panel.html +348 -163
- package/lib/router.js +41 -1
- package/lib/session.js +57 -0
- package/lib/state.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -32,7 +32,7 @@ Click **登录 Sign in** in the player and scan the QR code with the NetEase Clo
|
|
|
32
32
|
| `music_play` | Queue and play, by ids or a search query |
|
|
33
33
|
| `music_queue` | Show, append, insert, replace, remove, jump, clear |
|
|
34
34
|
| `music_control` | Play, pause, next, previous, seek, volume, mute, mode |
|
|
35
|
-
| `music_dj` | Run or configure the AI DJ, with an optional mood brief |
|
|
35
|
+
| `music_dj` | Run or configure the AI DJ, with an optional mood brief or a temporary boost |
|
|
36
36
|
| `music_now_playing` | What is playing and next, and whether you're signed in |
|
|
37
37
|
| `music_login` | Status, QR, poll, set a cookie, log out |
|
|
38
38
|
|
|
@@ -40,27 +40,31 @@ Music plays in the Harness window, so keep it open. Playback continues while you
|
|
|
40
40
|
|
|
41
41
|
## Using the player
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
On a wide window the player has two columns: what is playing on the left — cover, the song's controls, transport and lyrics — and what comes next on the right — the AI DJ card and the queue. On a narrow one they stack.
|
|
44
|
+
|
|
45
|
+
**Quality.** Pick a level under the transport controls: `standard`, `higher`, `exhigh` (320 kbps, the default), `lossless`, `hires`, or the spatial tiers `jymaster`, `dolby`, `sky`, `jyeffect`. If a track doesn't offer the level, playback steps down until something plays, and the caption shows what was actually served.
|
|
44
46
|
|
|
45
47
|
**Taste.** Each track is liked, unrated or disliked:
|
|
46
48
|
|
|
47
49
|
| Control | Effect |
|
|
48
50
|
|---|---|
|
|
49
|
-
| ♡ (
|
|
50
|
-
| ✕ (
|
|
51
|
+
| ♡ (beside the title, or on a queue row) | Like on your NetEase account. Click again to unlike. |
|
|
52
|
+
| ✕ (beside the title) | Dislike: the track leaves the queue, and the next one plays. Local only; the DJ stops picking it. |
|
|
51
53
|
| ✕ (queue row) | Remove the track. An unrated track is also recorded as disliked. |
|
|
52
54
|
|
|
53
55
|
**Skips.** Pressing next before 30 s (or before a quarter of a long track) counts as a skip. One skip lowers a track's rank; two remove it from the DJ's picks, and skipped plays count against the artist. A dislike is not also counted as a skip.
|
|
54
56
|
|
|
55
57
|
## The AI DJ
|
|
56
58
|
|
|
57
|
-
Turn it on in the player or with `music_dj`. When fewer than 3 tracks remain, the DJ appends a batch of 5. It only stocks the queue; it never starts or stops playback.
|
|
59
|
+
Turn it on with the switch in the player's AI DJ card, or with `music_dj`. When fewer than 3 tracks remain, the DJ appends a batch of 5. It only stocks the queue; it never starts or stops playback.
|
|
58
60
|
|
|
59
61
|
**How it learns your taste:** from your NetEase likes, and from songs you hear through. A song the DJ picked counts only once you've listened past the skip window, so its own picks can't teach it what you like.
|
|
60
62
|
|
|
61
63
|
**Where it looks:** songs similar to what you've heard and liked, personal FM and liked songs you haven't heard in three days (when signed in), the daily recommendations, new songs, and the four main charts. Signed in, the charts and new songs get fewer slots and your own sources more. Each source is cached for hours and sampled, so batches vary; requests to NetEase are spaced out rather than sent in a burst.
|
|
62
64
|
|
|
63
|
-
**
|
|
65
|
+
**Boosts.** Want more songs like the one playing for a while, or fewer, without a lasting like or dislike? Press **▲** (more like this) or **▼** (fewer like this) beside the song title. A boost lasts an hour, then expires on its own. While the DJ is on, **▲** also queues a few similar songs right after the current one, and **▼** takes the DJ's upcoming picks that are like it out of the queue (songs you queued yourself stay). Active boosts are listed in the AI DJ card with their time left; press ✕ on one, or the filled arrow, to end it early. The agent can set them too, for any length from 5 minutes to 12 hours.
|
|
66
|
+
|
|
67
|
+
**Mood brief.** Type a mood in the AI DJ card, such as `雨天 爵士` or `90s cantopop`. The DJ searches NetEase playlists for it. With a model available, the brief is first rewritten into Chinese search terms, once per brief.
|
|
64
68
|
|
|
65
69
|
**Who chooses:**
|
|
66
70
|
|
package/lib/dj.js
CHANGED
|
@@ -67,6 +67,18 @@ const SEED_HISTORY = 20;
|
|
|
67
67
|
/** Seeds taken from what was played; the rest come from likes. */
|
|
68
68
|
const HISTORY_SEEDS = 2;
|
|
69
69
|
|
|
70
|
+
/** "More like this" boosts that seed similarity, ahead of the regular seeds. */
|
|
71
|
+
const BOOST_SEEDS = 2;
|
|
72
|
+
|
|
73
|
+
/** Songs like a "more" boost queued straight after the current one. */
|
|
74
|
+
const BOOST_NEXT = 3;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* A boost weighs as much as the mood brief: both are the listener saying what
|
|
78
|
+
* they want now, and a boost would be no use if a favourite artist outranked it.
|
|
79
|
+
*/
|
|
80
|
+
const BOOST_WEIGHT = 3.0;
|
|
81
|
+
|
|
70
82
|
/** The newest likes whose artists inform the taste picture. */
|
|
71
83
|
const LIKED_TASTE = 200;
|
|
72
84
|
|
|
@@ -148,6 +160,14 @@ const SKIPS_TO_REPORT_ARTIST = 2;
|
|
|
148
160
|
/** Prefix for the minted curation identity, so logs and health read clearly. */
|
|
149
161
|
const SESSION_ID_PREFIX = 'music-dj-';
|
|
150
162
|
|
|
163
|
+
/** One line of the brief naming the boosts in one direction, or nothing. */
|
|
164
|
+
function boostLine(boosts, direction, heading) {
|
|
165
|
+
const named = (boosts ?? [])
|
|
166
|
+
.filter((boost) => boost.direction === direction)
|
|
167
|
+
.map((boost) => `${boost.name} — ${(boost.artists ?? []).join('/')}`);
|
|
168
|
+
return named.length ? `${heading}: ${named.join('; ')}` : '';
|
|
169
|
+
}
|
|
170
|
+
|
|
151
171
|
/**
|
|
152
172
|
* The provider-visible identity of the DJ's curation conversation.
|
|
153
173
|
*
|
|
@@ -442,7 +462,17 @@ export class AiDj {
|
|
|
442
462
|
...[...digest.skipCounts].filter(([, skips]) => skips >= SKIPS_TO_EXCLUDE).map(([id]) => id),
|
|
443
463
|
]);
|
|
444
464
|
const brief = prompt.trim();
|
|
445
|
-
const
|
|
465
|
+
const boosts = this.store.activeBoosts();
|
|
466
|
+
const fewer = new Set(boosts.filter((boost) => boost.direction === 'less').map((boost) => boost.id));
|
|
467
|
+
for (const id of fewer) excluded.add(id);
|
|
468
|
+
// A "more" boost seeds first, and its similar songs are kept whole; a
|
|
469
|
+
// "less" one never seeds.
|
|
470
|
+
const boostSeeds = boosts
|
|
471
|
+
.filter((boost) => boost.direction === 'more')
|
|
472
|
+
.map((boost) => boost.id)
|
|
473
|
+
.slice(0, BOOST_SEEDS);
|
|
474
|
+
const seeds = [...boostSeeds, ...this.#seeds(digest).filter((id) => !boostSeeds.includes(id) && !fewer.has(id))];
|
|
475
|
+
const nearBoosts = this.#nearBoosts(boosts);
|
|
446
476
|
// Every source is fetched at once and fails alone; the pool is then
|
|
447
477
|
// assembled in priority order, so a track two sources share is claimed by
|
|
448
478
|
// the one that ranks it higher, however the requests happened to finish.
|
|
@@ -452,7 +482,7 @@ export class AiDj {
|
|
|
452
482
|
prompt: brief ? settled(briefing.then((result) => result.tracks)) : [],
|
|
453
483
|
liked: settled(this.#tracksByIds(this.#likedSample(excluded))),
|
|
454
484
|
fm: settled(this.#fmTracks()),
|
|
455
|
-
similar: settled(this.#similarTracks(seeds, excluded)),
|
|
485
|
+
similar: settled(this.#similarTracks(seeds, excluded, boostSeeds.length + 1, boosts)),
|
|
456
486
|
daily: settled(this.#feedTracks(`daily:${this.#account()}`, TTL.daily, () => this.api.recommendSongs(30), this.#quota().daily, excluded)),
|
|
457
487
|
new: settled(this.#feedTracks('new', TTL.new, () => this.api.personalizedNewsongs(30), this.#quota().new, excluded)),
|
|
458
488
|
chart: settled(this.#chartTracks(excluded)),
|
|
@@ -462,13 +492,14 @@ export class AiDj {
|
|
|
462
492
|
// likes cost a lookup after the first plan.
|
|
463
493
|
const likedTaste = this.#tracksByIds(this.store.feedback.likes.slice(0, LIKED_TASTE)).catch(() => []);
|
|
464
494
|
|
|
495
|
+
const near = await nearBoosts;
|
|
465
496
|
const pool = [];
|
|
466
497
|
const seen = new Set();
|
|
467
498
|
for (const origin of ORIGINS) {
|
|
468
499
|
for (const track of await sources[origin]) {
|
|
469
500
|
if (!track?.id || seen.has(track.id) || excluded.has(track.id)) continue;
|
|
470
501
|
seen.add(track.id);
|
|
471
|
-
pool.push({ ...track, origin });
|
|
502
|
+
pool.push({ ...track, origin, ...this.#boostTag(track, near) });
|
|
472
503
|
}
|
|
473
504
|
}
|
|
474
505
|
const trimmed = pool.slice(0, MAX_POOL);
|
|
@@ -478,11 +509,109 @@ export class AiDj {
|
|
|
478
509
|
: trimmed;
|
|
479
510
|
return {
|
|
480
511
|
pool: covered,
|
|
481
|
-
digest: this.#withLikes(digest, await likedTaste),
|
|
512
|
+
digest: { ...this.#withLikes(digest, await likedTaste), boosts },
|
|
482
513
|
terms: briefing ? (await briefing).terms : [],
|
|
483
514
|
};
|
|
484
515
|
}
|
|
485
516
|
|
|
517
|
+
// ---------------------------------------------------------------- boosts
|
|
518
|
+
|
|
519
|
+
/** A track's similar songs, cached for a day like every similarity list. */
|
|
520
|
+
#similarOf(id) {
|
|
521
|
+
return this.cache
|
|
522
|
+
.get(`similar:${id}`, TTL.similar, () => this.pacer.run(() => this.api.simiSongs(id, { limit: 20 })))
|
|
523
|
+
.catch(() => []);
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
/**
|
|
527
|
+
* What "like this track" means for a boost: its similar songs, or — for a
|
|
528
|
+
* track NetEase has none for, such as 晴天 — its first artist's songs, so a
|
|
529
|
+
* boost is never silently a no-op.
|
|
530
|
+
*/
|
|
531
|
+
async #neighboursOf(boost) {
|
|
532
|
+
const similar = await this.#similarOf(boost.id);
|
|
533
|
+
const artist = boost.artists?.[0];
|
|
534
|
+
if (similar.length > 0 || !artist || !this.api.searchSongs) return similar;
|
|
535
|
+
const songs = await this.cache
|
|
536
|
+
.get(`artist:${artist}`, TTL.similar, () =>
|
|
537
|
+
this.pacer.run(() => this.api.searchSongs(artist, { limit: 20 }).then((result) => result.tracks)),
|
|
538
|
+
)
|
|
539
|
+
.catch(() => []);
|
|
540
|
+
return songs.filter((track) => track.id !== boost.id && (track.artists ?? []).includes(artist));
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
/**
|
|
544
|
+
* What each boost reaches: its similar songs, and its artists.
|
|
545
|
+
* @returns {Promise<{more: {ids: Set<number>, artists: Set<string>}, less: {ids: Set<number>, artists: Set<string>}}>}
|
|
546
|
+
*/
|
|
547
|
+
async #nearBoosts(boosts) {
|
|
548
|
+
const near = { more: { ids: new Set(), artists: new Set() }, less: { ids: new Set(), artists: new Set() } };
|
|
549
|
+
await Promise.all(
|
|
550
|
+
boosts.map(async (boost) => {
|
|
551
|
+
const reach = near[boost.direction];
|
|
552
|
+
if (!reach) return;
|
|
553
|
+
for (const artist of boost.artists ?? []) reach.artists.add(artist);
|
|
554
|
+
for (const track of await this.#neighboursOf(boost)) reach.ids.add(track.id);
|
|
555
|
+
}),
|
|
556
|
+
);
|
|
557
|
+
return near;
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
/**
|
|
561
|
+
* Whether a candidate is near a boost. "Less" wins a tie: steering away is
|
|
562
|
+
* the stronger ask, and a song near both is the one the listener is unsure of.
|
|
563
|
+
*/
|
|
564
|
+
#boostTag(track, near) {
|
|
565
|
+
const touches = (reach) =>
|
|
566
|
+
reach.ids.has(track.id) || (track.artists ?? []).some((artist) => reach.artists.has(artist));
|
|
567
|
+
if (touches(near.less)) return { boost: 'less' };
|
|
568
|
+
if (touches(near.more)) return { boost: 'more' };
|
|
569
|
+
return {};
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
/**
|
|
573
|
+
* Make a fresh boost felt now rather than a batch or two later.
|
|
574
|
+
*
|
|
575
|
+
* "More" queues a few songs like it straight after the current one; "less"
|
|
576
|
+
* takes the DJ's own upcoming picks that are like it out of the queue — never
|
|
577
|
+
* a track the listener queued, and never the one playing. Both only while the
|
|
578
|
+
* DJ is on: with it off, the queue is the listener's alone.
|
|
579
|
+
*
|
|
580
|
+
* @param {{id: number, artists?: string[]}} track
|
|
581
|
+
* @param {'more'|'less'|'none'} direction
|
|
582
|
+
* @returns {Promise<{queued: number, removed: number}>}
|
|
583
|
+
*/
|
|
584
|
+
async applyBoost(track, direction) {
|
|
585
|
+
const effect = { queued: 0, removed: 0 };
|
|
586
|
+
if (!this.player.dj.enabled || !track?.id) return effect;
|
|
587
|
+
const similar = await this.#neighboursOf(track);
|
|
588
|
+
if (direction === 'more') {
|
|
589
|
+
const digest = this.store.tasteDigest();
|
|
590
|
+
const blocked = new Set([...digest.dislikedIds, ...digest.recentIds, ...this.player.queue.map((entry) => entry.id)]);
|
|
591
|
+
const next = sampleInOrder(similar.filter((entry) => entry?.id && !blocked.has(entry.id)), BOOST_NEXT);
|
|
592
|
+
if (next.length === 0) return effect;
|
|
593
|
+
const covered = next.some((entry) => !entry.picUrl)
|
|
594
|
+
? await this.pacer.run(() => this.api.withCovers(next)).catch(() => next)
|
|
595
|
+
: next;
|
|
596
|
+
effect.queued = this.player.insertNext(covered, { source: 'heuristic', queuedBy: 'dj' }).added;
|
|
597
|
+
} else if (direction === 'less') {
|
|
598
|
+
const near = new Set(similar.map((entry) => entry.id));
|
|
599
|
+
const artists = new Set(track.artists ?? []);
|
|
600
|
+
for (let index = this.player.queue.length - 1; index > this.player.index; index -= 1) {
|
|
601
|
+
const entry = this.player.queue[index];
|
|
602
|
+
if (entry.queuedBy !== 'dj') continue;
|
|
603
|
+
if (near.has(entry.id) || (entry.artists ?? []).some((artist) => artists.has(artist))) {
|
|
604
|
+
this.player.remove(index);
|
|
605
|
+
effect.removed += 1;
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
if (effect.queued || effect.removed) {
|
|
610
|
+
this.logger?.info?.(`[music] boost ${direction} on ${track.id}: queued ${effect.queued}, removed ${effect.removed}`);
|
|
611
|
+
}
|
|
612
|
+
return effect;
|
|
613
|
+
}
|
|
614
|
+
|
|
486
615
|
/**
|
|
487
616
|
* Who the personal sources belong to. The cookie, not the account record,
|
|
488
617
|
* because the record is fetched after a sign-in and would briefly read the
|
|
@@ -548,21 +677,21 @@ export class AiDj {
|
|
|
548
677
|
}
|
|
549
678
|
|
|
550
679
|
/**
|
|
551
|
-
* Similar tracks for each seed. Every eligible track of the
|
|
552
|
-
* one playing — is kept, and the other seeds
|
|
680
|
+
* Similar tracks for each seed. Every eligible track of the leading seeds —
|
|
681
|
+
* the boosted ones, then the one playing — is kept, and the other seeds
|
|
682
|
+
* share what is left of the quota.
|
|
553
683
|
*/
|
|
554
|
-
async #similarTracks(seeds, excluded) {
|
|
684
|
+
async #similarTracks(seeds, excluded, leading = 1, boosts = []) {
|
|
555
685
|
const lists = await Promise.all(
|
|
556
|
-
seeds.map((seed) =>
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
),
|
|
686
|
+
seeds.map((seed) => {
|
|
687
|
+
const boost = boosts.find((entry) => entry.id === seed);
|
|
688
|
+
return boost ? this.#neighboursOf(boost) : this.#similarOf(seed);
|
|
689
|
+
}),
|
|
561
690
|
);
|
|
562
691
|
const eligible = (tracks) => (tracks ?? []).filter((track) => track?.id && !excluded.has(track.id));
|
|
563
|
-
const
|
|
564
|
-
const lead =
|
|
565
|
-
return [...lead, ...sampleInOrder(
|
|
692
|
+
const eligibleLists = lists.map(eligible);
|
|
693
|
+
const lead = eligibleLists.slice(0, leading).flat().slice(0, this.#quota().similar);
|
|
694
|
+
return [...lead, ...sampleInOrder(eligibleLists.slice(leading).flat(), this.#quota().similar - lead.length)];
|
|
566
695
|
}
|
|
567
696
|
|
|
568
697
|
/**
|
|
@@ -838,7 +967,8 @@ export class AiDj {
|
|
|
838
967
|
const label = (track) => `${track.name} — ${(track.artists ?? []).join('/')}`;
|
|
839
968
|
const catalogue = pool
|
|
840
969
|
.map((track, index) =>
|
|
841
|
-
`${index}. ${label(track)}${track.album ? ` (${track.album})` : ''}${track.origin === 'liked' ? ' [liked]' : ''}`
|
|
970
|
+
`${index}. ${label(track)}${track.album ? ` (${track.album})` : ''}${track.origin === 'liked' ? ' [liked]' : ''}` +
|
|
971
|
+
(track.boost === 'more' ? ' [more]' : track.boost === 'less' ? ' [fewer]' : ''))
|
|
842
972
|
.join('\n');
|
|
843
973
|
const current = this.player.current();
|
|
844
974
|
const upNext = follows ? this.player.remaining().slice(-5) : [];
|
|
@@ -856,6 +986,8 @@ export class AiDj {
|
|
|
856
986
|
digest.topArtists.length ? `Favourite artists: ${digest.topArtists.join(', ')}` : '',
|
|
857
987
|
digest.liked.length ? `Liked: ${digest.liked.join('; ')}` : '',
|
|
858
988
|
digest.disliked.length ? `Disliked (never pick): ${digest.disliked.join('; ')}` : '',
|
|
989
|
+
boostLine(digest.boosts, 'more', 'Right now, more like'),
|
|
990
|
+
boostLine(digest.boosts, 'less', 'Right now, fewer like'),
|
|
859
991
|
digest.skipped.length ? `Skipped early (steer away from these): ${digest.skipped.join('; ')}` : '',
|
|
860
992
|
skippedArtists.length ? `Often skipped artists (skips): ${skippedArtists.join(', ')}` : '',
|
|
861
993
|
'',
|
|
@@ -881,6 +1013,7 @@ export class AiDj {
|
|
|
881
1013
|
'Favour artists the listener likes and the requested mood; keep variety — never place two tracks by the same artist back to back; ' +
|
|
882
1014
|
'avoid anything listed as recently played or disliked, and pick less of what the listener skips. ' +
|
|
883
1015
|
'Candidates marked [liked] are the listener\'s own likes, not heard for a while: mix one in when it fits, but do not fill the set with them. ' +
|
|
1016
|
+
'For the next while the listener asked for more or fewer songs like a few tracks: favour candidates marked [more], and avoid those marked [fewer] unless nothing else fits. ' +
|
|
884
1017
|
'Reply with JSON only, no prose, no code fence: ' +
|
|
885
1018
|
'{"vibe":"<one short line describing the set>","picks":[{"index":<candidate index>,"why":"<max 8 words>"}]}',
|
|
886
1019
|
},
|
|
@@ -992,6 +1125,8 @@ export class AiDj {
|
|
|
992
1125
|
// FM is personalised, similarity is not; a like is a known good song,
|
|
993
1126
|
// weighted lightly so the set stays a discovery rather than a replay.
|
|
994
1127
|
if (track.origin === 'prompt') score += 3.0;
|
|
1128
|
+
if (track.boost === 'more') score += BOOST_WEIGHT;
|
|
1129
|
+
else if (track.boost === 'less') score -= BOOST_WEIGHT;
|
|
995
1130
|
else if (track.origin === 'fm') score += 1.0;
|
|
996
1131
|
else if (track.origin === 'similar') score += 0.6;
|
|
997
1132
|
else if (track.origin === 'liked') score += 0.5;
|
package/lib/index.js
CHANGED
|
@@ -517,7 +517,9 @@ export function apply(ctx, config = {}) {
|
|
|
517
517
|
'Run or configure the continuous AI DJ for the user\'s NetEase Cloud Music panel. ' +
|
|
518
518
|
'With `enabled: true` the DJ keeps the queue stocked: it gathers candidates from similar songs, personal FM, ' +
|
|
519
519
|
'liked songs not heard lately, the daily recommendations, the charts and any mood brief, then either asks the model to choose or scores them by the ' +
|
|
520
|
-
'listener\'s liked artists,
|
|
520
|
+
'listener\'s liked artists and their likes, dislikes and skips. Pass `prompt` for a mood or vibe, and `replan` to refill now. ' +
|
|
521
|
+
'Pass `boost` to steer it for a while — `more` or `less` songs like a track (the playing one by default) for an hour, ' +
|
|
522
|
+
'or `none` to clear — when the listener wants more or fewer like a song without a lasting like or dislike.',
|
|
521
523
|
parameters: {
|
|
522
524
|
type: 'object',
|
|
523
525
|
additionalProperties: false,
|
|
@@ -530,6 +532,13 @@ export function apply(ctx, config = {}) {
|
|
|
530
532
|
description: 'How many tracks to plan (1-25; default 8 for `start`, the player\'s batch size for `replan`).',
|
|
531
533
|
},
|
|
532
534
|
start: { type: 'boolean', description: 'Replace the queue with a freshly planned batch (a full DJ session).' },
|
|
535
|
+
boost: {
|
|
536
|
+
type: 'string',
|
|
537
|
+
enum: ['more', 'less', 'none'],
|
|
538
|
+
description: 'Temporarily steer the DJ toward (`more`) or away from (`less`) songs like a track, or clear its boost (`none`).',
|
|
539
|
+
},
|
|
540
|
+
boostTrackId: { type: 'integer', description: 'The track to boost; defaults to the one playing.' },
|
|
541
|
+
boostMinutes: { type: 'integer', description: 'How long the boost lasts, 5-720 minutes (default 60).' },
|
|
533
542
|
},
|
|
534
543
|
},
|
|
535
544
|
render: (_args, value) => [
|
|
@@ -540,6 +549,15 @@ export function apply(ctx, config = {}) {
|
|
|
540
549
|
(value.modelError ? `Model tier unavailable: ${value.modelError}. ` : '') +
|
|
541
550
|
(value.vibe ? `Vibe: ${value.vibe}. ` : '') +
|
|
542
551
|
(value.searchedAs.length ? `Brief searched as: ${value.searchedAs.join('; ')}. ` : '') +
|
|
552
|
+
(value.boostError ? `Boost not applied: ${value.boostError}. ` : '') +
|
|
553
|
+
(value.boosted
|
|
554
|
+
? `Boost: ${value.boosted.direction === 'more' ? 'more' : 'fewer'} songs like ${value.boosted.name} for ` +
|
|
555
|
+
`${value.boosted.minutes} min${value.boosted.queued ? `, ${value.boosted.queued} queued next` : ''}` +
|
|
556
|
+
`${value.boosted.removed ? `, ${value.boosted.removed} removed from the queue` : ''}. `
|
|
557
|
+
: '') +
|
|
558
|
+
(value.boosts.length
|
|
559
|
+
? `Active boosts: ${value.boosts.map((boost) => `${boost.direction} like ${boost.name} (${boost.minutesLeft} min left)`).join('; ')}. `
|
|
560
|
+
: '') +
|
|
543
561
|
(value.names.length
|
|
544
562
|
? `Queued ${value.added} track(s):\n${value.names.map((entry, index) => `${index + 1}. ${entry}`).join('\n')}`
|
|
545
563
|
: value.note || 'No new tracks were queued.') +
|
|
@@ -551,6 +569,24 @@ export function apply(ctx, config = {}) {
|
|
|
551
569
|
const prompt = args.prompt === undefined ? undefined : String(args.prompt);
|
|
552
570
|
if (enabled !== undefined || prompt !== undefined) dj.setEnabled(enabled ?? player.dj.enabled, { prompt });
|
|
553
571
|
|
|
572
|
+
let boosted = null;
|
|
573
|
+
let boostError = null;
|
|
574
|
+
if (args.boost !== undefined) {
|
|
575
|
+
const trackId = args.boostTrackId ?? player.current()?.id;
|
|
576
|
+
const applied = trackId === undefined
|
|
577
|
+
? { ok: false, reason: 'nothing is playing, so pass boostTrackId' }
|
|
578
|
+
: await router.applyBoost(trackId, String(args.boost), args.boostMinutes);
|
|
579
|
+
if (!applied.ok) boostError = applied.reason;
|
|
580
|
+
else if (applied.boost) {
|
|
581
|
+
boosted = {
|
|
582
|
+
direction: applied.boost.direction,
|
|
583
|
+
name: applied.boost.name,
|
|
584
|
+
minutes: Math.round((applied.boost.until - Date.now()) / 60_000),
|
|
585
|
+
...applied.effect,
|
|
586
|
+
};
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
|
|
554
590
|
const count = Math.min(Math.max(Number(args.count) || 8, 1), 25);
|
|
555
591
|
let plan = null;
|
|
556
592
|
if (args.start) {
|
|
@@ -573,6 +609,14 @@ export function apply(ctx, config = {}) {
|
|
|
573
609
|
authenticated: api.authenticated,
|
|
574
610
|
current: summary.current,
|
|
575
611
|
remaining: summary.remaining,
|
|
612
|
+
boosted,
|
|
613
|
+
boostError,
|
|
614
|
+
boosts: store.activeBoosts().map((boost) => ({
|
|
615
|
+
id: boost.id,
|
|
616
|
+
name: boost.name,
|
|
617
|
+
direction: boost.direction,
|
|
618
|
+
minutesLeft: Math.max(Math.round((boost.until - Date.now()) / 60_000), 1),
|
|
619
|
+
})),
|
|
576
620
|
};
|
|
577
621
|
},
|
|
578
622
|
});
|
package/lib/panel.html
CHANGED
|
@@ -17,11 +17,15 @@
|
|
|
17
17
|
color-scheme: light dark;
|
|
18
18
|
--bg: var(--dsh-background, #ffffff);
|
|
19
19
|
--fg: var(--dsh-foreground, #1b1c1e);
|
|
20
|
-
--muted: color-mix(in srgb, var(--fg)
|
|
21
|
-
--
|
|
20
|
+
--muted: color-mix(in srgb, var(--fg) 56%, transparent);
|
|
21
|
+
--faint: color-mix(in srgb, var(--fg) 38%, transparent);
|
|
22
|
+
--line: color-mix(in srgb, var(--fg) 12%, transparent);
|
|
22
23
|
--panel: color-mix(in srgb, var(--fg) 4%, transparent);
|
|
24
|
+
--hover: color-mix(in srgb, var(--fg) 7%, transparent);
|
|
23
25
|
--accent: #e8503a;
|
|
24
|
-
--
|
|
26
|
+
--accent-soft: color-mix(in srgb, var(--accent) 13%, transparent);
|
|
27
|
+
--radius: 12px;
|
|
28
|
+
--gap: 16px;
|
|
25
29
|
}
|
|
26
30
|
* { box-sizing: border-box; }
|
|
27
31
|
html, body { margin: 0; height: 100%; }
|
|
@@ -35,126 +39,202 @@
|
|
|
35
39
|
background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
|
|
36
40
|
padding: 5px 10px; cursor: pointer; white-space: nowrap;
|
|
37
41
|
}
|
|
38
|
-
button:hover:not(:disabled) {
|
|
42
|
+
button:hover:not(:disabled) { background: var(--hover); }
|
|
43
|
+
/* The trip to NetEase is not instant on a cold cache; a click has to look
|
|
44
|
+
like it landed before the rows come back. */
|
|
39
45
|
button:disabled { opacity: 0.45; cursor: default; }
|
|
40
46
|
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
|
|
41
47
|
input, select {
|
|
42
|
-
background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 6px
|
|
48
|
+
background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px;
|
|
43
49
|
}
|
|
44
|
-
input:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); }
|
|
50
|
+
input:focus, select:focus, button:focus-visible { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 1px; }
|
|
51
|
+
svg { display: block; width: 18px; height: 18px; fill: currentColor; }
|
|
45
52
|
|
|
53
|
+
/* ------------------------------------------------------------ layout
|
|
54
|
+
Wide: the stage (what is playing) on the left, what comes next — the
|
|
55
|
+
DJ and the queue — on the right, each column scrolling on its own.
|
|
56
|
+
Narrow: one column, the whole page scrolling. */
|
|
46
57
|
#app { display: flex; flex-direction: column; height: 100%; }
|
|
47
|
-
|
|
48
58
|
header {
|
|
49
|
-
display: flex; align-items: center; gap:
|
|
50
|
-
border-bottom: 1px solid var(--line); flex
|
|
59
|
+
display: flex; align-items: center; gap: 10px; padding: 10px var(--gap);
|
|
60
|
+
border-bottom: 1px solid var(--line); flex: none;
|
|
51
61
|
}
|
|
52
62
|
.brand { font-weight: 650; letter-spacing: 0.2px; }
|
|
53
63
|
.brand small { font-weight: 400; color: var(--muted); margin-left: 6px; }
|
|
54
64
|
.spacer { flex: 1; }
|
|
55
|
-
#
|
|
56
|
-
#
|
|
57
|
-
#account {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
65
|
+
#account { display: flex; align-items: center; gap: 7px; color: var(--muted); min-width: 0; }
|
|
66
|
+
#account span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
67
|
+
#account img { width: 22px; height: 22px; border-radius: 50%; flex: none; }
|
|
68
|
+
|
|
69
|
+
main { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: auto; }
|
|
70
|
+
.stage, .side { display: flex; flex-direction: column; gap: var(--gap); padding: var(--gap); min-width: 0; }
|
|
71
|
+
@media (max-width: 859px) {
|
|
72
|
+
/* Stacked, the two columns share one gap rather than two paddings. */
|
|
73
|
+
.side { padding-top: 0; }
|
|
74
|
+
}
|
|
75
|
+
@media (min-width: 860px) {
|
|
76
|
+
main { display: grid; grid-template-columns: minmax(0, 1fr) minmax(340px, 30%); overflow: hidden; }
|
|
77
|
+
.stage { overflow: auto; }
|
|
78
|
+
.side { overflow: hidden; border-left: 1px solid var(--line); }
|
|
79
|
+
.side .queue-card { flex: 1; min-height: 0; }
|
|
80
|
+
.side #queue { overflow: auto; }
|
|
81
|
+
/* With a column of its own, the lyrics fill what the stage leaves. */
|
|
82
|
+
.stage .lyrics-card { flex: 1; min-height: 160px; }
|
|
83
|
+
.stage .lyrics { flex: 1; max-height: none; }
|
|
84
|
+
}
|
|
66
85
|
|
|
67
|
-
.
|
|
68
|
-
|
|
86
|
+
.card { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
|
|
87
|
+
.card-head {
|
|
88
|
+
display: flex; align-items: center; gap: 8px; padding: 10px 12px 6px;
|
|
89
|
+
color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px;
|
|
69
90
|
}
|
|
70
|
-
.
|
|
71
|
-
.
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
.row .meta { min-width: 0; flex: 1; }
|
|
75
|
-
.row .name { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
76
|
-
.row .sub { display: block; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
77
|
-
.row .tag { font-size: 10px; border: 1px solid var(--line); border-radius: 4px; padding: 1px 4px; color: var(--muted); flex: none; }
|
|
78
|
-
.row .dur { color: var(--muted); font-variant-numeric: tabular-nums; flex: none; font-size: 12px; }
|
|
79
|
-
.row .acts { display: none; gap: 4px; flex: none; }
|
|
80
|
-
.row:hover .acts { display: flex; }
|
|
81
|
-
/* The list's own like control. A liked track keeps its filled heart
|
|
82
|
-
visible; the hollow one only appears on hover, so an unrated list is
|
|
83
|
-
not a wall of outlines. */
|
|
84
|
-
.row .heart {
|
|
85
|
-
background: none; border: 0; padding: 0; width: 16px; flex: none;
|
|
86
|
-
font-size: 14px; line-height: 1; color: var(--muted); opacity: 0;
|
|
87
|
-
transition: opacity 0.12s;
|
|
91
|
+
.card-head .grow { flex: 1; }
|
|
92
|
+
.link {
|
|
93
|
+
background: none; border: 0; padding: 0; color: var(--muted); font: inherit;
|
|
94
|
+
text-transform: inherit; letter-spacing: inherit;
|
|
88
95
|
}
|
|
89
|
-
.
|
|
90
|
-
|
|
96
|
+
.link:hover:not(:disabled) { background: none; color: var(--fg); }
|
|
97
|
+
|
|
98
|
+
/* ------------------------------------------------------------- stage */
|
|
99
|
+
.np { display: flex; gap: 18px; align-items: flex-end; }
|
|
100
|
+
/* The frame holds the place, with a note in it, while there is no cover. */
|
|
101
|
+
.cover {
|
|
102
|
+
position: relative; width: clamp(96px, 22vw, 180px); aspect-ratio: 1; flex: none;
|
|
103
|
+
border-radius: var(--radius); overflow: hidden; background: var(--panel);
|
|
104
|
+
display: grid; place-items: center; color: var(--faint); font-size: 40px;
|
|
105
|
+
box-shadow: 0 6px 24px color-mix(in srgb, #000 14%, transparent);
|
|
106
|
+
}
|
|
107
|
+
.cover::before { content: "♪"; }
|
|
108
|
+
#cover { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
|
|
109
|
+
.np-text { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 2px; }
|
|
110
|
+
.now-title { font-size: 22px; font-weight: 700; line-height: 1.25; overflow-wrap: anywhere; }
|
|
111
|
+
.now-artists { font-size: 14px; }
|
|
112
|
+
.now-album { color: var(--muted); }
|
|
113
|
+
/* What to do about this track: the taste switchers and the boosts. A
|
|
114
|
+
state is an accent icon on a tint, never a solid block — the only
|
|
115
|
+
filled control on the stage is play. */
|
|
116
|
+
.taste { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
|
|
117
|
+
.taste button {
|
|
118
|
+
width: 34px; height: 34px; padding: 0; border-radius: 50%; display: grid; place-items: center;
|
|
119
|
+
background: none; font-size: 15px; line-height: 1; color: var(--muted);
|
|
120
|
+
}
|
|
121
|
+
.taste button:hover:not(:disabled) { color: var(--fg); background: var(--hover); }
|
|
122
|
+
.taste button.on { color: var(--accent); background: var(--accent-soft); border-color: transparent; }
|
|
91
123
|
|
|
92
|
-
.
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
.now-title { font-size: 16px; font-weight: 650; line-height: 1.3; }
|
|
96
|
-
.now-artists { color: var(--muted); margin-top: 3px; }
|
|
97
|
-
.now-album { color: var(--muted); font-size: 12px; margin-top: 2px; }
|
|
98
|
-
.bar { display: flex; align-items: center; gap: 8px; margin-top: 12px; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
|
|
99
|
-
input[type="range"] { -webkit-appearance: none; appearance: none; background: transparent; padding: 0; height: 16px; flex: 1; min-width: 0; }
|
|
100
|
-
input[type="range"]::-webkit-slider-runnable-track { height: 4px; border-radius: 4px; background: color-mix(in srgb, var(--fg) 18%, transparent); }
|
|
124
|
+
.progress { display: flex; align-items: center; gap: 10px; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
|
|
125
|
+
input[type="range"] { -webkit-appearance: none; appearance: none; background: transparent; border: 0; padding: 0; height: 16px; flex: 1; min-width: 0; }
|
|
126
|
+
input[type="range"]::-webkit-slider-runnable-track { height: 4px; border-radius: 4px; background: color-mix(in srgb, var(--fg) 16%, transparent); }
|
|
101
127
|
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 12px; height: 12px; margin-top: -4px; border-radius: 50%; background: var(--accent); }
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
.
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
.
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
.
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
text-transform: inherit; letter-spacing: inherit; cursor: pointer;
|
|
122
|
-
}
|
|
123
|
-
.section-title.head button:hover { color: var(--fg); }
|
|
124
|
-
/* The pane is a glance at the current line, not a page: four lines of
|
|
125
|
-
synced text, scrolled for the rest, so the queue keeps the space.
|
|
126
|
-
`--lyrics-lines` is the single knob (the padding below is the `+ 12px`). */
|
|
128
|
+
input[type="range"]:focus { outline: none; }
|
|
129
|
+
|
|
130
|
+
.transport { display: flex; align-items: center; justify-content: center; gap: 14px; }
|
|
131
|
+
.transport button { width: 40px; height: 40px; padding: 0; border-radius: 50%; display: grid; place-items: center; background: none; border-color: transparent; }
|
|
132
|
+
.transport button:hover:not(:disabled) { background: var(--hover); }
|
|
133
|
+
.transport #play { width: 52px; height: 52px; background: var(--accent); color: #fff; box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 35%, transparent); }
|
|
134
|
+
.transport #play:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 88%, #000); }
|
|
135
|
+
.transport #play svg { width: 22px; height: 22px; }
|
|
136
|
+
|
|
137
|
+
.secondary { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 12px; }
|
|
138
|
+
.secondary select, .secondary > button { padding: 4px 8px; font-size: 12px; }
|
|
139
|
+
#quality-info { color: var(--muted); }
|
|
140
|
+
#mute { background: none; border-color: transparent; padding: 4px; color: var(--muted); }
|
|
141
|
+
#mute:hover:not(:disabled) { color: var(--fg); }
|
|
142
|
+
#volume { flex: 0 0 96px; }
|
|
143
|
+
|
|
144
|
+
.lyrics-card { display: flex; flex-direction: column; min-height: 0; }
|
|
145
|
+
/* The pane is a glance at the current line, not a page: a few lines of
|
|
146
|
+
synced text, scrolled for the rest. `--lyrics-lines` is the single knob. */
|
|
127
147
|
.lyrics {
|
|
128
|
-
--lyrics-lines:
|
|
129
|
-
max-height: calc(var(--lyrics-lines) * 1.
|
|
130
|
-
|
|
148
|
+
--lyrics-lines: 6;
|
|
149
|
+
max-height: calc(var(--lyrics-lines) * 1.6em + var(--lyrics-lines) * 4px + 14px);
|
|
150
|
+
overflow: auto; padding: 2px 12px 14px; font-size: 14px; line-height: 1.6; scrollbar-width: none;
|
|
131
151
|
}
|
|
152
|
+
.lyrics::-webkit-scrollbar { display: none; }
|
|
132
153
|
.lyrics.collapsed { display: none; }
|
|
133
|
-
.lyrics p { margin: 0; padding: 2px 0; color: var(--
|
|
154
|
+
.lyrics p { margin: 0; padding: 2px 0; color: var(--faint); transition: color 0.15s; }
|
|
134
155
|
.lyrics p.on { color: var(--fg); font-weight: 600; }
|
|
135
|
-
|
|
136
|
-
.
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
156
|
+
|
|
157
|
+
.need-gesture {
|
|
158
|
+
background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
|
|
159
|
+
border-radius: var(--radius); padding: 8px 12px; font-size: 12px;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/* -------------------------------------------------------------- side */
|
|
163
|
+
.dj-card { padding-bottom: 12px; flex: none; }
|
|
164
|
+
.dj-card .card-head { padding-bottom: 8px; }
|
|
165
|
+
.dj-card .card-head .title { color: var(--fg); font-size: 13px; font-weight: 650; text-transform: none; letter-spacing: 0; }
|
|
166
|
+
.dj-body { display: flex; flex-direction: column; gap: 8px; padding: 0 12px; font-size: 12px; }
|
|
167
|
+
#dj-prompt { width: 100%; }
|
|
168
|
+
/* The DJ switch: a toggle that reads on or off at a glance. */
|
|
169
|
+
#dj-toggle {
|
|
170
|
+
position: relative; width: 38px; height: 22px; padding: 0; border-radius: 11px;
|
|
171
|
+
background: color-mix(in srgb, var(--fg) 20%, transparent); border: 0; color: transparent; overflow: hidden;
|
|
172
|
+
}
|
|
173
|
+
#dj-toggle::after {
|
|
174
|
+
content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%;
|
|
175
|
+
background: #fff; transition: transform 0.15s; box-shadow: 0 1px 3px color-mix(in srgb, #000 30%, transparent);
|
|
176
|
+
}
|
|
177
|
+
#dj-toggle.on { background: var(--accent); }
|
|
178
|
+
#dj-toggle.on::after { transform: translateX(16px); }
|
|
179
|
+
#dj-toggle:hover:not(:disabled) { filter: brightness(0.96); }
|
|
180
|
+
.plan b { color: var(--accent); }
|
|
181
|
+
.plan .muted, .muted { color: var(--muted); }
|
|
182
|
+
.plan > div + div { margin-top: 2px; }
|
|
183
|
+
|
|
184
|
+
#boosts:empty { display: none; }
|
|
185
|
+
#boosts { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; color: var(--muted); }
|
|
186
|
+
#boosts .boost {
|
|
187
|
+
display: inline-flex; gap: 2px; align-items: center; color: var(--fg);
|
|
188
|
+
background: var(--accent-soft); border-radius: 999px; padding: 1px 2px 1px 9px;
|
|
189
|
+
}
|
|
190
|
+
#boosts .boost button { border: 0; background: none; padding: 0 6px; color: var(--muted); }
|
|
191
|
+
#boosts .boost button:hover:not(:disabled) { color: var(--fg); }
|
|
192
|
+
|
|
193
|
+
/* The DJ model picker is a set-once setting, so it keeps only its header
|
|
194
|
+
row until asked. The header is the click target; the chevron inside it
|
|
195
|
+
is the keyboard one. */
|
|
196
|
+
.model { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 8px; }
|
|
142
197
|
.model-head { display: flex; align-items: baseline; gap: 8px; cursor: pointer; }
|
|
143
198
|
.model-head .model-now {
|
|
144
199
|
flex: 1; min-width: 0; text-align: right; color: var(--muted);
|
|
145
200
|
overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
|
|
146
201
|
}
|
|
147
|
-
.model-head .toggle {
|
|
148
|
-
|
|
149
|
-
color: var(--muted); cursor: pointer;
|
|
150
|
-
}
|
|
151
|
-
.model-head .toggle:hover { color: var(--fg); }
|
|
202
|
+
.model-head .toggle { background: none; border: 0; margin: 0; padding: 0 2px; font: inherit; color: var(--muted); }
|
|
203
|
+
.model-head .toggle:hover:not(:disabled) { background: none; color: var(--fg); }
|
|
152
204
|
.model-head .warn { color: var(--accent); }
|
|
153
205
|
.dj-model-body.collapsed { display: none; }
|
|
154
206
|
.row-inline { display: flex; gap: 6px; margin-top: 6px; align-items: center; }
|
|
155
207
|
.row-inline select, .row-inline input { flex: 1 1 0; min-width: 0; font-size: 12px; padding: 4px 6px; }
|
|
156
208
|
.row-inline button { font-size: 12px; padding: 4px 8px; }
|
|
209
|
+
|
|
210
|
+
.queue-card { display: flex; flex-direction: column; overflow: hidden; }
|
|
211
|
+
#queue { padding: 0 6px 6px; }
|
|
212
|
+
.row { display: flex; align-items: center; gap: 10px; padding: 6px; border-radius: 8px; cursor: pointer; }
|
|
213
|
+
.row:hover { background: var(--hover); }
|
|
214
|
+
.row.playing { background: var(--accent-soft); }
|
|
215
|
+
.row.playing .name { color: var(--accent); font-weight: 600; }
|
|
216
|
+
.row .idx { width: 20px; text-align: right; color: var(--faint); font-variant-numeric: tabular-nums; flex: none; font-size: 12px; }
|
|
217
|
+
.row.playing .idx { color: var(--accent); }
|
|
218
|
+
.row img { width: 36px; height: 36px; border-radius: 6px; object-fit: cover; flex: none; background: var(--panel); }
|
|
219
|
+
.row .meta { min-width: 0; flex: 1; }
|
|
220
|
+
.row .name { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
221
|
+
.row .sub { display: block; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
222
|
+
.row .tag { font-size: 10px; border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; color: var(--muted); flex: none; }
|
|
223
|
+
.row .dur { color: var(--muted); font-variant-numeric: tabular-nums; flex: none; font-size: 12px; min-width: 32px; text-align: right; }
|
|
224
|
+
.row .acts { display: none; gap: 4px; flex: none; }
|
|
225
|
+
.row .acts button { padding: 1px 6px; font-size: 11px; background: none; color: var(--muted); }
|
|
226
|
+
.row:hover .acts { display: flex; }
|
|
227
|
+
/* The list's own like control. A liked track keeps its filled heart
|
|
228
|
+
visible; the hollow one only appears on hover, so an unrated list is
|
|
229
|
+
not a wall of outlines. */
|
|
230
|
+
.row .heart {
|
|
231
|
+
background: none; border: 0; padding: 0; width: 16px; flex: none;
|
|
232
|
+
font-size: 14px; line-height: 1; color: var(--muted); opacity: 0; transition: opacity 0.12s;
|
|
233
|
+
}
|
|
234
|
+
.row:hover .heart { opacity: 1; }
|
|
235
|
+
.row .heart.on { opacity: 1; color: var(--accent); }
|
|
157
236
|
.empty { padding: 24px 14px; color: var(--muted); text-align: center; }
|
|
237
|
+
|
|
158
238
|
.toast {
|
|
159
239
|
position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%);
|
|
160
240
|
background: #1b1c1e; color: #fff; padding: 8px 14px; border-radius: 9px; font-size: 12px;
|
|
@@ -168,8 +248,8 @@
|
|
|
168
248
|
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
|
|
169
249
|
#qr { display: block; margin: 12px auto; width: 220px; height: 220px; image-rendering: pixelated; border-radius: 8px; background: #fff; padding: 8px; }
|
|
170
250
|
.hint { color: var(--muted); font-size: 12px; text-align: center; }
|
|
251
|
+
.lyrics .hint { text-align: left; }
|
|
171
252
|
.row-actions { display: flex; gap: 6px; justify-content: flex-end; margin-top: 14px; }
|
|
172
|
-
.need-gesture { background: color-mix(in srgb, var(--accent) 14%, transparent); border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent); border-radius: var(--radius); padding: 8px 11px; margin: 0 14px 12px; font-size: 12px; }
|
|
173
253
|
</style>
|
|
174
254
|
</head>
|
|
175
255
|
<body>
|
|
@@ -177,82 +257,104 @@
|
|
|
177
257
|
<header>
|
|
178
258
|
<div class="brand"><span data-i18n="brand">Music</span><small>music.163.com</small></div>
|
|
179
259
|
<div class="spacer"></div>
|
|
180
|
-
<input id="dj-prompt" data-i18n-ph="djPromptPh" placeholder="AI DJ mood, e.g. rainy afternoon jazz" />
|
|
181
|
-
<button id="dj-toggle" data-i18n-title="djToggleTitle" title="Continuous AI DJ: keep the queue stocked">AI DJ</button>
|
|
182
260
|
<div id="account"></div>
|
|
183
261
|
</header>
|
|
184
262
|
|
|
185
263
|
<main>
|
|
186
|
-
<section class="
|
|
187
|
-
<div
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
</div>
|
|
195
|
-
</div>
|
|
196
|
-
<div class="bar">
|
|
197
|
-
<span id="t-cur">0:00</span>
|
|
198
|
-
<input type="range" id="seek" min="0" max="1000" value="0" step="1" />
|
|
199
|
-
<span id="t-dur">0:00</span>
|
|
200
|
-
</div>
|
|
201
|
-
<div class="controls">
|
|
202
|
-
<button id="prev" data-i18n-title="prev" title="Previous">⏮</button>
|
|
203
|
-
<button id="play" class="primary" data-i18n-title="playPause" title="Play/pause">▶</button>
|
|
204
|
-
<button id="next" data-i18n-title="next" title="Next">⏭</button>
|
|
205
|
-
<button id="mode" class="mode" data-i18n-title="modeTitle" data-i18n="modeList" title="Playback mode">List</button>
|
|
206
|
-
<select id="quality" class="mode" data-i18n-title="qualityTitle" title="Streaming quality"></select>
|
|
207
|
-
<span id="quality-info" class="mode" style="color: var(--muted)"></span>
|
|
208
|
-
<span class="grow"></span>
|
|
264
|
+
<section class="stage">
|
|
265
|
+
<div id="notices"></div>
|
|
266
|
+
<div class="np">
|
|
267
|
+
<div class="cover"><img id="cover" alt="" /></div>
|
|
268
|
+
<div class="np-text">
|
|
269
|
+
<div class="now-title" id="np-title" data-i18n="nothingPlaying">Nothing playing</div>
|
|
270
|
+
<div class="now-artists" id="np-artists"></div>
|
|
271
|
+
<div class="now-album" id="np-album"></div>
|
|
209
272
|
<!-- Labels are state-dependent (a filled heart un-likes), so the
|
|
210
273
|
script owns text and title rather than data-i18n. -->
|
|
211
|
-
<
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
274
|
+
<div class="taste">
|
|
275
|
+
<button id="like" title="Like">♡</button>
|
|
276
|
+
<button id="dislike" title="Dislike">✕</button>
|
|
277
|
+
<button id="boost-more" title="More like this for an hour">▲</button>
|
|
278
|
+
<button id="boost-less" title="Fewer like this for an hour">▼</button>
|
|
279
|
+
</div>
|
|
215
280
|
</div>
|
|
216
281
|
</div>
|
|
217
282
|
|
|
218
|
-
<div class="
|
|
219
|
-
<span
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
<button id="lyrics-toggle" type="button" aria-expanded="true">Hide</button>
|
|
283
|
+
<div class="progress">
|
|
284
|
+
<span id="t-cur">0:00</span>
|
|
285
|
+
<input type="range" id="seek" min="0" max="1000" value="0" step="1" />
|
|
286
|
+
<span id="t-dur">0:00</span>
|
|
223
287
|
</div>
|
|
224
|
-
<div class="
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
<
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
288
|
+
<div class="transport">
|
|
289
|
+
<button id="prev" data-i18n-title="prev" title="Previous"><svg viewBox="0 0 24 24"><path d="M6 5h2v14H6zM20 5v14L9.5 12z"/></svg></button>
|
|
290
|
+
<button id="play" data-i18n-title="playPause" title="Play/pause"><svg viewBox="0 0 24 24"><path d="M8 5v14l11-7z"/></svg></button>
|
|
291
|
+
<button id="next" data-i18n-title="next" title="Next"><svg viewBox="0 0 24 24"><path d="M16 5h2v14h-2zM4 5v14l10.5-7z"/></svg></button>
|
|
292
|
+
</div>
|
|
293
|
+
<div class="secondary">
|
|
294
|
+
<button id="mode" data-i18n-title="modeTitle" data-i18n="modeList" title="Playback mode">List</button>
|
|
295
|
+
<select id="quality" data-i18n-title="qualityTitle" title="Streaming quality"></select>
|
|
296
|
+
<span id="quality-info"></span>
|
|
297
|
+
<span class="spacer"></span>
|
|
298
|
+
<button id="mute" data-i18n-title="mute" title="Mute"></button>
|
|
299
|
+
<input type="range" id="volume" min="0" max="1" step="0.01" value="0.8" />
|
|
300
|
+
</div>
|
|
301
|
+
|
|
302
|
+
<div class="card lyrics-card">
|
|
303
|
+
<div class="card-head">
|
|
304
|
+
<span data-i18n="lyrics">Lyrics</span>
|
|
305
|
+
<span class="grow"></span>
|
|
306
|
+
<!-- Label and title are state-dependent, so the script owns them
|
|
307
|
+
(applyStaticStrings cannot know which way the pane is now). -->
|
|
308
|
+
<button id="lyrics-toggle" class="link" type="button" aria-expanded="true">Hide</button>
|
|
238
309
|
</div>
|
|
239
|
-
<div class="
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
</
|
|
247
|
-
<
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
310
|
+
<div class="lyrics" id="lyrics"><p class="hint">—</p></div>
|
|
311
|
+
</div>
|
|
312
|
+
</section>
|
|
313
|
+
|
|
314
|
+
<aside class="side">
|
|
315
|
+
<div class="card dj-card">
|
|
316
|
+
<div class="card-head">
|
|
317
|
+
<span class="title">AI DJ</span>
|
|
318
|
+
<span class="grow"></span>
|
|
319
|
+
<button id="dj-toggle" role="switch" data-i18n-title="djToggleTitle" title="Continuous AI DJ: keep the queue stocked">AI DJ</button>
|
|
320
|
+
</div>
|
|
321
|
+
<div class="dj-body">
|
|
322
|
+
<input id="dj-prompt" data-i18n-ph="djPromptPh" placeholder="AI DJ mood, e.g. rainy afternoon jazz" />
|
|
323
|
+
<div id="dj-status"></div>
|
|
324
|
+
<div id="boosts"></div>
|
|
325
|
+
<div class="model" id="dj-model">
|
|
326
|
+
<!-- One always-visible line: the setting that matters at a glance is
|
|
327
|
+
the effective route, and the form below it is folded away until
|
|
328
|
+
asked for. -->
|
|
329
|
+
<div class="model-head" id="dj-model-head">
|
|
330
|
+
<span data-i18n="djModel">DJ model</span>
|
|
331
|
+
<span class="model-now"><span id="dj-model-route"></span><span id="dj-model-source"></span><span class="warn" id="dj-model-warn"></span></span>
|
|
332
|
+
<button id="dj-model-toggle" class="toggle" type="button" aria-controls="dj-model-body" aria-expanded="false"></button>
|
|
333
|
+
</div>
|
|
334
|
+
<div class="dj-model-body collapsed" id="dj-model-body">
|
|
335
|
+
<div class="row-inline">
|
|
336
|
+
<select id="dj-provider" title="provider route"></select>
|
|
337
|
+
<select id="dj-model-select" title="model"></select>
|
|
338
|
+
</div>
|
|
339
|
+
<div class="row-inline">
|
|
340
|
+
<input id="dj-model-custom" data-i18n-ph="customModelPh" placeholder="Custom model id" style="display: none" />
|
|
341
|
+
</div>
|
|
342
|
+
<div class="row-inline">
|
|
343
|
+
<button id="dj-model-save" class="primary" data-i18n="save">Save</button>
|
|
344
|
+
<button id="dj-model-test" data-i18n="test">Test</button>
|
|
345
|
+
<button id="dj-model-clear" data-i18n="revert" data-i18n-title="revertTitle" title="Revert to the profile patch">Revert</button>
|
|
346
|
+
</div>
|
|
347
|
+
<div id="dj-model-status" class="muted"></div>
|
|
348
|
+
</div>
|
|
251
349
|
</div>
|
|
252
|
-
<div id="dj-model-status" style="color: var(--muted)"></div>
|
|
253
350
|
</div>
|
|
254
351
|
</div>
|
|
255
|
-
|
|
352
|
+
|
|
353
|
+
<div class="card queue-card">
|
|
354
|
+
<div class="card-head"><span data-i18n="queue">Queue</span> <span id="counts"></span></div>
|
|
355
|
+
<div id="queue"></div>
|
|
356
|
+
</div>
|
|
357
|
+
</aside>
|
|
256
358
|
</main>
|
|
257
359
|
</div>
|
|
258
360
|
|
|
@@ -265,7 +367,6 @@
|
|
|
265
367
|
<button id="qr-close" class="primary" data-i18n="close">Close</button>
|
|
266
368
|
</div>
|
|
267
369
|
</dialog>
|
|
268
|
-
|
|
269
370
|
<div class="toast" id="toast"></div>
|
|
270
371
|
|
|
271
372
|
<script src="__BASE__/vendor/qrcode.js"></script>
|
|
@@ -364,6 +465,14 @@
|
|
|
364
465
|
liked: '已喜欢',
|
|
365
466
|
unliked: '已取消喜欢',
|
|
366
467
|
disliked: '不再推荐',
|
|
468
|
+
boostMore: '接下来一小时多放类似的',
|
|
469
|
+
boostLess: '接下来一小时少放类似的',
|
|
470
|
+
boostClear: '取消临时偏好',
|
|
471
|
+
boostedMore: '接下来一小时多放类似的',
|
|
472
|
+
boostedLess: '接下来一小时少放类似的',
|
|
473
|
+
boostCleared: '已取消临时偏好',
|
|
474
|
+
boostsTitle: '临时偏好',
|
|
475
|
+
boostMinutes: '{n} 分钟',
|
|
367
476
|
djOn: 'AI DJ 已开启',
|
|
368
477
|
djOff: 'AI DJ 已关闭',
|
|
369
478
|
connectFailed: '连接失败:',
|
|
@@ -453,6 +562,14 @@
|
|
|
453
562
|
liked: 'Liked',
|
|
454
563
|
unliked: 'Like removed',
|
|
455
564
|
disliked: 'Disliked',
|
|
565
|
+
boostMore: 'More like this for an hour',
|
|
566
|
+
boostLess: 'Fewer like this for an hour',
|
|
567
|
+
boostClear: 'Clear this boost',
|
|
568
|
+
boostedMore: 'More like this for the next hour',
|
|
569
|
+
boostedLess: 'Fewer like this for the next hour',
|
|
570
|
+
boostCleared: 'Boost cleared',
|
|
571
|
+
boostsTitle: 'Boosts',
|
|
572
|
+
boostMinutes: '{n} min',
|
|
456
573
|
djOn: 'AI DJ on',
|
|
457
574
|
djOff: 'AI DJ off',
|
|
458
575
|
connectFailed: 'Cannot reach the host: ',
|
|
@@ -480,6 +597,21 @@
|
|
|
480
597
|
}
|
|
481
598
|
|
|
482
599
|
/** Translate a key, interpolating `{name}` placeholders from `vars`. */
|
|
600
|
+
/** Monochrome icons for controls whose glyph changes with state. */
|
|
601
|
+
const ICONS = {
|
|
602
|
+
play: '<path d="M8 5v14l11-7z"/>',
|
|
603
|
+
pause: '<path d="M7 5h4v14H7zM13 5h4v14h-4z"/>',
|
|
604
|
+
volume: '<path d="M4 9v6h4l5 4V5L8 9zM16 8.5a4.5 4.5 0 0 1 0 7l-1-1.3a2.9 2.9 0 0 0 0-4.4zM17.8 5.6a8 8 0 0 1 0 12.8l-1-1.3a6.4 6.4 0 0 0 0-10.2z"/>',
|
|
605
|
+
muted: '<path d="M4 9v6h4l5 4V5L8 9zM16.3 9.4l1.1-1.1 2.1 2.1 2.1-2.1 1.1 1.1-2.1 2.1 2.1 2.1-1.1 1.1-2.1-2.1-2.1 2.1-1.1-1.1 2.1-2.1z"/>',
|
|
606
|
+
};
|
|
607
|
+
|
|
608
|
+
/** Paint `name` into `el`, touching the DOM only when it changes. */
|
|
609
|
+
function setIcon(el, name) {
|
|
610
|
+
if (!el || el.dataset.icon === name) return;
|
|
611
|
+
el.dataset.icon = name;
|
|
612
|
+
el.innerHTML = `<svg viewBox="0 0 24 24" aria-hidden="true">${ICONS[name]}</svg>`;
|
|
613
|
+
}
|
|
614
|
+
|
|
483
615
|
function t(key, vars) {
|
|
484
616
|
let text = DICT[LANG]?.[key] ?? DICT.en[key] ?? key;
|
|
485
617
|
if (vars) {
|
|
@@ -867,7 +999,7 @@
|
|
|
867
999
|
$('lyrics').innerHTML = '<p class="hint">—</p>';
|
|
868
1000
|
}
|
|
869
1001
|
}
|
|
870
|
-
$('play')
|
|
1002
|
+
setIcon($('play'), state.playing ? 'pause' : 'play');
|
|
871
1003
|
$('mode').textContent = { list: t('modeList'), single: t('modeSingle'), shuffle: t('modeShuffle') }[state.mode] || t('modeList');
|
|
872
1004
|
$('counts').textContent = state.counts ? `(${state.counts.queued})` : '';
|
|
873
1005
|
$('dj-toggle').classList.toggle('on', Boolean(state.dj?.enabled));
|
|
@@ -886,11 +1018,11 @@
|
|
|
886
1018
|
// DJ status
|
|
887
1019
|
const dj = state.dj || {};
|
|
888
1020
|
$('dj-status').innerHTML = dj.enabled || dj.lastPlan
|
|
889
|
-
? `<div class="
|
|
1021
|
+
? `<div class="plan">${dj.busy ? esc(t('djPlanning')) : dj.error ? `AI DJ: ${esc(dj.error)}` : ''}${
|
|
890
1022
|
dj.lastPlan
|
|
891
|
-
? `<div><b
|
|
1023
|
+
? `<div><b>+${dj.lastPlan.added}</b> ${esc(dj.lastPlan.vibe || '')}</div><div class="muted">${esc((dj.lastPlan.names || []).slice(-3).join(' · '))}</div>`
|
|
892
1024
|
: ''
|
|
893
|
-
}${dj.modelError && !dj.lastPlan?.route ? `<div
|
|
1025
|
+
}${dj.modelError && !dj.lastPlan?.route ? `<div class="muted">${esc(t('modelTierUnavailable'))}: ${esc(dj.modelError)}</div>` : ''}${dj.lastPlan?.source === 'heuristic' ? `<div class="muted">${esc(t('heuristics'))}</div>` : ''}</div>`
|
|
894
1026
|
: '';
|
|
895
1027
|
|
|
896
1028
|
if (autoplayBlocked()) {
|
|
@@ -899,7 +1031,7 @@
|
|
|
899
1031
|
el.id = 'gesture';
|
|
900
1032
|
el.className = 'need-gesture';
|
|
901
1033
|
el.innerHTML = `${esc(t('gestureText'))} — <button id="gesture-go" class="primary">${esc(t('gesturePlay'))}</button> <span style="color:var(--muted)">${esc(t('gestureNote'))}</span>`;
|
|
902
|
-
$('
|
|
1034
|
+
$('notices').append(el);
|
|
903
1035
|
el.querySelector('#gesture-go').onclick = resumeWithGesture;
|
|
904
1036
|
}
|
|
905
1037
|
} else {
|
|
@@ -909,7 +1041,7 @@
|
|
|
909
1041
|
// The engine owns the real volume; mirror it unless the user is
|
|
910
1042
|
// mid-drag, when overwriting the thumb would fight the pointer.
|
|
911
1043
|
if (document.activeElement !== $('volume')) $('volume').value = state.volume;
|
|
912
|
-
$('mute')
|
|
1044
|
+
setIcon($('mute'), state.muted || state.volume === 0 ? 'muted' : 'volume');
|
|
913
1045
|
|
|
914
1046
|
// Same for quality: the host is authoritative, the select mirrors it.
|
|
915
1047
|
const preferredLevel = state.audio?.preferred;
|
|
@@ -987,6 +1119,46 @@
|
|
|
987
1119
|
$('like').title = t(liked ? 'unlike' : 'like');
|
|
988
1120
|
$('dislike').classList.toggle('on', disliked);
|
|
989
1121
|
$('dislike').title = t(disliked ? 'undislike' : 'dislike');
|
|
1122
|
+
// A filled arrow is the boost in force; clicking it clears the boost.
|
|
1123
|
+
const boost = track?.boost ?? null;
|
|
1124
|
+
$('boost-more').classList.toggle('on', boost === 'more');
|
|
1125
|
+
$('boost-more').title = t(boost === 'more' ? 'boostClear' : 'boostMore');
|
|
1126
|
+
$('boost-less').classList.toggle('on', boost === 'less');
|
|
1127
|
+
$('boost-less').title = t(boost === 'less' ? 'boostClear' : 'boostLess');
|
|
1128
|
+
paintBoosts();
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
/**
|
|
1132
|
+
* The boosts in force, each with its time left and a ✕ to end it early —
|
|
1133
|
+
* so a temporary push is never invisible, and never outlives the mood.
|
|
1134
|
+
*/
|
|
1135
|
+
function paintBoosts() {
|
|
1136
|
+
const boosts = state?.boosts ?? [];
|
|
1137
|
+
const now = Date.now();
|
|
1138
|
+
$('boosts').innerHTML = boosts.length
|
|
1139
|
+
? `<span>${esc(t('boostsTitle'))}:</span>` +
|
|
1140
|
+
boosts
|
|
1141
|
+
.map((boost) => {
|
|
1142
|
+
const minutes = Math.max(Math.round((boost.until - now) / 60_000), 1);
|
|
1143
|
+
return `<span class="boost">${boost.direction === 'more' ? '▲' : '▼'} ${esc(boost.name)} · ${esc(t('boostMinutes', { n: minutes }))}<button data-unboost="${boost.id}" title="${esc(t('boostClear'))}">✕</button></span>`;
|
|
1144
|
+
})
|
|
1145
|
+
.join('')
|
|
1146
|
+
: '';
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
/** Boost a track, or clear its boost with `none`, and adopt the host's answer. */
|
|
1150
|
+
async function sendBoost(trackId, direction, button) {
|
|
1151
|
+
if (button) button.disabled = true;
|
|
1152
|
+
try {
|
|
1153
|
+
state = await api('/boost', { method: 'POST', body: { trackId, direction } });
|
|
1154
|
+
render();
|
|
1155
|
+
applyTransport();
|
|
1156
|
+
toast(t(direction === 'more' ? 'boostedMore' : direction === 'less' ? 'boostedLess' : 'boostCleared'));
|
|
1157
|
+
} catch (error) {
|
|
1158
|
+
toast(failureText(error));
|
|
1159
|
+
} finally {
|
|
1160
|
+
if (button) button.disabled = false;
|
|
1161
|
+
}
|
|
990
1162
|
}
|
|
991
1163
|
|
|
992
1164
|
/**
|
|
@@ -1525,7 +1697,7 @@
|
|
|
1525
1697
|
// The engine owns the real gain; mirror it locally and throttle the
|
|
1526
1698
|
// round-trip while the pointer is still down.
|
|
1527
1699
|
if (state) state.volume = value;
|
|
1528
|
-
$('mute')
|
|
1700
|
+
setIcon($('mute'), value === 0 ? 'muted' : 'volume');
|
|
1529
1701
|
if (Date.now() - volumePostAt > 150) {
|
|
1530
1702
|
volumePostAt = Date.now();
|
|
1531
1703
|
control({ action: 'volume', value });
|
|
@@ -1556,6 +1728,19 @@
|
|
|
1556
1728
|
if (await sendTaste(track, 'disliked', event?.currentTarget)) toast(t('disliked'));
|
|
1557
1729
|
};
|
|
1558
1730
|
|
|
1731
|
+
// Both boost buttons are switchers too: the filled one clears its boost.
|
|
1732
|
+
for (const direction of ['more', 'less']) {
|
|
1733
|
+
$(`boost-${direction}`).onclick = (event) => {
|
|
1734
|
+
const track = state?.current;
|
|
1735
|
+
if (!track) return;
|
|
1736
|
+
return sendBoost(track.id, track.boost === direction ? 'none' : direction, event?.currentTarget);
|
|
1737
|
+
};
|
|
1738
|
+
}
|
|
1739
|
+
$('boosts').onclick = (event) => {
|
|
1740
|
+
const target = event.target?.closest?.('[data-unboost]');
|
|
1741
|
+
if (target) return sendBoost(Number(target.dataset.unboost), 'none', target);
|
|
1742
|
+
};
|
|
1743
|
+
|
|
1559
1744
|
$('dj-toggle').onclick = async () => {
|
|
1560
1745
|
try {
|
|
1561
1746
|
const data = await api('/dj', { method: 'POST', body: { enabled: !state?.dj?.enabled, prompt: $('dj-prompt').value } });
|
package/lib/router.js
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
import { Readable } from 'node:stream';
|
|
23
23
|
|
|
24
24
|
import { DEFAULT_LEVEL, LEVELS, isLevel } from './netease.js';
|
|
25
|
-
import { TASTE_LEVELS } from './session.js';
|
|
25
|
+
import { BOOST_DIRECTIONS, TASTE_LEVELS } from './session.js';
|
|
26
26
|
|
|
27
27
|
/** Resolved CDN URLs are reused for this long (they live 20 minutes). */
|
|
28
28
|
const URL_CACHE_MS = 15 * 60 * 1000;
|
|
@@ -309,9 +309,35 @@ export class MusicRouter {
|
|
|
309
309
|
...track,
|
|
310
310
|
liked: this.likes.isLiked(track.id),
|
|
311
311
|
disliked: this.store.taste(track.id) === 'disliked',
|
|
312
|
+
/** A temporary "more/less like this", or null. */
|
|
313
|
+
boost: this.store.boostOf(track.id),
|
|
312
314
|
};
|
|
313
315
|
}
|
|
314
316
|
|
|
317
|
+
/**
|
|
318
|
+
* Boost a track for a while, or clear its boost, and let the DJ act on it now.
|
|
319
|
+
*
|
|
320
|
+
* The track is looked up in the queue first, so the boost can name it without
|
|
321
|
+
* a request; one that is not queued is resolved through NetEase.
|
|
322
|
+
*
|
|
323
|
+
* @returns {Promise<{ok: boolean, status?: number, reason?: string, boost?: object|null, effect?: object}>}
|
|
324
|
+
*/
|
|
325
|
+
async applyBoost(trackId, direction, minutes) {
|
|
326
|
+
const id = Number(trackId);
|
|
327
|
+
if (!Number.isFinite(id)) return { ok: false, status: 400, reason: `invalid track id "${trackId}"` };
|
|
328
|
+
if (direction !== 'none' && !BOOST_DIRECTIONS.includes(direction)) {
|
|
329
|
+
return { ok: false, status: 400, reason: `unknown boost "${direction}" (expected more, less or none)` };
|
|
330
|
+
}
|
|
331
|
+
const track =
|
|
332
|
+
this.player.queue.find((entry) => entry.id === id) ??
|
|
333
|
+
(await this.api.songDetail([id]).then((found) => found[0]).catch(() => null));
|
|
334
|
+
if (!track) return { ok: false, status: 404, reason: `track ${id} not found` };
|
|
335
|
+
const boost = this.store.setBoost(track, direction, minutes);
|
|
336
|
+
const effect = await this.dj.applyBoost(track, direction).catch(() => ({ queued: 0, removed: 0 }));
|
|
337
|
+
this.player.bump();
|
|
338
|
+
return { ok: true, boost, effect };
|
|
339
|
+
}
|
|
340
|
+
|
|
315
341
|
/**
|
|
316
342
|
* The panel's poll target: full player snapshot including account and DJ.
|
|
317
343
|
*
|
|
@@ -326,6 +352,8 @@ export class MusicRouter {
|
|
|
326
352
|
...base,
|
|
327
353
|
queue: base.queue.map((track) => this.tasteView(track)),
|
|
328
354
|
current: this.tasteView(base.current),
|
|
355
|
+
/** Boosts still in force, newest first, with when each ends. */
|
|
356
|
+
boosts: this.store.activeBoosts(),
|
|
329
357
|
account: this.api.account,
|
|
330
358
|
authenticated: this.api.authenticated,
|
|
331
359
|
settings: this.store.settings,
|
|
@@ -561,6 +589,18 @@ export class MusicRouter {
|
|
|
561
589
|
* so a click cannot be turned into the wrong direction by a stale poll, and
|
|
562
590
|
* disliking a liked track is one request rather than two racing ones.
|
|
563
591
|
*/
|
|
592
|
+
/**
|
|
593
|
+
* A temporary push on the DJ: `direction` is `more` or `less` for an hour
|
|
594
|
+
* (or `minutes`), and `none` clears it. Unlike a taste level it expires on
|
|
595
|
+
* its own.
|
|
596
|
+
*/
|
|
597
|
+
if (route === '/boost' && method === 'POST') {
|
|
598
|
+
const { trackId, direction, minutes } = await readJson(req);
|
|
599
|
+
const applied = await this.applyBoost(trackId, direction, minutes);
|
|
600
|
+
if (!applied.ok) return sendJson(res, applied.status ?? 502, { error: applied.reason });
|
|
601
|
+
return sendJson(res, 200, await this.snapshot({ boostEffect: applied.effect }));
|
|
602
|
+
}
|
|
603
|
+
|
|
564
604
|
if (route === '/taste' && method === 'POST') {
|
|
565
605
|
const { trackId, level } = await readJson(req);
|
|
566
606
|
const applied = await this.applyTaste(trackId, level);
|
package/lib/session.js
CHANGED
|
@@ -29,6 +29,17 @@ const MAX_FEEDBACK = 500;
|
|
|
29
29
|
*/
|
|
30
30
|
export const TASTE_LEVELS = ['liked', 'none', 'disliked'];
|
|
31
31
|
|
|
32
|
+
/** The directions a temporary boost can push the DJ in. */
|
|
33
|
+
export const BOOST_DIRECTIONS = ['more', 'less'];
|
|
34
|
+
|
|
35
|
+
/** How long a boost lasts unless asked otherwise, and the bounds on asking. */
|
|
36
|
+
export const BOOST_DEFAULT_MINUTES = 60;
|
|
37
|
+
const BOOST_MIN_MINUTES = 5;
|
|
38
|
+
const BOOST_MAX_MINUTES = 12 * 60;
|
|
39
|
+
|
|
40
|
+
/** Boosts held at once; the oldest goes first. */
|
|
41
|
+
const MAX_BOOSTS = 10;
|
|
42
|
+
|
|
32
43
|
/** QR codes are refreshed before the API reports them expired. */
|
|
33
44
|
const QR_TTL_MS = 110_000;
|
|
34
45
|
|
|
@@ -71,6 +82,12 @@ function emptyState() {
|
|
|
71
82
|
},
|
|
72
83
|
history: [],
|
|
73
84
|
feedback: { likes: [], dislikes: [], skips: [] },
|
|
85
|
+
/**
|
|
86
|
+
* Temporary pushes on the DJ: "more like this" or "less like this" for one
|
|
87
|
+
* track, until `until`. Unlike a taste level they expire on their own, so a
|
|
88
|
+
* passing mood does not become a standing preference.
|
|
89
|
+
*/
|
|
90
|
+
boosts: [],
|
|
74
91
|
};
|
|
75
92
|
}
|
|
76
93
|
|
|
@@ -335,6 +352,46 @@ export class SessionStore {
|
|
|
335
352
|
return this.state.feedback;
|
|
336
353
|
}
|
|
337
354
|
|
|
355
|
+
// ---------------------------------------------------------------- boosts
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* Boost one track for a while, replacing any boost it already has, or clear
|
|
359
|
+
* it with direction `none`.
|
|
360
|
+
*
|
|
361
|
+
* @param {{id: number, name?: string, artists?: string[]}} track
|
|
362
|
+
* @param {'more'|'less'|'none'} direction
|
|
363
|
+
* @param {number} [minutes] how long it lasts; clamped to 5 minutes – 12 hours.
|
|
364
|
+
* @returns {object|null} the boost now held, or null when it was cleared.
|
|
365
|
+
*/
|
|
366
|
+
setBoost(track, direction, minutes = BOOST_DEFAULT_MINUTES) {
|
|
367
|
+
const id = Number(track?.id);
|
|
368
|
+
if (!Number.isFinite(id)) return null;
|
|
369
|
+
const now = Date.now();
|
|
370
|
+
this.state.boosts = (this.state.boosts ?? []).filter((boost) => boost.id !== id && boost.until > now);
|
|
371
|
+
if (!BOOST_DIRECTIONS.includes(direction)) {
|
|
372
|
+
this.save();
|
|
373
|
+
return null;
|
|
374
|
+
}
|
|
375
|
+
const span = Math.min(Math.max(Number(minutes) || BOOST_DEFAULT_MINUTES, BOOST_MIN_MINUTES), BOOST_MAX_MINUTES);
|
|
376
|
+
const boost = { id, name: track.name ?? '', artists: track.artists ?? [], direction, until: now + span * 60_000 };
|
|
377
|
+
this.state.boosts.unshift(boost);
|
|
378
|
+
if (this.state.boosts.length > MAX_BOOSTS) this.state.boosts.length = MAX_BOOSTS;
|
|
379
|
+
// Written through: a boost is a deliberate act, and it is short-lived
|
|
380
|
+
// enough that losing it to a crash would be most of its life.
|
|
381
|
+
this.save();
|
|
382
|
+
return boost;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
/** The boosts still in force, newest first. Expired ones are simply not returned. */
|
|
386
|
+
activeBoosts(now = Date.now()) {
|
|
387
|
+
return (this.state.boosts ?? []).filter((boost) => boost.until > now);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/** One track's boost direction, or null. */
|
|
391
|
+
boostOf(trackId, now = Date.now()) {
|
|
392
|
+
return this.activeBoosts(now).find((boost) => boost.id === Number(trackId))?.direction ?? null;
|
|
393
|
+
}
|
|
394
|
+
|
|
338
395
|
/**
|
|
339
396
|
* A compact digest for the DJ prompt: what has been played, what is liked,
|
|
340
397
|
* what is disliked — never the raw cookie or account details.
|
package/lib/state.js
CHANGED
|
@@ -169,11 +169,11 @@ export class Player {
|
|
|
169
169
|
}
|
|
170
170
|
|
|
171
171
|
/** Insert tracks directly after the cursor. */
|
|
172
|
-
insertNext(tracks, { source } = {}) {
|
|
172
|
+
insertNext(tracks, { source, queuedBy } = {}) {
|
|
173
173
|
const existing = new Set(this.queue.map((track) => track.id));
|
|
174
174
|
const added = [];
|
|
175
175
|
for (const raw of tracks) {
|
|
176
|
-
const track = normalizeTrack(raw) ?? raw;
|
|
176
|
+
const track = tag(normalizeTrack(raw) ?? raw, queuedBy);
|
|
177
177
|
if (!track?.id || existing.has(track.id)) continue;
|
|
178
178
|
existing.add(track.id);
|
|
179
179
|
added.push(track);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@doitian/dsh-music",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "NetEase Cloud Music (music.163.com) player and AI DJ for DeepSeek Harness: a sidebar page with in-app playback, QR sign-in, and agent tools that curate the queue.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dsh",
|