{ "id": "TApiWf49Discourse01", "name": "Discourse Analysis Pipeline (TranscriptAPI)", "nodes": [ { "parameters": {}, "id": "49494949-4949-4949-8949-494949494901", "name": "Start", "type": "n8n-nodes-base.manualTrigger", "typeVersion": 1, "position": [ -300, 0 ] }, { "parameters": { "assignments": { "assignments": [ { "id": "49494949-4949-4949-8949-4949494949a1", "name": "searchQuery", "value": "REPLACE_WITH_TOPIC_OR_QUERY", "type": "string" } ] }, "options": {} }, "id": "49494949-4949-4949-8949-494949494902", "name": "Set Topic", "type": "n8n-nodes-base.set", "typeVersion": 3.4, "position": [ -80, 0 ] }, { "parameters": { "url": "https://transcriptapi.com/api/v2/youtube/search", "authentication": "genericCredentialType", "genericAuthType": "httpHeaderAuth", "sendQuery": true, "queryParameters": { "parameters": [ { "name": "q", "value": "={{ $json.searchQuery }}" }, { "name": "type", "value": "video" } ] }, "options": {} }, "id": "49494949-4949-4949-8949-494949494903", "name": "Search Videos (TranscriptAPI)", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [ 140, 0 ], "credentials": { "httpHeaderAuth": { "id": "REPLACE_TRANSCRIPTAPI_CRED_ID", "name": "TranscriptAPI - Authorization Bearer" } } }, { "parameters": { "jsCode": "const data = $input.first().json;\nreturn (data.results || []).filter((r) => r.hasCaptions).map((r) => ({ json: { videoId: r.videoId, title: r.title || null, channelTitle: r.channelTitle || null, videoUrl: 'https://www.youtube.com/watch?v=' + r.videoId } }));" }, "id": "49494949-4949-4949-8949-494949494904", "name": "Extract Captioned Results", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 360, 0 ] }, { "parameters": { "maxItems": 5 }, "id": "49494949-4949-4949-8949-494949494905", "name": "Keep Top 5", "type": "n8n-nodes-base.limit", "typeVersion": 1, "position": [ 580, 0 ] }, { "parameters": { "url": "https://transcriptapi.com/api/v2/youtube/transcript", "authentication": "genericCredentialType", "genericAuthType": "httpHeaderAuth", "sendQuery": true, "queryParameters": { "parameters": [ { "name": "video_url", "value": "={{ $json.videoUrl }}" }, { "name": "format", "value": "json" }, { "name": "send_metadata", "value": "true" } ] }, "options": {} }, "id": "49494949-4949-4949-8949-494949494906", "name": "Get Transcript (TranscriptAPI)", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [ 800, 0 ], "credentials": { "httpHeaderAuth": { "id": "REPLACE_TRANSCRIPTAPI_CRED_ID", "name": "TranscriptAPI - Authorization Bearer" } }, "onError": "continueRegularOutput" }, { "parameters": { "jsCode": "function ts(sec) {\n const s = Math.floor(sec || 0);\n const h = Math.floor(s / 3600), m = Math.floor((s % 3600) / 60), r = s % 60;\n const mm = (r < 10 ? '0' : '') + r;\n return h > 0 ? (h + ':' + (m < 10 ? '0' : '') + m + ':' + mm) : (m + ':' + mm);\n}\nconst MAX = 4000; const sources = []; const blocks = [];\nfor (const item of $input.all()) {\n const d = item.json; const seg = Array.isArray(d.transcript) ? d.transcript : [];\n if (seg.length === 0) continue;\n const meta = d.metadata || {}; const vid = d.video_id; const title = meta.title || vid;\n const url = 'https://www.youtube.com/watch?v=' + vid;\n const lines = seg.map((s) => '[' + ts(s.start) + '] ' + s.text).join('\\n').slice(0, MAX);\n sources.push({ title, videoUrl: url });\n blocks.push('### ' + title + ' (' + url + ')\\n' + lines);\n}\nreturn [ { json: { topic: $('Set Topic').first().json.searchQuery, sources, sourceCount: sources.length, combinedText: blocks.join('\\n\\n') } } ];" }, "id": "49494949-4949-4949-8949-494949494907", "name": "Collect Transcripts", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 1020, 0 ] }, { "parameters": { "method": "POST", "url": "https://api.openai.com/v1/chat/completions", "authentication": "genericCredentialType", "genericAuthType": "httpHeaderAuth", "sendBody": true, "specifyBody": "json", "jsonBody": "={{ JSON.stringify({ model: 'gpt-4o-mini', response_format: { type: 'json_object' }, messages: [ { role: 'system', content: 'You are a neutral discourse analyst. Using ONLY the supplied timestamped transcripts about a topic, produce a thematic analysis. Respond with a JSON object with keys: recurring_frames (array of strings — common ways the topic is framed), stance_clusters (array of objects with stance (a short label) and summary), evidence_snippets (array of objects with quote (short, near-verbatim), timestamp (the [m:ss] marker), source_title), caveats (array of limitations of this analysis). Stay descriptive and neutral; do not take sides or invent content.' }, { role: 'user', content: 'Topic: ' + $json.topic + '\\n\\nSource transcripts (timestamped):\\n\\n' + $json.combinedText } ] }) }}", "options": {} }, "id": "49494949-4949-4949-8949-494949494908", "name": "Discourse Analysis (LLM)", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [ 1240, 0 ], "credentials": { "httpHeaderAuth": { "id": "REPLACE_OPENAI_CRED_ID", "name": "OpenAI - Authorization Bearer" } } }, { "parameters": { "jsCode": "const raw = ($json.choices && $json.choices[0] && $json.choices[0].message.content) || '';\nlet r; try { r = JSON.parse(raw); } catch (e) { r = {}; }\nconst src = $('Collect Transcripts').first().json;\nreturn [ { json: { topic: src.topic, recurringFrames: r.recurring_frames || [], stanceClusters: r.stance_clusters || [], evidenceSnippets: r.evidence_snippets || [], caveats: r.caveats || [], sources: src.sources } } ];" }, "id": "49494949-4949-4949-8949-494949494909", "name": "Format Report", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 1460, 0 ] } ], "connections": { "Start": { "main": [ [ { "node": "Set Topic", "type": "main", "index": 0 } ] ] }, "Set Topic": { "main": [ [ { "node": "Search Videos (TranscriptAPI)", "type": "main", "index": 0 } ] ] }, "Search Videos (TranscriptAPI)": { "main": [ [ { "node": "Extract Captioned Results", "type": "main", "index": 0 } ] ] }, "Extract Captioned Results": { "main": [ [ { "node": "Keep Top 5", "type": "main", "index": 0 } ] ] }, "Keep Top 5": { "main": [ [ { "node": "Get Transcript (TranscriptAPI)", "type": "main", "index": 0 } ] ] }, "Get Transcript (TranscriptAPI)": { "main": [ [ { "node": "Collect Transcripts", "type": "main", "index": 0 } ] ] }, "Collect Transcripts": { "main": [ [ { "node": "Discourse Analysis (LLM)", "type": "main", "index": 0 } ] ] }, "Discourse Analysis (LLM)": { "main": [ [ { "node": "Format Report", "type": "main", "index": 0 } ] ] } }, "active": false, "settings": { "executionOrder": "v1" }, "pinData": {} }