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:
@@ -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));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user