{
  "nodes": [
    {
      "parameters": {
        "url": "https://raw.githubusercontent.com/YOUR_USERNAME/YOUR_REPOSITORY/main/animal_facts.json",
        "responseFormat": "json"
      },
      "name": "Fetch Animal Facts",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "operation": "limit",
        "maxItems": 1,
        "options": {
          "randomItem": true
        }
      },
      "name": "Select Random Fact",
      "type": "n8n-nodes-base.limit",
      "typeVersion": 1,
      "position": [
        450,
        300
      ]
    },
    {
      "parameters": {
        "channelId": "YOUR_DISCORD_CHANNEL_ID",
        "operation": "getAll",
        "limit": 100,
        "filters": {
          "content": "{{$('Select Random Fact').item.json.animal}}"
        }
      },
      "name": "Search Midjourney Image",
      "type": "n8n-nodes-base.discord",
      "typeVersion": 1,
      "position": [
        650,
        300
      ],
      "credentials": {
        "discordApi": "<your credential>"
      }
    },
    {
      "parameters": {
        "operation": "download",
        "url": "{{$('Search Midjourney Image').item.json.attachments[0].url}}",
        "filePath": "/tmp/midjourney_image.png"
      },
      "name": "Download Midjourney Image",
      "type": "n8n-nodes-base.fileManager",
      "typeVersion": 1,
      "position": [
        850,
        300
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.elevenlabs.io/v1/text-to-speech/YOUR_VOICE_ID",
        "headers": {
          "parameters": [
            {
              "name": "xi-api-key",
              "value": "{{$credentials.elevenLabsApiKey}}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "jsonBody": "{\"text\": \"{{$('Select Random Fact').item.json.fact}}\", \"model_id\": \"eleven_monolingual_v1\", \"voice_settings\": {\"stability\": 0.5, \"similarity_boost\": 0.5}}",
        "responseFormat": "binary"
      },
      "name": "Generate Voiceover",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        650,
        500
      ],
      "credentials": {
        "httpHeaderAuth": "<your credential>"
      }
    },
    {
      "parameters": {
        "operation": "writeBinary",
        "filePath": "/tmp/voiceover.mp3",
        "binaryData": "{{$('Generate Voiceover').item.binary.data}}"
      },
      "name": "Save Voiceover",
      "type": "n8n-nodes-base.fileManager",
      "typeVersion": 1,
      "position": [
        850,
        500
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.suno.ai/v1/music",
        "headers": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer {{$credentials.sunoApiKey}}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "jsonBody": "{\"prompt\": \"upbeat music for animal facts\", \"duration\": 30}",
        "responseFormat": "json"
      },
      "name": "Generate Music",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        650,
        700
      ],
      "credentials": {
        "httpHeaderAuth": "<your credential>"
      }
    },
    {
      "parameters": {
        "operation": "download",
        "url": "{{$('Generate Music').item.json.audio_url}}",
        "filePath": "/tmp/music.mp3"
      },
      "name": "Save Music",
      "type": "n8n-nodes-base.fileManager",
      "typeVersion": 1,
      "position": [
        850,
        700
      ]
    },
    {
      "parameters": {
        "code": "from moviepy.editor import ImageClip, AudioFileClip, CompositeAudioClip, CompositeVideoClip, TextClip\n\nimage_path = '/tmp/midjourney_image.png'\nvoiceover_path = '/tmp/voiceover.mp3'\nmusic_path = '/tmp/music.mp3'\nfact_text = $('Select Random Fact').item.json.fact\n\nvideo_duration = 30\nimage_clip = ImageClip(image_path).set_duration(video_duration)\n\nvoiceover_audio = AudioFileClip(voiceover_path)\nmusic_audio = AudioFileClip(music_path).subclip(0, video_duration)\nfinal_audio = CompositeAudioClip([music_audio.volumex(0.3), voiceover_audio])\n\ntext_clip = TextClip(fact_text, fontsize=24, color='white', bg_color='black', size=(image_clip.w, None)).set_position(('center', 'bottom')).set_duration(video_duration)\n\nfinal_video = CompositeVideoClip([image_clip.set_audio(final_audio), text_clip])\nfinal_video.write_videofile('/tmp/output.mp4', fps=24, codec='mpeg4')\n\nreturn [{'json': {'video_path': '/tmp/output.mp4'}}];"
      },
      "name": "Create Video",
      "type": "n8n-nodes-base.code",
      "typeVersion": 1,
      "position": [
        1050,
        400
      ]
    },
    {
      "parameters": {
        "operation": "readBinary",
        "filePath": "/tmp/output.mp4"
      },
      "name": "Read Video",
      "type": "n8n-nodes-base.fileManager",
      "typeVersion": 1,
      "position": [
        1250,
        400
      ]
    },
    {
      "parameters": {
        "operation": "upload",
        "title": "Animal Fact: {{$('Select Random Fact').item.json.fact}}",
        "description": "{{$('Select Random Fact').item.json.fact}}",
        "tags": "animals, facts, {{$('Select Random Fact').item.json.animal}}",
        "privacyStatus": "public",
        "binaryPropertyName": "data"
      },
      "name": "Upload to YouTube",
      "type": "n8n-nodes-base.youtube",
      "typeVersion": 1,
      "position": [
        1450,
        400
      ],
      "credentials": {
        "youtubeOAuth2Api": "<your credential>"
      }
    }
  ],
  "connections": {
    "Fetch Animal Facts": {
      "main": [
        [
          {
            "node": "Select Random Fact",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Select Random Fact": {
      "main": [
        [
          {
            "node": "Search Midjourney Image",
            "type": "main",
            "index": 0
          },
          {
            "node": "Generate Voiceover",
            "type": "main",
            "index": 0
          },
          {
            "node": "Create Video",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Search Midjourney Image": {
      "main": [
        [
          {
            "node": "Download Midjourney Image",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Midjourney Image": {
      "main": [
        [
          {
            "node": "Create Video",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Voiceover": {
      "main": [
        [
          {
            "node": "Save Voiceover",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Voiceover": {
      "main": [
        [
          {
            "node": "Create Video",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Music": {
      "main": [
        [
          {
            "node": "Save Music",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Music": {
      "main": [
        [
          {
            "node": "Create Video",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Video": {
      "main": [
        [
          {
            "node": "Read Video",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Video": {
      "main": [
        [
          {
            "node": "Upload to YouTube",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}