dsh-movie-workbench 1.5.0 → 1.6.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/README.md +3 -3
- package/README.zh.md +3 -2
- package/client.js +133 -15
- package/lib/host.js +46 -4
- package/lib/providers.js +15 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -20,8 +20,8 @@ DSH **Movies workbench** : Search for movies and TV series from **TMDB**, **IMDb
|
|
|
20
20
|
each genre; TV lists group 官方榜单, 年度榜单 and 高分经典 / 近期热门 for the same genres.
|
|
21
21
|
Generated charts use their first title's poster as the card cover. Open a chart to see the
|
|
22
22
|
ranked titles with the same paged infinite scroll.
|
|
23
|
-
- **BT resources** — search BT resources, sortable by size, seeders or downloads
|
|
24
|
-
link or open the source page.
|
|
23
|
+
- **BT resources** — search BT resources, sortable by size, seeders or downloads, with paged
|
|
24
|
+
loading (scroll or 加载更多 for the next page); copy the magnet link or open the source page.
|
|
25
25
|
|
|
26
26
|
## Installation
|
|
27
27
|
|
|
@@ -65,7 +65,7 @@ The Host side (`index.js` + `lib/`) exposes a single prefix route, `/movie-workb
|
|
|
65
65
|
| `GET /charts?source=douban&kind=movie\|tv` | one chart catalog: `movie` (default) has 3 official charts with live metadata, 10 annual charts (高分/热门 for 2025–2021), 27 hidden-gem charts (one per genre) and 54 genre charts (94 total); `tv` has 3 official, 10 annual and 54 genre charts (67 total, no hidden gems) |
|
|
66
66
|
| `GET /chart?source=douban&id=&start=&count=` | one page of a chart's ranked titles; `id` is an official id, `year:<yyyy>:<S or U>`, `hidden:<genre>`, `genre:<genre>:<S or U>`, or the TV forms `tv-year:<yyyy>:<S or U>` / `tv-genre:<genre>:<S or U>` (S = high-score, U = recent hits) |
|
|
67
67
|
| `GET /detail?source=douban&id=` | synopsis and metadata for a DouBan title |
|
|
68
|
-
| `GET /torrents?q=&alt=&source=&limit=` | BT resource search |
|
|
68
|
+
| `GET /torrents?q=&alt=&source=&limit=&page=` | BT resource search; one page of results (`page` 1–20) plus `hasMore` for scroll loading |
|
|
69
69
|
| `GET /image?url=` | proxy posters from allowlisted image hosts |
|
|
70
70
|
|
|
71
71
|
All upstream HTTP requests happen in the Host, so the page stays same-origin and DouBan's `Referer`
|
package/README.zh.md
CHANGED
|
@@ -17,7 +17,8 @@ DSH **影视工作台**:在一个页面里检索 **TMDB**、**IMDb** 和 **豆
|
|
|
17
17
|
官方榜单、年度榜单(2025–2021,含高分/热门两档)、高分经典(27 个类型)、近期热门(27 个类型)和
|
|
18
18
|
冷门佳作(27 个类型);剧集榜单包含官方榜单、年度榜单和高分经典 / 近期热门。
|
|
19
19
|
无封面的榜单自动取第一名作品的封面,点开榜单按排名展示影片,同样支持下滑加载更多。
|
|
20
|
-
- **BT 资源** — 查找 BT
|
|
20
|
+
- **BT 资源** — 查找 BT 资源,可按大小、做种、下载排序,支持下滑/「加载更多」分页;
|
|
21
|
+
可复制磁力链接或打开来源页。
|
|
21
22
|
|
|
22
23
|
## 安装
|
|
23
24
|
|
|
@@ -59,7 +60,7 @@ Host 端(`index.js` + `lib/`)只有一个前缀路由 `/movie-workbench/api`
|
|
|
59
60
|
| `GET /charts?source=douban&kind=movie\|tv` | 单个榜单目录:`movie`(默认)含 3 个官方榜单(实时元数据)+ 10 个年度榜单(2025–2021 的高分/热门)+ 27 个类型冷门佳作 + 54 个分类题材榜单(共 94 个);`tv` 含 3 个官方 + 10 个年度 + 54 个分类题材榜单(共 67 个,无冷门佳作) |
|
|
60
61
|
| `GET /chart?source=douban&id=&start=&count=` | 某个榜单的一页按排名条目;`id` 为官方榜单 id、`year:<年份>:<S 或 U>`、`hidden:<类型>`、`genre:<类型>:<S 或 U>`,以及剧集形式 `tv-year:<年份>:<S 或 U>` / `tv-genre:<类型>:<S 或 U>`(S 高分经典,U 近期热门) |
|
|
61
62
|
| `GET /detail?source=douban&id=` | 豆瓣条目的简介与元数据 |
|
|
62
|
-
| `GET /torrents?q=&alt=&source=&limit=` | BT
|
|
63
|
+
| `GET /torrents?q=&alt=&source=&limit=&page=` | BT 资源搜索;返回一页结果(`page` 1–20)及 `hasMore` 供下滑加载 |
|
|
63
64
|
| `GET /image?url=` | 代理白名单图床的海报 |
|
|
64
65
|
|
|
65
66
|
所有上游 HTTP 请求都在 Host 完成,因此页面保持同源,豆瓣的 `Referer` 要求也在服务端
|
package/client.js
CHANGED
|
@@ -147,6 +147,10 @@ window.__ModuleLoader__.load({
|
|
|
147
147
|
'torrent.title': 'BT 资源',
|
|
148
148
|
'torrent.note': '来自公开 BT 索引,仅供检索,请自行判断内容合法性',
|
|
149
149
|
'torrent.loading': '正在搜索 BT 资源…',
|
|
150
|
+
'torrent.loadMore': '加载更多',
|
|
151
|
+
'torrent.loadingMore': '正在加载…',
|
|
152
|
+
'torrent.moreFailed': '加载更多失败',
|
|
153
|
+
'torrent.end': '没有更多了',
|
|
150
154
|
'torrent.empty': '没有找到相关 BT 资源',
|
|
151
155
|
'torrent.failed': 'BT 资源搜索失败',
|
|
152
156
|
'torrent.retry': '重试',
|
|
@@ -263,6 +267,10 @@ window.__ModuleLoader__.load({
|
|
|
263
267
|
'torrent.title': 'BT resources',
|
|
264
268
|
'torrent.note': 'From public torrent indexes; search only — check legality yourself',
|
|
265
269
|
'torrent.loading': 'Searching torrent indexes…',
|
|
270
|
+
'torrent.loadMore': 'Load more',
|
|
271
|
+
'torrent.loadingMore': 'Loading more…',
|
|
272
|
+
'torrent.moreFailed': 'Could not load more',
|
|
273
|
+
'torrent.end': 'No more results',
|
|
266
274
|
'torrent.empty': 'No BT resources found',
|
|
267
275
|
'torrent.failed': 'Torrent search failed',
|
|
268
276
|
'torrent.retry': 'Retry',
|
|
@@ -787,6 +795,8 @@ window.__ModuleLoader__.load({
|
|
|
787
795
|
'.mw-torrent-copy{cursor:pointer;}',
|
|
788
796
|
'.mw-torrent-loading{display:flex;flex-direction:column;gap:8px;}',
|
|
789
797
|
'.mw-torrent-skeleton{display:flex;flex-direction:column;gap:6px;padding:12px;border-radius:10px;border:0.5px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-layer-1);}',
|
|
798
|
+
'.mw-torrent-more{display:flex;justify-content:center;padding:10px 0 2px;}',
|
|
799
|
+
'.mw-torrent-more-note{margin:10px 0 2px;text-align:center;font-size:12px;color:var(--dsw-alias-label-tertiary);}',
|
|
790
800
|
'.mw-torrent-empty{margin:0;font-size:13px;line-height:20px;color:var(--dsw-alias-label-secondary);}',
|
|
791
801
|
'.mw-torrent-links{display:flex;flex-wrap:wrap;gap:8px;margin-top:10px;}',
|
|
792
802
|
'.mw-torrent-links .mw-btn{height:30px;padding:0 12px;font-size:12px;border-radius:15px;}',
|
|
@@ -1628,43 +1638,66 @@ window.__ModuleLoader__.load({
|
|
|
1628
1638
|
const [attempt, setAttempt] = useState(0)
|
|
1629
1639
|
const [copyState, setCopyState] = useState(null)
|
|
1630
1640
|
const [sort, setSort] = useState({ key: 'default', direction: 'desc' })
|
|
1641
|
+
const [loadingMore, setLoadingMore] = useState(false)
|
|
1642
|
+
const [moreFailure, setMoreFailure] = useState(null)
|
|
1631
1643
|
const copyTimerRef = useRef(null)
|
|
1644
|
+
const moreRef = useRef(null)
|
|
1645
|
+
const moreTimerRef = useRef(null)
|
|
1632
1646
|
|
|
1633
1647
|
useEffect(() => () => {
|
|
1634
1648
|
if (copyTimerRef.current) window.clearTimeout(copyTimerRef.current)
|
|
1649
|
+
if (moreTimerRef.current) window.clearTimeout(moreTimerRef.current)
|
|
1635
1650
|
}, [])
|
|
1636
1651
|
const { q: primaryQuery, alt } = torrentQuery(item)
|
|
1637
1652
|
|
|
1653
|
+
/** Request one page of BT rows for this title (page 1 is the first page). */
|
|
1654
|
+
function requestTorrentsPage(page, signal) {
|
|
1655
|
+
const { q, alt: altQuery } = torrentQuery(item)
|
|
1656
|
+
const params = new URLSearchParams()
|
|
1657
|
+
params.set('q', q)
|
|
1658
|
+
params.set('source', 'all')
|
|
1659
|
+
params.set('limit', '20')
|
|
1660
|
+
params.set('page', String(page))
|
|
1661
|
+
if (altQuery) params.set('alt', altQuery)
|
|
1662
|
+
return callApi('/torrents?' + params.toString(), {
|
|
1663
|
+
headers: { accept: 'application/json' },
|
|
1664
|
+
signal: signal,
|
|
1665
|
+
}).then(body => ({
|
|
1666
|
+
rows: Array.isArray(body.results) ? body.results : [],
|
|
1667
|
+
errors: Array.isArray(body.errors) ? body.errors : [],
|
|
1668
|
+
tookMs: body.tookMs || 0,
|
|
1669
|
+
page: body.page || page,
|
|
1670
|
+
hasMore: Boolean(body.hasMore),
|
|
1671
|
+
query: body.query || q,
|
|
1672
|
+
}))
|
|
1673
|
+
}
|
|
1674
|
+
|
|
1638
1675
|
useEffect(() => {
|
|
1639
1676
|
if (attempt === 0) {
|
|
1640
1677
|
const hit = session.torrents && session.torrents[cacheKey]
|
|
1641
1678
|
if (hit && hit.status !== 'loading') return undefined
|
|
1642
1679
|
}
|
|
1643
|
-
const { q
|
|
1680
|
+
const { q } = torrentQuery(item)
|
|
1644
1681
|
if (!q) {
|
|
1645
1682
|
setView({ status: 'done', results: [], errors: [], tookMs: 0, query: '' })
|
|
1646
1683
|
return undefined
|
|
1647
1684
|
}
|
|
1648
1685
|
const controller = new AbortController()
|
|
1649
1686
|
let live = true
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
params.set('source', 'all')
|
|
1653
|
-
params.set('limit', '20')
|
|
1654
|
-
if (altQuery) params.set('alt', altQuery)
|
|
1687
|
+
setMoreFailure(null)
|
|
1688
|
+
setLoadingMore(false)
|
|
1655
1689
|
setView({ status: 'loading', results: [], errors: [], tookMs: 0, query: q })
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
signal: controller.signal,
|
|
1659
|
-
})
|
|
1660
|
-
.then(body => {
|
|
1690
|
+
requestTorrentsPage(1, controller.signal)
|
|
1691
|
+
.then(page => {
|
|
1661
1692
|
if (!live) return
|
|
1662
1693
|
const done = {
|
|
1663
1694
|
status: 'done',
|
|
1664
|
-
results:
|
|
1665
|
-
errors:
|
|
1666
|
-
tookMs:
|
|
1667
|
-
|
|
1695
|
+
results: page.rows,
|
|
1696
|
+
errors: page.errors,
|
|
1697
|
+
tookMs: page.tookMs,
|
|
1698
|
+
page: page.page,
|
|
1699
|
+
hasMore: page.hasMore,
|
|
1700
|
+
query: page.query,
|
|
1668
1701
|
}
|
|
1669
1702
|
session.torrents = { ...(session.torrents || {}), [cacheKey]: done }
|
|
1670
1703
|
setView(done)
|
|
@@ -1686,7 +1719,55 @@ window.__ModuleLoader__.load({
|
|
|
1686
1719
|
}
|
|
1687
1720
|
}, [cacheKey, attempt])
|
|
1688
1721
|
|
|
1722
|
+
/**
|
|
1723
|
+
* Append the next page of BT rows. Rows are deduped by info hash because
|
|
1724
|
+
* pages from different indexes can overlap, and the last failed page is
|
|
1725
|
+
* kept so the retry button can ask for it again.
|
|
1726
|
+
*/
|
|
1727
|
+
function loadMore() {
|
|
1728
|
+
if (loadingMore || !view.hasMore || view.status !== 'done') return
|
|
1729
|
+
const nextPage = (view.page || 1) + 1
|
|
1730
|
+
setLoadingMore(true)
|
|
1731
|
+
setMoreFailure(null)
|
|
1732
|
+
const controller = new AbortController()
|
|
1733
|
+
requestTorrentsPage(nextPage, controller.signal)
|
|
1734
|
+
.then(page => {
|
|
1735
|
+
const seen = new Set((view.results || []).map(row => row && row.id))
|
|
1736
|
+
const extra = page.rows.filter(row => row && !seen.has(row.id))
|
|
1737
|
+
const merged = {
|
|
1738
|
+
...view,
|
|
1739
|
+
results: (view.results || []).concat(extra),
|
|
1740
|
+
errors: page.errors,
|
|
1741
|
+
tookMs: page.tookMs,
|
|
1742
|
+
page: page.page,
|
|
1743
|
+
hasMore: page.hasMore,
|
|
1744
|
+
}
|
|
1745
|
+
session.torrents = { ...(session.torrents || {}), [cacheKey]: merged }
|
|
1746
|
+
setView(merged)
|
|
1747
|
+
})
|
|
1748
|
+
.catch(error => {
|
|
1749
|
+
if (controller.signal.aborted) return
|
|
1750
|
+
setMoreFailure(error && error.code ? error.code : 'network')
|
|
1751
|
+
})
|
|
1752
|
+
.finally(() => setLoadingMore(false))
|
|
1753
|
+
}
|
|
1754
|
+
|
|
1755
|
+
/* Infinite scroll: the footer sentinel loads the next page when it comes
|
|
1756
|
+
near the viewport (with a button as the accessible fallback). */
|
|
1757
|
+
useEffect(() => {
|
|
1758
|
+
if (view.status !== 'done' || !view.hasMore || loadingMore) return undefined
|
|
1759
|
+
const node = moreRef.current
|
|
1760
|
+
if (!node || typeof IntersectionObserver !== 'function') return undefined
|
|
1761
|
+
const observer = new IntersectionObserver(entries => {
|
|
1762
|
+
if (entries.some(entry => entry.isIntersecting)) loadMore()
|
|
1763
|
+
}, { rootMargin: '240px 0px' })
|
|
1764
|
+
observer.observe(node)
|
|
1765
|
+
return () => observer.disconnect()
|
|
1766
|
+
}, [view.status, view.hasMore, view.page, loadingMore, view.results.length])
|
|
1767
|
+
|
|
1689
1768
|
const retry = () => {
|
|
1769
|
+
setMoreFailure(null)
|
|
1770
|
+
setLoadingMore(false)
|
|
1690
1771
|
setView({ status: 'loading', results: [], errors: [], tookMs: 0, query: primaryQuery })
|
|
1691
1772
|
setAttempt(value => value + 1)
|
|
1692
1773
|
}
|
|
@@ -1756,6 +1837,38 @@ window.__ModuleLoader__.load({
|
|
|
1756
1837
|
}
|
|
1757
1838
|
const fallbackQuery = alt || primaryQuery || item.title || ''
|
|
1758
1839
|
|
|
1840
|
+
/* Paged loading footer: sentinel + button while more pages exist, a
|
|
1841
|
+
failure hint that retries the same page, and an end note. */
|
|
1842
|
+
let moreFooter = null
|
|
1843
|
+
if (view.status === 'done' && sortedResults.length > 0) {
|
|
1844
|
+
if (moreFailure) {
|
|
1845
|
+
moreFooter = h(RecommendHint, {
|
|
1846
|
+
t: t,
|
|
1847
|
+
text: t('torrent.moreFailed'),
|
|
1848
|
+
actionLabel: t('torrent.retry'),
|
|
1849
|
+
onAction: loadMore,
|
|
1850
|
+
})
|
|
1851
|
+
} else if (loadingMore) {
|
|
1852
|
+
moreFooter = h(
|
|
1853
|
+
'p',
|
|
1854
|
+
{ className: 'mw-torrent-more-note', role: 'status' },
|
|
1855
|
+
t('torrent.loadingMore'),
|
|
1856
|
+
)
|
|
1857
|
+
} else if (view.hasMore) {
|
|
1858
|
+
moreFooter = h(
|
|
1859
|
+
'div',
|
|
1860
|
+
{ className: 'mw-torrent-more', ref: moreRef },
|
|
1861
|
+
h(
|
|
1862
|
+
'button',
|
|
1863
|
+
{ type: 'button', className: 'mw-btn', onClick: loadMore },
|
|
1864
|
+
t('torrent.loadMore'),
|
|
1865
|
+
),
|
|
1866
|
+
)
|
|
1867
|
+
} else {
|
|
1868
|
+
moreFooter = h('p', { className: 'mw-torrent-more-note' }, t('torrent.end'))
|
|
1869
|
+
}
|
|
1870
|
+
}
|
|
1871
|
+
|
|
1759
1872
|
let body = null
|
|
1760
1873
|
if (view.status === 'loading') {
|
|
1761
1874
|
const rows = []
|
|
@@ -1803,6 +1916,9 @@ window.__ModuleLoader__.load({
|
|
|
1803
1916
|
)
|
|
1804
1917
|
} else {
|
|
1805
1918
|
body = h(
|
|
1919
|
+
'div',
|
|
1920
|
+
null,
|
|
1921
|
+
h(
|
|
1806
1922
|
'div',
|
|
1807
1923
|
{ className: 'mw-torrent-list', role: 'list' },
|
|
1808
1924
|
sortedResults.map((row, index) => {
|
|
@@ -1857,6 +1973,8 @@ window.__ModuleLoader__.load({
|
|
|
1857
1973
|
),
|
|
1858
1974
|
)
|
|
1859
1975
|
}),
|
|
1976
|
+
),
|
|
1977
|
+
moreFooter,
|
|
1860
1978
|
)
|
|
1861
1979
|
}
|
|
1862
1980
|
|
package/lib/host.js
CHANGED
|
@@ -87,6 +87,11 @@ const TORRENT_SOURCES = ['bitsearch', 'bt4g']
|
|
|
87
87
|
const DEFAULT_TORRENT_LIMIT = 20
|
|
88
88
|
const MAX_TORRENT_LIMIT = 30
|
|
89
89
|
const MAX_TORRENT_QUERY_CHARS = 160
|
|
90
|
+
const MAX_TORRENT_PAGE = 20
|
|
91
|
+
/** BitSearch returns about 20 cards per result page. */
|
|
92
|
+
const BITSEARCH_PAGE_SIZE = 20
|
|
93
|
+
/** Providers that can page past the first result page (BT4G's RSS has one page). */
|
|
94
|
+
const TORRENT_PAGE_SOURCES = Object.freeze(['bitsearch'])
|
|
90
95
|
/** Scraped index pages are slower than the JSON APIs; give them a floor. */
|
|
91
96
|
const TORRENT_TIMEOUT_FLOOR_MS = 15000
|
|
92
97
|
|
|
@@ -726,13 +731,26 @@ async function handleTorrents(req, res, searchParams, settings) {
|
|
|
726
731
|
}
|
|
727
732
|
|
|
728
733
|
const limit = parseTorrentLimit(searchParams)
|
|
734
|
+
const page = parseTorrentPage(searchParams)
|
|
735
|
+
if (page === null) {
|
|
736
|
+
sendJson(req, res, 400, {
|
|
737
|
+
ok: false,
|
|
738
|
+
code: 'bad_page',
|
|
739
|
+
message: `The "page" query parameter must be an integer between 1 and ${MAX_TORRENT_PAGE}.`,
|
|
740
|
+
})
|
|
741
|
+
return
|
|
742
|
+
}
|
|
743
|
+
/* BT4G's RSS endpoint is a single page, so page 2+ only asks the indexes
|
|
744
|
+
that can page; an explicit bt4g page 2 is a valid, empty page. */
|
|
745
|
+
const pageable = page > 1
|
|
746
|
+
const names = (source === 'all' ? TORRENT_SOURCES : [source])
|
|
747
|
+
.filter((name) => !pageable || TORRENT_PAGE_SOURCES.indexOf(name) !== -1)
|
|
729
748
|
const queries = alt ? [query, alt] : [query]
|
|
730
|
-
const names = source === 'all' ? TORRENT_SOURCES : [source]
|
|
731
749
|
const startedAt = Date.now()
|
|
732
750
|
const outcomes = await Promise.all(
|
|
733
751
|
names.map(async (name) => {
|
|
734
752
|
try {
|
|
735
|
-
return { source: name,
|
|
753
|
+
return { source: name, ...(await torrentSource(name, { queries, settings, page })) }
|
|
736
754
|
} catch (error) {
|
|
737
755
|
return { source: name, error: providerFailure(name, error) }
|
|
738
756
|
}
|
|
@@ -742,13 +760,16 @@ async function handleTorrents(req, res, searchParams, settings) {
|
|
|
742
760
|
.filter((outcome) => !outcome.error)
|
|
743
761
|
.map((outcome) => ({ source: outcome.source, rows: outcome.rows }))
|
|
744
762
|
const errors = outcomes.filter((outcome) => outcome.error).map((outcome) => outcome.error)
|
|
763
|
+
const hasMore = outcomes.some((outcome) => !outcome.error && outcome.hasMore)
|
|
745
764
|
|
|
746
765
|
sendJson(req, res, 200, {
|
|
747
766
|
ok: true,
|
|
748
767
|
query,
|
|
749
768
|
alt: alt || null,
|
|
769
|
+
page,
|
|
750
770
|
tookMs: Math.max(0, Date.now() - startedAt),
|
|
751
771
|
results: mergeTorrentProviders(groups, limit),
|
|
772
|
+
hasMore,
|
|
752
773
|
errors,
|
|
753
774
|
})
|
|
754
775
|
}
|
|
@@ -768,6 +789,23 @@ function parseTorrentLimit(searchParams) {
|
|
|
768
789
|
return Math.min(MAX_TORRENT_LIMIT, Math.floor(value))
|
|
769
790
|
}
|
|
770
791
|
|
|
792
|
+
/**
|
|
793
|
+
* Read the optional `/torrents` `page` parameter (contract v1.12): an integer
|
|
794
|
+
* 1–20, default 1. Returns null for an invalid value.
|
|
795
|
+
*
|
|
796
|
+
* @param {URLSearchParams} searchParams
|
|
797
|
+
* @returns {number | null}
|
|
798
|
+
*/
|
|
799
|
+
function parseTorrentPage(searchParams) {
|
|
800
|
+
const raw = (searchParams.get('page') || '').trim()
|
|
801
|
+
if (!raw) return 1
|
|
802
|
+
const value = Number(raw)
|
|
803
|
+
if (!Number.isFinite(value) || Math.floor(value) !== value || value < 1 || value > MAX_TORRENT_PAGE) {
|
|
804
|
+
return null
|
|
805
|
+
}
|
|
806
|
+
return value
|
|
807
|
+
}
|
|
808
|
+
|
|
771
809
|
/**
|
|
772
810
|
* Run one torrent provider across its queries and merge the rows.
|
|
773
811
|
*
|
|
@@ -775,21 +813,25 @@ function parseTorrentLimit(searchParams) {
|
|
|
775
813
|
* @param {{ queries: string[], settings: object }} context
|
|
776
814
|
* @returns {Promise<object[]>} deduped rows sorted by seeders (nulls last)
|
|
777
815
|
*/
|
|
778
|
-
async function torrentSource(name, { queries, settings }) {
|
|
816
|
+
async function torrentSource(name, { queries, settings, page = 1 }) {
|
|
779
817
|
const rows = []
|
|
818
|
+
let hasMore = false
|
|
780
819
|
const timeoutMs = Math.max(settings.requestTimeoutMs, TORRENT_TIMEOUT_FLOOR_MS)
|
|
781
820
|
for (const query of queries) {
|
|
782
821
|
const options = {
|
|
783
822
|
query,
|
|
823
|
+
page,
|
|
784
824
|
timeoutMs,
|
|
785
825
|
userAgent: settings.userAgent,
|
|
786
826
|
}
|
|
827
|
+
/* BT4G's RSS endpoint is a single page, so it never reports more. */
|
|
787
828
|
const found = name === 'bt4g'
|
|
788
829
|
? await searchTorrentsBt4g(options)
|
|
789
830
|
: await searchTorrentsBitsearch(options)
|
|
831
|
+
if (name === 'bitsearch' && found.length >= BITSEARCH_PAGE_SIZE) hasMore = true
|
|
790
832
|
rows.push(...found)
|
|
791
833
|
}
|
|
792
|
-
return mergeTorrentRows(rows, Number.POSITIVE_INFINITY)
|
|
834
|
+
return { rows: mergeTorrentRows(rows, Number.POSITIVE_INFINITY), hasMore }
|
|
793
835
|
}
|
|
794
836
|
|
|
795
837
|
/**
|
package/lib/providers.js
CHANGED
|
@@ -1662,19 +1662,22 @@ export async function searchTorrentsBt4g({ query, timeoutMs, userAgent }) {
|
|
|
1662
1662
|
}
|
|
1663
1663
|
|
|
1664
1664
|
/**
|
|
1665
|
-
* Search BitSearch
|
|
1666
|
-
* are followed and the accessible result cards are parsed.
|
|
1665
|
+
* Search one BitSearch result page. The site 301s to `bitsearch.eu`; redirects
|
|
1666
|
+
* are followed and the accessible result cards are parsed. Page 1 uses the
|
|
1667
|
+
* bare query URL; deeper pages append `&page=<n>`.
|
|
1667
1668
|
*
|
|
1668
1669
|
* @param {object} options
|
|
1669
1670
|
* @param {string} options.query
|
|
1671
|
+
* @param {number} [options.page]
|
|
1670
1672
|
* @param {number} options.timeoutMs
|
|
1671
1673
|
* @param {string} [options.userAgent]
|
|
1672
1674
|
* @returns {Promise<object[]>} normalized torrent rows with swarm counts
|
|
1673
1675
|
*/
|
|
1674
|
-
export async function searchTorrentsBitsearch({ query, timeoutMs, userAgent }) {
|
|
1675
|
-
const cached = readTorrentCache('bitsearch', query)
|
|
1676
|
+
export async function searchTorrentsBitsearch({ query, page = 1, timeoutMs, userAgent }) {
|
|
1677
|
+
const cached = readTorrentCache('bitsearch', query, page)
|
|
1676
1678
|
if (cached) return cached
|
|
1677
|
-
const
|
|
1679
|
+
const pageParam = page > 1 ? `&page=${page}` : ''
|
|
1680
|
+
const url = `${BITSEARCH_SEARCH_URL}?q=${encodeURIComponent(query)}${pageParam}`
|
|
1678
1681
|
let lastError = null
|
|
1679
1682
|
// BitSearch occasionally answers with a challenge shell (zero parsable cards)
|
|
1680
1683
|
// or a transient 429/5xx; one short retry keeps the merged list complete.
|
|
@@ -1682,7 +1685,7 @@ export async function searchTorrentsBitsearch({ query, timeoutMs, userAgent }) {
|
|
|
1682
1685
|
try {
|
|
1683
1686
|
const rows = await requestBitsearchPage(url, timeoutMs, userAgent)
|
|
1684
1687
|
if (rows.length > 0) {
|
|
1685
|
-
writeTorrentCache('bitsearch', query, rows)
|
|
1688
|
+
writeTorrentCache('bitsearch', query, rows, page)
|
|
1686
1689
|
return rows
|
|
1687
1690
|
}
|
|
1688
1691
|
lastError = new ProviderError(ERROR_UPSTREAM, 'BitSearch returned no parsable rows.')
|
|
@@ -1894,10 +1897,11 @@ function toCount(raw) {
|
|
|
1894
1897
|
/**
|
|
1895
1898
|
* @param {'bt4g' | 'bitsearch'} provider
|
|
1896
1899
|
* @param {string} query
|
|
1900
|
+
* @param {number} [page]
|
|
1897
1901
|
* @returns {object[] | null}
|
|
1898
1902
|
*/
|
|
1899
|
-
function readTorrentCache(provider, query) {
|
|
1900
|
-
const key = `${provider}|${String(query).toLowerCase()}`
|
|
1903
|
+
function readTorrentCache(provider, query, page = 1) {
|
|
1904
|
+
const key = `${provider}|${String(query).toLowerCase()}|${page}`
|
|
1901
1905
|
const hit = torrentCache.get(key)
|
|
1902
1906
|
if (!hit) return null
|
|
1903
1907
|
if (Date.now() - hit.at > TORRENT_CACHE_TTL_MS) {
|
|
@@ -1911,10 +1915,11 @@ function readTorrentCache(provider, query) {
|
|
|
1911
1915
|
* @param {'bt4g' | 'bitsearch'} provider
|
|
1912
1916
|
* @param {string} query
|
|
1913
1917
|
* @param {object[]} rows
|
|
1918
|
+
* @param {number} [page]
|
|
1914
1919
|
*/
|
|
1915
|
-
function writeTorrentCache(provider, query, rows) {
|
|
1920
|
+
function writeTorrentCache(provider, query, rows, page = 1) {
|
|
1916
1921
|
if (torrentCache.size >= TORRENT_CACHE_LIMIT) torrentCache.clear()
|
|
1917
|
-
torrentCache.set(`${provider}|${String(query).toLowerCase()}`, { at: Date.now(), rows })
|
|
1922
|
+
torrentCache.set(`${provider}|${String(query).toLowerCase()}|${page}`, { at: Date.now(), rows })
|
|
1918
1923
|
}
|
|
1919
1924
|
|
|
1920
1925
|
/**
|
package/package.json
CHANGED