@doitian/dsh-music 0.1.6 → 0.1.8
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 +14 -7
- package/lib/dj.js +151 -16
- package/lib/index.js +54 -1
- package/lib/netease.js +56 -2
- package/lib/panel.html +348 -163
- package/lib/router.js +41 -1
- package/lib/scrobble.js +85 -0
- package/lib/session.js +57 -0
- package/lib/state.js +57 -2
- package/lib/weapi.js +58 -0
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -24,6 +24,8 @@ Optional. Signed out, search, charts, playlists, lyrics and non-VIP playback all
|
|
|
24
24
|
|
|
25
25
|
Click **登录 Sign in** in the player and scan the QR code with the NetEase Cloud Music app, or ask the agent to use `music_login`. The cookie is stored in `$DSH_HOME/music/session.json`.
|
|
26
26
|
|
|
27
|
+
**Listening history.** Signed in, songs you play here show up in your NetEase history — 最近播放 and 听歌排行 — on every device, as plays from the web. A song counts once you've listened past the skip window (30 seconds, or a quarter of a long song); one you skip sooner isn't recorded. To keep your plays local, set `scrobble: false` (see [Configuration](#configuration)).
|
|
28
|
+
|
|
27
29
|
## Agent tools
|
|
28
30
|
|
|
29
31
|
| Tool | Purpose |
|
|
@@ -32,7 +34,7 @@ Click **登录 Sign in** in the player and scan the QR code with the NetEase Clo
|
|
|
32
34
|
| `music_play` | Queue and play, by ids or a search query |
|
|
33
35
|
| `music_queue` | Show, append, insert, replace, remove, jump, clear |
|
|
34
36
|
| `music_control` | Play, pause, next, previous, seek, volume, mute, mode |
|
|
35
|
-
| `music_dj` | Run or configure the AI DJ, with an optional mood brief |
|
|
37
|
+
| `music_dj` | Run or configure the AI DJ, with an optional mood brief or a temporary boost |
|
|
36
38
|
| `music_now_playing` | What is playing and next, and whether you're signed in |
|
|
37
39
|
| `music_login` | Status, QR, poll, set a cookie, log out |
|
|
38
40
|
|
|
@@ -40,27 +42,31 @@ Music plays in the Harness window, so keep it open. Playback continues while you
|
|
|
40
42
|
|
|
41
43
|
## Using the player
|
|
42
44
|
|
|
43
|
-
|
|
45
|
+
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.
|
|
46
|
+
|
|
47
|
+
**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
48
|
|
|
45
49
|
**Taste.** Each track is liked, unrated or disliked:
|
|
46
50
|
|
|
47
51
|
| Control | Effect |
|
|
48
52
|
|---|---|
|
|
49
|
-
| ♡ (
|
|
50
|
-
| ✕ (
|
|
53
|
+
| ♡ (beside the title, or on a queue row) | Like on your NetEase account. Click again to unlike. |
|
|
54
|
+
| ✕ (beside the title) | Dislike: the track leaves the queue, and the next one plays. Local only; the DJ stops picking it. |
|
|
51
55
|
| ✕ (queue row) | Remove the track. An unrated track is also recorded as disliked. |
|
|
52
56
|
|
|
53
57
|
**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
58
|
|
|
55
59
|
## The AI DJ
|
|
56
60
|
|
|
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.
|
|
61
|
+
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
62
|
|
|
59
63
|
**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
64
|
|
|
61
65
|
**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
66
|
|
|
63
|
-
**
|
|
67
|
+
**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.
|
|
68
|
+
|
|
69
|
+
**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
70
|
|
|
65
71
|
**Who chooses:**
|
|
66
72
|
|
|
@@ -91,6 +97,7 @@ All fields are optional, under the plugin entry's `config` in your profile's `co
|
|
|
91
97
|
| `audioLevel` | `exhigh` | Starting quality, until you pick one in the player |
|
|
92
98
|
| `dataDir` | `$DSH_HOME/music` | Where `session.json` lives |
|
|
93
99
|
| `requestTimeoutMs` | `15000` | NetEase request deadline |
|
|
100
|
+
| `scrobble` | `true` | Report your plays to your NetEase listening history |
|
|
94
101
|
| `dj.provider` / `dj.model` | session model | The DJ's model, as above |
|
|
95
102
|
|
|
96
103
|
Batch size (`djBatchSize`, 5) and refill threshold (`djAutoExtendBelow`, 3) have no control in the player. Edit them in `session.json` while the harness is stopped.
|
|
@@ -112,6 +119,6 @@ Batch size (`djBatchSize`, 5) and refill threshold (`djAutoExtendBelow`, 3) have
|
|
|
112
119
|
## Known limitations
|
|
113
120
|
|
|
114
121
|
- VIP tracks don't play while signed out, and some tracks are sold per album, so they don't play even with VIP (for example 晴天, `id 186016`).
|
|
115
|
-
-
|
|
122
|
+
- There is no playlist editing and no heartbeat mode (心动模式), and a dislike stays local: NetEase has no plain endpoint for any of them.
|
|
116
123
|
- The DJ's model mode hasn't yet been tested end to end with a real model. If it misbehaves, `dj.modelError` says why, and the DJ keeps working without it.
|
|
117
124
|
- Only your newest 500 likes are offered back as candidates.
|
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
|
@@ -24,6 +24,7 @@ import { Player } from './state.js';
|
|
|
24
24
|
import { AiDj } from './dj.js';
|
|
25
25
|
import { LikeState } from './likes.js';
|
|
26
26
|
import { MusicRouter } from './router.js';
|
|
27
|
+
import { Scrobbler } from './scrobble.js';
|
|
27
28
|
|
|
28
29
|
export const name = 'music';
|
|
29
30
|
|
|
@@ -237,6 +238,12 @@ export function apply(ctx, config = {}) {
|
|
|
237
238
|
});
|
|
238
239
|
player.onHeard = (track) => store.confirmPlay(track.id);
|
|
239
240
|
|
|
241
|
+
// Plays reach the account's listening history the way the web player's do.
|
|
242
|
+
// On by default; `config.scrobble: false` keeps them local.
|
|
243
|
+
const scrobbler = new Scrobbler({ api, enabled: config.scrobble !== false, logger });
|
|
244
|
+
player.onStart = (track) => scrobbler.start(track);
|
|
245
|
+
player.onFinish = (track, play) => void scrobbler.finish(track, play);
|
|
246
|
+
|
|
240
247
|
// A periodic sweep catches the cases the track-end hook misses: a paused
|
|
241
248
|
// panel, a failed track, or a DJ that was switched on with a short queue.
|
|
242
249
|
const sweep = setInterval(() => {
|
|
@@ -286,6 +293,8 @@ export function apply(ctx, config = {}) {
|
|
|
286
293
|
},
|
|
287
294
|
/** How much of the account's like state is cached, and why it is not. */
|
|
288
295
|
likes: likes.status(),
|
|
296
|
+
/** Whether plays are reported to the listening history, and how the last went. */
|
|
297
|
+
scrobble: scrobbler.status(),
|
|
289
298
|
dataDir,
|
|
290
299
|
session: { authenticated: api.authenticated, nickname: api.account?.nickname ?? null, vip: Boolean(api.account?.vip) },
|
|
291
300
|
uptimeMs: Math.round(process.uptime() * 1000),
|
|
@@ -517,7 +526,9 @@ export function apply(ctx, config = {}) {
|
|
|
517
526
|
'Run or configure the continuous AI DJ for the user\'s NetEase Cloud Music panel. ' +
|
|
518
527
|
'With `enabled: true` the DJ keeps the queue stocked: it gathers candidates from similar songs, personal FM, ' +
|
|
519
528
|
'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,
|
|
529
|
+
'listener\'s liked artists and their likes, dislikes and skips. Pass `prompt` for a mood or vibe, and `replan` to refill now. ' +
|
|
530
|
+
'Pass `boost` to steer it for a while — `more` or `less` songs like a track (the playing one by default) for an hour, ' +
|
|
531
|
+
'or `none` to clear — when the listener wants more or fewer like a song without a lasting like or dislike.',
|
|
521
532
|
parameters: {
|
|
522
533
|
type: 'object',
|
|
523
534
|
additionalProperties: false,
|
|
@@ -530,6 +541,13 @@ export function apply(ctx, config = {}) {
|
|
|
530
541
|
description: 'How many tracks to plan (1-25; default 8 for `start`, the player\'s batch size for `replan`).',
|
|
531
542
|
},
|
|
532
543
|
start: { type: 'boolean', description: 'Replace the queue with a freshly planned batch (a full DJ session).' },
|
|
544
|
+
boost: {
|
|
545
|
+
type: 'string',
|
|
546
|
+
enum: ['more', 'less', 'none'],
|
|
547
|
+
description: 'Temporarily steer the DJ toward (`more`) or away from (`less`) songs like a track, or clear its boost (`none`).',
|
|
548
|
+
},
|
|
549
|
+
boostTrackId: { type: 'integer', description: 'The track to boost; defaults to the one playing.' },
|
|
550
|
+
boostMinutes: { type: 'integer', description: 'How long the boost lasts, 5-720 minutes (default 60).' },
|
|
533
551
|
},
|
|
534
552
|
},
|
|
535
553
|
render: (_args, value) => [
|
|
@@ -540,6 +558,15 @@ export function apply(ctx, config = {}) {
|
|
|
540
558
|
(value.modelError ? `Model tier unavailable: ${value.modelError}. ` : '') +
|
|
541
559
|
(value.vibe ? `Vibe: ${value.vibe}. ` : '') +
|
|
542
560
|
(value.searchedAs.length ? `Brief searched as: ${value.searchedAs.join('; ')}. ` : '') +
|
|
561
|
+
(value.boostError ? `Boost not applied: ${value.boostError}. ` : '') +
|
|
562
|
+
(value.boosted
|
|
563
|
+
? `Boost: ${value.boosted.direction === 'more' ? 'more' : 'fewer'} songs like ${value.boosted.name} for ` +
|
|
564
|
+
`${value.boosted.minutes} min${value.boosted.queued ? `, ${value.boosted.queued} queued next` : ''}` +
|
|
565
|
+
`${value.boosted.removed ? `, ${value.boosted.removed} removed from the queue` : ''}. `
|
|
566
|
+
: '') +
|
|
567
|
+
(value.boosts.length
|
|
568
|
+
? `Active boosts: ${value.boosts.map((boost) => `${boost.direction} like ${boost.name} (${boost.minutesLeft} min left)`).join('; ')}. `
|
|
569
|
+
: '') +
|
|
543
570
|
(value.names.length
|
|
544
571
|
? `Queued ${value.added} track(s):\n${value.names.map((entry, index) => `${index + 1}. ${entry}`).join('\n')}`
|
|
545
572
|
: value.note || 'No new tracks were queued.') +
|
|
@@ -551,6 +578,24 @@ export function apply(ctx, config = {}) {
|
|
|
551
578
|
const prompt = args.prompt === undefined ? undefined : String(args.prompt);
|
|
552
579
|
if (enabled !== undefined || prompt !== undefined) dj.setEnabled(enabled ?? player.dj.enabled, { prompt });
|
|
553
580
|
|
|
581
|
+
let boosted = null;
|
|
582
|
+
let boostError = null;
|
|
583
|
+
if (args.boost !== undefined) {
|
|
584
|
+
const trackId = args.boostTrackId ?? player.current()?.id;
|
|
585
|
+
const applied = trackId === undefined
|
|
586
|
+
? { ok: false, reason: 'nothing is playing, so pass boostTrackId' }
|
|
587
|
+
: await router.applyBoost(trackId, String(args.boost), args.boostMinutes);
|
|
588
|
+
if (!applied.ok) boostError = applied.reason;
|
|
589
|
+
else if (applied.boost) {
|
|
590
|
+
boosted = {
|
|
591
|
+
direction: applied.boost.direction,
|
|
592
|
+
name: applied.boost.name,
|
|
593
|
+
minutes: Math.round((applied.boost.until - Date.now()) / 60_000),
|
|
594
|
+
...applied.effect,
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
|
|
554
599
|
const count = Math.min(Math.max(Number(args.count) || 8, 1), 25);
|
|
555
600
|
let plan = null;
|
|
556
601
|
if (args.start) {
|
|
@@ -573,6 +618,14 @@ export function apply(ctx, config = {}) {
|
|
|
573
618
|
authenticated: api.authenticated,
|
|
574
619
|
current: summary.current,
|
|
575
620
|
remaining: summary.remaining,
|
|
621
|
+
boosted,
|
|
622
|
+
boostError,
|
|
623
|
+
boosts: store.activeBoosts().map((boost) => ({
|
|
624
|
+
id: boost.id,
|
|
625
|
+
name: boost.name,
|
|
626
|
+
direction: boost.direction,
|
|
627
|
+
minutesLeft: Math.max(Math.round((boost.until - Date.now()) / 60_000), 1),
|
|
628
|
+
})),
|
|
576
629
|
};
|
|
577
630
|
},
|
|
578
631
|
});
|
package/lib/netease.js
CHANGED
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
* Minimal, dependency-free client for the NetEase Cloud Music (music.163.com)
|
|
3
3
|
* web API.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
* encryption and work with a normal browser session cookie.
|
|
5
|
+
* The plain (non-`weapi`/`eapi`) endpoints are used wherever they work: they
|
|
6
|
+
* need no request encryption and work with a normal browser session cookie.
|
|
7
|
+
* The one exception is scrobbling ({@link Netease#weblog}), which only counts
|
|
8
|
+
* when sent the way the web player sends it. Authentication
|
|
7
9
|
* upgrades the client from anonymous browsing to personal recommendations and
|
|
8
10
|
* VIP song URLs; everything else works without it.
|
|
9
11
|
*
|
|
@@ -17,13 +19,31 @@
|
|
|
17
19
|
* - `api/song/like` POST: like / un-like, needs a session
|
|
18
20
|
* - `api/song/like/check` which of these ids the account liked
|
|
19
21
|
* - `api/login/qrcode/*` QR login handshake
|
|
22
|
+
* - `weapi/feedback/weblog` on clientlogusf.music.163.com: play logs,
|
|
23
|
+
* which is what the listening history is built from
|
|
20
24
|
*
|
|
21
25
|
* @module dsh-music/netease
|
|
22
26
|
*/
|
|
23
27
|
|
|
28
|
+
import { weapiEncrypt } from './weapi.js';
|
|
29
|
+
|
|
24
30
|
/** Hosts used by the public web client. */
|
|
25
31
|
const API_ORIGIN = 'https://music.163.com';
|
|
26
32
|
|
|
33
|
+
/**
|
|
34
|
+
* Where the web player sends its play logs. The same path on music.163.com
|
|
35
|
+
* answers `success` and records nothing, which is why plays from this plugin
|
|
36
|
+
* never reached the listening history until this host was found.
|
|
37
|
+
*/
|
|
38
|
+
const LOG_ORIGIN = 'https://clientlogusf.music.163.com';
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The cookies that mark a request as the desktop client. A play log carrying
|
|
42
|
+
* them is dropped, so the log request sends the session without them — as the
|
|
43
|
+
* web player, which it is.
|
|
44
|
+
*/
|
|
45
|
+
const CLIENT_COOKIES = /^(os|appver|channel)=/;
|
|
46
|
+
|
|
27
47
|
/** A desktop-browser UA; NetEase serves different shapes to unknown agents. */
|
|
28
48
|
const UA =
|
|
29
49
|
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36';
|
|
@@ -579,6 +599,40 @@ export class Netease {
|
|
|
579
599
|
return normalizeTracks(data?.data);
|
|
580
600
|
}
|
|
581
601
|
|
|
602
|
+
// --------------------------------------------------------------- play logs
|
|
603
|
+
|
|
604
|
+
/**
|
|
605
|
+
* Send play logs the way the web player does: weapi-encrypted, to the log
|
|
606
|
+
* host, with the session but not the desktop-client cookies. Verified live —
|
|
607
|
+
* a `startplay` then a `play` of 阴天 reached 最近播放 within 20 seconds,
|
|
608
|
+
* while the same logs with `os=pc` set, or sent to music.163.com, were
|
|
609
|
+
* accepted and never recorded.
|
|
610
|
+
*
|
|
611
|
+
* @param {object[]} logs `{action, json}` entries, as the web player builds them.
|
|
612
|
+
* @throws {NeteaseError} when NetEase refuses the logs.
|
|
613
|
+
*/
|
|
614
|
+
async weblog(logs) {
|
|
615
|
+
const csrf = this.jar.get('__csrf') ?? '';
|
|
616
|
+
const cookie = this.jar
|
|
617
|
+
.header()
|
|
618
|
+
.split(/;\s*/)
|
|
619
|
+
.filter((pair) => pair && !CLIENT_COOKIES.test(pair))
|
|
620
|
+
.join('; ');
|
|
621
|
+
const data = await this.call(`${LOG_ORIGIN}/weapi/feedback/weblog`, {
|
|
622
|
+
method: 'POST',
|
|
623
|
+
query: { csrf_token: csrf },
|
|
624
|
+
body: weapiEncrypt({ logs: JSON.stringify(logs), csrf_token: csrf }),
|
|
625
|
+
headers: { Cookie: cookie },
|
|
626
|
+
});
|
|
627
|
+
if (String(data?.code) !== '200') {
|
|
628
|
+
throw new NeteaseError(data?.message || `weblog refused (code ${data?.code})`, {
|
|
629
|
+
code: data?.code,
|
|
630
|
+
endpoint: 'feedback/weblog',
|
|
631
|
+
});
|
|
632
|
+
}
|
|
633
|
+
return data;
|
|
634
|
+
}
|
|
635
|
+
|
|
582
636
|
// ------------------------------------------------------------------ likes
|
|
583
637
|
|
|
584
638
|
/**
|