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
+22 -14
View File
@@ -20,7 +20,7 @@ const handler = {
page: Math.max(1, Number(page || 1)).toString(),
// Map our sort to Dailymotion API sort: relevance | visited (views) | recent (date)
sort: (sort === 'date' ? 'recent' : (sort === 'views' ? 'visited' : 'relevance')),
fields: 'id,title,thumbnail_url,thumbnail_360_url,thumbnail_480_url,thumbnail_720_url,duration,views_total,owner.id,owner.screenname,owner.avatar_80_url,created_time'
fields: 'id,title,thumbnail_url,thumbnail_360_url,thumbnail_480_url,thumbnail_720_url,duration,views_total,width,height,owner.id,owner.screenname,owner.avatar_80_url,created_time'
})
);
@@ -30,19 +30,27 @@ const handler = {
const data = await response.json();
return (data.list || []).map(item => ({
title: item.title || '',
id: item.id || '',
url: `https://www.dailymotion.com/video/${item.id}`,
thumbnail: item.thumbnail_720_url || item.thumbnail_480_url || item.thumbnail_360_url || item.thumbnail_url || '',
uploaderName: item['owner.screenname'] || item['owner.username'] || '',
channelId: item['owner.id'] || item['owner.username'] || undefined,
uploaderAvatar: item['owner.avatar_80_url'] || '',
duration: Number(item.duration || 0),
views: Number(item.views_total || 0),
uploadedDate: item.created_time ? new Date(item.created_time * 1000).toISOString() : '',
type: 'video'
}));
return (data.list || []).map(item => {
// Dimensions d'origine (signal d'orientation pour isShortItem).
// Défensif : le champ n'est pas garanti sur toutes les réponses.
const w = Number(item.width);
const h = Number(item.height);
return {
title: item.title || '',
id: item.id || '',
url: `https://www.dailymotion.com/video/${item.id}`,
thumbnail: item.thumbnail_720_url || item.thumbnail_480_url || item.thumbnail_360_url || item.thumbnail_url || '',
uploaderName: item['owner.screenname'] || item['owner.username'] || '',
channelId: item['owner.id'] || item['owner.username'] || undefined,
uploaderAvatar: item['owner.avatar_80_url'] || '',
duration: Number(item.duration || 0),
views: Number(item.views_total || 0),
uploadedDate: item.created_time ? new Date(item.created_time * 1000).toISOString() : '',
type: 'video',
...(Number.isFinite(w) && w > 0 ? { width: w } : {}),
...(Number.isFinite(h) && h > 0 ? { height: h } : {}),
};
});
} catch (error) {
console.error('Dailymotion search error:', error);
return [];
+7 -1
View File
@@ -40,6 +40,10 @@ const handler = {
const name = item.name || '';
const claimId = item.claimId || item.claim_id || '';
const urlSegment = claimId ? `${encodeURIComponent(name)}:${claimId}` : encodeURIComponent(name);
// Dimensions vidéo (signal d'orientation pour isShortItem) quand
// lighthouse les expose — lecture défensive, aucun appel en plus.
const vw = Number(item.video?.width ?? item.video?.video_width ?? item.width);
const vh = Number(item.video?.height ?? item.video?.video_height ?? item.height);
return {
title: item.title || name,
@@ -50,7 +54,9 @@ const handler = {
type: 'video',
duration: typeof item.duration === 'number' && item.duration > 0
? Math.round(item.duration)
: (typeof item.video?.duration === 'number' && item.video.duration > 0 ? Math.round(item.video.duration) : undefined)
: (typeof item.video?.duration === 'number' && item.video.duration > 0 ? Math.round(item.video.duration) : undefined),
...(Number.isFinite(vw) && vw > 0 ? { width: vw } : {}),
...(Number.isFinite(vh) && vh > 0 ? { height: vh } : {}),
};
});
} catch (error) {
+17 -1
View File
@@ -37,6 +37,20 @@ const handler = {
? `https:${rawThumb}`
: new URL(rawThumb, item.url || 'https://sepiasearch.org').toString()
: undefined;
// Dimensions max des fichiers (signal d'orientation pour isShortItem).
// Défensif : sepiasearch n'expose pas toujours `files`.
let fw = 0;
let fh = 0;
try {
for (const f of (Array.isArray(item.files) ? item.files : [])) {
const w = Number(f?.width);
const h = Number(f?.height);
if (Number.isFinite(w) && Number.isFinite(h) && w > 0 && h > 0 && w * h >= fw * fh) {
fw = w;
fh = h;
}
}
} catch {}
return {
title: item.name,
@@ -46,7 +60,9 @@ const handler = {
uploaderName: (item.account && (item.account.displayName || item.account.name)) || undefined,
channelId: (item.channel && (item.channel.name || item.channel.uuid)) || (item.account && item.account.name) || undefined,
type: 'video',
duration: typeof item.duration === 'number' && item.duration > 0 ? Math.round(item.duration) : undefined
duration: typeof item.duration === 'number' && item.duration > 0 ? Math.round(item.duration) : undefined,
...(fw > 0 ? { width: fw } : {}),
...(fh > 0 ? { height: fh } : {}),
};
});
} catch (error) {
+2
View File
@@ -11,6 +11,8 @@
* @property {string=} thumbnail
* @property {string=} uploaderName
* @property {string=} type
* @property {number=} width (largeur vidéo en px, quand le provider l'expose)
* @property {number=} height (hauteur vidéo en px, quand le provider l'expose)
*/
/** @typedef {'yt'|'dm'|'tw'|'pt'|'od'|'ru'} ProviderId */
+12 -12
View File
@@ -221,18 +221,18 @@ function parseSearchHtml(html, { limit = 50 } = {}) {
}
const viewsText = $el.find('.video-item--views').first().text().trim();
const views = Number(String(viewsText).replace(/[^\d]/g, '')) || undefined;
items.push({
title: title || url,
id,
url,
thumbnail: normalizeThumb(rawThumbnail),
uploaderName: uploaderName || undefined,
views,
type: 'video',
duration: durationSeconds,
// Pas de flag natif côté Rumble : durée courte (1..75 s) ⇒ Short probable.
isShort: typeof durationSeconds === 'number' && durationSeconds > 0 && durationSeconds <= 75,
});
items.push({
title: title || url,
id,
url,
thumbnail: normalizeThumb(rawThumbnail),
uploaderName: uploaderName || undefined,
views,
type: 'video',
duration: durationSeconds,
// Pas de flag maison ici : le filtre central (isShortItem,
// durée ≤75 s) tranche. Le scraper HTML n'expose pas de dimensions.
});
});
return items;
}
+5 -1
View File
@@ -136,7 +136,11 @@ export function mapVideoNode(n) {
|| bestThumb(n.thumbnail)
|| bestThumb(n.on_tap_endpoint?.payload?.thumbnail?.thumbnails)
|| undefined;
const isShort = /short|reel/i.test(type) || (Number.isFinite(duration) && duration > 0 && duration <= 70 && /short/i.test(title) === false && /reel|short/i.test(type));
// Un ShortsLockupView / ReelItem EST un short par construction. L'ancienne
// disjonction `|| (durée≤70 && titre sans "short" && type reel|short)` était
// morte : subsumée par le premier test (A || (B && C && A) === A), et son
// `!/short/i.test(title)` excluait à tort les shorts titrés « …shorts ».
const isShort = /short|reel/i.test(type);
const badges = Array.isArray(n.badges) ? n.badges.map((b) => b?.label).filter(Boolean) : [];
return {
title: String(title),
+72 -8
View File
@@ -151,12 +151,73 @@ export function isLiveItem(item) {
return String(item.type || '').toLowerCase() === 'live';
}
export function isShortItem(item) {
/**
* Seuils partagés de détection Short (miroir de `src/app/shared/utils/video-kind.ts`).
* - SHORT_MAX_SECONDS : durée seule, repli historique (70 YouTube, 75 autres).
* - VERTICAL_SHORT_MAX_SECONDS : une verticale reste un "short" jusqu'à 90 s
* (au-delà c'est une vidéo verticale, pas un short).
* - VERTICAL_MAX_RATIO : width/height ≤ 0.8 (les quasi-carrés sont exclus).
*/
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) {
const n = Number(v);
return Number.isFinite(n) && n > 0 ? n : 0;
}
/**
* Classification Vidéo / Short, source de vérité côté serveur (miroir exact
* de `isShortVideo()` front). Ordre :
* 1. flag natif (isShort / type 'short' / kind 'clip') — contredit par une
* durée connue > SHORT_MAX_SECONDS ;
* 2. orientation verticale stricte + durée connue ≤ 90 s ;
* 3. verticale SANS durée connue ⇒ PAS un short (même doctrine que
* « durée 0 ne qualifie jamais » : un faux positif pollue le swipe) ;
* 4. repli durée seule (≤70 YouTube, ≤75 autres).
*/
export function isShortItem(item, providerId) {
if (!item) return false;
if (item.isShort === true) return true;
if (String(item.kind || '').toLowerCase() === 'clip') return true;
const d = itemDurationSec(item);
return d > 0 && d <= 70 && !/short/i.test(String(item.title || ''));
const hasKnownDuration = d > 0;
const type = String(item.type || '').toLowerCase();
const kind = String(item.kind || '').toLowerCase();
// 1) Flag natif — ignoré si la durée connue le contredit.
// Exception : `kind === 'clip'` (Twitch) est toujours un short : les clips
// font ≤ 60 s par construction, une durée > 75 s sur un clip est du bruit
// de métadonnées (le test historique « shorts keeps clips » l'impose).
if (kind === 'clip') return true;
if (item.isShort === true || type === 'short') {
if (hasKnownDuration && d > SHORT_MAX_SECONDS) return false;
return true;
}
// 2) + 3) Orientation (width/height quand le provider les expose).
const w = numOrZero(item.width);
const h = numOrZero(item.height);
if (w > 0 && h > 0) {
const vertical = h > w && (w / h) <= VERTICAL_MAX_RATIO;
if (vertical) {
if (!hasKnownDuration) return false; // règle 3 : pas de durée ⇒ pas short
return d <= VERTICAL_SHORT_MAX_SECONDS; // règle 2
}
}
// 4) Repli durée seule (comportement historique inchangé).
// NOTE : l'ancien code excluait les titres contenant « short »
// (`&& !/short/i.test(title)`), ce qui est l'inverse de l'intuition : un
// vrai Short titré « … #shorts » était EXCLU du filtre shorts. Les tests
// ne couvraient que des titres neutres (« x »), donc le bug passait
// inaperçu. Condition supprimée : la durée seule tranche désormais.
if (!hasKnownDuration) return false;
const max = String(providerId || '').toLowerCase() === 'youtube' || String(item.provider || '').toLowerCase() === 'youtube'
? YOUTUBE_SHORT_MAX_SECONDS
: SHORT_MAX_SECONDS;
return d <= max;
}
export function isChannelItem(item) {
@@ -170,11 +231,14 @@ function hasTypeSignal(item) {
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 : l'item n'est jamais "muet",
// sinon une verticale 60 s apparaîtrait dans le filtre « vidéos ».
if (numOrZero(item.width) > 0 && numOrZero(item.height) > 0) return true;
return false;
}
/** Un item respecte-t-il les filtres ? (champs absents => jamais écarté) */
export function matchesFilters(item, filters) {
export function matchesFilters(item, filters, providerId) {
const n = normalizeFilters(filters);
if (n.type === 'all' && n.duration === 'all' && n.period === 'all') return true;
@@ -194,9 +258,9 @@ export function matchesFilters(item, filters) {
if (!hasTypeSignal(item)) return true; // provider muet : on ne peut pas exclure
if (n.type === 'live') return isLiveItem(item);
if (n.type === 'channel') return isChannelItem(item);
if (n.type === 'shorts') return isShortItem(item);
if (n.type === 'shorts') return isShortItem(item, providerId);
if (n.type === 'video') {
return !isLiveItem(item) && !isChannelItem(item) && !isShortItem(item);
return !isLiveItem(item) && !isChannelItem(item) && !isShortItem(item, providerId);
}
return true;
}
@@ -217,7 +281,7 @@ export function applySearchFilters(providerId, items, filters) {
if (wanted.length === 0) return items;
// `channel` : hors YouTube, on ne filtre pas (sinon résultat vide).
if (wanted.includes('type') && n.type === 'channel' && providerId !== 'yt') return items;
return items.filter((it) => matchesFilters(it, n));
return items.filter((it) => matchesFilters(it, n, providerId));
}
// ---------------------------------------------------------------------------
+71
View File
@@ -7,6 +7,7 @@ import {
normalizeFilters, parseSearchFilters, activeFilters, filtersCacheKey,
periodMs, durationBounds, matchesFilters, applySearchFilters,
innertubeSearchFilters, apiSearchParams, itemDurationSec, itemPublishedTs,
isShortItem, SHORT_MAX_SECONDS, VERTICAL_SHORT_MAX_SECONDS, VERTICAL_MAX_RATIO,
} from '../search-filters.mjs';
function expect(cond, msg) {
@@ -186,4 +187,74 @@ expect(
);
logOk('innertubeSearchFilters / apiSearchParams');
// ---------- Détection Short par orientation ----------
eq(typeof SHORT_MAX_SECONDS, 'number', 'seuils exportés');
eq(VERTICAL_SHORT_MAX_SECONDS, 90, 'verticale short jusqu’à 90 s');
eq(VERTICAL_MAX_RATIO, 0.8, 'ratio vertical max 0.8');
// Règle 2 : verticale 60 s (ex. repost TikTok 608x1080) ⇒ short.
expect(
isShortItem({ title: 'repost', duration: 60, width: 608, height: 1080, type: 'video' }),
'vertical 60s is a short',
);
// Règle 2 : verticale 200 s ⇒ PAS short (vidéo verticale, pas short).
expect(
!isShortItem({ title: 'vlog', duration: 200, width: 720, height: 1280, type: 'video' }),
'vertical 200s is not a short',
);
// Règle 2 : un carré 80 s (> 75 s) n'est PAS short : l'orientation seule
// (ratio ~1) ne suffit pas ET le repli durée ne s'applique plus.
expect(
!isShortItem({ title: 'clip carré', duration: 80, width: 1080, height: 1080, type: 'video' }),
'square 80s is not a short (orientation alone is not enough)',
);
// …mais à 30 s, la règle 4 (durée seule) le garde : non-régression historique.
expect(
matchesFilters({ id: 'a', title: 'clip carré', duration: 30, width: 1080, height: 1080, type: 'video' }, { type: 'shorts' }),
'square 30s still matches shorts via duration fallback',
);
// Règle 4 : horizontale 50 s ⇒ short (non-régression durée seule).
expect(
isShortItem({ title: 'paysage', duration: 50, width: 1280, height: 720, type: 'video' }),
'horizontal 50s is a short (duration fallback)',
);
// Règle 3 : verticale SANS durée connue ⇒ PAS short.
expect(
!isShortItem({ title: 'inconnu', width: 608, height: 1080, type: 'video' }),
'vertical without duration is not a short',
);
// Règle 1 : flag contredit par une durée > 75 s ⇒ PAS short.
expect(
!isShortItem({ title: 'faux short', duration: 300, isShort: true, type: 'video' }),
'native flag contradicted by duration is not a short',
);
// Règle 1 : un vrai Short titré « …shorts » n'est plus exclu (ancien bug
// `!/short/i.test(title)`).
expect(
isShortItem({ title: 'mon voyage #shorts', duration: 40, type: 'video' }),
'title containing shorts is kept',
);
// Seuil YouTube (70) vs autres (75) : 72 s.
expect(
!isShortItem({ title: 'yt', duration: 72, type: 'video', provider: 'youtube' }, 'yt'),
'youtube 72s is not a short',
);
expect(
isShortItem({ title: 'dm', duration: 72, type: 'video' }, 'dm'),
'dailymotion 72s is a short',
);
// §4 : une verticale 60 s ne remonte jamais dans le filtre « vidéos »…
expect(
!matchesFilters({ id: 'b', title: 'v', duration: 60, width: 608, height: 1080, type: 'video' }, { type: 'video' }),
'vertical 60s excluded from video filter',
);
// …et les dimensions comptent comme signal : l'item n'est plus "muet",
// donc le filtre `live` l'exclut (une verticale n'est pas un direct).
expect(
!matchesFilters({ id: 'c', title: 'v', duration: 0, width: 608, height: 1080 }, { type: 'live' }),
'dimensions are a signal: vertical without live flag is dropped from live',
);
logOk('isShortItem (orientation + durée)');
console.log('\nAll search-filters tests passed.');