const test = require('node:test'); const assert = require('node:assert'); const { buildTitleKeywords } = require('../lib/ytdlp.js'); // The keywords become `title ~= (?i)` match-filters in yt-dlp, i.e. every keyword must match // the candidate title case-insensitively. This mirrors that check. const accepts = (title, candidate) => buildTitleKeywords(title).every(kw => new RegExp(kw, 'i').test(candidate)); test('a number in the title is always required, however short', () => { const kws = buildTitleKeywords('700 Main Street'); assert.ok(kws.some(k => k.includes('700')), `700 fehlt in ${JSON.stringify(kws)}`); }); test('rejects a same-shaped title with a different number', () => { // The real regression: "777 Main Street" (Release - Topic) was downloaded for DAT ADAM's // "700 Main Street", because only the two longest words (Street, Main) were required. assert.equal(accepts('700 Main Street', '777 Main Street'), false); assert.equal(accepts('700 Main Street', '700 Main Street'), true); }); test('accepts the abbreviated spelling uploaders use', () => { assert.equal(accepts('700 Main Street', '700 Main st (cr-Version)'), true); assert.equal(accepts('700 Main Street', 'DAT ADAM - 700 Main St [FULL SONG]'), true); }); test('the abbreviation does not match inside another word', () => { assert.equal(accepts('700 Main Street', '700 Main Stuff'), false); }); test('titles without numbers keep the previous two-longest-words behaviour', () => { assert.deepEqual(buildTitleKeywords('Bohemian Rhapsody'), ['Bohemian', 'Rhapsody']); assert.equal(accepts('Bohemian Rhapsody', 'Queen - Bohemian Rhapsody (Official Video)'), true); assert.equal(accepts('Bohemian Rhapsody', 'Queen - Another One Bites The Dust'), false); }); test('a remaster year is not required — YouTube titles never carry it', () => { // "… - 2020 Remaster" steht auf der Veröffentlichung, der Upload heißt schlicht // "Take Me Home, Country Roads". Vor dieser Ausnahme hätte die 2020 ihn abgelehnt. assert.equal(accepts('Take Me Home, Country Roads - 2020 Remaster', 'John Denver - Take Me Home, Country Roads'), true); }); test('a year that IS the title stays required', () => { assert.equal(accepts('1999', 'Prince - 1999 (Official Music Video)'), true); assert.equal(accepts('1999', 'Prince - 1984 (Official Music Video)'), false); }); const { buildVariantFilter } = require('../lib/ytdlp.js'); // Der Variantenfilter ist eine yt-dlp-Ausdruckskette "title !~= (?i)\bx\b & …". // Diese Hilfsfunktion wertet sie so aus, wie yt-dlp es tut. const variantAccepts = (searchTitle, candidate) => { const f = buildVariantFilter(searchTitle); if (!f) return true; return f.split(' & ').every(part => { const m = /^title !~= \(\?i\)(.+)$/.exec(part); return !new RegExp(m[1], 'i').test(candidate); }); }; test('rejects a live recording — is_live only covers running streams', () => { // Der echte Fall: auf dem Kuenstlerkanal, Dauer im Fenster, Titel passend. assert.equal(variantAccepts('UFO', 'Dat Adam - Ufo Video Days 2015 Live'), false); assert.equal(variantAccepts('UFO', 'DAT ADAM - 700 Main St | ROCK AM RING 2017 [LIVE]'), false); assert.equal(variantAccepts('UFO', 'UFO'), true); }); test('a deliberately live title keeps its live results', () => { assert.equal(variantAccepts('Live Forever', 'Oasis - Live Forever'), true); assert.equal(variantAccepts('Unplugged in New York (Live)', 'Nirvana - All Apologies (Live)'), true); }); test('"live" inside another word does not disable the rule', () => { // "deliver" enthaelt "live" als Teilstring — die Regel muss trotzdem greifen. assert.equal(variantAccepts('Deliver', 'Artist - Deliver (Live at Wembley)'), false); assert.equal(variantAccepts('Deliver', 'Artist - Deliver'), true); });