Add basic behavior to play, show catalog and more basic feature

This commit is contained in:
stilobique committed 2026-11-08 12:06:15 +01:00
1 parent df847becc8
commit 8e6392a84c
17 files changed
+1455 -34

No files matched your search

+44
View File
@@ -0,0 +1,44 @@
.pragma library
// Ce que le Freebox Player (Revolution) sait lire, déclaré à Jellyfin dans PlaybackInfo.
// Jellyfin choisit alors : lecture directe si le fichier convient, sinon transcodage HLS.
// Hypothèses prudentes (H.264 seulement : pas de HEVC sur la Revolution), à ajuster
// d'après les essais sur la box.
var maxBitrate = 20000000;
function profile() {
return {
Name: "Freebox Player",
MaxStreamingBitrate: maxBitrate,
MaxStaticBitrate: maxBitrate,
DirectPlayProfiles: [
{ Type: "Video", Container: "mp4,m4v,mkv,ts,mov", VideoCodec: "h264", AudioCodec: "aac,mp3,ac3" }
],
TranscodingProfiles: [
{
Type: "Video", Container: "ts", Protocol: "hls", Context: "Streaming",
VideoCodec: "h264", AudioCodec: "aac,ac3", MaxAudioChannels: "6",
MinSegments: 1, BreakOnNonKeyFrames: true
}
],
CodecProfiles: [
{
Type: "Video", Codec: "h264",
Conditions: [
{ Condition: "LessThanEqual", Property: "Width", Value: "1920" },
{ Condition: "LessThanEqual", Property: "VideoBitDepth", Value: "8" }
]
}
],
// Sous-titres texte déclarés « externes » : sans ça, Jellyfin transcode pour les
// incruster (SubtitleCodecNotSupported). Le lecteur ne les affiche pas encore.
SubtitleProfiles: [
{ Format: "srt", Method: "External" },
{ Format: "subrip", Method: "External" },
{ Format: "ass", Method: "External" },
{ Format: "ssa", Method: "External" },
{ Format: "vtt", Method: "External" }
]
};
}
+12
View File
@@ -10,6 +10,7 @@ FocusScope {
property var session: null
property int depth: 0
readonly property bool fullscreen: loader.item !== null && loader.item.fullscreen === true
property var _stack: []
function push(name, props) {
@@ -36,6 +37,17 @@ FocusScope {
push(name, props);
}
// Ouvre l'écran adapté à un élément du catalogue (Session._toItem()).
function openItem(item) {
if (item.type === "CollectionFolder")
push("Library", { library: { id: item.id, name: item.name, collectionType: item.collectionType } });
else if (item.type === "Season")
push("Season", { seriesId: item.seriesId, seasonId: item.id, seasonName: item.name,
seriesName: item.seriesName });
else
push("Details", { itemId: item.id });
}
function _load() {
var entry = _stack[_stack.length - 1];
var props = { navigator: root, session: root.session };
+241 -12
View File
@@ -1,5 +1,6 @@
import QtQuick 2.5
import fbx.application 1.0
import "DeviceProfile.js" as DeviceProfile
// État de connexion et appels à l'API Jellyfin : serveurs enregistrés,
// serveur et utilisateur courants, jeton d'accès.
@@ -59,7 +60,7 @@ QtObject {
callback("Le port doit être un nombre entre 1 et 65535.");
return;
}
_probeCandidates(serverCandidates(host, portText), 0, function (err, server) {
_probeCandidates(serverCandidates(host, portText), function (err, server) {
if (err) {
callback(err);
return;
@@ -229,6 +230,207 @@ QtObject {
});
}
// --------------------------------------------------------------- Catalogue
// Les éléments renvoyés sont « aplatis » par _toItem() (voir ses champs) pour
// pouvoir aller tels quels dans un ListModel ou un modèle JS.
// Bibliothèques de l'utilisateur : Films, Séries…
function loadLibraries(callback) {
callback = _guard(callback);
_request("GET", "/UserViews?" + _query({ userId: currentUser.id }), null, function (err, data) {
callback(err ? _describe(err) : null, err ? [] : _toItems(data.Items));
});
}
// « Reprendre » : vidéos commencées.
function loadResume(callback) {
callback = _guard(callback);
_request("GET", "/UserItems/Resume?" + _query({
userId: currentUser.id, limit: 20, mediaTypes: "Video", enableTotalRecordCount: false
}), null, function (err, data) {
callback(err ? _describe(err) : null, err ? [] : _toItems(data.Items));
});
}
// Derniers ajouts d'une bibliothèque.
function loadLatest(libraryId, callback) {
callback = _guard(callback);
_request("GET", "/Items/Latest?" + _query({ userId: currentUser.id, parentId: libraryId, limit: 20 }),
null, function (err, data) {
callback(err ? _describe(err) : null, err ? [] : _toItems(data));
});
}
// Contenu d'une bibliothèque, par pages. callback(err, items, total)
function loadLibraryItems(library, startIndex, limit, callback) {
callback = _guard(callback);
var types = library.collectionType === "tvshows" ? "Series"
: library.collectionType === "movies" ? "Movie" : "Movie,Series,Video";
_request("GET", "/Items?" + _query({
userId: currentUser.id, parentId: library.id, recursive: true, includeItemTypes: types,
sortBy: "SortName", sortOrder: "Ascending", startIndex: startIndex, limit: limit,
fields: "PrimaryImageAspectRatio"
}), null, function (err, data) {
if (err)
callback(_describe(err), [], 0);
else
callback(null, _toItems(data.Items), data.TotalRecordCount || 0);
});
}
function loadItem(itemId, callback) {
callback = _guard(callback);
_request("GET", "/Items/" + itemId + "?" + _query({ userId: currentUser.id }), null, function (err, data) {
callback(err ? _describe(err) : null, err ? null : _toItem(data));
});
}
function loadSeasons(seriesId, callback) {
callback = _guard(callback);
_request("GET", "/Shows/" + seriesId + "/Seasons?" + _query({ userId: currentUser.id }), null,
function (err, data) {
callback(err ? _describe(err) : null, err ? [] : _toItems(data.Items));
});
}
function loadEpisodes(seriesId, seasonId, callback) {
callback = _guard(callback);
_request("GET", "/Shows/" + seriesId + "/Episodes?" + _query({
userId: currentUser.id, seasonId: seasonId, fields: "Overview"
}), null, function (err, data) {
callback(err ? _describe(err) : null, err ? [] : _toItems(data.Items));
});
}
// URL d'image (pas d'authentification nécessaire). kind : "Primary", "Backdrop", "Thumb".
function imageUrl(itemId, kind, tag, maxHeight) {
if (!currentServer || !itemId || !tag)
return "";
return currentServer.address + "/Items/" + itemId + "/Images/" + kind + "?"
+ _query({ tag: tag, maxHeight: maxHeight || 360, quality: 90 });
}
// Affiche : celle de l'élément, sinon celle de sa série.
function posterUrl(item, maxHeight) {
if (item.imageTag)
return imageUrl(item.id, "Primary", item.imageTag, maxHeight);
return imageUrl(item.seriesId, "Primary", item.seriesPrimaryTag, maxHeight);
}
// Vignette 16:9 : image principale des bibliothèques/épisodes, sinon Thumb, sinon fond.
function thumbUrl(item, maxHeight) {
maxHeight = maxHeight || 300;
if ((item.type === "CollectionFolder" || item.type === "Episode") && item.imageTag)
return imageUrl(item.id, "Primary", item.imageTag, maxHeight);
if (item.thumbTag)
return imageUrl(item.id, "Thumb", item.thumbTag, maxHeight);
return backdropUrl(item, maxHeight) || posterUrl(item, maxHeight);
}
function backdropUrl(item, maxHeight) {
if (item.backdropTag)
return imageUrl(item.id, "Backdrop", item.backdropTag, maxHeight || 720);
return imageUrl(item.parentBackdropItemId, "Backdrop", item.parentBackdropTag, maxHeight || 720);
}
// ----------------------------------------------------------------- Lecture
// Demande à Jellyfin comment lire l'élément pour ce Player (profil DeviceProfile.js).
// callback(err, { url, itemId, mediaSourceId, playSessionId, playMethod })
function preparePlayback(itemId, callback) {
callback = _guard(callback);
_request("POST", "/Items/" + itemId + "/PlaybackInfo?" + _query({ userId: currentUser.id }),
// SubtitleStreamIndex -1 : pas de sous-titres (évite leur incrustation par transcodage).
{ DeviceProfile: DeviceProfile.profile(), MaxStreamingBitrate: DeviceProfile.maxBitrate,
SubtitleStreamIndex: -1 },
function (err, data) {
if (err) {
callback(_describe(err));
return;
}
var source = data.MediaSources && data.MediaSources[0];
if (data.ErrorCode || !source) {
callback("Lecture impossible (" + (data.ErrorCode || "aucune source") + ").");
return;
}
var info = { itemId: itemId, mediaSourceId: source.Id, playSessionId: data.PlaySessionId };
if (source.SupportsDirectPlay || source.SupportsDirectStream) {
info.playMethod = source.SupportsDirectPlay ? "DirectPlay" : "DirectStream";
info.url = currentServer.address + "/Videos/" + itemId + "/stream?" + _query({
static: true, mediaSourceId: source.Id, playSessionId: data.PlaySessionId,
deviceId: _settings.deviceId, api_key: accessToken
});
} else if (source.SupportsTranscoding && source.TranscodingUrl) {
info.playMethod = "Transcode";
info.url = currentServer.address + source.TranscodingUrl;
} else {
callback("Ce média ne peut pas être lu sur la Freebox.");
return;
}
console.log("Lecture : " + info.playMethod + " (" + (source.Container || "?") + ")");
callback(null, info);
});
}
// Suivi de lecture côté serveur (reprise, « vu »). event : "start", "progress", "stop".
function reportPlayback(event, info, positionMs, paused) {
var path = event === "start" ? "/Sessions/Playing"
: event === "stop" ? "/Sessions/Playing/Stopped" : "/Sessions/Playing/Progress";
_request("POST", path, {
ItemId: info.itemId, MediaSourceId: info.mediaSourceId, PlaySessionId: info.playSessionId,
PlayMethod: info.playMethod, PositionTicks: Math.floor((positionMs || 0) * 10000),
IsPaused: !!paused, CanSeek: true
}, function () {});
}
function _query(params) {
var parts = [];
for (var key in params) {
if (params[key] !== undefined && params[key] !== null && params[key] !== "")
parts.push(encodeURIComponent(key) + "=" + encodeURIComponent(params[key]));
}
return parts.join("&");
}
function _toItems(list) {
var items = [];
for (var i = 0; i < (list || []).length; i++)
items.push(_toItem(list[i]));
return items;
}
function _toItem(i) {
var userData = i.UserData || {};
return {
id: i.Id,
name: i.Name || "",
type: i.Type || "",
collectionType: i.CollectionType || "",
isFolder: !!i.IsFolder,
year: i.ProductionYear || 0,
overview: i.Overview || "",
runtimeTicks: i.RunTimeTicks || 0,
rating: i.OfficialRating || "",
communityRating: i.CommunityRating || 0,
imageTag: (i.ImageTags && i.ImageTags.Primary) || "",
thumbTag: (i.ImageTags && i.ImageTags.Thumb) || "",
backdropTag: (i.BackdropImageTags && i.BackdropImageTags[0]) || "",
parentBackdropItemId: i.ParentBackdropItemId || "",
parentBackdropTag: (i.ParentBackdropImageTags && i.ParentBackdropImageTags[0]) || "",
seriesId: i.SeriesId || "",
seriesName: i.SeriesName || "",
seriesPrimaryTag: i.SeriesPrimaryImageTag || "",
seasonId: i.SeasonId || "",
// (pas de champ « index » : rôle réservé dans les ListModel)
indexNumber: i.IndexNumber || 0,
parentIndexNumber: i.ParentIndexNumber || 0,
childCount: i.ChildCount || 0,
positionTicks: userData.PlaybackPositionTicks || 0,
playedPercentage: userData.PlayedPercentage || 0,
played: !!userData.Played
};
}
// ------------------------------------------------------------------ Divers
// Ignore les réponses en attente (appelé quand un écran est détruit).
@@ -253,20 +455,47 @@ QtObject {
return currentUser;
}
// Essaie les adresses une par une ; renvoie la première qui répond comme un serveur Jellyfin.
function _probeCandidates(candidates, index, callback) {
if (index >= candidates.length) {
// Essaie toutes les adresses en parallèle et retient la première, dans l'ordre de
// priorité, qui répond comme un serveur Jellyfin. Une adresse moins prioritaire (http)
// n'est retenue qu'une fois les plus prioritaires (https) réellement en échec : un
// premier échange TLS lent (chargement des certificats, CPU de la box) ne doit pas
// faire basculer sur http.
function _probeCandidates(candidates, callback) {
var results = [];
var settled = false;
function settle() {
if (settled)
return;
for (var i = 0; i < candidates.length; i++) {
if (results[i] === undefined)
return; // une adresse plus prioritaire n'a pas encore répondu
if (results[i]) {
settled = true;
callback(null, results[i]);
return;
}
}
settled = true;
callback("Aucun serveur Jellyfin trouvé à cette adresse.");
}
if (candidates.length === 0) {
callback("Aucun serveur Jellyfin trouvé à cette adresse.");
return;
}
var address = candidates[index];
_request("GET", "/System/Info/Public", null, function (err, info) {
if (!err && info && info.Id) {
callback(null, { name: info.ServerName || _hostOf(address), address: address, id: info.Id });
return;
}
_probeCandidates(candidates, index + 1, callback);
}, { baseUrl: address, timeout: 5000 });
for (var i = 0; i < candidates.length; i++) {
(function (index, address) {
_request("GET", "/System/Info/Public", null, function (err, info) {
results[index] = !err && info && info.Id
? { name: info.ServerName || _hostOf(address), address: address, id: info.Id }
: null;
if (!results[index])
console.log("Serveur : " + address + " ne répond pas (" + (err ? err.kind + " " + err.status : "réponse inattendue") + ")");
settle();
}, { baseUrl: address, timeout: 10000 });
})(i, candidates[i]);
}
}
function _describe(err) {