From 048571975a2b42dc96bbfe2ee87f74c71c11ef8f Mon Sep 17 00:00:00 2001 From: Thomas Dannenberg Date: Thu, 28 Aug 2025 19:45:59 +0000 Subject: [PATCH] Kapitel 13/Tutorial.md aktualisiert --- Kapitel 13/Tutorial.md | 70 ++++++++++++++++++++++++++++-------------- 1 file changed, 47 insertions(+), 23 deletions(-) diff --git a/Kapitel 13/Tutorial.md b/Kapitel 13/Tutorial.md index 375fa3d..4354a96 100644 --- a/Kapitel 13/Tutorial.md +++ b/Kapitel 13/Tutorial.md @@ -344,7 +344,7 @@ Im Ergebnis findest du im Feld `data[0].id` deine **User-ID** (z. B. `123456789` 2. **HTTP Request (Get Videos):** ``` - https://api.twitch.tv/helix/videos?user_id=&type=archive&first=1 + https://api.twitch.tv/helix/videos?user_id=&type=archive ``` 3. **SSH Credentials in n8n anlegen** @@ -427,36 +427,60 @@ Im Ergebnis findest du im Feld `data[0].id` deine **User-ID** (z. B. `123456789` ``` Damit hat der Switch-Node drei klar benannte Ausgänge, die die weitere Logik steuern. -8. Pfad CREATE_AND_DOWNLOAD +8. Regel 1: CREATE_AND_DOWNLOAD - Verkabelung: - Switch-Node (Output: CREATE_AND_DOWNLOAD) - → SSH: State-Datei anlegen - → SSH: VOD herunterladen (yt-dlp) + Verkabelung (ein einzelnes VOD): + - Switch-Output **CREATE_AND_DOWNLOAD** → **Merge (Combine → All Possible Combinations)** (Eingang 1) + - **HTTP Request: VOD-Daten abrufen** → **Item Lists: Split Out Items (Input = data)** → **Merge (Combine → All Possible Combinations)** (Eingang 2) + - **Merge (Combine → All Possible Combinations)** → **SSH: State-Datei anlegen** → **SSH: VOD herunterladen (yt-dlp)** - - Node 1: SSH – State-Datei anlegen - Typ: SSH - Credentials: SSH Clipper - Operation: Execute Command - Command is an Expression: ON + > [!NOTE] + > Durch **Split Out Items** wird aus jedem Eintrag in `data[]` genau **ein Item**. Wenn Twitch nur ein aktuelles VOD liefert, ergibt sich 1×1 = 1 Item. > Wenn mehrere VODs geliefert werden, laufen die folgenden Nodes **pro VOD** einmal. + + Item Lists – Einstellungen (nach dem HTTP Request): + - Typ: Item Lists + - Operation: **Split Out Items** + - Field to Split Out: **data** + + + Merge – Einstellungen: + - Typ: Merge + - Mode: **Combine** + - Combine Mode: **All Possible Combinations** + - Eingang 1: vom Switch-Branch (liefert 1 Item) + - Eingang 2: vom **Split Out Items** (liefert N Items) + - Ergebnis: **1×N** Kombination → ein Item **pro VOD**, VOD-Felder sind im JSON verfügbar (z. B. `id`, `title`, …). + + + Set (optional, empfehlenswert): + - `vodId` → `{{ $json.id ?? $json.data?.id ?? $json.data?.[0]?.id }}` + + + SSH – State-Datei anlegen (nur wenn State-Datei **nicht existiert**): + - Typ: SSH + - Credentials: SSH Clipper + - Operation: Execute Command + - Command is an Expression: ON Command (Expression): - ```git + ``` {{`set -euo pipefail; mkdir -p /srv/clipper/state; printf "%s - " "${$json.data[0].id}" > /srv/clipper/state/vod_seen.list`}} + " "${$json.vodId ?? $json.id}" > /srv/clipper/state/vod_seen.list`}} ``` - Node 2: SSH – VOD herunterladen (yt-dlp) - Typ: SSH - Credentials: SSH Clipper - Operation: Execute Command - Command is an Expression: ON + + SSH – VOD herunterladen (yt-dlp): + - Typ: SSH + - Credentials: SSH Clipper + - Operation: Execute Command + - Command is an Expression: ON Command (Expression): - ```git - {{`set -euo pipefail; mkdir -p /srv/clipper/watch; URL="https://www.twitch.tv/videos/${$json.data[0].id}"; yt-dlp --no-progress --remux-video mp4 -o "/srv/clipper/watch/%(id)s.%(ext)s" "$URL"`}} ``` + {{`set -euo pipefail; mkdir -p /srv/clipper/watch; URL="https://www.twitch.tv/videos/${$json.vodId ?? $json.id}"; yt-dlp --no-progress --remux-video mp4 -o "/srv/clipper/watch/%(id)s.%(ext)s" "$URL"`}} + ``` + Ergebnis: - - /srv/clipper/state/vod_seen.list existiert und enthält die aktuelle VOD-ID (eine Zeile). - - Das VOD liegt als MP4 unter /srv/clipper/watch/.mp4 bereit. + - `/srv/clipper/state/vod_seen.list` existiert und enthält die **erste** VOD-ID. + - Für **jedes VOD** wird eine MP4 unter `/srv/clipper/watch/.mp4` gespeichert. + - Durch **Split Out Items + Combine (All Possible Combinations)** werden **alle VODs** zuverlässig durch den Pfad geführt. \ No newline at end of file