{
  "name": "Arabic AI YouTube Shorts Every 4 Hours - FFmpeg Ready",
  "nodes": [
    {
      "parameters": {
        "triggerTimes": {
          "mode": "everyXHours",
          "hours": 4
        }
      },
      "name": "Cron Trigger",
      "type": "n8n-nodes-base.cron",
      "typeVersion": 1,
      "position": [
        100,
        200
      ]
    },
    {
      "parameters": {
        "functionCode": "const types = ['\u0645\u0639\u0644\u0648\u0645\u0629', '\u0623\u062f\u0627\u0629', '\u0646\u0635\u064a\u062d\u0629', '\u062a\u062d\u0641\u064a\u0632'];\nconst selectedType = types[Math.floor(Math.random() * types.length)];\nreturn [{ json: { contentType: selectedType } }];"
      },
      "name": "Select Content Type",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        300,
        200
      ]
    },
    {
      "parameters": {
        "requestMethod": "POST",
        "url": "https://api-inference.huggingface.co/models/gpt-neox",
        "jsonParameters": true,
        "bodyParametersJson": "{\"inputs\": \"Generate a friendly Arabic YouTube Shorts script (30-60 seconds) about AI tools and concepts, based on type: {{$json[\\\"contentType\\\"]}}. Make it educational + motivational in easy-to-understand Arabic.\"}"
      },
      "name": "Generate Arabic Script (AI)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        500,
        200
      ]
    },
    {
      "parameters": {
        "requestMethod": "POST",
        "url": "https://ttsmp3.com/makemp3_new.php",
        "jsonParameters": true,
        "bodyParametersJson": "{\"msg\": {{$json[\\\"text\\\"]}}, \"lang\": \"ar-SA\", \"source\": \"ttsmp3\"}",
        "responseFormat": "file"
      },
      "name": "TTS Arabic (MP3)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        700,
        200
      ]
    },
    {
      "parameters": {
        "requestMethod": "GET",
        "url": "https://pixabay.com/api/videos/?key=52826070-b4b43fb9db34f9f088d6ed0d9&q=short+animation&per_page=5",
        "jsonParameters": true
      },
      "name": "Download Video Clip",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        900,
        200
      ]
    },
    {
      "parameters": {
        "functionCode": "return [{ json: { video_path: $json[\"video_url\"], audio_path: $json[\"audio_url\"], text_overlay: $json[\"text\"] } }];"
      },
      "name": "Prepare FFmpeg Inputs",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        1100,
        200
      ]
    },
    {
      "parameters": {
        "operation": "merge",
        "videoFile": "={{$json[\"video_path\"]}}",
        "audioFile": "={{$json[\"audio_path\"]}}",
        "text": "={{$json[\"text_overlay\"]}}",
        "fontSize": 28,
        "fontColor": "white",
        "textPosition": "bottom",
        "outputFileName": "final_video.mp4"
      },
      "name": "FFmpeg Merge Video + Audio + Text",
      "type": "n8n-nodes-base.ffmpeg",
      "typeVersion": 1,
      "position": [
        1300,
        200
      ]
    },
    {
      "parameters": {
        "resource": "video",
        "operation": "upload",
        "videoUrl": "={{$node[\"FFmpeg Merge Video + Audio + Text\"].json[\"outputFile\"]}}",
        "title": "={{$json[\"text\"]}}",
        "description": "#\u0630\u0643\u0627\u0621_\u0627\u0635\u0637\u0646\u0627\u0639\u064a #\u0627\u062f\u0648\u0627\u062a_AI #AI #AITools #Shorts",
        "privacyStatus": "public",
        "authentication": "oAuth2",
        "clientId": "531307366437-1739v3aiontg76f6m7c5ieke3hfu8h79.apps.googleusercontent.com",
        "clientSecret": "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"
      },
      "name": "Upload to YouTube",
      "type": "n8n-nodes-base.youtube",
      "typeVersion": 1,
      "position": [
        1500,
        200
      ]
    },
    {
      "parameters": {
        "functionCode": "try { return items; } catch(error) { return [{ json: { error: error.message, timestamp: new Date() } }]; }"
      },
      "name": "Error Handling & Logging",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        1700,
        200
      ]
    }
  ],
  "connections": {
    "Cron Trigger": {
      "main": [
        [
          {
            "node": "Select Content Type",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Select Content Type": {
      "main": [
        [
          {
            "node": "Generate Arabic Script (AI)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Arabic Script (AI)": {
      "main": [
        [
          {
            "node": "TTS Arabic (MP3)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "TTS Arabic (MP3)": {
      "main": [
        [
          {
            "node": "Download Video Clip",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Video Clip": {
      "main": [
        [
          {
            "node": "Prepare FFmpeg Inputs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare FFmpeg Inputs": {
      "main": [
        [
          {
            "node": "FFmpeg Merge Video + Audio + Text",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "FFmpeg Merge Video + Audio + Text": {
      "main": [
        [
          {
            "node": "Upload to YouTube",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload to YouTube": {
      "main": [
        [
          {
            "node": "Error Handling & Logging",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}