@soffits/dsh-media-hub 0.7.0 → 0.7.1
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/CHANGELOG.md +3 -3
- package/README.md +1 -1
- package/dist/index.js +48 -64
- package/locale/en.json +1 -1
- package/locale/fr.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +1 -1
- package/web/details.js +3 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
## 0.7.
|
|
3
|
+
## 0.7.1
|
|
4
4
|
|
|
5
|
-
-
|
|
6
|
-
- The "Refresh info" menu item and the quiet backfill of details are gone
|
|
5
|
+
- Opening the page no longer waits on the sources. Each show's details (title, blurb, score, related works, episode titles, cover) come from the copy saved with it, at once, as before 0.7.0. A copy that is missing (a show just added) or about a day old is refreshed from its source in the background, a couple of requests at a time and never for a source that just failed, and the new details show on the next look. A copy over a week old says when it was saved.
|
|
6
|
+
- The "Refresh info" menu item and the quiet backfill of details are gone; the background refresh replaces both.
|
|
7
7
|
|
|
8
8
|
## 0.6.2
|
|
9
9
|
|
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ This plugin was called Video Sync (`@soffits/dsh-video-sync`) until 0.2.0; the r
|
|
|
14
14
|
- **Sources**: one search box over *All sources* or one of them; each source is a configured command line tool that speaks a small JSON protocol ([docs/source-protocol.md](docs/source-protocol.md), the hub's public interface for extensions, see [docs/extensions.md](docs/extensions.md)) and brings its kinds. The defaults are `fanqie` (short dramas, audiobooks, novels) and `bookfetch source` (ebooks and papers); every request runs through the source's command, so any proxy its launcher enforces holds, and a wrapper for another site is one more entry. *Watch* opens it at once, for you alone (*Watch together* in the player opens that room to others where it stands and copies its link); *Save to library* adds the show; *Download all (offline)* keeps every episode on disk. Sources implement one small interface (`src/sources/index.js`).
|
|
15
15
|
- **Search results as cards**: cover, title, score, how many watched it ("36.7万次播放" or "36.7K plays", by the page language), episodes, whether it is finished, tags; *Details* shows everything the source gives (cast, heat, last update…) and the other seasons and linked works.
|
|
16
16
|
- **Pictures for everything**: a work's cover, a show's poster and a room's preview all come from the host and are cached under `<stateDir>/covers`: a source's cover through the source's own command (so its proxy keeps applying), a link's thumbnail through the `proxies` setting, and a still of the video for local files and shows without a cover. A browser never contacts a site's CDN, and a placeholder shows only when there is no picture at all.
|
|
17
|
-
- **Details
|
|
17
|
+
- **Details kept with a show**: a show from a source keeps what the source said about its work (cover, score, popularity, tags, blurb, other fields, related works, episode titles), so the library, a room's *About* tab and the episode list show it at once; a missing or day-old copy is refreshed in the background, and a copy over a week old says when it was saved.
|
|
18
18
|
- **Follow**: a followed work is checked about once a day through its source (and when someone opens it). A new season is added to the library as an empty show, grouped with the earlier ones and followed too, and shows under *New* in Watching and in the watch log; more episodes extend the show. With `notifyCommand` set, that command gets one line of JSON on its standard input for each piece of news.
|
|
19
19
|
- **Rolling cache**: a show from a source lists every episode, but only a window is on disk: the episode people are on is fetched first, then the next few (`cacheAhead`, 5), and `cacheBehind` (1) watched ones stay. Watched episodes that fall out of the window are deleted (the watch log still marks them watched). Jumping to an episode that is not cached fetches it first (the room shows it as preparing), then refills the window around it. A show kept offline (*Download all (offline)*, or the library menu) is never trimmed. All cached episodes of other shows together stay under `cacheLimitGb` (5 GB): past it the least recently watched go first, never one near an open room. The library says *cached N of M* (and *offline*), and the episode list marks the ones not on disk.
|
|
20
20
|
- **Watch log**: `<stateDir>/watch-log.jsonl`, one JSON object per line: rooms opened and closed, viewers joining and leaving, episodes started and finished, and where each viewer stopped (`position` lines when someone leaves, the episode changes, the room closes, and every two minutes while playing).
|
package/dist/index.js
CHANGED
|
@@ -12255,7 +12255,7 @@ function createHandler({ connection, service, settings = () => ({ label: "", pre
|
|
|
12255
12255
|
const route = `${req.method} ${parts.slice(1).join("/")}`;
|
|
12256
12256
|
const query = (name2) => url.searchParams.get(name2) ?? "";
|
|
12257
12257
|
if (route === "GET rooms") return sendJson(res, 200, { rooms: await hub.listRooms() });
|
|
12258
|
-
if (req.method === "GET" && parts[1] === "rooms" && parts.length === 4 && parts[3] === "work") return sendJson(res, 200,
|
|
12258
|
+
if (req.method === "GET" && parts[1] === "rooms" && parts.length === 4 && parts[3] === "work") return sendJson(res, 200, hub.roomWork(parts[2]));
|
|
12259
12259
|
if (req.method === "DELETE" && parts[1] === "rooms" && parts.length === 3) return sendJson(res, 200, hub.closeRoom(parts[2]));
|
|
12260
12260
|
if (req.method === "POST" && parts[1] === "rooms" && parts.length === 4 && parts[3] === "together") return sendJson(res, 200, hub.watchTogether(parts[2]));
|
|
12261
12261
|
if (route === "GET library") return sendJson(res, 200, await hub.library());
|
|
@@ -14204,15 +14204,14 @@ function createLibrary(options) {
|
|
|
14204
14204
|
if (isNearEnd(resume2.position, resume2.duration)) return index + 1 < slots.length ? slots[index + 1].n : null;
|
|
14205
14205
|
return slots[index].n;
|
|
14206
14206
|
}
|
|
14207
|
-
|
|
14208
|
-
async function describe(path, live = false) {
|
|
14207
|
+
async function describe(path) {
|
|
14209
14208
|
const info = await stat9(path).catch(() => null);
|
|
14210
14209
|
if (info === null) return null;
|
|
14211
14210
|
const files = await episodeFiles(path);
|
|
14212
14211
|
const state = download(path);
|
|
14213
14212
|
if ((files === null || files.length === 0) && state === null && !isSourced(record(path))) return null;
|
|
14214
14213
|
const names = (files ?? []).map((file) => file.name);
|
|
14215
|
-
const entry =
|
|
14214
|
+
const entry = record(path);
|
|
14216
14215
|
const slots = slotsOf(entry, files ?? []);
|
|
14217
14216
|
if (names.length === 0 && state === null && !isSourced(entry)) return null;
|
|
14218
14217
|
const resume2 = resumeFrom(path, slots);
|
|
@@ -14264,13 +14263,13 @@ function createLibrary(options) {
|
|
|
14264
14263
|
listeners.add(listener);
|
|
14265
14264
|
return () => listeners.delete(listener);
|
|
14266
14265
|
},
|
|
14267
|
-
/** Every show, newest first, with totals and the free space of the download folder's disk.
|
|
14268
|
-
async list(
|
|
14266
|
+
/** Every show, newest first, with totals and the free space of the download folder's disk. */
|
|
14267
|
+
async list() {
|
|
14269
14268
|
const paths = [];
|
|
14270
14269
|
for (const root of roots) {
|
|
14271
14270
|
for (const name2 of await readdir7(root).catch(() => [])) if (!name2.startsWith(".")) paths.push(join15(root, name2));
|
|
14272
14271
|
}
|
|
14273
|
-
const shows = (await Promise.all(paths.map((path) => describe(path
|
|
14272
|
+
const shows = (await Promise.all(paths.map((path) => describe(path)))).filter((show) => show !== null);
|
|
14274
14273
|
shows.sort((a, b) => b.addedAt - a.addedAt);
|
|
14275
14274
|
groupSeasons(shows);
|
|
14276
14275
|
const disk = await statfs(roots[0]).catch(() => null);
|
|
@@ -14283,8 +14282,7 @@ function createLibrary(options) {
|
|
|
14283
14282
|
},
|
|
14284
14283
|
async episodes(path) {
|
|
14285
14284
|
const target = requireShow(path);
|
|
14286
|
-
const
|
|
14287
|
-
const slots = slotsOf(entry, await episodeFiles(target) ?? []);
|
|
14285
|
+
const slots = slotsOf(record(target), await episodeFiles(target) ?? []);
|
|
14288
14286
|
return slots.map((slot) => ({
|
|
14289
14287
|
n: slot.n,
|
|
14290
14288
|
name: slot.file?.name ?? null,
|
|
@@ -14608,63 +14606,48 @@ function createFollows({ library, source, refreshed, addSeason, record, notify,
|
|
|
14608
14606
|
};
|
|
14609
14607
|
}
|
|
14610
14608
|
|
|
14611
|
-
// src/
|
|
14609
|
+
// src/work-refresh.js
|
|
14612
14610
|
var DAY_MS3 = 864e5;
|
|
14613
|
-
var
|
|
14614
|
-
function
|
|
14615
|
-
const flying = /* @__PURE__ */ new
|
|
14616
|
-
const
|
|
14611
|
+
var HOUR_MS = 36e5;
|
|
14612
|
+
function createWorkRefresh({ source, keep, maxAgeMs = DAY_MS3, retryMs = HOUR_MS, parallel = 2, now = Date.now, logger }) {
|
|
14613
|
+
const flying = /* @__PURE__ */ new Set();
|
|
14614
|
+
const failedAt = /* @__PURE__ */ new Map();
|
|
14615
|
+
const waiting = [];
|
|
14617
14616
|
let running = 0;
|
|
14618
|
-
function
|
|
14619
|
-
while (running < parallel &&
|
|
14617
|
+
function pump() {
|
|
14618
|
+
while (running < parallel && waiting.length > 0) {
|
|
14620
14619
|
running += 1;
|
|
14621
|
-
|
|
14622
|
-
|
|
14623
|
-
|
|
14624
|
-
const limited = (task) => new Promise((resolve7, reject) => {
|
|
14625
|
-
queue.push(() => task().then(resolve7, reject).finally(() => {
|
|
14626
|
-
running -= 1;
|
|
14627
|
-
turn();
|
|
14628
|
-
}));
|
|
14629
|
-
turn();
|
|
14630
|
-
});
|
|
14631
|
-
function ask(path, entry) {
|
|
14632
|
-
const { source: sourceId, id } = entry.source;
|
|
14633
|
-
const key = `${sourceId}
|
|
14634
|
-
${id}`;
|
|
14635
|
-
if (!flying.has(key)) {
|
|
14636
|
-
const request = limited(() => source(sourceId).info(id, { person: entry.source.person })).then((info) => {
|
|
14637
|
-
const work = snapshotOf(info, now());
|
|
14638
|
-
if (!sameAs(entry.work, work, now())) keep(path, work);
|
|
14639
|
-
return work;
|
|
14640
|
-
}).finally(() => flying.delete(key));
|
|
14641
|
-
request.catch(() => {
|
|
14620
|
+
waiting.shift()().finally(() => {
|
|
14621
|
+
running -= 1;
|
|
14622
|
+
pump();
|
|
14642
14623
|
});
|
|
14643
|
-
flying.set(key, request);
|
|
14644
14624
|
}
|
|
14645
|
-
return flying.get(key);
|
|
14646
14625
|
}
|
|
14647
|
-
|
|
14648
|
-
|
|
14649
|
-
const found =
|
|
14650
|
-
if (found === void 0)
|
|
14651
|
-
|
|
14652
|
-
|
|
14653
|
-
|
|
14626
|
+
return function touch(path, entry) {
|
|
14627
|
+
const sourceId = entry.source?.source;
|
|
14628
|
+
const found = sourceId ? source(sourceId) : void 0;
|
|
14629
|
+
if (found === void 0 || entry.work && now() - entry.work.at < maxAgeMs) return;
|
|
14630
|
+
const key = `${sourceId}
|
|
14631
|
+
${entry.source.id}`;
|
|
14632
|
+
if (flying.has(key) || now() - (failedAt.get(key) ?? -Infinity) < retryMs) return;
|
|
14633
|
+
flying.add(key);
|
|
14634
|
+
waiting.push(async () => {
|
|
14635
|
+
try {
|
|
14636
|
+
keep(path, snapshotOf(await found.info(entry.source.id, { person: entry.source.person }), now()));
|
|
14637
|
+
failedAt.delete(key);
|
|
14638
|
+
} catch (error) {
|
|
14639
|
+
failedAt.set(key, now());
|
|
14640
|
+
logger.warn("no details for %s from %s: %s", path, sourceId, error.message);
|
|
14641
|
+
} finally {
|
|
14642
|
+
flying.delete(key);
|
|
14643
|
+
}
|
|
14654
14644
|
});
|
|
14655
|
-
|
|
14656
|
-
return await Promise.race([ask(path, entry), late]) ?? offline(entry);
|
|
14657
|
-
} catch (error) {
|
|
14658
|
-
logger.warn("no live details for %s from %s: %s", path, entry.source.source, error.message);
|
|
14659
|
-
return offline(entry);
|
|
14660
|
-
} finally {
|
|
14661
|
-
clearTimeout(timer);
|
|
14662
|
-
}
|
|
14645
|
+
pump();
|
|
14663
14646
|
};
|
|
14664
14647
|
}
|
|
14665
14648
|
|
|
14666
14649
|
// src/media.js
|
|
14667
|
-
var
|
|
14650
|
+
var HOUR_MS2 = 36e5;
|
|
14668
14651
|
var MIN_FREE_BYTES = 1e9;
|
|
14669
14652
|
var NO_CONVERTER = Object.freeze({ command: "", available: async () => false });
|
|
14670
14653
|
var hubError = (code, message) => Object.assign(new Error(message), { code });
|
|
@@ -14690,9 +14673,8 @@ function createMediaHub(options) {
|
|
|
14690
14673
|
logger,
|
|
14691
14674
|
now
|
|
14692
14675
|
});
|
|
14693
|
-
const
|
|
14676
|
+
const refreshWork = createWorkRefresh({ source: (id) => sources.get(id), keep: (path, work) => library.keepWork(path, work), maxAgeMs: options.workMaxAgeMs, logger, now });
|
|
14694
14677
|
const library = createLibrary({
|
|
14695
|
-
liveWork,
|
|
14696
14678
|
roots: libraryRoots,
|
|
14697
14679
|
stateDir,
|
|
14698
14680
|
autoDeleteDays: options.autoDeleteDays,
|
|
@@ -14734,7 +14716,7 @@ function createMediaHub(options) {
|
|
|
14734
14716
|
});
|
|
14735
14717
|
cache.enforce().catch(() => {
|
|
14736
14718
|
});
|
|
14737
|
-
},
|
|
14719
|
+
}, HOUR_MS2);
|
|
14738
14720
|
async function onFiles(job) {
|
|
14739
14721
|
await rooms.syncShow(job.dir);
|
|
14740
14722
|
if (job.status === "failed") rooms.failWaiting(job.dir, job.error ?? "the download failed", job.reason ?? null);
|
|
@@ -14780,9 +14762,10 @@ function createMediaHub(options) {
|
|
|
14780
14762
|
now,
|
|
14781
14763
|
...options.follow
|
|
14782
14764
|
});
|
|
14783
|
-
const
|
|
14765
|
+
const shownEntry = (show) => {
|
|
14784
14766
|
const entry = { source: library.workSource(show), work: library.workOf(show) };
|
|
14785
|
-
|
|
14767
|
+
refreshWork(show, entry);
|
|
14768
|
+
return entry;
|
|
14786
14769
|
};
|
|
14787
14770
|
const withCovers = (show) => show.work && show.source?.source ? { ...show, work: covers.decorate(show.source.source, show.work) } : show;
|
|
14788
14771
|
function source(id) {
|
|
@@ -14836,7 +14819,7 @@ ${item.id}`).digest("hex").slice(0, 8);
|
|
|
14836
14819
|
/** Open rooms with a preview of what plays: the show's cover and a frame of the episode now on. */
|
|
14837
14820
|
async listRooms() {
|
|
14838
14821
|
return Promise.all(rooms.listRooms().map(async ({ file, ...room }) => {
|
|
14839
|
-
const show = room.show === null ? null : withCovers(
|
|
14822
|
+
const show = room.show === null ? null : withCovers({ source: library.workSource(room.show), work: library.workOf(room.show) });
|
|
14840
14823
|
return { ...room, cover: show?.work?.cover ?? null, frame: file === null ? null : await covers.ofFrame(file, room.duration > 30 ? Math.round(room.duration / 10) : 3) };
|
|
14841
14824
|
}));
|
|
14842
14825
|
},
|
|
@@ -14871,14 +14854,15 @@ ${item.id}`).digest("hex").slice(0, 8);
|
|
|
14871
14854
|
},
|
|
14872
14855
|
// ---------------------------------------------------------- library
|
|
14873
14856
|
async library() {
|
|
14874
|
-
const list = await library.list(
|
|
14857
|
+
const list = await library.list();
|
|
14858
|
+
for (const show of list.shows) if (show.source?.source) refreshWork(show.path, { source: show.source, work: show.work });
|
|
14875
14859
|
return { ...list, shows: list.shows.map(withCovers) };
|
|
14876
14860
|
},
|
|
14877
14861
|
/** The details of the work a room's show came from, or null. */
|
|
14878
|
-
|
|
14862
|
+
roomWork(id) {
|
|
14879
14863
|
const room = rooms.listRooms().find((entry) => entry.id === id);
|
|
14880
14864
|
if (room === void 0) throw hubError("not_found", "no such room");
|
|
14881
|
-
return { work: room.show === null ? null : withCovers(
|
|
14865
|
+
return { work: room.show === null ? null : withCovers(shownEntry(room.show)).work ?? null, source: library.workSource(room.show)?.source ?? null, id: library.workSource(room.show)?.id ?? null };
|
|
14882
14866
|
},
|
|
14883
14867
|
episodes: (path) => library.episodes(path),
|
|
14884
14868
|
removeShow: (path, by) => library.remove(path, { by }),
|
package/locale/en.json
CHANGED
|
@@ -143,7 +143,7 @@
|
|
|
143
143
|
"library.offline": "offline",
|
|
144
144
|
"library.notCached": "not cached",
|
|
145
145
|
"library.episodeN": "Episode {n}",
|
|
146
|
-
"library.
|
|
146
|
+
"library.oldCopy": "Details last updated {date}.",
|
|
147
147
|
"library.playFromFetch": "Watch from this episode (it is fetched first)",
|
|
148
148
|
"library.downloadAll": "Download all (offline)",
|
|
149
149
|
"library.stopOffline": "Stop keeping offline",
|
package/locale/fr.json
CHANGED
|
@@ -143,7 +143,7 @@
|
|
|
143
143
|
"library.offline": "hors ligne",
|
|
144
144
|
"library.notCached": "pas en cache",
|
|
145
145
|
"library.episodeN": "Épisode {n}",
|
|
146
|
-
"library.
|
|
146
|
+
"library.oldCopy": "Infos mises à jour le {date}.",
|
|
147
147
|
"library.playFromFetch": "Regarder à partir de cet épisode (il est d’abord récupéré)",
|
|
148
148
|
"library.downloadAll": "Tout télécharger (hors ligne)",
|
|
149
149
|
"library.stopOffline": "Ne plus garder hors ligne",
|
package/locale/zh.json
CHANGED
|
@@ -143,7 +143,7 @@
|
|
|
143
143
|
"library.offline": "离线",
|
|
144
144
|
"library.notCached": "未缓存",
|
|
145
145
|
"library.episodeN": "第 {n} 集",
|
|
146
|
-
"library.
|
|
146
|
+
"library.oldCopy": "详情更新于 {date}。",
|
|
147
147
|
"library.playFromFetch": "从这一集开始看(先下载它)",
|
|
148
148
|
"library.downloadAll": "全部下载(离线)",
|
|
149
149
|
"library.stopOffline": "不再离线保存",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soffits/dsh-media-hub",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "A media hub for DeepSeek Harness: search shows, novels, ebooks and papers across sources, watch together in sync, and download books in the format you want onto your own shelf.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
package/web/details.js
CHANGED
|
@@ -10,6 +10,8 @@ import { useKnownWork } from './known.js'
|
|
|
10
10
|
import { Icon, Spinner, asPerson, base, clock, day, fill, h, plural, query, React } from './ui.js'
|
|
11
11
|
|
|
12
12
|
const INFO_CONCURRENCY = 3
|
|
13
|
+
/** A saved copy of a work this old says so, quietly. */
|
|
14
|
+
const OLD_COPY_MS = 7 * 86_400_000
|
|
13
15
|
|
|
14
16
|
/** Fetch work details a few at a time, so a page of results doesn't start ten downloads of metadata at once. */
|
|
15
17
|
function createInfoQueue() {
|
|
@@ -92,7 +94,7 @@ export function WorkDetails({ t, info, source, onFocus }) {
|
|
|
92
94
|
const rows = info.meta ?? []
|
|
93
95
|
const related = info.related ?? []
|
|
94
96
|
return h('div', { className: 'vsync-details' },
|
|
95
|
-
info.
|
|
97
|
+
info.at && Date.now() - info.at > OLD_COPY_MS && h('p', { className: 'vsync-note', role: 'status' }, fill(t('library.oldCopy'), { date: day(t, info.at) })),
|
|
96
98
|
info.blurb && h('p', { className: 'vsync-fullBlurb' }, info.blurb),
|
|
97
99
|
info.latest && h('p', { className: 'vsync-note' }, fill(t('search.latest'), { title: info.latest })),
|
|
98
100
|
rows.length > 0 && h('dl', { className: 'vsync-facts' }, rows.flatMap(row => [h('dt', { key: `${row.key}-k` }, metaLabel(t, row)), h('dd', { key: `${row.key}-v` }, row.value)])),
|