feat: détection short par orientation vidéo
CI / build-and-test (push) Successful in 14m6s

Règle partagée front/back : flag natif, verticale stricte (ratio ≤ 0.8, ≤ 90 s), verticale sans durée jamais short, repli durée (70 YT / 75 autres). Dimensions alimentées par Dailymotion/Odysee/PeerTube, flag maison Rumble supprimé, condition innertube morte simplifiée. Shorts : langues utilisateur (UI + transcripts) via relevanceLanguage/languageOneOf/Twitch language, son activé par défaut.
This commit is contained in:
2026-09-29 12:17:10 -04:00
parent 3f4cd56f14
commit f443a470f9
22 changed files with 454 additions and 73 deletions
+3
View File
@@ -32,6 +32,9 @@ export class DmAdapter implements ProviderAdapter<VideoItem> {
// Signaux de type pour le raffinement client des filtres.
type: typeof it.type === 'string' ? it.type : undefined,
isShort: it.isShort === true ? true : undefined,
// Dimensions (signal d'orientation pour la détection Short).
width: typeof it.width === 'number' ? it.width : undefined,
height: typeof it.height === 'number' ? it.height : undefined,
} as VideoItem));
return { items, total: Array.isArray(res?.groups?.dm) ? res.groups.dm.length : 0, providerError };
}
+3
View File
@@ -41,6 +41,9 @@ export class OdAdapter implements ProviderAdapter<VideoItem> {
// Signaux de type pour le raffinement client des filtres.
type: typeof it.type === 'string' ? it.type : undefined,
isShort: it.isShort === true ? true : undefined,
// Dimensions (signal d'orientation pour la détection Short).
width: typeof it.width === 'number' ? it.width : undefined,
height: typeof it.height === 'number' ? it.height : undefined,
} as VideoItem;
});
return { items, total: Array.isArray(res?.groups?.od) ? res.groups.od.length : 0, providerError };
+3
View File
@@ -38,6 +38,9 @@ export class PtAdapter implements ProviderAdapter<VideoItem> {
// Signaux de type pour le raffinement client des filtres.
type: typeof it.type === 'string' ? it.type : undefined,
isShort: it.isShort === true ? true : undefined,
// Dimensions (signal d'orientation pour la détection Short).
width: typeof it.width === 'number' ? it.width : undefined,
height: typeof it.height === 'number' ? it.height : undefined,
} as VideoItem;
});
return { items, total: Array.isArray(res?.groups?.pt) ? res.groups.pt.length : 0, providerError };
+3
View File
@@ -29,6 +29,9 @@ export class RuAdapter implements ProviderAdapter<VideoItem> {
// Signaux de type (Shorts / direct) pour le raffinement client.
type: typeof it.type === 'string' ? it.type : undefined,
isShort: it.isShort === true ? true : undefined,
// Dimensions (signal d'orientation pour la détection Short).
width: typeof it.width === 'number' ? it.width : undefined,
height: typeof it.height === 'number' ? it.height : undefined,
} as VideoItem));
return { items, total: Array.isArray(res?.groups?.ru) ? res.groups.ru.length : 0, providerError };
}
+3
View File
@@ -46,6 +46,9 @@ export class TwAdapter implements ProviderAdapter<VideoItem> {
isLive: typeof it.isLive === 'boolean' ? it.isLive : undefined,
kind: typeof it.kind === 'string' ? it.kind : undefined,
isShort: it.isShort === true ? true : undefined,
// Dimensions (signal d'orientation pour la détection Short).
width: typeof it.width === 'number' ? it.width : undefined,
height: typeof it.height === 'number' ? it.height : undefined,
game: typeof it.game === 'string' ? it.game : undefined,
} as VideoItem;
}).filter((v: VideoItem) => v.id != null && String(v.id).length > 0 && (v.thumbnailUrl || v.channelAvatarUrl));
+3
View File
@@ -34,6 +34,9 @@ export class YtAdapter implements ProviderAdapter<VideoItem> {
type: typeof it.type === 'string' ? it.type : undefined,
isLive: typeof it.isLive === 'boolean' ? it.isLive : undefined,
isShort: it.isShort === true ? true : undefined,
// Dimensions (signal d'orientation pour la détection Short).
width: typeof it.width === 'number' ? it.width : undefined,
height: typeof it.height === 'number' ? it.height : undefined,
} as VideoItem));
return { items, total: Array.isArray(res?.groups?.yt) ? res.groups.yt.length : 0, providerError };
}
+8
View File
@@ -378,7 +378,12 @@ export function isShortItem(item: any): boolean {
return isShortVideo({
duration: itemDurationSec(item),
type: typeof item.type === 'string' ? item.type : undefined,
kind: typeof item.kind === 'string' ? item.kind : undefined,
url: typeof item.url === 'string' ? item.url : undefined,
provider: typeof item.provider === 'string' ? item.provider : undefined,
isShort: item.isShort === true ? true : undefined,
width: typeof item.width === 'number' ? item.width : undefined,
height: typeof item.height === 'number' ? item.height : undefined,
});
}
@@ -401,6 +406,9 @@ function hasTypeSignal(item: any): boolean {
if (item.isShort === true || item.isShort === false) return true;
if (String(item.type || '').trim()) return true;
if (String(item.kind || '').trim()) return true;
// Des dimensions connues sont un signal (miroir back) : une verticale
// 60 s ne doit jamais apparaître dans le filtre « vidéos ».
if (typeof item.width === 'number' && item.width > 0 && typeof item.height === 'number' && item.height > 0) return true;
return false;
}
@@ -21,4 +21,6 @@ export interface VideoItem {
isShort?: boolean; // true when the provider flagged a Short/clip
kind?: string; // e.g. Twitch 'vod' | 'clip'
game?: string; // e.g. Twitch game/category name
width?: number; // video width in px (orientation signal, when exposed)
height?: number; // video height in px (orientation signal, when exposed)
}
+78
View File
@@ -0,0 +1,78 @@
import {
isShortVideo, isLiveVideo, classifyVideo,
SHORT_MAX_SECONDS, YOUTUBE_SHORT_MAX_SECONDS,
VERTICAL_SHORT_MAX_SECONDS, VERTICAL_MAX_RATIO,
} from './video-kind';
/**
* Classification Vidéo / Short (orientation + durée).
* Miroir de `server/tests/search-filters.test.mjs`.
* Run with: npm run test:kind
*/
function assertEqual(actual: unknown, expected: unknown, message: string): void {
const a = JSON.stringify(actual);
const b = JSON.stringify(expected);
if (a !== b) {
console.error(`FAIL: ${message}\n actual: ${a}\n expected: ${b}`);
process.exitCode = 1;
} else {
console.log(`ok: ${message}`);
}
}
assertEqual(typeof SHORT_MAX_SECONDS, 'number', 'seuils exportés');
assertEqual(VERTICAL_SHORT_MAX_SECONDS, 90, 'verticale short jusqu’à 90 s');
assertEqual(VERTICAL_MAX_RATIO, 0.8, 'ratio vertical max 0.8');
assertEqual(YOUTUBE_SHORT_MAX_SECONDS, 70, 'seuil YouTube 70 s');
// Règle 1 : flag natif / clip.
assertEqual(isShortVideo({ duration: 40, isShort: true }), true, 'flag natif 40 s ⇒ short');
assertEqual(isShortVideo({ duration: 300, isShort: true }), false, 'flag contredit par 300 s ⇒ pas short');
assertEqual(isShortVideo({ duration: 100, kind: 'clip' }), true, 'clip Twitch ⇒ short');
assertEqual(isShortVideo({ duration: 45, type: 'short' }), true, "type 'short' ⇒ short");
assertEqual(isShortVideo({ duration: 45, url: 'https://www.youtube.com/shorts/abc' }), true, 'URL /shorts/ ⇒ short');
// Règle 2 : verticale 60 s (ex. 608x1080) ⇒ short.
assertEqual(
isShortVideo({ duration: 60, width: 608, height: 1080 }),
true,
'verticale 60 s ⇒ short',
);
// Règle 2 : verticale 200 s ⇒ PAS short.
assertEqual(
isShortVideo({ duration: 200, width: 720, height: 1280 }),
false,
'verticale 200 s ⇒ pas short',
);
// Règle 2 : carré 80 s (ratio ~1) ⇒ PAS short (l'orientation seule ne suffit pas).
assertEqual(
isShortVideo({ duration: 80, width: 1080, height: 1080 }),
false,
'carré 80 s ⇒ pas short',
);
// Règle 3 : verticale SANS durée ⇒ PAS short.
assertEqual(
isShortVideo({ width: 608, height: 1080 }),
false,
'verticale sans durée ⇒ pas short',
);
assertEqual(
isShortVideo({ duration: 0, width: 608, height: 1080 }),
false,
'verticale durée 0 ⇒ pas short',
);
// Règle 4 : repli durée seule (non-régression).
assertEqual(isShortVideo({ duration: 50, width: 1280, height: 720 }), true, 'horizontale 50 s ⇒ short');
assertEqual(isShortVideo({ duration: 50 }), true, '50 s sans dimensions ⇒ short');
assertEqual(isShortVideo({ duration: 72 }), true, '72 s non-YouTube ⇒ short (≤ 75)');
assertEqual(isShortVideo({ duration: 72, provider: 'youtube' }), false, '72 s YouTube ⇒ pas short (> 70)');
assertEqual(isShortVideo({ duration: 0 }), false, 'durée 0 ⇒ jamais short');
assertEqual(isShortVideo(null), false, 'null ⇒ pas short');
// Live / classification globale.
assertEqual(isLiveVideo({ isLive: true }), true, 'isLive ⇒ live');
assertEqual(isLiveVideo({ type: 'channel' }), true, 'channel ⇒ live (direct ou chaîne)');
assertEqual(classifyVideo({ duration: 60, width: 608, height: 1080 }), 'short', 'classify verticale 60 s');
assertEqual(classifyVideo({ duration: 500 }), 'video', 'classify 500 s');
assertEqual(classifyVideo({ isLive: true }), 'live', 'classify live');
+35 -13
View File
@@ -1,13 +1,16 @@
/**
* Classification partagée Vidéo / Short / Live.
*
* Règles (alignées front + back) :
* - `isShort === true` (flag natif) ⇒ Short, sauf durée connue > 75 s.
* - Twitch `kind === 'clip'` ⇒ Short (les clips font ≤ 60 s par construction).
* - YouTube : URL `/shorts/` ⇒ Short ; sinon durée 1..70 s ⇒ Short.
* - Autres providers : durée 1..75 s ⇒ Short.
* - IMPORTANT : une durée `0` / absente ne qualifie JAMAIS un Short
* (les scrapers renvoient 0 quand la durée est inconnue).
* Miroir exact de `isShortItem()` (`server/search-filters.mjs`). Ordre :
* 1. `kind === 'clip'` (Twitch) ⇒ Short (les clips font ≤ 60 s par
* construction ; une durée aberrante est du bruit, pas une preuve).
* 2. Flag natif (`isShort`, `type === 'short'`, URL `/shorts/`) ⇒ Short,
* sauf durée connue > SHORT_MAX_SECONDS.
* 3. Orientation verticale stricte (`height > width`, ratio ≤ 0.8) ET durée
* connue ≤ VERTICAL_SHORT_MAX_SECONDS (90 s) ⇒ Short.
* 4. Verticale SANS durée connue ⇒ PAS un Short (même doctrine que
* « durée 0 ne qualifie jamais »).
* 5. Repli durée seule : 1..70 s (YouTube), 1..75 s (autres).
*/
export type VideoKind = 'short' | 'live' | 'video';
@@ -19,11 +22,20 @@ export interface ClassifiableVideo {
provider?: string | null;
isShort?: boolean | null;
isLive?: boolean | null;
isVertical?: boolean | null;
width?: number | null;
height?: number | null;
}
export const SHORT_MAX_SECONDS = 75;
export const YOUTUBE_SHORT_MAX_SECONDS = 70;
export const VERTICAL_SHORT_MAX_SECONDS = 90;
// ponytail: ratio 0.8 arbitré, 0.75 si de faux carrés Instagram apparaissent.
export const VERTICAL_MAX_RATIO = 0.8;
function numOrZero(v: unknown): number {
const n = Number(v);
return Number.isFinite(n) && n > 0 ? n : 0;
}
export function isShortVideo(v: ClassifiableVideo | null | undefined): boolean {
if (!v) return false;
@@ -34,18 +46,28 @@ export function isShortVideo(v: ClassifiableVideo | null | undefined): boolean {
const url = String((v as { url?: unknown }).url || '');
const provider = String((v as { provider?: unknown }).provider || '').toLowerCase();
// Clips Twitch = équivalent Shorts (durée max 60 s côté Twitch).
// 1) Clips Twitch = équivalent Shorts.
if (kind === 'clip') return true;
if (type === 'short') return true;
// Flag natif (Rumble router, YouTube, …) — ignoré si la durée connue le contredit.
if ((v as { isShort?: unknown }).isShort === true) {
// 2) Flag natif — ignoré si la durée connue le contredit.
if ((v as { isShort?: unknown }).isShort === true || type === 'short' || url.includes('/shorts/')) {
if (hasKnownDuration && duration > SHORT_MAX_SECONDS) return false;
return true;
}
// 3) + 4) Orientation (width/height quand le provider les expose).
const w = numOrZero((v as { width?: unknown }).width);
const h = numOrZero((v as { height?: unknown }).height);
if (w > 0 && h > 0) {
const vertical = h > w && w / h <= VERTICAL_MAX_RATIO;
if (vertical) {
if (!hasKnownDuration) return false;
return duration <= VERTICAL_SHORT_MAX_SECONDS;
}
}
// 5) Repli durée seule (comportement historique inchangé).
if (!hasKnownDuration) return false;
if (url.includes('/shorts/')) return true;
if (provider === 'youtube') return duration <= YOUTUBE_SHORT_MAX_SECONDS;
return duration <= SHORT_MAX_SECONDS;
}