Migration 1200 passed regexes with `?` through knex, which made them bindings: the live function held blu-$1ray, web-$2dl and h\.$326[45], so BluRay, WEB-DL and H.264 names without a resolution were Misc. 93% of recent releases were Misc, as the category came from the name alone. category becomes a plain column (DROP EXPRESSION, no rewrite) set by a trigger: the name's category (fixed, no `?` anywhere; adds XXX, audiobooks, console and PC games, and TV codes like S01e07[ and S04E01E02), else the prober's inner name's, else one given before (a spot's), else the groups'. The spot inspector sets a spot's category (spot_category) on Misc releases it links and on its own releases. The Newznab and web category lists gain Console, PC Games, Audiobook, Anime, XXX and Comics. releases:recategorize recomputes existing rows in id batches, writing only changed rows and waiting under a free-space floor. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
66 lines
3.8 KiB
TypeScript
66 lines
3.8 KiB
TypeScript
import { test } from '@japa/runner'
|
|
import db from '@adonisjs/lucid/services/db'
|
|
import testUtils from '@adonisjs/core/services/test_utils'
|
|
|
|
const categoryOf = async (name: string) => Number((await db.rawQuery(`SELECT release_category(?) AS c`, [name])).rows[0].c)
|
|
|
|
test.group('Release categories', (group) => {
|
|
group.each.setup(() => testUtils.db().withGlobalTransaction())
|
|
|
|
test('by name: the sources and codes the first function lost or missed, XXX, audio, books, games', async ({ assert }) => {
|
|
const expected: [string, number][] = [
|
|
// Lost to knex's bindings in migration 1200 (`blu-$1ray`, `web-$2dl`, `h\.$326[45]`).
|
|
['Some.Movie.2020.BluRay.DTS-X', 2040],
|
|
['Some.Movie.2020.WEB-DL.DDP5', 2030],
|
|
['Some.Movie.2020.H.264', 2030],
|
|
['Some.Movie.2020.2160p.WEB-DL', 2045],
|
|
// TV codes it missed.
|
|
['Rizzoli & Isles S01e07[Mux XviD', 5030],
|
|
['Rush S04E01E02 WS PDTVXviD', 5030],
|
|
['Show.S01E02.1080p.WEB', 5040],
|
|
['Show.1x02.HDTV', 5030],
|
|
['Resolution 1920x1080 wallpapers', 8010],
|
|
['Studio.24.10.22.Some.Name.XXX.1080p.MP4-GRP', 6040],
|
|
['Studio.Some.Name.XXX.2160p', 6045],
|
|
['Some.Name.XXX.IMAGESET-GRP', 6060],
|
|
['Artist-Album-WEB-2026-GRP', 3010],
|
|
['Artist - Album (2020) FLAC', 3040],
|
|
['Author - Title (Audiobook)', 3030],
|
|
['Book.Title.EPUB', 7020],
|
|
['Game.Title-CODEX', 4050],
|
|
['Game.Title.NSW-VENOM', 1000],
|
|
['TsIgNBewuFbuwWy', 8010],
|
|
]
|
|
const got: [string, number][] = []
|
|
for (const [name] of expected) got.push([name, await categoryOf(name)])
|
|
assert.deepEqual(got, expected)
|
|
})
|
|
|
|
test("the name's, else the inner name's, else a given one (a spot's), else the groups'", async ({ assert }) => {
|
|
const row = (key: string, extra: Record<string, unknown>) => ({ release_key: key.padEnd(40, '0'), identity_key: key.padEnd(40, '0'), source: 'stem', files: 1, groups: '["alt.binaries.misc"]', ...extra })
|
|
await db.table('releases').multiInsert([
|
|
row('a', { name: 'Show.S01E02.1080p.WEB' }),
|
|
row('b', { name: 'TsIgNBewuFbuwWy' }),
|
|
row('c', { name: 'TsIgNBewuFbuwWy', groups: '["alt.binaries.pictures.erotica.puffies"]' }),
|
|
// A spot's release of its own, inserted with the spot's category.
|
|
row('d', { name: 'Some spot title', category: 2040 }),
|
|
])
|
|
const byName = async () => Object.fromEntries((await db.from('releases').select('release_key', 'category')).map((r) => [r.release_key[0], r.category]))
|
|
assert.deepEqual(await byName(), { a: 5040, b: 8010, c: 6060, d: 2040 })
|
|
// The prober finds an inner name; a spot links a release (the spot inspector sets a Misc one's category).
|
|
await db.from('releases').where('release_key', 'b'.padEnd(40, '0')).update({ inner_name: 'Some.Movie.2020.1080p.BluRay.x264-GRP.mkv' })
|
|
await db.from('releases').where('release_key', 'c'.padEnd(40, '0')).update({ category: 5030 })
|
|
await db.from('releases').where('release_key', 'c'.padEnd(40, '0')).update({ inner_name: 'nothing.bin' })
|
|
assert.deepEqual(await byName(), { a: 5040, b: 2040, c: 5030, d: 2040 })
|
|
})
|
|
|
|
test("a spot's category in Newznab's", async ({ assert }) => {
|
|
const { rows } = await db.rawQuery(
|
|
`SELECT spot_category(0, '{"a":[9],"z":[0]}') AS movie_hd, spot_category(0, '{"a":[15],"z":[1]}') AS series_uhd, spot_category(0, '{"a":[0],"z":[3]}') AS erotica,
|
|
spot_category(0, '{"a":[5]}') AS epub, spot_category(0, '{"z":[4]}') AS picture, spot_category(1, '{"a":[8]}') AS flac, spot_category(1, '{"a":[0],"z":[3]}') AS audiobook,
|
|
spot_category(2, '{"a":[0]}') AS pc_game, spot_category(2, '{"a":[12]}') AS console, spot_category(3, '{}') AS app`
|
|
)
|
|
assert.deepEqual(rows[0], { movie_hd: 2040, series_uhd: 5045, erotica: 6070, epub: 7020, picture: null, flac: 3040, audiobook: 3030, pc_game: 4050, console: 1000, app: 4000 })
|
|
})
|
|
})
|