{
  "id": "yt-channel-06",
  "meta": {
    "instanceId": "vorlux-hub"
  },
  "name": "Vorlux AI | YouTube Channel Analyzer (Weekly Monday)",
  "active": true,
  "nodes": [
    {
      "id": "f6a7b8c9-0006-4fff-8006-000000000001",
      "name": "Monday 9am",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [220, 300],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours",
              "hoursInterval": 168
            }
          ]
        }
      }
    },
    {
      "id": "f6a7b8c9-0006-4fff-8006-000000000002",
      "name": "Fetch Channel Stats",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [460, 200],
      "parameters": {
        "method": "GET",
        "url": "={{$env.VORLUX_HUB_URL}}/api/integrations/youtube?action=channel_stats",
        "options": {
          "timeout": 15000
        }
      },
      "notes": "Gets subscriber count, total views, video count from YouTube API"
    },
    {
      "id": "f6a7b8c9-0006-4fff-8006-000000000003",
      "name": "Fetch Top Videos",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [460, 400],
      "parameters": {
        "method": "GET",
        "url": "={{$env.VORLUX_HUB_URL}}/api/integrations/youtube?action=top_videos&limit=20&period=7d",
        "options": {
          "timeout": 15000
        }
      },
      "notes": "Gets top performing videos from the last 7 days"
    },
    {
      "id": "f6a7b8c9-0006-4fff-8006-000000000004",
      "name": "Fetch Audience Retention",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [460, 600],
      "parameters": {
        "method": "GET",
        "url": "={{$env.VORLUX_HUB_URL}}/api/integrations/youtube?action=audience_retention&period=30d",
        "options": {
          "timeout": 15000
        }
      }
    },
    {
      "id": "f6a7b8c9-0006-4fff-8006-000000000005",
      "name": "Analyze Performance",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [740, 300],
      "notes": "Calculates growth rates, engagement trends, best content types",
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const channelStats = $('Fetch Channel Stats').first().json.data || {};\nconst topVideos = $('Fetch Top Videos').first().json.data || [];\nconst retention = $('Fetch Audience Retention').first().json.data || {};\n\n// Calculate engagement metrics\nconst totalViews = topVideos.reduce((s, v) => s + (v.views || 0), 0);\nconst totalLikes = topVideos.reduce((s, v) => s + (v.likes || 0), 0);\nconst totalComments = topVideos.reduce((s, v) => s + (v.comments || 0), 0);\nconst avgViews = topVideos.length ? Math.round(totalViews / topVideos.length) : 0;\nconst engagementRate = totalViews ? ((totalLikes + totalComments) / totalViews * 100).toFixed(2) : 0;\n\n// Content type analysis\nconst contentTypes = {};\nfor (const v of topVideos) {\n  const type = v.category || v.content_type || 'general';\n  if (!contentTypes[type]) contentTypes[type] = { count: 0, views: 0, likes: 0 };\n  contentTypes[type].count++;\n  contentTypes[type].views += v.views || 0;\n  contentTypes[type].likes += v.likes || 0;\n}\n\n// Best performing type\nconst bestType = Object.entries(contentTypes).sort((a, b) => (b[1].views / b[1].count) - (a[1].views / a[1].count))[0];\n\n// Growth calculation\nconst prevSubs = channelStats.previous_subscribers || channelStats.subscribers || 0;\nconst currentSubs = channelStats.subscribers || 0;\nconst growthRate = prevSubs ? ((currentSubs - prevSubs) / prevSubs * 100).toFixed(2) : 0;\n\nconst analysis = {\n  period: '7d',\n  channel: {\n    subscribers: currentSubs,\n    growthRate: parseFloat(growthRate),\n    totalViews: channelStats.total_views || 0\n  },\n  performance: {\n    videosAnalyzed: topVideos.length,\n    avgViews,\n    engagementRate: parseFloat(engagementRate),\n    totalViews,\n    totalLikes,\n    totalComments\n  },\n  contentTypes,\n  bestContentType: bestType ? { type: bestType[0], avgViews: Math.round(bestType[1].views / bestType[1].count) } : null,\n  topVideos: topVideos.slice(0, 5).map(v => ({ title: v.title, views: v.views, likes: v.likes })),\n  retention: {\n    avg: retention.average_retention || 0,\n    dropoffPoints: retention.dropoff_points || []\n  }\n};\n\nreturn [{ json: analysis }];"
      }
    },
    {
      "id": "f6a7b8c9-0006-4fff-8006-000000000006",
      "name": "Store Analytics",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [1000, 200],
      "parameters": {
        "method": "POST",
        "url": "={{$env.VORLUX_HUB_URL}}/api/analytics",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ type: 'youtube_channel_weekly', data: $json, period: '7d' }) }}",
        "options": {
          "timeout": 15000
        }
      }
    },
    {
      "id": "f6a7b8c9-0006-4fff-8006-000000000007",
      "name": "Generate Recommendations",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [1000, 400],
      "parameters": {
        "method": "POST",
        "url": "={{$env.OLLAMA_BASE_URL || 'http://localhost:11434'}}/api/generate",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ model: 'qwen2.5:7b', stream: false, prompt: 'You are a YouTube growth strategist for Vorlux AI HUB. Based on this weekly analytics data, provide 3-5 actionable recommendations for next week. Focus on content strategy, upload timing, and engagement tactics.\\n\\nData: ' + JSON.stringify($json).substring(0, 4000) + '\\n\\nGive concise, specific recommendations.' }) }}",
        "options": {
          "timeout": 60000
        }
      }
    },
    {
      "id": "f6a7b8c9-0006-4fff-8006-000000000008",
      "name": "Discord Report",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [1260, 300],
      "parameters": {
        "method": "POST",
        "url": "={{$env.DISCORD_OPS_WEBHOOK}}",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\"embeds\":[{\"title\":\"YouTube Weekly Channel Analysis\",\"description\":\"**Subscribers:** {{ $('Analyze Performance').first().json.channel.subscribers }} ({{ $('Analyze Performance').first().json.channel.growthRate }}% growth)\\n**Avg Views:** {{ $('Analyze Performance').first().json.performance.avgViews }}\\n**Engagement:** {{ $('Analyze Performance').first().json.performance.engagementRate }}%\\n**Best Content:** {{ ($('Analyze Performance').first().json.bestContentType || {}).type || 'N/A' }}\\n\\n**Top 5 Videos:**\\n{{ ($('Analyze Performance').first().json.topVideos || []).map((v,i) => (i+1) + '. ' + v.title + ' (' + v.views + ' views)').join('\\\\n') }}\\n\\n**AI Recommendations:**\\n{{ ($json.response || 'No recommendations generated').substring(0, 800) }}\",\"color\":16711680,\"footer\":{\"text\":\"Weekly Monday 9am - YouTube Channel Analyzer\"}}]}",
        "options": {
          "timeout": 10000
        }
      }
    }
  ],
  "connections": {
    "Monday 9am": {
      "main": [
        [
          {
            "node": "Fetch Channel Stats",
            "type": "main",
            "index": 0
          },
          {
            "node": "Fetch Top Videos",
            "type": "main",
            "index": 0
          },
          {
            "node": "Fetch Audience Retention",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Channel Stats": {
      "main": [
        [
          {
            "node": "Analyze Performance",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Top Videos": {
      "main": [
        [
          {
            "node": "Analyze Performance",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Audience Retention": {
      "main": [
        [
          {
            "node": "Analyze Performance",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Analyze Performance": {
      "main": [
        [
          {
            "node": "Store Analytics",
            "type": "main",
            "index": 0
          },
          {
            "node": "Generate Recommendations",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Recommendations": {
      "main": [
        [
          {
            "node": "Discord Report",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "saveManualExecutions": true,
    "saveExecutionProgress": true
  },
  "tags": [
    { "name": "youtube" },
    { "name": "analytics" },
    { "name": "weekly" }
  ],
  "versionId": "2"
}