{
  "name": "Chinese Drama Auto Downloader Extended",
  "nodes": [
    {
      "parameters": {
        "triggerTimes": {
          "item": [
            {
              "hour": 9,
              "minute": 0
            }
          ]
        }
      },
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "url": "https://www.youtube.com/watch?v=YOUR_VIDEO_ID",
        "responseFormat": "file",
        "options": {}
      },
      "name": "Download YouTube Video",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        450,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "const videoFile = items[0].binary.data;\n\nreturn items;"
      },
      "name": "Prepare Video File",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        650,
        300
      ]
    },
    {
      "parameters": {
        "options": {},
        "command": "ffmpeg -i {{$binary.data.fileName}} -vn -acodec pcm_s16le -ar 16000 -ac 1 audio.wav",
        "waitForProcess": true
      },
      "name": "Extract Audio (FFmpeg)",
      "type": "n8n-nodes-base.executeCommand",
      "typeVersion": 1,
      "position": [
        850,
        300
      ]
    },
    {
      "parameters": {
        "url": "https://api.openai.com/v1/audio/transcriptions",
        "method": "POST",
        "responseFormat": "json",
        "options": {},
        "bodyParametersUi": {
          "parameter": [
            {
              "name": "file",
              "value": "={{$binary[\"audio.wav\"]}}"
            },
            {
              "name": "model",
              "value": "whisper-1"
            },
            {
              "name": "language",
              "value": "zh"
            }
          ]
        },
        "headerParametersUi": {
          "parameter": [
            {
              "name": "Authorization",
              "value": "Bearer YOUR_OPENAI_API_KEY"
            }
          ]
        }
      },
      "name": "Transcribe Audio (Whisper)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        1050,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "return [{ json: { chinese_subtitles: $json.text } }];"
      },
      "name": "Extract Subtitle Text",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        1250,
        300
      ]
    },
    {
      "parameters": {
        "url": "https://libretranslate.de/translate",
        "method": "POST",
        "responseFormat": "json",
        "options": {},
        "bodyParametersUi": {
          "parameter": [
            {
              "name": "q",
              "value": "={{$json.chinese_subtitles}}"
            },
            {
              "name": "source",
              "value": "zh"
            },
            {
              "name": "target",
              "value": "en"
            },
            {
              "name": "format",
              "value": "text"
            }
          ]
        }
      },
      "name": "Translate Subtitles",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        1450,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "return [{ json: { english_subtitles: $json.translatedText } }];"
      },
      "name": "Extract English Text",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        1650,
        300
      ]
    },
    {
      "parameters": {
        "url": "https://api.coqui.ai/tts",
        "method": "POST",
        "responseFormat": "file",
        "options": {},
        "bodyParametersUi": {
          "parameter": [
            {
              "name": "text",
              "value": "={{$json.english_subtitles}}"
            },
            {
              "name": "voice",
              "value": "en_1"
            }
          ]
        }
      },
      "name": "Generate English Voice (TTS)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        1850,
        300
      ]
    },
    {
      "parameters": {
        "options": {},
        "command": "ffmpeg -i {{$binary.data.fileName}} -i audio_tts.wav -c:v copy -map 0:v:0 -map 1:a:0 -shortest dubbed_video.mp4",
        "waitForProcess": true
      },
      "name": "Merge Dub Audio & Video",
      "type": "n8n-nodes-base.executeCommand",
      "typeVersion": 1,
      "position": [
        2050,
        300
      ]
    },
    {
      "parameters": {
        "options": {},
        "command": "ffmpeg -i dubbed_video.mp4 -vf subtitles=english_subtitles.srt final_video.mp4",
        "waitForProcess": true
      },
      "name": "Add English Subtitles Hardcoded",
      "type": "n8n-nodes-base.executeCommand",
      "typeVersion": 1,
      "position": [
        2250,
        300
      ]
    },
    {
      "parameters": {
        "options": {},
        "command": "ffmpeg -ss 00:01:00 -to 00:01:30 -i final_video.mp4 -c copy clip1.mp4",
        "waitForProcess": true
      },
      "name": "Create Social Clip",
      "type": "n8n-nodes-base.executeCommand",
      "typeVersion": 1,
      "position": [
        2450,
        300
      ]
    }
  ],
  "connections": {
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Download YouTube Video",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download YouTube Video": {
      "main": [
        [
          {
            "node": "Prepare Video File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Video File": {
      "main": [
        [
          {
            "node": "Extract Audio (FFmpeg)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Audio (FFmpeg)": {
      "main": [
        [
          {
            "node": "Transcribe Audio (Whisper)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Transcribe Audio (Whisper)": {
      "main": [
        [
          {
            "node": "Extract Subtitle Text",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Subtitle Text": {
      "main": [
        [
          {
            "node": "Translate Subtitles",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Translate Subtitles": {
      "main": [
        [
          {
            "node": "Extract English Text",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract English Text": {
      "main": [
        [
          {
            "node": "Generate English Voice (TTS)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate English Voice (TTS)": {
      "main": [
        [
          {
            "node": "Merge Dub Audio & Video",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge Dub Audio & Video": {
      "main": [
        [
          {
            "node": "Add English Subtitles Hardcoded",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add English Subtitles Hardcoded": {
      "main": [
        [
          {
            "node": "Create Social Clip",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}