stream: name a yt-dlp track's provider from its source domain
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
yt-dlp pulls from many sites, so a fixed "YouTube" label was wrong for bandcamp, soundcloud, etc. Derive the provider name from the source page's host instead (www.youtube.com -> YouTube, *.bandcamp.com -> Bandcamp), falling back to the bare host for unmapped sites. Other origins keep their fixed PROVIDER_NAMES labels. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
d302cf1c88
commit
a1f7fc29b3
1 changed files with 43 additions and 4 deletions
|
|
@ -313,10 +313,11 @@
|
|||
const player = document.getElementById("player");
|
||||
|
||||
// Noms d'affichage des providers d'ingestion (champ `origin` du morceau).
|
||||
// Inconnu → on réutilise tel quel, faute de mieux.
|
||||
// Inconnu → on réutilise tel quel, faute de mieux. yt-dlp est absent
|
||||
// volontairement : il pioche sur de nombreux sites, donc on nomme sa
|
||||
// provenance d'après le domaine de la page source (voir hostLabel).
|
||||
const PROVIDER_NAMES = {
|
||||
subsonic: "OpenSubsonic",
|
||||
ytdlp: "YouTube",
|
||||
listenbrainz: "ListenBrainz",
|
||||
// Filet de secours : morceau rejoué depuis le cache local (déjà diffusé),
|
||||
// quand l'ingest n'a rien à proposer (démarrage, panne…).
|
||||
|
|
@ -325,6 +326,36 @@
|
|||
request: "une demande",
|
||||
};
|
||||
|
||||
// Noms lisibles par domaine, pour les morceaux yt-dlp dont l'origine réelle
|
||||
// est le site de la page source (www.youtube.com → YouTube). La clé est le
|
||||
// domaine enregistrable ; les sous-domaines (artiste.bandcamp.com) sont
|
||||
// ramenés à cette clé par hostLabel.
|
||||
const HOST_NAMES = {
|
||||
"youtube.com": "YouTube",
|
||||
"youtu.be": "YouTube",
|
||||
"bandcamp.com": "Bandcamp",
|
||||
"soundcloud.com": "SoundCloud",
|
||||
"vimeo.com": "Vimeo",
|
||||
"dailymotion.com": "Dailymotion",
|
||||
"mixcloud.com": "Mixcloud",
|
||||
};
|
||||
|
||||
// Nom d'affichage d'un hôte : on retire le « www. » puis on remonte de
|
||||
// sous-domaine en sous-domaine (foo.bar.bandcamp.com → bar.bandcamp.com →
|
||||
// bandcamp.com) pour retrouver une entrée connue ; à défaut, on renvoie
|
||||
// l'hôte nu, qui reste une provenance lisible.
|
||||
function hostLabel(host) {
|
||||
host = host.replace(/^www\./, "");
|
||||
let h = host;
|
||||
while (h) {
|
||||
if (HOST_NAMES[h]) return HOST_NAMES[h];
|
||||
const dot = h.indexOf(".");
|
||||
if (dot < 0) break;
|
||||
h = h.slice(dot + 1);
|
||||
}
|
||||
return host;
|
||||
}
|
||||
|
||||
// Tant que le buffer de préchargement (PREFETCH côté ingest) n'est pas
|
||||
// rempli, on affiche « Préchargement N/M » plutôt que « en cours ». L'info
|
||||
// vient du daemon d'ingestion, relayée par le stream via /ingest/status.
|
||||
|
|
@ -486,9 +517,17 @@
|
|||
: escapeHtml(label);
|
||||
artistEl.textContent = a;
|
||||
// Provenance discrète : nom lisible du provider, masqué s'il est absent.
|
||||
// yt-dlp pioche sur de nombreux sites : on nomme sa provenance d'après
|
||||
// le domaine de la page source (u) plutôt qu'un « YouTube » systématique.
|
||||
const origin = (m.origin || "").trim();
|
||||
if (origin) {
|
||||
providerEl.textContent = "via " + (PROVIDER_NAMES[origin] || origin);
|
||||
let provider = "";
|
||||
if (origin === "ytdlp" && u) {
|
||||
try { provider = hostLabel(new URL(u).hostname); } catch (e) { /* url invalide */ }
|
||||
} else if (origin) {
|
||||
provider = PROVIDER_NAMES[origin] || origin;
|
||||
}
|
||||
if (provider) {
|
||||
providerEl.textContent = "via " + provider;
|
||||
providerEl.hidden = false;
|
||||
} else {
|
||||
providerEl.hidden = true;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue