Add scripts to fetch random items from Jellyfin API with detailed logging [skip ci]
This commit is contained in:
44
test_scripts/fetch_random_item_browser_console.js
Normal file
44
test_scripts/fetch_random_item_browser_console.js
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
(async () => {
|
||||||
|
// 1. Prüfen, ob wir im Jellyfin-Kontext sind
|
||||||
|
if (!window.ApiClient) {
|
||||||
|
console.error("ApiClient nicht gefunden. Bist du sicher, dass Jellyfin im Browser offen ist?");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const apiClient = window.ApiClient;
|
||||||
|
const userId = apiClient.currentUserId();
|
||||||
|
|
||||||
|
// 2. Alle Items abrufen (Filme und Serien)
|
||||||
|
// Wir fordern extra viele Felder an, um "alle verfügbaren Einträge" zu erhalten
|
||||||
|
const response = await apiClient.getItems(userId, {
|
||||||
|
Recursive: true,
|
||||||
|
IncludeItemTypes: "Movie,Series,Episode",
|
||||||
|
Fields: "Overview,Genres,Path,OfficialRating,Tags,CommunityRating,ExternalUrls,MediaSources,ProductionYear",
|
||||||
|
EnableImageTypes: "Primary,Backdrop,Banner"
|
||||||
|
});
|
||||||
|
|
||||||
|
const items = response.Items;
|
||||||
|
|
||||||
|
if (!items || items.length === 0) {
|
||||||
|
console.warn("Keine Items in deiner Bibliothek gefunden.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Zufälliges Item auswählen
|
||||||
|
const randomItem = items[Math.floor(Math.random() * items.length)];
|
||||||
|
|
||||||
|
// 4. Ausgabe in der Konsole
|
||||||
|
console.log(`%c🎲 Zufälliges Item: ${randomItem.Name}`, "color: #00a4dc; font-weight: bold; font-size: 1.4em;");
|
||||||
|
|
||||||
|
// Gibt alle Metadaten als ausklappbares Objekt aus
|
||||||
|
console.log("Vollständige Metadaten:", randomItem);
|
||||||
|
|
||||||
|
// Erstellt eine übersichtliche Tabelle der wichtigsten Werte
|
||||||
|
console.table({
|
||||||
|
Name: randomItem.Name,
|
||||||
|
Typ: randomItem.Type,
|
||||||
|
Jahr: randomItem.ProductionYear,
|
||||||
|
ID: randomItem.Id,
|
||||||
|
Pfad: randomItem.Path
|
||||||
|
});
|
||||||
|
})();
|
||||||
32
test_scripts/fetch_random_item_browser_console_2.js
Normal file
32
test_scripts/fetch_random_item_browser_console_2.js
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
(async () => {
|
||||||
|
// 1. Get Auth Data from the active client
|
||||||
|
const apiClient = window.ApiClient;
|
||||||
|
if (!apiClient) {
|
||||||
|
console.error("ApiClient not found. Are you logged in?");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
console.log("Fetching random item...");
|
||||||
|
|
||||||
|
// 2. Fetch 1 random item
|
||||||
|
// const result = await apiClient.getItems(apiClient.getCurrentUserId(), { SortBy: "Random", Limit: 1, Recursive: true, IncludeItemTypes: "Movie,Series" });
|
||||||
|
const result = await apiClient.getItems(apiClient.getCurrentUserId(), {
|
||||||
|
SortBy: "Random",
|
||||||
|
Limit: 1,
|
||||||
|
Recursive: true,
|
||||||
|
IncludeItemTypes: "Movie,Series", // Optional: filter types
|
||||||
|
Fields: "Overview,RemoteTrailers,Genres,CommunityRating,CriticRating,OfficialRating,PremiereDate,RunTimeTicks,ProductionYear,MediaSources" // Request ALL fields
|
||||||
|
});
|
||||||
|
|
||||||
|
if (result.Items.length > 0) {
|
||||||
|
const item = result.Items[0];
|
||||||
|
console.log("Random Item Found:", item.Name);
|
||||||
|
console.dir(item); // Prints the full interactive object
|
||||||
|
} else {
|
||||||
|
console.warn("No items found.");
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching item:", error);
|
||||||
|
}
|
||||||
|
})();
|
||||||
Reference in New Issue
Block a user