@vicyangorg/dsh-music 0.3.0 → 0.4.0
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/client/index.js +201 -22
- package/host/history.js +65 -22
- package/host/likes.js +203 -59
- package/host/main.js +2 -2
- package/host/reco/discover.js +155 -72
- package/host/reco/index.js +36 -6
- package/host/reco/pools.js +28 -0
- package/icon.png +0 -0
- package/package.json +3 -3
- package/icon.svg +0 -16
package/client/index.js
CHANGED
|
@@ -96,6 +96,23 @@ window.__ModuleLoader__.load({
|
|
|
96
96
|
lang_pt: '葡萄牙语',
|
|
97
97
|
lang_it: '意大利语',
|
|
98
98
|
welcomeTasteNote: '偏好只用于微调探索批次,不会锁死你的推荐;之后随时能改。',
|
|
99
|
+
libTabsLabel: '曲库视图',
|
|
100
|
+
libTabLibrary: '曲库',
|
|
101
|
+
libTabLikes: '我喜欢',
|
|
102
|
+
playLikes: '播放我喜欢',
|
|
103
|
+
likesEmptyTitle: '还没有喜欢的歌',
|
|
104
|
+
likesEmptyBody: '在曲库里点 ♥,歌曲会自动入库并出现在这里。',
|
|
105
|
+
dislikeBtn: '不喜欢',
|
|
106
|
+
undislikeBtn: '取消不喜欢',
|
|
107
|
+
undislikedBtn: '已标记不喜欢,点击取消',
|
|
108
|
+
statDislikes: '不喜欢',
|
|
109
|
+
dislikesTitle: '不喜欢的歌',
|
|
110
|
+
dislikesEmpty: '还没有标记不喜欢的歌',
|
|
111
|
+
genre_pop: '流行',
|
|
112
|
+
genre_rock: '摇滚',
|
|
113
|
+
genre_hiphop: '说唱',
|
|
114
|
+
genre_punk: '朋克',
|
|
115
|
+
genre_country: '乡村',
|
|
99
116
|
welcomePathLabel: '音乐目录(可选)',
|
|
100
117
|
welcomePathPlaceholder: '~/Music/我的音乐',
|
|
101
118
|
welcomePathHint: '留空则使用已经扫描到的曲库;填了会自动挂载并重新扫描。',
|
|
@@ -338,6 +355,23 @@ window.__ModuleLoader__.load({
|
|
|
338
355
|
lang_pt: 'Portuguese',
|
|
339
356
|
lang_it: 'Italian',
|
|
340
357
|
welcomeTasteNote: 'Preferences only bias the discovery batch - nothing is locked, and you can change them any time.',
|
|
358
|
+
libTabsLabel: 'Library views',
|
|
359
|
+
libTabLibrary: 'Library',
|
|
360
|
+
libTabLikes: 'Liked',
|
|
361
|
+
playLikes: 'Play liked',
|
|
362
|
+
likesEmptyTitle: 'No liked songs yet',
|
|
363
|
+
likesEmptyBody: 'Hit the heart on any song to add it to your library and to this list.',
|
|
364
|
+
dislikeBtn: 'Dislike',
|
|
365
|
+
undislikeBtn: 'Undo dislike',
|
|
366
|
+
undislikedBtn: 'Marked as disliked — click to undo',
|
|
367
|
+
statDislikes: 'Disliked',
|
|
368
|
+
dislikesTitle: 'Disliked songs',
|
|
369
|
+
dislikesEmpty: 'Nothing disliked yet',
|
|
370
|
+
genre_pop: 'Pop',
|
|
371
|
+
genre_rock: 'Rock',
|
|
372
|
+
genre_hiphop: 'Hip-hop',
|
|
373
|
+
genre_punk: 'Punk',
|
|
374
|
+
genre_country: 'Country',
|
|
341
375
|
welcomePathLabel: 'Music folder (optional)',
|
|
342
376
|
welcomePathPlaceholder: '~/Music/My Music',
|
|
343
377
|
welcomePathHint: 'Leave empty to use the library already scanned; a folder is mounted and rescanned.',
|
|
@@ -715,6 +749,12 @@ window.__ModuleLoader__.load({
|
|
|
715
749
|
['path', { d: 'M12 20s-7.4-4.6-9.3-9C1.4 7.6 3.4 4.5 6.6 4.5c2 0 3.4 1.1 4.2 2.4l1.2 2 1.2-2c.8-1.3 2.2-2.4 4.2-2.4 3.2 0 5.2 3.1 3.9 6.5-1.9 4.4-9.3 9-9.3 9z' }],
|
|
716
750
|
], { 'data-heart': 1 });
|
|
717
751
|
|
|
752
|
+
/* Thumbs-down: an outline hand, drawn for the dislike (taste) button. */
|
|
753
|
+
const IconThumbDown = makeIcon([
|
|
754
|
+
['path', { d: 'M10.5 14.5V4.2c0-.7.6-1.2 1.3-1.2h4.4c.6 0 1.1.4 1.3 1l2.4 6.6c.2.5.1 1.1-.2 1.5-.3.4-.8.7-1.3.7h-4.1l.8 3.9c.2.9-.3 1.8-1.1 2.2-.5.3-1.1.3-1.6 0-.3-.2-.6-.5-.8-.9l-1.1-2.9z' }],
|
|
755
|
+
['path', { d: 'M6.8 14.5H4.9c-.7 0-1.2-.5-1.2-1.2V4.2c0-.7.5-1.2 1.2-1.2h1.9c.7 0 1.2.5 1.2 1.2v9.1c0 .7-.5 1.2-1.2 1.2z' }],
|
|
756
|
+
], { 'data-thumbdown': 1 });
|
|
757
|
+
|
|
718
758
|
/* ================================================================
|
|
719
759
|
* 4. Styles — every color is a host theme token (--dsw-alias-*)
|
|
720
760
|
* ================================================================ */
|
|
@@ -786,6 +826,11 @@ window.__ModuleLoader__.load({
|
|
|
786
826
|
.dshm-tab-dot{width:6px;height:6px;border-radius:50%;background:var(--dsw-alias-brand-primary);animation:dshm-pulse 1.6s ease-in-out infinite;}
|
|
787
827
|
.dshm-body{flex:1;min-height:0;display:flex;flex-direction:column;container-type:inline-size;}
|
|
788
828
|
.dshm-toolbar{flex:none;display:flex;align-items:center;gap:8px;padding:10px 20px;border-bottom:1px solid var(--dsw-alias-border-l1);flex-wrap:wrap;width:100%;max-width:1120px;margin:0 auto;}
|
|
829
|
+
.dshm-libtabs{display:flex;align-items:center;gap:4px;padding:8px 20px 0;width:100%;max-width:1120px;margin:0 auto;flex:none;}
|
|
830
|
+
.dshm-libtabs-btn{appearance:none;border:1px solid transparent;background:transparent;color:var(--dsw-alias-label-secondary);font:inherit;font-size:12.5px;padding:5px 12px;border-radius:8px;cursor:pointer;display:inline-flex;align-items:center;gap:6px;transition:background .12s,color .12s,border-color .12s;white-space:nowrap;}
|
|
831
|
+
.dshm-libtabs-btn:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary);}
|
|
832
|
+
.dshm-libtabs-on{background:var(--dsw-alias-interactive-bg-active);color:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-border-l2);font-weight:600;}
|
|
833
|
+
.dshm-libtabs-count{font-size:10.5px;color:var(--dsw-alias-label-tertiary);background:var(--dsw-alias-bg-layer-1);border-radius:999px;padding:0 6px;line-height:16px;}
|
|
789
834
|
.dshm-search{display:flex;align-items:center;gap:8px;flex:1;min-width:180px;max-width:340px;background:var(--dsw-alias-bg-layer-2);border:1px solid var(--dsw-alias-border-l1);border-radius:9px;padding:6px 10px;color:var(--dsw-alias-label-tertiary);transition:border-color .15s;}
|
|
790
835
|
.dshm-search:focus-within{border-color:var(--dsw-alias-brand-primary);color:var(--dsw-alias-label-secondary);}
|
|
791
836
|
.dshm-search input{flex:1;min-width:0;border:0;background:transparent;color:var(--dsw-alias-label-primary);font:inherit;outline:none;}
|
|
@@ -805,7 +850,7 @@ window.__ModuleLoader__.load({
|
|
|
805
850
|
.dshm-list::-webkit-scrollbar-thumb:hover{background:var(--dsw-alias-scrollbar-hover-l2);}
|
|
806
851
|
.dshm-group-head{position:sticky;top:0;z-index:1;display:flex;align-items:center;gap:6px;padding:10px 8px 6px;background:var(--dsw-alias-bg-base);color:var(--dsw-alias-label-secondary);font-size:12px;font-weight:600;}
|
|
807
852
|
.dshm-group-head .dshm-group-count{color:var(--dsw-alias-label-tertiary);font-weight:400;}
|
|
808
|
-
.dshm-row{display:grid;grid-template-columns:40px minmax(0,1fr) auto auto auto 26px;align-items:center;gap:12px;padding:7px 8px;border-radius:10px;cursor:pointer;transition:background .12s;outline:none;}
|
|
853
|
+
.dshm-row{display:grid;grid-template-columns:40px minmax(0,1fr) auto auto auto auto 26px;align-items:center;gap:12px;padding:7px 8px;border-radius:10px;cursor:pointer;transition:background .12s;outline:none;}
|
|
809
854
|
.dshm-row-actions{display:flex;gap:2px;opacity:0;}
|
|
810
855
|
.dshm-row:hover .dshm-row-actions,.dshm-row:focus-within .dshm-row-actions{opacity:1;}
|
|
811
856
|
.dshm-row:hover{background:var(--dsw-alias-interactive-bg-hover);}
|
|
@@ -972,7 +1017,7 @@ window.__ModuleLoader__.load({
|
|
|
972
1017
|
.dshm-col-count{font-size:11px;color:var(--dsw-alias-label-tertiary);}
|
|
973
1018
|
.dshm-col-play{margin-left:auto;}
|
|
974
1019
|
.dshm-col-list{flex:1;min-height:0;overflow-y:auto;padding:2px 8px 16px;scrollbar-width:thin;scrollbar-color:var(--dsw-alias-scrollbar-bg-l2) transparent;}
|
|
975
|
-
.dshm-srow{display:grid;grid-template-columns:38px minmax(0,1fr) auto auto;align-items:center;gap:10px;padding:6px;border-radius:10px;transition:background .12s;}
|
|
1020
|
+
.dshm-srow{display:grid;grid-template-columns:38px minmax(0,1fr) auto auto auto;align-items:center;gap:10px;padding:6px;border-radius:10px;transition:background .12s;}
|
|
976
1021
|
.dshm-srow:hover{background:var(--dsw-alias-interactive-bg-hover);}
|
|
977
1022
|
.dshm-srow-main{min-width:0;display:flex;flex-direction:column;gap:1px;border:0;background:transparent;font:inherit;color:inherit;text-align:left;padding:0;cursor:pointer;}
|
|
978
1023
|
.dshm-srow-title{font-size:12.5px;font-weight:560;color:var(--dsw-alias-label-primary);}
|
|
@@ -985,6 +1030,13 @@ window.__ModuleLoader__.load({
|
|
|
985
1030
|
.dshm-like-btn:hover{color:var(--dsw-alias-label-primary);background:var(--dsw-alias-interactive-bg-hover);}
|
|
986
1031
|
.dshm-like-btn:active{transform:scale(1.18);}
|
|
987
1032
|
.dshm-like-btn-on{color:var(--dsw-alias-state-error-primary);}
|
|
1033
|
+
.dshm-row-off{opacity:.55;cursor:not-allowed;}
|
|
1034
|
+
.dshm-row-off:hover{background:transparent;}
|
|
1035
|
+
.dshm-dislike-btn-on{color:var(--dsw-alias-label-secondary);background:var(--dsw-alias-interactive-bg-hover);}
|
|
1036
|
+
.dshm-dislikes{margin-top:14px;}
|
|
1037
|
+
.dshm-dislike-row{display:flex;align-items:center;gap:10px;padding:6px 8px;border-radius:9px;font-size:12.5px;color:var(--dsw-alias-label-secondary);}
|
|
1038
|
+
.dshm-dislike-row:hover{background:var(--dsw-alias-interactive-bg-hover);}
|
|
1039
|
+
.dshm-dislike-undo{flex:none;}
|
|
988
1040
|
.dshm-playround{appearance:none;border:0;width:30px;height:30px;border-radius:50%;background:var(--dsw-alias-button-primary-fill);color:var(--dsw-alias-label-primary-inverted);display:inline-flex;align-items:center;justify-content:center;cursor:pointer;padding:0;flex:none;transition:background .13s,transform .1s;}
|
|
989
1041
|
.dshm-playround:hover{background:var(--dsw-alias-button-primary-hover);transform:scale(1.06);}
|
|
990
1042
|
.dshm-playround:disabled{opacity:.45;cursor:default;transform:none;}
|
|
@@ -1176,6 +1228,13 @@ window.__ModuleLoader__.load({
|
|
|
1176
1228
|
method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body),
|
|
1177
1229
|
}),
|
|
1178
1230
|
likes: () => request('/dsh-music/api/library/likes'),
|
|
1231
|
+
dislike: (body) => request('/dsh-music/api/library/dislike', {
|
|
1232
|
+
method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body),
|
|
1233
|
+
}),
|
|
1234
|
+
dislikes: () => request('/dsh-music/api/library/dislikes'),
|
|
1235
|
+
taste: (trackId, artist, title) => request('/dsh-music/api/library/taste' + (trackId
|
|
1236
|
+
? '?trackId=' + encodeURIComponent(trackId)
|
|
1237
|
+
: '?artist=' + encodeURIComponent(artist || '') + '&title=' + encodeURIComponent(title || ''))),
|
|
1179
1238
|
preview: (body) => request('/dsh-music/api/library/preview', {
|
|
1180
1239
|
method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body),
|
|
1181
1240
|
}),
|
|
@@ -1575,16 +1634,24 @@ window.__ModuleLoader__.load({
|
|
|
1575
1634
|
}
|
|
1576
1635
|
|
|
1577
1636
|
function createLikesService(api, onAutoDownload) {
|
|
1578
|
-
|
|
1637
|
+
/* keys/dislikes are mutually exclusive on the host: a dislike clears the
|
|
1638
|
+
* like and vice versa, so both maps are refreshed after every action. */
|
|
1639
|
+
const store = createStore({ keys: {}, dislikes: {}, items: [], dislikeItems: [], loaded: false, error: null });
|
|
1579
1640
|
async function load() {
|
|
1580
1641
|
try {
|
|
1581
1642
|
const data = await api.likes();
|
|
1582
1643
|
const keys = {};
|
|
1583
1644
|
for (const it of (data && data.items) || []) if (it.liked !== false) keys[likeKey(it)] = it;
|
|
1584
|
-
store.set({ keys, loaded: true, error: null });
|
|
1645
|
+
store.set({ keys, items: (data && data.items) || [], loaded: true, error: null });
|
|
1585
1646
|
} catch (err) {
|
|
1586
1647
|
store.set({ loaded: true, error: (err && err.message) || String(err) });
|
|
1587
1648
|
}
|
|
1649
|
+
try {
|
|
1650
|
+
const d = await api.dislikes();
|
|
1651
|
+
const dislikes = {};
|
|
1652
|
+
for (const it of (d && d.items) || []) dislikes[likeKey(it)] = it;
|
|
1653
|
+
store.set({ dislikes, dislikeItems: (d && d.items) || [] });
|
|
1654
|
+
} catch { /* dislikes are optional: an older host just has no such route */ }
|
|
1588
1655
|
}
|
|
1589
1656
|
async function toggle(item, liked) {
|
|
1590
1657
|
const body = item.id
|
|
@@ -1594,17 +1661,39 @@ window.__ModuleLoader__.load({
|
|
|
1594
1661
|
try { res = await api.like(body); } catch (err) { return { error: (err && err.message) || String(err) }; }
|
|
1595
1662
|
const key = likeKey(res && res.key ? { artist: res.key.split('::')[0], title: res.key.split('::')[1] } : item);
|
|
1596
1663
|
const keys = { ...store.getSnapshot().keys };
|
|
1664
|
+
const dislikes = { ...store.getSnapshot().dislikes };
|
|
1597
1665
|
if (liked) keys[key] = { artist: item.artist, title: item.title, trackId: res && res.trackId, inLibrary: res && res.inLibrary };
|
|
1598
1666
|
else delete keys[key];
|
|
1599
|
-
|
|
1667
|
+
/* Host keeps taste binary: liking clears a dislike. */
|
|
1668
|
+
if (liked && res && res.disliked === false) delete dislikes[key];
|
|
1669
|
+
store.set({ keys, dislikes });
|
|
1600
1670
|
if (res && res.downloading && onAutoDownload) onAutoDownload();
|
|
1601
1671
|
return res || {};
|
|
1602
1672
|
}
|
|
1673
|
+
async function setDislike(item, disliked) {
|
|
1674
|
+
const body = item.id
|
|
1675
|
+
? { trackId: item.id, disliked }
|
|
1676
|
+
: { artist: item.artist, title: item.title, album: item.album, durationMs: item.durationMs, disliked };
|
|
1677
|
+
let res = null;
|
|
1678
|
+
try { res = await api.dislike(body); } catch (err) { return { error: (err && err.message) || String(err) }; }
|
|
1679
|
+
const key = res && res.key ? res.key : likeKey(item);
|
|
1680
|
+
const keys = { ...store.getSnapshot().keys };
|
|
1681
|
+
const dislikes = { ...store.getSnapshot().dislikes };
|
|
1682
|
+
if (res && res.clearedLike) delete keys[key];
|
|
1683
|
+
if (res && res.disliked) dislikes[key] = { artist: item.artist, title: item.title, trackId: res.trackId, inLibrary: res.inLibrary, dislikedAt: Date.now() };
|
|
1684
|
+
else delete dislikes[key];
|
|
1685
|
+
store.set({ keys, dislikes });
|
|
1686
|
+
load();
|
|
1687
|
+
return res || {};
|
|
1688
|
+
}
|
|
1603
1689
|
function isLiked(item) {
|
|
1604
1690
|
return !!store.getSnapshot().keys[likeKey(item)];
|
|
1605
1691
|
}
|
|
1692
|
+
function isDisliked(item) {
|
|
1693
|
+
return !!store.getSnapshot().dislikes[likeKey(item)];
|
|
1694
|
+
}
|
|
1606
1695
|
load();
|
|
1607
|
-
return { source: store, toggle, isLiked, load };
|
|
1696
|
+
return { source: store, toggle, setDislike, isLiked, isDisliked, load };
|
|
1608
1697
|
}
|
|
1609
1698
|
|
|
1610
1699
|
function createPreviewService(api) {
|
|
@@ -2079,7 +2168,8 @@ window.__ModuleLoader__.load({
|
|
|
2079
2168
|
const [busy, setBusy] = useState(false);
|
|
2080
2169
|
const [failed, setFailed] = useState(false);
|
|
2081
2170
|
|
|
2082
|
-
const genreOptions = ['jazz', 'classical', '
|
|
2171
|
+
const genreOptions = ['pop', 'rock', 'electronic', 'hip hop', 'jazz', 'classical', 'folk', 'blues', 'soul', 'funk', 'reggae', 'metal', 'punk', 'country', 'ambient'];
|
|
2172
|
+
const genreLabel = (g) => 'genre_' + g.replace(/[^a-z]/g, '');
|
|
2083
2173
|
const langOptions = [
|
|
2084
2174
|
{ value: '中文', key: 'lang_zh' }, { value: '英语', key: 'lang_en' }, { value: '粤语', key: 'lang_yue' },
|
|
2085
2175
|
{ value: '日语', key: 'lang_ja' }, { value: '韩语', key: 'lang_ko' }, { value: '法语', key: 'lang_fr' },
|
|
@@ -2153,7 +2243,7 @@ window.__ModuleLoader__.load({
|
|
|
2153
2243
|
h('p', { className: 'dshm-wstep-sub' }, t('welcomeTasteSub')),
|
|
2154
2244
|
h('div', { className: 'dshm-wgroup' },
|
|
2155
2245
|
h('div', { className: 'dshm-wlabel' }, t('welcomeGenres')),
|
|
2156
|
-
h('div', { className: 'dshm-wchips' }, genreOptions.map((g) => tasteChip(g, t(
|
|
2246
|
+
h('div', { className: 'dshm-wchips' }, genreOptions.map((g) => tasteChip(g, t(genreLabel(g)), genres, setGenres)))),
|
|
2157
2247
|
h('div', { className: 'dshm-wgroup' },
|
|
2158
2248
|
h('div', { className: 'dshm-wlabel' }, t('welcomeLanguages')),
|
|
2159
2249
|
h('div', { className: 'dshm-wchips' }, langOptions.map((o) => tasteChip(o.value, t(o.key), langs, setLangs)))),
|
|
@@ -2309,9 +2399,21 @@ window.__ModuleLoader__.load({
|
|
|
2309
2399
|
}, h(IconHeart, { size: 15, style: liked ? { fill: 'currentColor' } : undefined }));
|
|
2310
2400
|
}
|
|
2311
2401
|
|
|
2312
|
-
function
|
|
2402
|
+
function DislikeButton({ t, item, likes, useLikes }) {
|
|
2403
|
+
const disliked = useLikes((st) => !!((st.dislikes || {})[likeKey(item)]));
|
|
2404
|
+
return h('button', {
|
|
2405
|
+
type: 'button',
|
|
2406
|
+
className: cx('dshm-like-btn', 'dshm-dislike-btn', disliked && 'dshm-dislike-btn-on'),
|
|
2407
|
+
'aria-label': disliked ? t('undislikeBtn') : t('dislikeBtn'),
|
|
2408
|
+
'aria-pressed': !!disliked,
|
|
2409
|
+
title: disliked ? t('undislikedBtn') : t('dislikeBtn'),
|
|
2410
|
+
onClick: (e) => { e.stopPropagation(); likes.setDislike(item, !disliked); },
|
|
2411
|
+
}, h(IconThumbDown, { size: 15, style: disliked ? { fill: 'currentColor' } : undefined }));
|
|
2412
|
+
}
|
|
2413
|
+
|
|
2414
|
+
function TrackRow({ track, index, isCurrent, playing, onPlay, onDelete, onReveal, onOpenArtist, likes, useLikes, t, muted }) {
|
|
2313
2415
|
return h('div', {
|
|
2314
|
-
className: cx('dshm-row', isCurrent && 'dshm-row-current'),
|
|
2416
|
+
className: cx('dshm-row', isCurrent && 'dshm-row-current', muted && 'dshm-row-off'),
|
|
2315
2417
|
role: 'button', tabIndex: 0,
|
|
2316
2418
|
'aria-label': t('playTrack') + ': ' + track.title,
|
|
2317
2419
|
onClick: () => onPlay(track, index),
|
|
@@ -2335,6 +2437,7 @@ window.__ModuleLoader__.load({
|
|
|
2335
2437
|
track.album ? ' · ' + track.album : '')),
|
|
2336
2438
|
h('span', { className: 'dshm-row-dur' }, formatTime(track.duration)),
|
|
2337
2439
|
likes ? h(LikeButton, { t, item: track, likes, useLikes }) : null,
|
|
2440
|
+
likes ? h(DislikeButton, { t, item: track, likes, useLikes }) : null,
|
|
2338
2441
|
onDelete ? h('span', { className: 'dshm-row-actions', onClick: (e) => e.stopPropagation() },
|
|
2339
2442
|
h(IconButton, { label: t('revealTrack'), onClick: (e) => { e.stopPropagation(); onReveal(track); } }, h(IconDisc, { size: 14 })),
|
|
2340
2443
|
h(IconButton, { label: t('deleteTrack'), onClick: (e) => { e.stopPropagation(); onDelete(track); } }, h(IconClose, { size: 14 }))) : null,
|
|
@@ -2353,6 +2456,7 @@ window.__ModuleLoader__.load({
|
|
|
2353
2456
|
const [query, setQuery] = useState('');
|
|
2354
2457
|
const [searchState, setSearchState] = useState({ status: 'idle', local: [], remote: [] });
|
|
2355
2458
|
const [groupBy, setGroupBy] = useState('none');
|
|
2459
|
+
const [libTab, setLibTab] = useState('library');
|
|
2356
2460
|
const [rowError, setRowError] = useState('');
|
|
2357
2461
|
const [playNotice, setPlayNotice] = useState('');
|
|
2358
2462
|
const searchRef = useRef(null);
|
|
@@ -2363,6 +2467,17 @@ window.__ModuleLoader__.load({
|
|
|
2363
2467
|
const syncHint = useSync ? useSync((st) => st.hint) : null;
|
|
2364
2468
|
const syncUsable = syncAvail !== false;
|
|
2365
2469
|
const syncState = useSync ? useSync((st) => st.phase) : 'idle';
|
|
2470
|
+
const likeItems = useLikes((st) => st.items || []);
|
|
2471
|
+
/* Liked rows reuse the library row layout; host resolves trackId/audioUrl
|
|
2472
|
+
* for everything inside the library, so those rows are directly playable. */
|
|
2473
|
+
const likedTracks = useMemo(() => likeItems.map((it) => ({
|
|
2474
|
+
id: it.trackId || ('liked::' + it.key),
|
|
2475
|
+
title: it.title, artist: it.artist, album: it.album,
|
|
2476
|
+
duration: it.durationMs ? Math.round(it.durationMs / 1000) : (it.duration || 0),
|
|
2477
|
+
audioUrl: it.audioUrl || null, coverUrl: it.coverUrl || null,
|
|
2478
|
+
muted: !it.audioUrl,
|
|
2479
|
+
})), [likeItems]);
|
|
2480
|
+
const likedPlayable = useMemo(() => likedTracks.filter((tr) => !!tr.audioUrl), [likedTracks]);
|
|
2366
2481
|
|
|
2367
2482
|
/* Backend search (local filter + MusicBrainz completion), debounced.
|
|
2368
2483
|
* Empty query keeps the pure client-side browse below. */
|
|
@@ -2399,6 +2514,14 @@ window.__ModuleLoader__.load({
|
|
|
2399
2514
|
}, [tracks, query]);
|
|
2400
2515
|
/* While the backend search is ready, its local list wins (it shares the
|
|
2401
2516
|
* same normalization); otherwise fall back to instant client filtering. */
|
|
2517
|
+
const likedFiltered = useMemo(() => {
|
|
2518
|
+
const q = normalizeZh(query.trim());
|
|
2519
|
+
if (!q) return likedTracks;
|
|
2520
|
+
return likedTracks.filter((tr) =>
|
|
2521
|
+
normalizeZh(tr.title).includes(q) ||
|
|
2522
|
+
normalizeZh(tr.artist).includes(q) ||
|
|
2523
|
+
normalizeZh(tr.album).includes(q));
|
|
2524
|
+
}, [likedTracks, query]);
|
|
2402
2525
|
const searching = !!query.trim();
|
|
2403
2526
|
const shownList = searching && searchState.status === 'ready' ? searchState.local : filtered;
|
|
2404
2527
|
|
|
@@ -2437,6 +2560,13 @@ window.__ModuleLoader__.load({
|
|
|
2437
2560
|
try { setRowError(''); await library.reveal(track.id); }
|
|
2438
2561
|
catch (err) { setRowError((err && err.message) || t('deleteFailed')); }
|
|
2439
2562
|
}
|
|
2563
|
+
function playLiked(track) {
|
|
2564
|
+
if (!track.audioUrl) { setPlayNotice(t('topUnplayable')); return; }
|
|
2565
|
+
setPlayNotice('');
|
|
2566
|
+
const idx = likedPlayable.indexOf(track);
|
|
2567
|
+
player.playTracks(likedPlayable, idx >= 0 ? idx : 0);
|
|
2568
|
+
}
|
|
2569
|
+
|
|
2440
2570
|
const renderRow = (tr, i) => h(TrackRow, {
|
|
2441
2571
|
key: tr.id || i, track: tr, index: i,
|
|
2442
2572
|
isCurrent: currentId === tr.id, playing,
|
|
@@ -2481,7 +2611,27 @@ window.__ModuleLoader__.load({
|
|
|
2481
2611
|
|
|
2482
2612
|
let content;
|
|
2483
2613
|
const remoteList = searching && searchState.status === 'ready' ? searchState.remote : [];
|
|
2484
|
-
if (
|
|
2614
|
+
if (libTab === 'likes') {
|
|
2615
|
+
content = likeItems.length === 0
|
|
2616
|
+
? h(EmptyState, {
|
|
2617
|
+
icon: h(IconHeart, { size: 28 }),
|
|
2618
|
+
title: t('likesEmptyTitle'), body: t('likesEmptyBody'),
|
|
2619
|
+
}, h('button', {
|
|
2620
|
+
type: 'button', className: 'dshm-chipbtn dshm-chipbtn-primary',
|
|
2621
|
+
onClick: () => setLibTab('library'),
|
|
2622
|
+
}, h(IconNote, { size: 14 }), t('goLibrary')))
|
|
2623
|
+
: likedFiltered.length === 0
|
|
2624
|
+
? h(EmptyState, {
|
|
2625
|
+
icon: h(IconSearch, { size: 28 }),
|
|
2626
|
+
title: '“' + query.trim() + '”', body: t('searchNoLocal'),
|
|
2627
|
+
})
|
|
2628
|
+
: h('div', { className: 'dshm-list' },
|
|
2629
|
+
likedFiltered.map((tr, i) => h(TrackRow, {
|
|
2630
|
+
key: tr.id || ('liked' + i), track: tr, index: i,
|
|
2631
|
+
isCurrent: currentId === tr.id, playing, muted: tr.muted,
|
|
2632
|
+
onPlay: playLiked, onOpenArtist: openArtistPage, likes, useLikes, t,
|
|
2633
|
+
})));
|
|
2634
|
+
} else if (status === 'loading' && tracks.length === 0) {
|
|
2485
2635
|
content = h('div', { className: 'dshm-list' }, h(SkeletonRows));
|
|
2486
2636
|
} else if (status === 'error' && tracks.length === 0) {
|
|
2487
2637
|
content = h(EmptyState, {
|
|
@@ -2552,6 +2702,18 @@ window.__ModuleLoader__.load({
|
|
|
2552
2702
|
return h(React.Fragment, null,
|
|
2553
2703
|
sync ? h(SyncPanel, { t, sync, useSync }) : null,
|
|
2554
2704
|
rowError ? h('div', { className: 'dshm-errorline', role: 'alert', style: { margin: '8px 24px 0' } }, rowError) : null,
|
|
2705
|
+
h('div', { className: 'dshm-libtabs', role: 'tablist', 'aria-label': t('libTabsLabel') },
|
|
2706
|
+
h('button', {
|
|
2707
|
+
type: 'button', role: 'tab', 'aria-selected': libTab === 'library',
|
|
2708
|
+
className: cx('dshm-libtabs-btn', libTab === 'library' && 'dshm-libtabs-on'),
|
|
2709
|
+
onClick: () => setLibTab('library'),
|
|
2710
|
+
}, t('libTabLibrary')),
|
|
2711
|
+
h('button', {
|
|
2712
|
+
type: 'button', role: 'tab', 'aria-selected': libTab === 'likes',
|
|
2713
|
+
className: cx('dshm-libtabs-btn', libTab === 'likes' && 'dshm-libtabs-on'),
|
|
2714
|
+
onClick: () => setLibTab('likes'),
|
|
2715
|
+
}, h(IconHeart, { size: 13 }), t('libTabLikes'),
|
|
2716
|
+
likeItems.length > 0 ? h('span', { className: 'dshm-libtabs-count' }, likeItems.length) : null)),
|
|
2555
2717
|
h('div', { className: 'dshm-toolbar' },
|
|
2556
2718
|
h('label', { className: 'dshm-search' },
|
|
2557
2719
|
h(IconSearch, { size: 15 }),
|
|
@@ -2564,14 +2726,15 @@ window.__ModuleLoader__.load({
|
|
|
2564
2726
|
className: 'dshm-select', value: groupBy, 'aria-label': t('groupLabel'),
|
|
2565
2727
|
onChange: (e) => setGroupBy(e.target.value),
|
|
2566
2728
|
},
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2729
|
+
libTab === 'library' ? h(React.Fragment, null,
|
|
2730
|
+
h('option', { value: 'none' }, t('groupNone')),
|
|
2731
|
+
h('option', { value: 'artist' }, t('groupArtist')),
|
|
2732
|
+
h('option', { value: 'album' }, t('groupAlbum'))) : null),
|
|
2570
2733
|
h('button', {
|
|
2571
2734
|
type: 'button', className: 'dshm-chipbtn dshm-chipbtn-primary',
|
|
2572
|
-
disabled: busy || shownList.length === 0,
|
|
2573
|
-
onClick: () => player.playAll(shownList),
|
|
2574
|
-
}, h(IconPlay, { size: 13 }), t('playAll')),
|
|
2735
|
+
disabled: busy || (libTab === 'likes' ? likedPlayable.length === 0 : shownList.length === 0),
|
|
2736
|
+
onClick: () => player.playAll(libTab === 'likes' ? likedPlayable : shownList),
|
|
2737
|
+
}, h(IconPlay, { size: 13 }), libTab === 'likes' ? t('playLikes') : t('playAll')),
|
|
2575
2738
|
h('button', {
|
|
2576
2739
|
type: 'button', className: cx('dshm-chipbtn', 'dshm-mode-cycle'),
|
|
2577
2740
|
'aria-label': mode.label, title: mode.hint + ' · ' + t('modeCycleHint'),
|
|
@@ -2585,7 +2748,8 @@ window.__ModuleLoader__.load({
|
|
|
2585
2748
|
}, h(IconRefresh, { size: 13, className: syncState === 'running' ? 'dshm-spin' : undefined }),
|
|
2586
2749
|
syncState === 'running' ? t('syncing') : t('syncBtn')) : null,
|
|
2587
2750
|
h('span', { className: 'dshm-count', style: { marginLeft: 'auto' } },
|
|
2588
|
-
busy && tracks.length === 0 ? t('rescanning')
|
|
2751
|
+
busy && tracks.length === 0 ? t('rescanning')
|
|
2752
|
+
: (libTab === 'likes' ? likedFiltered.length : shownList.length) + ' ' + t('tracksUnit'))),
|
|
2589
2753
|
playNotice
|
|
2590
2754
|
? h('div', { className: 'dshm-mode-hint', style: { margin: '0 20px 6px', textAlign: 'right' }, role: 'status' }, playNotice)
|
|
2591
2755
|
: null,
|
|
@@ -2792,6 +2956,7 @@ window.__ModuleLoader__.load({
|
|
|
2792
2956
|
title: liked ? t('likedBtn') : t('likeBtn'),
|
|
2793
2957
|
onClick: () => likes.toggle(item, !liked),
|
|
2794
2958
|
}, h(IconHeart, { size: 15, style: liked ? { fill: 'currentColor' } : undefined })),
|
|
2959
|
+
likes ? h(DislikeButton, { t, item, likes, useLikes }) : null,
|
|
2795
2960
|
h('button', {
|
|
2796
2961
|
type: 'button', className: 'dshm-playround',
|
|
2797
2962
|
'aria-label': isCurrent && playing ? t('pause') : t('play'),
|
|
@@ -3186,7 +3351,7 @@ window.__ModuleLoader__.load({
|
|
|
3186
3351
|
return d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate();
|
|
3187
3352
|
}
|
|
3188
3353
|
|
|
3189
|
-
function HistoryView({ t, history, player, openArtistPage, artistImages, useHistory, useLibrary, useArtistImages }) {
|
|
3354
|
+
function HistoryView({ t, history, player, openArtistPage, artistImages, likes, useHistory, useLibrary, useArtistImages, useLikes }) {
|
|
3190
3355
|
const s = useHistory((st) => st);
|
|
3191
3356
|
const [notice, setNotice] = useState('');
|
|
3192
3357
|
const tracks = useLibrary ? useLibrary((st) => st.tracks) : [];
|
|
@@ -3221,7 +3386,8 @@ window.__ModuleLoader__.load({
|
|
|
3221
3386
|
statCard(t('statSongs'), String(stats.uniqueSongs || 0)),
|
|
3222
3387
|
statCard(t('statArtists'), String(stats.uniqueArtists || 0)),
|
|
3223
3388
|
statCard(t('statSkipped'), String(stats.skippedCount || 0)),
|
|
3224
|
-
statCard(t('statCompletion'), Math.round((stats.avgCompletion || 0) * 100) + '%')
|
|
3389
|
+
statCard(t('statCompletion'), Math.round((stats.avgCompletion || 0) * 100) + '%'),
|
|
3390
|
+
statCard(t('statDislikes'), String((stats.dislikes && stats.dislikes.count) || 0))),
|
|
3225
3391
|
h('div', { className: 'dshm-trend' },
|
|
3226
3392
|
h('div', { className: 'dshm-asec-title' }, h(IconQueue, { size: 13 }), t('trendTitle')),
|
|
3227
3393
|
h('div', { className: 'dshm-bars' }, daily.map((d, i) => h('div', { className: 'dshm-bar-col', key: i },
|
|
@@ -3263,7 +3429,20 @@ window.__ModuleLoader__.load({
|
|
|
3263
3429
|
h('span', { className: 'dshm-top-rank' }, String(i + 1)),
|
|
3264
3430
|
h('span', { className: 'dshm-ellipsis', style: { flex: 1 } }, it.name || ''),
|
|
3265
3431
|
h('span', { className: 'dshm-count' }, (it.plays || 0) + ' ' + t('playsUnit'))))
|
|
3266
|
-
: h('div', { className: 'dshm-lyrics-hint' }, t('noSection'))))
|
|
3432
|
+
: h('div', { className: 'dshm-lyrics-hint' }, t('noSection')))),
|
|
3433
|
+
h('div', { className: 'dshm-dislikes' },
|
|
3434
|
+
h('div', { className: 'dshm-asec-title' }, h(IconThumbDown, { size: 13 }), t('dislikesTitle')),
|
|
3435
|
+
((stats.dislikes && stats.dislikes.songs) || []).length
|
|
3436
|
+
? stats.dislikes.songs.map((it, i) => h('div', { className: 'dshm-dislike-row', key: i },
|
|
3437
|
+
h('span', { className: 'dshm-ellipsis', style: { flex: 1 } },
|
|
3438
|
+
(it.title || '') + (it.artist ? ' · ' + it.artist : '')),
|
|
3439
|
+
h('span', { className: 'dshm-count' }, it.dislikedAt ? new Date(it.dislikedAt).toISOString().slice(0, 10) : ''),
|
|
3440
|
+
likes ? h('button', {
|
|
3441
|
+
type: 'button', className: 'dshm-chipbtn dshm-dislike-undo',
|
|
3442
|
+
title: t('undislikeBtn'),
|
|
3443
|
+
onClick: () => likes.setDislike({ artist: it.artist, title: it.title }, false),
|
|
3444
|
+
}, t('undislikeBtn')) : null))
|
|
3445
|
+
: h('div', { className: 'dshm-lyrics-hint' }, t('dislikesEmpty')))))
|
|
3267
3446
|
: null;
|
|
3268
3447
|
|
|
3269
3448
|
let list;
|
|
@@ -3474,7 +3653,7 @@ window.__ModuleLoader__.load({
|
|
|
3474
3653
|
: view === 'artist'
|
|
3475
3654
|
? h(ArtistPageView, { t, reco, player, likes, preview, library, openView, openArtistPage, artistImages, useUi, useLikes, useLibrary, usePlayer, useArtistImages })
|
|
3476
3655
|
: view === 'history'
|
|
3477
|
-
? h(HistoryView, { t, history, player, openArtistPage, artistImages, useHistory, useLibrary, useArtistImages })
|
|
3656
|
+
? h(HistoryView, { t, history, player, openArtistPage, artistImages, likes, useHistory, useLibrary, useArtistImages, useLikes })
|
|
3478
3657
|
: h(NowPlayingView, { t, player, lyrics, usePlayer, useLyrics, openView, openArtistPage, artistImages, useArtistImages });
|
|
3479
3658
|
|
|
3480
3659
|
return h(React.Fragment, null,
|
package/host/history.js
CHANGED
|
@@ -42,27 +42,52 @@ export function createHistory({ storage, library, logger }) {
|
|
|
42
42
|
return entry
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
/**
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
45
|
+
/** 追加一条口味事件(不喜欢/取消不喜欢)。只进历史与统计,不算播放;
|
|
46
|
+
* reco 等播放画像默认读不到(read 默认过滤),因此不会污染推荐。 */
|
|
47
|
+
async function appendTaste(event = {}) {
|
|
48
|
+
const kind = event.kind === 'undislike' ? 'undislike' : event.kind === 'dislike' ? 'dislike' : null
|
|
49
|
+
if (!kind) throw new Error('kind 必须是 dislike 或 undislike')
|
|
50
|
+
const artist = typeof event.artist === 'string' ? event.artist.trim() : ''
|
|
51
|
+
const title = typeof event.title === 'string' ? event.title.trim() : ''
|
|
52
|
+
if (!artist || !title) throw new Error('缺少歌手名 artist 或歌名 title')
|
|
53
|
+
let trackId = null
|
|
54
|
+
if (event.trackId !== undefined && event.trackId !== null) {
|
|
55
|
+
const rec = library.getRecord(event.trackId)
|
|
56
|
+
if (!rec) {
|
|
57
|
+
const err = new Error('trackId 不存在于曲库,请先重新扫描')
|
|
58
|
+
err.code = 'UNKNOWN_TRACK'
|
|
59
|
+
throw err
|
|
60
60
|
}
|
|
61
|
+
trackId = rec.id
|
|
62
|
+
}
|
|
63
|
+
const entry = {
|
|
64
|
+
type: kind,
|
|
65
|
+
trackId,
|
|
66
|
+
artist,
|
|
67
|
+
title,
|
|
68
|
+
timestamp: Number.isFinite(event.timestamp) ? event.timestamp : Date.now(),
|
|
69
|
+
reason: kind,
|
|
61
70
|
}
|
|
71
|
+
const line = JSON.stringify(entry) + '\n'
|
|
72
|
+
const write = chain.then(() => appendFile(file, line, 'utf8'))
|
|
73
|
+
chain = write.catch((err) => logger?.warn?.(`dsh-music: 写口味事件失败: ${err.message}`))
|
|
74
|
+
await write
|
|
75
|
+
return entry
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** 读取历史( newest first )。limit 上限 10000,供推荐引擎一次取全量。
|
|
79
|
+
* 默认只返回播放事件;includeTaste=true 时口味事件也返回(归一 type='play')。 */
|
|
80
|
+
async function read({ limit = 200, offset = 0, includeTaste = false } = {}) {
|
|
81
|
+
let events = await readAll()
|
|
82
|
+
if (!includeTaste) events = events.filter((e) => e.type === undefined || e.type === 'play')
|
|
62
83
|
const total = events.length
|
|
63
84
|
const lim = Math.min(Math.max(Number(limit) || 200, 1), 10000)
|
|
64
85
|
const off = Math.max(Number(offset) || 0, 0)
|
|
65
|
-
|
|
86
|
+
const slice = events.slice().reverse().slice(off, off + lim)
|
|
87
|
+
return {
|
|
88
|
+
events: includeTaste ? slice.map((e) => ({ ...e, type: e.type ?? 'play' })) : slice,
|
|
89
|
+
total,
|
|
90
|
+
}
|
|
66
91
|
}
|
|
67
92
|
|
|
68
93
|
/** 读取全部事件(坏行跳过,不排序不截断)。 */
|
|
@@ -85,9 +110,17 @@ export function createHistory({ storage, library, logger }) {
|
|
|
85
110
|
return out
|
|
86
111
|
}
|
|
87
112
|
|
|
88
|
-
/** 聚合统计(只读本地):总播放/总时长(估算)/去重歌曲歌手/TOP/近7天/跳过/平均完整度。
|
|
113
|
+
/** 聚合统计(只读本地):总播放/总时长(估算)/去重歌曲歌手/TOP/近7天/跳过/平均完整度。
|
|
114
|
+
* 只统计播放事件;口味事件单独计数(dislikeEvents/undislikeEvents)。 */
|
|
89
115
|
async function stats() {
|
|
90
|
-
const
|
|
116
|
+
const all = await readAll()
|
|
117
|
+
const events = all.filter((e) => e.type === undefined || e.type === 'play')
|
|
118
|
+
let dislikeEvents = 0
|
|
119
|
+
let undislikeEvents = 0
|
|
120
|
+
for (const e of all) {
|
|
121
|
+
if (e.type === 'dislike') dislikeEvents++
|
|
122
|
+
else if (e.type === 'undislike') undislikeEvents++
|
|
123
|
+
}
|
|
91
124
|
const pad = (n) => String(n).padStart(2, '0')
|
|
92
125
|
const localDate = (ts) => {
|
|
93
126
|
const d = new Date(ts)
|
|
@@ -149,13 +182,16 @@ export function createHistory({ storage, library, logger }) {
|
|
|
149
182
|
daily,
|
|
150
183
|
skippedCount,
|
|
151
184
|
avgCompletion: events.length === 0 ? 0 : Math.round((completionSum / events.length) * 1000) / 1000,
|
|
185
|
+
// 口味信号(八期④):不喜欢事件计数,与播放统计分离
|
|
186
|
+
dislikeEvents,
|
|
187
|
+
undislikeEvents,
|
|
152
188
|
}
|
|
153
189
|
}
|
|
154
190
|
|
|
155
|
-
return { file, append, read, readAll, stats }
|
|
191
|
+
return { file, append, appendTaste, read, readAll, stats }
|
|
156
192
|
}
|
|
157
193
|
|
|
158
|
-
export function registerHistoryRoutes(webServer, { history, logger }) {
|
|
194
|
+
export function registerHistoryRoutes(webServer, { history, likes, logger }) {
|
|
159
195
|
const warn = (msg) => logger?.warn?.(msg)
|
|
160
196
|
const sendJson = (res, status, value) => {
|
|
161
197
|
const body = JSON.stringify(value)
|
|
@@ -187,7 +223,8 @@ export function registerHistoryRoutes(webServer, { history, logger }) {
|
|
|
187
223
|
const url = new URL(req.url ?? '/', 'http://dsh-music.local')
|
|
188
224
|
const limit = url.searchParams.get('limit') ?? 200
|
|
189
225
|
const offset = url.searchParams.get('offset') ?? 0
|
|
190
|
-
|
|
226
|
+
const includeTaste = url.searchParams.get('includeTaste') === '1' || url.searchParams.get('includeTaste') === 'true'
|
|
227
|
+
return sendJson(res, 200, await history.read({ limit, offset, includeTaste }))
|
|
191
228
|
}
|
|
192
229
|
if (req.method === 'POST') {
|
|
193
230
|
let event
|
|
@@ -219,7 +256,13 @@ export function registerHistoryRoutes(webServer, { history, logger }) {
|
|
|
219
256
|
handler: async (req, res) => {
|
|
220
257
|
if (req.method !== 'GET') return sendJson(res, 405, { error: '方法不允许' })
|
|
221
258
|
try {
|
|
222
|
-
|
|
259
|
+
const value = await history.stats()
|
|
260
|
+
// 合并当前不喜欢清单摘要(八期④:不喜欢也进统计卡)
|
|
261
|
+
if (likes && typeof likes.summary === 'function') {
|
|
262
|
+
const summary = await likes.summary(10)
|
|
263
|
+
value.dislikes = { count: summary.count, events: value.dislikeEvents ?? 0, songs: summary.songs }
|
|
264
|
+
}
|
|
265
|
+
return sendJson(res, 200, value)
|
|
223
266
|
} catch (err) {
|
|
224
267
|
warn(`dsh-music: 历史统计错误: ${err.message}`)
|
|
225
268
|
return sendJson(res, 500, { error: '历史统计内部错误' })
|