Untitled
unknown
plain_text
8 months ago
2.4 kB
6
Indexable
{
"nodes": [
{
"id": "webhook",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 1,
"position": [200, 200],
"parameters": {
"path": "youtube-sub",
"httpMethod": "POST",
"responseMode": "lastNode"
}
},
{
"id": "python",
"name": "Get Transcript (Python)",
"type": "n8n-nodes-base.python",
"typeVersion": 1,
"position": [500, 200],
"parameters": {
"functionCode": "from youtube_transcript_api import YouTubeTranscriptApi\nimport re\n\ninput_data = $json\n\nurl_or_id = input_data.get(\"videoId\") or input_data.get(\"url\")\n\n# Nếu là URL thì trích videoId\nif \"youtube.com\" in url_or_id or \"youtu.be\" in url_or_id:\n match = re.search(r\"(?:v=|youtu\\.be/)([\\w-]+)\", url_or_id)\n video_id = match.group(1) if match else url_or_id\nelse:\n video_id = url_or_id\n\ntry:\n transcript = YouTubeTranscriptApi.get_transcript(video_id)\n text = \"\\n\".join([i[\"text\"] for i in transcript])\n result = {\"videoId\": video_id, \"transcript\": text}\nexcept Exception as e:\n result = {\"videoId\": video_id, \"error\": str(e)}\n\nreturn [result]"
}
},
{
"id": "return",
"name": "Return JSON",
"type": "n8n-nodes-base.set",
"typeVersion": 1,
"position": [800, 200],
"parameters": {
"keepOnlySet": false,
"values": {
"json": [
{
"name": "videoId",
"value": "={{$json.videoId}}"
},
{
"name": "transcript",
"value": "={{$json.transcript}}"
},
{
"name": "error",
"value": "={{$json.error}}"
}
]
}
}
}
],
"connections": {
"Webhook": {
"main": [
[
{
"node": "Get Transcript (Python)",
"type": "main",
"index": 0
}
]
]
},
"Get Transcript (Python)": {
"main": [
[
{
"node": "Return JSON",
"type": "main",
"index": 0
}
]
]
}
},
"name": "YouTube Subtitles Fetcher",
"active": false,
"version": 1
}
Editor is loading...
Leave a Comment