Kapitel 10/Free Rhohtext.md aktualisiert
This commit is contained in:
@@ -872,34 +872,66 @@ Kopiere den folgenden Code vollständig in das Code-Feld:
|
|||||||
|
|
||||||
```
|
```
|
||||||
/**
|
/**
|
||||||
* INPUT: Array von Items aus "Parse ICS"
|
* INPUT: items[0].json ODER items[0].json.body (String) vom HTTP Request /helix/schedule
|
||||||
* OUTPUT: nur das nächste bevorstehende Event
|
* OUTPUT: pro Segment ein Item in deinem Schema:
|
||||||
|
* { uid, cancelled, title, description, startIso, endIso, tz, hash }
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const now = Date.now();
|
const input = items[0]?.json ?? {};
|
||||||
|
let payload;
|
||||||
|
|
||||||
const upcoming = items
|
if (typeof input.body === 'string') {
|
||||||
.map(i => i.json)
|
// HTTP-Node hat "Response Format: Text" -> JSON-String in body
|
||||||
.filter(e => !e.cancelled && new Date(e.startIso).getTime() > now)
|
try { payload = JSON.parse(input.body); }
|
||||||
.sort((a, b) => new Date(a.startIso) - new Date(b.startIso));
|
catch (e) { throw new Error('HTTP body ist kein gültiges JSON'); }
|
||||||
|
} else if (input.data) {
|
||||||
if (upcoming.length === 0) {
|
// HTTP-Node hat "Response Format: JSON"
|
||||||
return [{ json: { message: 'Kein bevorstehender Stream gefunden' } }];
|
payload = input;
|
||||||
|
} else if (typeof input === 'string') {
|
||||||
|
payload = JSON.parse(input);
|
||||||
|
} else {
|
||||||
|
throw new Error('Unerwartete Eingabeform. Erwartet JSON oder body-String.');
|
||||||
}
|
}
|
||||||
|
|
||||||
const next = upcoming[0];
|
const segments = Array.isArray(payload.data?.segments) ? payload.data.segments : [];
|
||||||
|
|
||||||
return [{
|
// Hash wie in deinem ICS-Code
|
||||||
|
function hashHex(s) {
|
||||||
|
let h = 5381;
|
||||||
|
for (let i = 0; i < s.length; i++) h = ((h << 5) + h) ^ s.charCodeAt(i);
|
||||||
|
return (h >>> 0).toString(16).padStart(8, '0');
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildTitle() { return 'Streamtime'; }
|
||||||
|
|
||||||
|
function buildDesc(seg) {
|
||||||
|
const lines = [];
|
||||||
|
if (seg.title) lines.push(`Originaltitel: ${seg.title}`);
|
||||||
|
if (seg.category?.name) lines.push(`Kategorie/Game: ${seg.category.name}`);
|
||||||
|
return lines.join('\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
const tz = 'Europe/Berlin';
|
||||||
|
|
||||||
|
const out = segments.map(seg => {
|
||||||
|
const startIso = seg.start_time; // ISO-UTC laut Twitch
|
||||||
|
const endIso = seg.end_time;
|
||||||
|
const title = buildTitle();
|
||||||
|
const description = buildDesc(seg);
|
||||||
|
const hash = hashHex(`${title}|${startIso}|${endIso}|${description}`);
|
||||||
|
const kategorie = seg.category?.name;
|
||||||
|
return {
|
||||||
json: {
|
json: {
|
||||||
uid: next.uid,
|
uid: seg.id,
|
||||||
title: next.title,
|
cancelled: Boolean(seg.canceled_until),
|
||||||
description: next.description,
|
title, description,
|
||||||
startIso: next.startIso,
|
startIso, endIso, tz,
|
||||||
endIso: next.endIso,
|
hash, kategorie
|
||||||
tz: next.tz,
|
|
||||||
hash: next.hash
|
|
||||||
}
|
}
|
||||||
}];
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
return out;
|
||||||
```
|
```
|
||||||
|
|
||||||
[!TIP]
|
[!TIP]
|
||||||
|
|||||||
Reference in New Issue
Block a user