@audiofool/moondog 0.4.0-beta.2 → 0.4.0-beta.4
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 +19 -8
- package/package.json +1 -1
- package/scripts/moondog.mjs +130 -106
- package/src/core/apple-library-source-status.mjs +64 -18
- package/src/core/apple-projection-domain-services.mjs +67 -52
- package/src/core/capability-catalog.mjs +18 -2
- package/src/core/import-source-history.mjs +28 -0
- package/src/core/library-draft.mjs +16 -0
- package/src/core/library-names.mjs +12 -0
- package/src/core/library-store.mjs +361 -23
- package/src/core/listener-avoids.mjs +31 -0
- package/src/core/listening-action.mjs +41 -0
- package/src/core/listening-moment.mjs +67 -0
- package/src/core/listening-now.mjs +69 -28
- package/src/core/listening-profile-domain-services.mjs +32 -18
- package/src/core/listening-scope.mjs +119 -0
- package/src/core/moondog-application.mjs +1045 -270
- package/src/core/play-follower.mjs +104 -0
- package/src/core/portable-playlist.mjs +125 -0
- package/src/core/profile-discovery-draft.mjs +35 -0
- package/src/core/track-title.mjs +70 -4
- package/src/i18n/import-history.mjs +647 -0
- package/src/i18n/messages/de.mjs +3 -3
- package/src/i18n/messages/en.mjs +3 -3
- package/src/i18n/messages/es.mjs +3 -3
- package/src/i18n/messages/fr.mjs +3 -3
- package/src/i18n/messages/it.mjs +3 -3
- package/src/i18n/messages/ja.mjs +3 -3
- package/src/i18n/messages/ko.mjs +3 -3
- package/src/i18n/messages/pt.mjs +3 -3
- package/src/i18n/messages/zh-Hant.mjs +3 -3
- package/src/i18n/messages/zh.mjs +3 -3
- package/src/i18n/screen/es.mjs +90 -26
- package/src/i18n/screen/ja.mjs +89 -25
- package/src/i18n/screen/pt.mjs +90 -26
- package/src/i18n/screen/zh.mjs +89 -25
- package/src/importers/apple-music-library/import-batch.mjs +64 -32
- package/src/importers/apple-music-library/normalize.mjs +36 -6
- package/src/importers/apple-music-library/save-time.mjs +17 -0
- package/src/importers/zip-reader.mjs +24 -2
- package/src/integrations/apple-music/catalog-playlist-reader.mjs +111 -0
- package/src/integrations/apple-music/catalog.mjs +84 -25
- package/src/integrations/apple-music/music-app-listening.mjs +107 -0
- package/src/integrations/apple-music/music-app.mjs +6 -2
- package/src/integrations/apple-music/song-id.mjs +13 -0
- package/src/integrations/apple-music/terminal-preview-player.mjs +154 -44
- package/src/integrations/listenbrainz/history-file.mjs +63 -35
- package/src/integrations/netease/ncm-cli-player.mjs +355 -68
- package/src/integrations/netease/queue-occurrence.mjs +138 -0
- package/src/integrations/playlist-links.mjs +93 -30
- package/src/integrations/public-playlists.mjs +21 -15
- package/src/integrations/spotify/account-data-history.mjs +9 -10
- package/src/integrations/spotify/account-data-profile.mjs +1 -0
- package/src/integrations/spotify/extended-streaming-history.mjs +57 -52
- package/src/integrations/spotify/history-archive.mjs +8 -18
- package/src/integrations/spotify/library-snapshot.mjs +2 -1
- package/src/integrations/spotify/service.mjs +29 -11
- package/src/integrations/spotify/web-api-client.mjs +2 -2
- package/src/integrations/stable-audio/local-generator.mjs +13 -5
- package/src/integrations/youtube-music/takeout.mjs +12 -8
- package/src/memory/local-memory-store.mjs +479 -27
- package/src/memory/reflection-worker.mjs +19 -0
- package/src/profile/apple-library-import.mjs +56 -2
- package/src/profile/history-import.mjs +58 -27
- package/src/profile/listener-corrections.mjs +2 -4
- package/src/profile/listener-profile-build.mjs +133 -46
- package/src/profile/listener-profile-store.mjs +57 -4
- package/src/profile/listener-profile-verification.mjs +11 -5
- package/src/profile/listener-profile-worker.mjs +36 -10
- package/src/profile/listening-history-store.mjs +975 -354
- package/src/profile/listening-profile-projection.mjs +130 -160
- package/src/profile/local-file-import.mjs +172 -0
- package/src/profile/moondog-suggestions.mjs +40 -11
- package/src/profile/profile-exploration.mjs +36 -6
- package/src/profile/recorded-measures.mjs +5 -0
- package/src/profile/spotify-archive-taste.mjs +41 -65
- package/src/runtime/pi/agent-runtime.mjs +368 -221
- package/src/runtime/pi/custom-endpoints.mjs +30 -8
- package/src/runtime/pi/memory-agent-runtime.mjs +45 -3
- package/src/runtime/pi/moondog-model.mjs +6 -0
- package/src/runtime/pi/playback-rules.mjs +100 -0
- package/src/runtime/pi/profile-build-runtime.mjs +85 -24
- package/src/surfaces/cli/brand-components.mjs +9 -6
- package/src/surfaces/cli/command-completions.mjs +8 -1
- package/src/surfaces/cli/format-output.mjs +207 -34
- package/src/surfaces/cli/history-import-view.mjs +130 -21
- package/src/surfaces/cli/listenbrainz-command.mjs +7 -2
- package/src/surfaces/cli/listener-profile-command.mjs +67 -8
- package/src/surfaces/cli/listening-menu.mjs +3 -0
- package/src/surfaces/cli/profile-command.mjs +1 -0
- package/src/surfaces/cli/spotify-command.mjs +17 -25
- package/src/surfaces/cli/taste-period.mjs +22 -0
- package/src/surfaces/cli/taste-profile-model.mjs +52 -32
- package/src/surfaces/cli/tui.mjs +557 -170
- package/src/surfaces/html/tasteprint.mjs +181 -93
- package/src/surfaces/import-source-history.mjs +80 -0
|
@@ -1,8 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { recentListeningPeriod, recordedHistoryThrough } from "./taste-period.mjs";
|
|
2
|
+
import { utcDay } from "../import-source-history.mjs";
|
|
3
|
+
import { collectionCoverageLines, profiledListeningMetrics, sanitizeTerminalText } from "./format-output.mjs";
|
|
2
4
|
import { intlLocale, screenTranslator } from "../../i18n/index.mjs";
|
|
3
5
|
|
|
4
6
|
const MAX_ITEMS_PER_SOURCE = 10;
|
|
5
7
|
|
|
8
|
+
// The listener can review every choice they've saved. Listening rankings and agent summaries stay bounded.
|
|
9
|
+
export async function readTasteReviewProfile(application) {
|
|
10
|
+
const profile = await application.getProfileSummary({ maxItems: MAX_ITEMS_PER_SOURCE }, { includeReviewTracks: true });
|
|
11
|
+
const reviewChoices = application.tasteReviewChoices?.();
|
|
12
|
+
return Array.isArray(reviewChoices) ? { ...profile, reviewChoices } : profile;
|
|
13
|
+
}
|
|
14
|
+
|
|
6
15
|
function items(value) {
|
|
7
16
|
return Array.isArray(value) ? value.slice(0, MAX_ITEMS_PER_SOURCE) : [];
|
|
8
17
|
}
|
|
@@ -39,6 +48,15 @@ function date(value) {
|
|
|
39
48
|
Number.isFinite(Date.parse(value)) ? inline(value).slice(0, 10) : "";
|
|
40
49
|
}
|
|
41
50
|
|
|
51
|
+
function playsInMultipleYears(item) {
|
|
52
|
+
const first = utcDay(item?.first_played_at);
|
|
53
|
+
const last = utcDay(item?.last_played_at);
|
|
54
|
+
if (first && last) return first.slice(0, 4) < last.slice(0, 4);
|
|
55
|
+
const years = Array.isArray(item?.yearly_plays) ? item.yearly_plays : [];
|
|
56
|
+
const played = years.filter(row => Number.isInteger(row?.year) && Number.isInteger(row.plays) && row.plays > 0);
|
|
57
|
+
return new Set(played.map(row => row.year)).size > 1;
|
|
58
|
+
}
|
|
59
|
+
|
|
42
60
|
function targetFor(item, kind) {
|
|
43
61
|
const label = kind === "artist" ? item?.name ?? item?.label : item?.label;
|
|
44
62
|
if (!inline(label) || !["artist", "track"].includes(kind)) return null;
|
|
@@ -83,32 +101,27 @@ function itemMetrics(item, tr) {
|
|
|
83
101
|
return values;
|
|
84
102
|
}
|
|
85
103
|
|
|
86
|
-
function overview(profile, tr) {
|
|
104
|
+
function overview(profile, tr, { playCount, timedCount, hours }) {
|
|
87
105
|
const coverage = profile?.coverage ?? {};
|
|
88
106
|
const lines = [];
|
|
89
|
-
const durationUnavailable =
|
|
90
|
-
const hours = durationUnavailable ? undefined : amount(coverage.listening_hours, tr.locale);
|
|
107
|
+
const durationUnavailable = playCount > 0 && timedCount === 0;
|
|
91
108
|
const listening = [
|
|
92
|
-
...(count(
|
|
93
|
-
...(hours
|
|
109
|
+
...(count(playCount) !== undefined ? [tr.n(playCount, "{count} play", "{count} plays")] : []),
|
|
110
|
+
...(hours ? [hours] : []),
|
|
94
111
|
...(count(coverage.listening_tracks) !== undefined ? [tr.n(coverage.listening_tracks, "{count} track", "{count} tracks")] : []),
|
|
95
112
|
];
|
|
96
113
|
if (durationUnavailable) listening.push(tr("listening time unknown"));
|
|
97
|
-
|
|
114
|
+
const collections = collectionCoverageLines(coverage, tr);
|
|
115
|
+
if (listening.length && !(playCount === 0 && collections.length)) {
|
|
98
116
|
lines.push(listening.join(" · "));
|
|
99
117
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
lines.push(loved === undefined ? tr("Apple Music library: {tracks}", { tracks })
|
|
104
|
-
: tr("Apple Music library: {tracks} · {loved} loved", { tracks, loved: tr.number(coverage.loved_or_favorited) }));
|
|
118
|
+
lines.push(...collections);
|
|
119
|
+
if (timedCount > 0 && timedCount < playCount) {
|
|
120
|
+
lines.push(tr("Listening time is known for {count} of those plays", { count: tr.number(timedCount) }));
|
|
105
121
|
}
|
|
122
|
+
const privatePlays = profile?.listening_behavior?.context?.incognito_events_excluded;
|
|
123
|
+
if (privatePlays > 0) lines.push(tr.n(privatePlays, "{count} private-session play left out", "{count} private-session plays left out"));
|
|
106
124
|
const source = profile?.listening_source ?? {};
|
|
107
|
-
const collections = items(coverage.collection_sources).filter((collection) => collection.tracks > 0);
|
|
108
|
-
if (collections.length > 1) lines.push(tr("{songs} across {count} services", { songs: tr.n(coverage.collection_tracks, "{count} song", "{count} songs"), count: collections.length }));
|
|
109
|
-
for (const collection of collections) {
|
|
110
|
-
if (collection.tracks > 0) lines.push(`${inline(collection.label)}: ${tr.n(collection.tracks, "{count} song", "{count} songs")}`);
|
|
111
|
-
}
|
|
112
125
|
const providers = items(source.providers).map(inline).filter(Boolean).map((provider) => ({
|
|
113
126
|
spotify: "Spotify",
|
|
114
127
|
listenbrainz: "ListenBrainz",
|
|
@@ -149,20 +162,23 @@ function explicitKind(item) {
|
|
|
149
162
|
|
|
150
163
|
/** Build a private, bounded review view from structured profile evidence. */
|
|
151
164
|
export function buildTasteProfileModel(profile = {}, tr = screenTranslator("en")) {
|
|
152
|
-
const
|
|
165
|
+
const listening = profiledListeningMetrics(profile, tr);
|
|
166
|
+
const metrics = (item) => itemMetrics(listening.timedCount === 0
|
|
153
167
|
? { ...item, listening_minutes: undefined } : item, tr);
|
|
154
168
|
const withDetails = (source, details) => details.length ? tr("{source}: {details}", { source, details: details.join(" · ") }) : source;
|
|
155
169
|
const subjects = new Map();
|
|
156
|
-
const
|
|
170
|
+
const appleLibrary = tr("In your Apple Music library");
|
|
171
|
+
const applePlayCount = tr("Apple Music play count");
|
|
157
172
|
const assertions = profile?.listener_assertions ?? {};
|
|
158
173
|
const behavior = profile?.listening_behavior ?? {};
|
|
159
174
|
const curated = profile?.curated_preferences ?? {};
|
|
160
175
|
|
|
161
|
-
function add(item, kind, source, detail, { assertion = false } = {}) {
|
|
176
|
+
function add(item, kind, source, detail, { assertion = false, membership = false } = {}) {
|
|
162
177
|
const target = targetFor(item, kind);
|
|
163
178
|
if (!target) return;
|
|
164
179
|
const key = subjectKey(target);
|
|
165
180
|
let subject = subjects.get(key);
|
|
181
|
+
if (membership && subject?.evidence.some(entry => entry.source === appleLibrary || entry.source === applePlayCount)) return;
|
|
166
182
|
if (!subject) {
|
|
167
183
|
subject = {
|
|
168
184
|
key,
|
|
@@ -174,9 +190,8 @@ export function buildTasteProfileModel(profile = {}, tr = screenTranslator("en")
|
|
|
174
190
|
evidence: [],
|
|
175
191
|
};
|
|
176
192
|
subjects.set(key, subject);
|
|
177
|
-
seenDetails.set(key, new Set());
|
|
178
193
|
}
|
|
179
|
-
const evidenceId = identifier(item?.evidence_id);
|
|
194
|
+
const evidenceId = identifier(item?.evidence_id ?? (assertion ? item?.correction_id : null));
|
|
180
195
|
if (evidenceId && !subject.evidence.some((evidence) => evidence.id === evidenceId)) {
|
|
181
196
|
subject.evidence.push({ id: evidenceId, source: inline(source) });
|
|
182
197
|
subject.evidenceId ??= evidenceId;
|
|
@@ -187,13 +202,12 @@ export function buildTasteProfileModel(profile = {}, tr = screenTranslator("en")
|
|
|
187
202
|
if (correctionId) subject.correctionId = correctionId;
|
|
188
203
|
}
|
|
189
204
|
const line = inline(detail);
|
|
190
|
-
if (line && !
|
|
205
|
+
if (line && !subject.detailLines.includes(line)) {
|
|
191
206
|
subject.detailLines.push(line);
|
|
192
|
-
seenDetails.get(key).add(line);
|
|
193
207
|
}
|
|
194
208
|
}
|
|
195
209
|
|
|
196
|
-
const activeAssertions = [
|
|
210
|
+
const activeAssertions = profile?.reviewChoices ?? [
|
|
197
211
|
...items(assertions.active),
|
|
198
212
|
...items(assertions.preferences),
|
|
199
213
|
...items(assertions.avoids),
|
|
@@ -206,24 +220,26 @@ export function buildTasteProfileModel(profile = {}, tr = screenTranslator("en")
|
|
|
206
220
|
const key = subjectKey(target);
|
|
207
221
|
if (seenAssertions.has(key)) continue;
|
|
208
222
|
seenAssertions.add(key);
|
|
209
|
-
const when = date(item.asserted_at);
|
|
223
|
+
const when = date(item.asserted_at ?? item.occurred_at);
|
|
210
224
|
const note = inline(item.note);
|
|
211
225
|
add(item, item.entity_type, tr("Your choice"), [item.stance === "like" ? tr("You said: I like this") : tr("You said: keep this out"),
|
|
212
226
|
...(when ? [when] : []), ...(note ? [`"${note}"`] : [])].join(" · "), { assertion: true });
|
|
213
227
|
}
|
|
214
228
|
|
|
215
|
-
const
|
|
216
|
-
const recentSource = recentDays ? tr("Lately (last {count} days)", { count: recentDays }) : tr("Lately");
|
|
229
|
+
const recentSource = `${tr("Lately")} · ${recentListeningPeriod(profile, tr)}`;
|
|
217
230
|
for (const [field, kind, source] of [
|
|
218
231
|
["repeat_tracks", "track", tr("Most played")],
|
|
219
|
-
["enduring_artists", "artist", tr("
|
|
232
|
+
["enduring_artists", "artist", tr("All recorded listening")],
|
|
220
233
|
["recent_tracks", "track", recentSource],
|
|
221
234
|
["recent_artists", "artist", recentSource],
|
|
222
|
-
["rediscovery_tracks", "track", tr("Gone quiet")],
|
|
235
|
+
["rediscovery_tracks", "track", `${tr("Gone quiet")} · ${recordedHistoryThrough(profile, tr)}`],
|
|
223
236
|
["historical_return_tracks", "track", tr("Came back")],
|
|
224
237
|
["back_to_back_tracks", "track", tr("Played in a row")],
|
|
225
238
|
]) {
|
|
226
|
-
for (const item of items(behavior[field]))
|
|
239
|
+
for (const item of items(behavior[field])) {
|
|
240
|
+
const label = field === "enduring_artists" && playsInMultipleYears(item) ? tr("Across the years") : source;
|
|
241
|
+
add(item, kind, label, withDetails(label, metrics(item)));
|
|
242
|
+
}
|
|
227
243
|
}
|
|
228
244
|
for (const item of items(behavior.time_capsule_tracks)) {
|
|
229
245
|
const year = count(item?.capsule_year);
|
|
@@ -282,6 +298,10 @@ export function buildTasteProfileModel(profile = {}, tr = screenTranslator("en")
|
|
|
282
298
|
: tr("Shows up through one of their tracks."));
|
|
283
299
|
}
|
|
284
300
|
|
|
301
|
+
for (const track of Array.isArray(profile?.reviewLibraryTracks) ? profile.reviewLibraryTracks : []) {
|
|
302
|
+
add(track, "track", appleLibrary, appleLibrary, { membership: true });
|
|
303
|
+
}
|
|
304
|
+
|
|
285
305
|
for (const subject of subjects.values()) {
|
|
286
306
|
if (subject.kind !== "track") continue;
|
|
287
307
|
const artist = subjects.get(subjectKey({ entityType: "artist", label: subject.target.artistCredit }));
|
|
@@ -295,7 +315,7 @@ export function buildTasteProfileModel(profile = {}, tr = screenTranslator("en")
|
|
|
295
315
|
}
|
|
296
316
|
|
|
297
317
|
return {
|
|
298
|
-
summaryLines: overview(profile, tr),
|
|
318
|
+
summaryLines: overview(profile, tr, listening),
|
|
299
319
|
subjects: [...subjects.values()],
|
|
300
320
|
emptyLines: [
|
|
301
321
|
tr("Nothing to look at yet."),
|