78 lines
2.4 KiB
JavaScript
78 lines
2.4 KiB
JavaScript
.pragma library
|
||
|
||
// Mise en forme des durées et des libellés de médias.
|
||
|
||
var TICKS_PER_MS = 10000; // Jellyfin compte en « ticks » de 100 ns
|
||
|
||
function ticksToMs(ticks) {
|
||
return Math.floor((ticks || 0) / TICKS_PER_MS);
|
||
}
|
||
|
||
function msToTicks(ms) {
|
||
return Math.floor((ms || 0) * TICKS_PER_MS);
|
||
}
|
||
|
||
// « 1 h 34 min », « 52 min »
|
||
function runtime(ticks) {
|
||
var minutes = Math.round(ticksToMs(ticks) / 60000);
|
||
if (minutes <= 0)
|
||
return "";
|
||
if (minutes < 60)
|
||
return minutes + " min";
|
||
var m = minutes % 60;
|
||
return Math.floor(minutes / 60) + " h" + (m > 0 ? " " + (m < 10 ? "0" : "") + m + " min" : "");
|
||
}
|
||
|
||
// « 1:02:03 », « 4:05 »
|
||
function clock(ms) {
|
||
var total = Math.max(0, Math.floor((ms || 0) / 1000));
|
||
var h = Math.floor(total / 3600);
|
||
var m = Math.floor((total % 3600) / 60);
|
||
var s = total % 60;
|
||
var mm = h > 0 && m < 10 ? "0" + m : String(m);
|
||
return (h > 0 ? h + ":" : "") + mm + ":" + (s < 10 ? "0" : "") + s;
|
||
}
|
||
|
||
// « S1 · É3 » pour un épisode
|
||
function episodeCode(item) {
|
||
if (!item || item.type !== "Episode")
|
||
return "";
|
||
return "S" + (item.parentIndexNumber || 0) + " · É" + (item.indexNumber || 0);
|
||
}
|
||
|
||
// Libellés des cartes du catalogue.
|
||
function cardTitle(item) {
|
||
return item.type === "Episode" && item.seriesName ? item.seriesName : item.name;
|
||
}
|
||
|
||
function cardSubtitle(item) {
|
||
if (item.type === "Episode")
|
||
return episodeCode(item) + " – " + item.name;
|
||
if (item.type === "Series" && item.childCount)
|
||
return item.childCount + " saison" + (item.childCount > 1 ? "s" : "");
|
||
return item.year ? String(item.year) : "";
|
||
}
|
||
|
||
// Avancement 0..1 (pour la barre de progression des cartes).
|
||
function progress(item) {
|
||
if (item.playedPercentage)
|
||
return item.playedPercentage / 100;
|
||
return item.runtimeTicks ? item.positionTicks / item.runtimeTicks : 0;
|
||
}
|
||
|
||
// Ligne d'informations : « 1997 · 1 h 34 min · Tous publics »
|
||
function infoLine(item) {
|
||
var parts = [];
|
||
if (item.type === "Episode")
|
||
parts.push(episodeCode(item));
|
||
if (item.year)
|
||
parts.push(String(item.year));
|
||
if (item.runtimeTicks)
|
||
parts.push(runtime(item.runtimeTicks));
|
||
if (item.rating)
|
||
parts.push(item.rating);
|
||
if (item.communityRating)
|
||
parts.push(item.communityRating.toFixed(1).replace(".", ",") + "/10");
|
||
return parts.join(" · ");
|
||
}
|