Spotnet import, header backfill, staging and counter grouping, faster search

Spotnet (CONCEPT D29):
- Index free.pt fully and import spots with their descriptions, categories
  and NZBs; a spot renames its release, since Spotnet names are more
  trustworthy than names derived from subjects.
- Find passwords in spot descriptions too, and tell "needs a password we
  have" from "needs a password we don't have".

Content inspection:
- List the contents of 7z (.7z.001) archives, SFV sets, nicovideo uploads
  and other archive-like files; mark yEncBin .bin containers as encrypted.
- Take real names from yEnc headers for randomly named files, and merge
  uploads that were split across posts.

Storage (D31, D32):
- Store segment lists zstd-compressed behind the FileStore accessor.
- group:backfill indexes older headers at low priority and pauses when
  the NVMe or HDD part of the database gets too large.

Grouping (D35, D36):
- Lone header segments wait in staged_segments until a second segment of
  their file arrives, which drops the per-article junk binaries.
- Counter grouping joins random-subject uploads by poster, [i/M] counter,
  part count and day.

Search and maintenance (D33, D34):
- A trigram-indexed search_text column, smaller indexes, estimated stats.
- Passes that clean up nonsense names; weekly index maintenance; GC budgets
  per kind.
- Web UI: grey out stale results while a search runs and cancel superseded
  requests. Count only up to 1,000 matches for the page, which made filter
  clicks take seconds (Newznab keeps the 10,000 cap).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Daan MeijerandClaude Opus 5.5 committed 2026-10-03 19:59:23 +02:00
1 parent bcb9be5da9
commit be8a3d4580
97 files changed
+4454 -268

No files matched your search

+13
View File
@@ -0,0 +1,13 @@
import { sevenZipVolume } from '../sevenzip/index.js'
/**
* Files whose first segment says what an archive holds: named first RAR
* volumes (.part01.rar, .rar), 7z (.7z, .7z.001) and `.bin`, an extension
* uploaders use for archive volumes too (sniffed by content).
*/
export function isArchiveStart(name: string): boolean {
if (/\.bin$/i.test(name)) return true
const volume = sevenZipVolume(name)
if (volume === 0 || volume === 1) return true
return /\.part0*1\.rar$/i.test(name) || (/\.rar$/i.test(name) && !/\.part\d+\.rar$/i.test(name))
}
+3
View File
@@ -2,3 +2,6 @@
* Content recognition by magic bytes, independent of AdonisJS.
*/
export { sniffContentType, type ContentType } from './sniff.js'
export { isArchiveStart } from './archive_names.js'
export { parseSfv, sfvReleaseName, type SfvEntry } from './sfv.js'
export { NICOVIDEO_FILE, NICOVIDEO_RELEASE, nicovideoInfo, nicovideoReleaseName, zstdPrefix, tarEntries, type NicovideoInfo } from './nicovideo.js'
+76
View File
@@ -0,0 +1,76 @@
import { createZstdDecompress } from 'node:zlib'
/**
* Captures of niconico videos (`<unixtime>_nicovideo_jp_watch_sm<id>.tar.zst`,
* one poster, ~190k files on homelab). The tar's first entry after its
* directory is `server_response.metadata`: the site's API response for the
* watch page, 30–70 KB, so the first article of the file holds it.
*/
export const NICOVIDEO_FILE = /^\d{9,11}_nicovideo_jp_watch_(sm\d+)\.tar\.zst$/i
export const NICOVIDEO_RELEASE = /^\d{9,11}_nicovideo_jp_watch_(sm\d+)$/i
export interface NicovideoInfo {
id: string
title: string
owner: string | null
registeredAt: string | null
tags: string[]
}
/** As much of a zstd stream as `data` (a prefix of it) decompresses to. */
export function zstdPrefix(data: Buffer, maxBytes = 4 * 1024 * 1024): Promise<Buffer> {
return new Promise((resolve) => {
const out: Buffer[] = []
let length = 0
const z = createZstdDecompress()
const done = () => resolve(Buffer.concat(out))
z.on('data', (chunk: Buffer) => {
out.push(chunk)
length += chunk.length
if (length >= maxBytes) z.destroy()
})
z.on('error', done)
z.on('close', done)
z.on('end', done)
z.end(data)
})
}
/** Entries at the start of a (possibly truncated) ustar archive. */
export function* tarEntries(tar: Buffer): Generator<{ name: string; data: Buffer }> {
let offset = 0
while (offset + 512 <= tar.length) {
const header = tar.subarray(offset, offset + 512)
const name = header.subarray(0, 100).toString('utf8').replace(/\0.*$/s, '')
if (!name) return
const prefix = header.subarray(345, 500).toString('utf8').replace(/\0.*$/s, '')
const size = Number.parseInt(header.subarray(124, 136).toString('latin1').replace(/\0.*$/s, '').trim() || '0', 8) || 0
yield { name: prefix ? `${prefix}/${name}` : name, data: tar.subarray(offset + 512, offset + 512 + size) }
offset += 512 + Math.ceil(size / 512) * 512
}
}
/** Title, uploader and tags from the start of a capture, or null when they aren't in it. */
export function nicovideoInfo(tar: Buffer): NicovideoInfo | null {
for (const entry of tarEntries(tar)) {
if (!entry.name.endsWith('/server_response.metadata')) continue
try {
const text = entry.data.toString('utf8')
const json = JSON.parse(text.slice(text.indexOf('{')))
const video = json?.data?.response?.video
if (!video?.title) return null
const owner = json.data.response.owner?.nickname ?? json.data.response.channel?.name ?? json.data.metadata?.jsonLds?.[0]?.author?.name ?? null
const tags = (json.data.response.tag?.items ?? []).map((t: any) => String(t.name)).filter(Boolean)
return { id: String(video.id ?? ''), title: String(video.title).trim(), owner: owner ? String(owner).trim() : null, registeredAt: video.registeredAt ?? null, tags }
} catch {
return null
}
}
return null
}
/** Release name for a capture: `<title> - <uploader> (nicovideo sm123)`. */
export function nicovideoReleaseName(info: NicovideoInfo, fallbackId: string): string {
const id = info.id || fallbackId
return `${info.title}${info.owner ? ` - ${info.owner}` : ''} (nicovideo ${id})`
}
+29
View File
@@ -0,0 +1,29 @@
/**
* SFV checksum lists: one `name CRC32` per line, `;` comments. Scene
* releases (music in particular) post one with every album; it names every
* file that belongs to it.
*/
export interface SfvEntry {
name: string
crc: string
}
export function parseSfv(text: string): SfvEntry[] {
const entries: SfvEntry[] = []
for (const raw of text.split(/\r?\n/)) {
const line = raw.trim()
if (!line || line.startsWith(';')) continue
const match = /^(.+?)\s+([0-9a-f]{8})$/i.exec(line)
if (match) entries.push({ name: match[1].replace(/^"|"$/g, '').split(/[\\/]/).pop()!, crc: match[2].toLowerCase() })
}
return entries
}
/**
* The album name an SFV gives a release: its stem without the leading
* track number scene groups put on the playlist/SFV/cover files
* (`00-artist-album-web-2026-grp.sfv` → `artist-album-web-2026-grp`).
*/
export function sfvReleaseName(sfvName: string): string {
return sfvName.replace(/\.sfv$/i, '').replace(/^0{1,3}-/, '')
}
+9 -2
View File
@@ -2,6 +2,8 @@
* Recognises a file type from its first bytes, independent of AdonisJS.
* `nzbe` is an encrypted-NZB container seen on Usenet (LOG.md 2026-09-28 (11)):
* "nzbe", 16 random bytes (salt/IV), then ciphertext.
* `yencbin` is the encrypted `.bin` container of `yEncBin@Poster.com`
* (LOG.md 2026-09-30 (3)): a fixed header, then data with 8 bits/byte of entropy.
*/
export type ContentType =
| 'nzbe'
@@ -16,6 +18,7 @@ export type ContentType =
| 'matroska'
| 'mp4'
| 'rclone'
| 'yencbin'
| 'iso'
| 'udf'
| 'pdf'
@@ -29,7 +32,11 @@ export type ContentType =
| 'ogg'
| 'bzip2'
const SIGNATURES: [ContentType, number, number[]][] = [
/** Magic bytes at an offset; null matches any byte. */
const SIGNATURES: [ContentType, number, (number | null)[]][] = [
// Two header variants seen (54f399d117c49269 6e4dc4ef5b60c11d…, 54f399e917c49269 6a4e9fb05b60c31d…):
// the bytes they share.
['yencbin', 0, [0x54, 0xf3, 0x99, null, 0x17, 0xc4, 0x92, 0x69, null, null, null, null, 0x5b, 0x60, null, 0x1d, 0x7f, 0x83, 0xe9, 0x2d]],
['nzbe', 0, [0x6e, 0x7a, 0x62, 0x65]],
['par2', 0, [0x50, 0x41, 0x52, 0x32, 0x00, 0x50, 0x4b, 0x54]],
['rar5', 0, [0x52, 0x61, 0x72, 0x21, 0x1a, 0x07, 0x01, 0x00]],
@@ -53,7 +60,7 @@ const SIGNATURES: [ContentType, number, number[]][] = [
export function sniffContentType(data: Buffer): ContentType | null {
for (const [type, offset, bytes] of SIGNATURES) {
if (data.length >= offset + bytes.length && bytes.every((b, i) => data[offset + i] === b)) return type
if (data.length >= offset + bytes.length && bytes.every((b, i) => b === null || data[offset + i] === b)) return type
}
// Disc images, visible when the first part is big enough (sector 16 at 32 KiB):
// ISO 9660 has "CD001"; UDF (DVD/Blu-ray) has BEA01 followed by NSR02/NSR03.