8
n8n 中文网amn8n.com

使用Redis缓存和嵌入式视频播放器创建YouTube视频RSS订阅源

高级

这是一个Personal Productivity领域的自动化工作流,包含 31 个节点。主要使用 If, Set, Code, Sort, Merge 等节点。 使用Redis缓存和嵌入式视频播放器创建YouTube视频RSS订阅源

前置要求
  • Redis 服务器连接信息
  • HTTP Webhook 端点(n8n 会自动生成)
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "nodes": [
    {
      "id": "6d182711-1edf-4889-9c13-c8ee0e518843",
      "name": "响应 Webhook",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        3424,
        -256
      ],
      "parameters": {
        "options": {
          "responseHeaders": {
            "entries": [
              {
                "name": "content-type",
                "value": "application/xml"
              }
            ]
          }
        },
        "respondWith": "text",
        "responseBody": "={{ $json.feed }}"
      },
      "typeVersion": 1.4
    },
    {
      "id": "9386dd85-0bfe-4d8d-838f-abf338966ca7",
      "name": "获取相关 RSS 字段",
      "type": "n8n-nodes-base.set",
      "position": [
        2080,
        128
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "09842e7e-29a6-42ec-b381-3325911f5e20",
              "name": "title",
              "type": "string",
              "value": "={{ $json.snippet.title }}"
            },
            {
              "id": "7f487063-3850-41b5-be43-90cbb64c7583",
              "name": "content",
              "type": "string",
              "value": "={{ $json.snippet.description }}"
            },
            {
              "id": "af1803d3-6bb2-43e1-9ab8-b42cfdf934d0",
              "name": "thumbnail",
              "type": "object",
              "value": "={{ $json.snippet.thumbnails.standard }}"
            },
            {
              "id": "71e7124f-f275-4e09-997f-9bc0d60109ea",
              "name": "link",
              "type": "string",
              "value": "={{ $('Filter Out Shorts and Old Videos').item.json.link }}"
            },
            {
              "id": "01a85bdc-f859-43ec-8977-d7941bafa1d2",
              "name": "pubDate",
              "type": "string",
              "value": "={{ $('Filter Out Shorts and Old Videos').item.json.pubDate }}"
            },
            {
              "id": "2309c6f2-5cb5-44a0-b579-7ca82c2fb7f8",
              "name": "author",
              "type": "string",
              "value": "={{ $('Filter Out Shorts and Old Videos').item.json.author }}"
            },
            {
              "id": "c8a915cc-f295-4062-8736-72dae0e06536",
              "name": "id",
              "type": "string",
              "value": "={{ $('RSS Read YouTube Channel Feeds').item.json.id }}"
            },
            {
              "id": "01201f32-1b08-48f7-99e0-422ab7761ddd",
              "name": "description",
              "type": "string",
              "value": "={{ $json.description }}"
            },
            {
              "id": "5ef0579e-c4da-4033-b5be-b488843b383e",
              "name": "playerEmbedHtml",
              "type": "string",
              "value": "={{ $json.player.embedHtml }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "154b038b-1eb5-404c-a93f-c77cff0fc6af",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -496,
        -416
      ],
      "parameters": {
        "color": 3,
        "width": 432,
        "height": 560,
        "content": "## 1) 设置要拉取视频的频道"
      },
      "typeVersion": 1
    },
    {
      "id": "82876559-2d62-4ead-8937-b07507027bfe",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -912,
        -288
      ],
      "parameters": {
        "color": 3,
        "width": 384,
        "height": 304,
        "content": "## 4) 复制 Webhook URL"
      },
      "typeVersion": 1
    },
    {
      "id": "23bb70f4-2f7c-46a6-900f-fc86052d3eb6",
      "name": "用于测试的手动触发器",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -784,
        64
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "dff5c80f-a170-4fde-b937-1e75778f4888",
      "name": "RSS Webhook",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -784,
        -128
      ],
      "webhookId": "ca2154fe-8ea8-4f2e-bb93-897de6df8bb1",
      "parameters": {
        "path": "ca2154fe-8ea8-4f2e-bb93-897de6df8bb1",
        "options": {},
        "responseMode": "responseNode"
      },
      "typeVersion": 2
    },
    {
      "id": "23b31fab-636a-4d9a-a865-bacf46ab1772",
      "name": "便签 2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -32,
        -192
      ],
      "parameters": {
        "color": 7,
        "width": 672,
        "height": 336,
        "content": "## 读取 YouTube 频道的 RSS 源"
      },
      "typeVersion": 1
    },
    {
      "id": "d15a8043-bcbf-454e-a482-970c6b6ea386",
      "name": "便签 3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        672,
        -368
      ],
      "parameters": {
        "color": 3,
        "width": 224,
        "height": 512,
        "content": "## 2) 添加 Redis 凭据"
      },
      "typeVersion": 1
    },
    {
      "id": "acaaf9d0-78d1-442e-afdb-625cfe27e7ca",
      "name": "将每个频道设为一项",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        32,
        -32
      ],
      "parameters": {
        "options": {},
        "fieldToSplitOut": "channels"
      },
      "typeVersion": 1
    },
    {
      "id": "dff0de6a-dadb-4977-a5de-cd10b2f33abf",
      "name": "RSS 读取 YouTube 频道源",
      "type": "n8n-nodes-base.rssFeedRead",
      "position": [
        256,
        -32
      ],
      "parameters": {
        "url": "=https://www.youtube.com/feeds/videos.xml?channel_id={{ $json.id }}",
        "options": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "1313dbf8-8d05-4b53-ae87-3296ac191723",
      "name": "过滤掉 Shorts 和旧视频",
      "type": "n8n-nodes-base.filter",
      "position": [
        480,
        -32
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "3ed40225-f1e1-4bcc-a0db-5196de9b2f4b",
              "operator": {
                "type": "string",
                "operation": "notStartsWith"
              },
              "leftValue": "={{ $json.link }}",
              "rightValue": "https://www.youtube.com/shorts"
            },
            {
              "id": "b768fc70-8137-41d7-80ff-9f6787c153f1",
              "operator": {
                "type": "dateTime",
                "operation": "after"
              },
              "leftValue": "={{ $json.pubDate }}",
              "rightValue": "={{ new Date(Date.now() - 7 * 24 * 60 * 60 * 1000).toISOString() }}"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "8f890a75-d90a-4cc5-b21a-c1f9472f25a7",
      "name": "从缓存获取视频信息",
      "type": "n8n-nodes-base.redis",
      "position": [
        736,
        -32
      ],
      "parameters": {
        "key": "=yt-rss-item:{{ $json.id }}",
        "keyType": "string",
        "options": {},
        "operation": "get",
        "propertyName": "rss_item"
      },
      "credentials": {},
      "typeVersion": 1
    },
    {
      "id": "6b2acfb9-d372-4826-8a6f-ad3585e3e4f3",
      "name": "视频在缓存中吗?",
      "type": "n8n-nodes-base.if",
      "position": [
        960,
        -32
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "df02e029-38de-416e-bfc5-83c93252a865",
              "operator": {
                "type": "string",
                "operation": "exists",
                "singleValue": true
              },
              "leftValue": "={{ $json.rss_item }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "d1aa68d6-3521-4af2-8460-93422604fe8a",
      "name": "获取视频 ID",
      "type": "n8n-nodes-base.set",
      "position": [
        1184,
        128
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "17f17f7d-f980-44bf-90b8-463b7efba3d8",
              "name": "id",
              "type": "string",
              "value": "={{ $('Filter Out Shorts and Old Videos').item.json.id }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "c3d7972c-3d10-471f-9e45-2f7e08f08dc5",
      "name": "获取视频详情",
      "type": "n8n-nodes-base.youTube",
      "position": [
        1520,
        128
      ],
      "parameters": {
        "part": [
          "snippet",
          "player"
        ],
        "options": {},
        "videoId": "={{ $json.id.split(':')[2] }}",
        "resource": "video",
        "operation": "get"
      },
      "credentials": {},
      "typeVersion": 1
    },
    {
      "id": "032097af-3c37-4707-b7a0-ce89ada8d0ff",
      "name": "提取简短描述",
      "type": "n8n-nodes-base.code",
      "position": [
        1856,
        128
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "// Add a new field called 'myNewField' to the JSON of the item\nlet firstNewLine = $json.snippet.description.indexOf('\\n')\n$input.item.json.description = $json.snippet.description.substring(0, firstNewLine)\n\nreturn $input.item;"
      },
      "typeVersion": 2
    },
    {
      "id": "773ff2f1-7def-4a12-9907-ddcc891d491e",
      "name": "创建 RSS 项",
      "type": "n8n-nodes-base.code",
      "position": [
        2304,
        128
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "return {\n  rss_item: \n`<item>\n  <title>${$json.title}</title>\n  <id>$json.id</id>\n  <link>${$json.link}</link>\n  <description>${$json.description}</description>\n  <content:encoded><![CDATA[<div>${$json.playerEmbedHtml}</div> ${$json.content.replaceAll('\\n', '<br>')}]]></content:encoded>\n  <author>${$json.author}</author>\n  <pubDate>${$json.pubDate}</pubDate>\n</item>`\n}\n\n// <a href=\"${$json.link}\"><img src=\"${$json.thumbnail.url}\" alt=\"Thumbnail\" width=\"${$json.thumbnail.width}\" height=\"${$json.thumbnail.height}\"></a>"
      },
      "typeVersion": 2
    },
    {
      "id": "a0c813b7-6039-49b4-989e-0e4c12401cf9",
      "name": "获取要缓存的字段",
      "type": "n8n-nodes-base.set",
      "position": [
        2528,
        160
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "3b45f4e3-7e35-483a-a2c4-45a2e79a144a",
              "name": "rss_item",
              "type": "string",
              "value": "={{ $json.rss_item }}"
            },
            {
              "id": "6d69f0f0-ff88-4023-b5c9-ea328c04d4b6",
              "name": "id",
              "type": "string",
              "value": "={{ $('Get Video ID').item.json.id }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "b8da92fa-8d6c-403a-a722-cc1a7587d130",
      "name": "缓存视频信息",
      "type": "n8n-nodes-base.redis",
      "position": [
        2752,
        160
      ],
      "parameters": {
        "key": "=yt-rss-item:{{ $json.id }}",
        "ttl": 604800,
        "value": "={{ $json.rss_item }}",
        "expire": true,
        "keyType": "string",
        "operation": "set"
      },
      "credentials": {},
      "typeVersion": 1
    },
    {
      "id": "c6cc038b-2795-4b39-90d8-c22656d41da4",
      "name": "获取新的 RSS 项",
      "type": "n8n-nodes-base.set",
      "position": [
        2528,
        -160
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "63d9e896-1aef-4578-a308-414b492a1973",
              "name": "rss_item",
              "type": "string",
              "value": "={{ $json.rss_item }}"
            },
            {
              "id": "efa26308-d147-4d07-90d5-c2830b475ebb",
              "name": "pubDate",
              "type": "string",
              "value": "={{ $('Get relevant RSS fields').item.json.pubDate }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "d5b68cb9-ca51-4f99-bbcf-b7c411be7f6f",
      "name": "获取缓存的 RSS 项",
      "type": "n8n-nodes-base.set",
      "position": [
        2528,
        -352
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "63d9e896-1aef-4578-a308-414b492a1973",
              "name": "rss_item",
              "type": "string",
              "value": "={{ $json.rss_item }}"
            },
            {
              "id": "22dda3dc-9162-43e0-b6d9-a150d8c5b748",
              "name": "pubDate",
              "type": "string",
              "value": "={{ $('Filter Out Shorts and Old Videos').item.json.pubDate }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "ec795e54-980c-42ef-9120-cba68a332e85",
      "name": "按日期排序",
      "type": "n8n-nodes-base.sort",
      "position": [
        2976,
        -256
      ],
      "parameters": {
        "options": {},
        "sortFieldsUi": {
          "sortField": [
            {
              "order": "descending",
              "fieldName": "pubDate"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "aaea0eea-fbfa-45c0-a07a-e498169c243f",
      "name": "构建 RSS 源",
      "type": "n8n-nodes-base.code",
      "position": [
        3200,
        -256
      ],
      "parameters": {
        "jsCode": "let feed =\n`<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\">\n\n<channel>\n  <description>YouTube: videos from my channels</description>\n  <image>\n      <link>https://www.youtube.com</link>\n      <title>YouTube</title>\n      <width>128</width>\n      <height>128</height>\n      <url>https://favicon.is/youtube.com</url>\n  </image>\n  <link>https://www.youtube.com</link>\n  <title>My YouTube Feed</title>\n  ${$input.all().map(e => e.json.rss_item).join('\\n')}\n</channel>\n\n</rss>`;\n\nreturn [{\n  json: {\n    feed: feed\n  }\n}];"
      },
      "typeVersion": 2
    },
    {
      "id": "93e1345c-cd0d-43ef-abac-03323711088e",
      "name": "便签 4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        928,
        -416
      ],
      "parameters": {
        "color": 7,
        "width": 1520,
        "height": 736,
        "content": "## 从未缓存的视频拉取信息"
      },
      "typeVersion": 1
    },
    {
      "id": "3c7fcde8-8d1c-4ba8-b0d3-bab0f13c26a5",
      "name": "便签 5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1344,
        0
      ],
      "parameters": {
        "color": 3,
        "width": 448,
        "height": 288,
        "content": "## 3) 添加 Google 凭据"
      },
      "typeVersion": 1
    },
    {
      "id": "cb75f678-64f3-473b-9d11-2ac25b3186e7",
      "name": "便签6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2480,
        32
      ],
      "parameters": {
        "color": 7,
        "width": 464,
        "height": 288,
        "content": "## 将 RSS 项保存到缓存"
      },
      "typeVersion": 1
    },
    {
      "id": "4fdff9ce-8759-4da6-91b4-faaf32c9854f",
      "name": "便签7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2480,
        -480
      ],
      "parameters": {
        "color": 7,
        "width": 1136,
        "height": 480,
        "content": "## 构建 RSS 源"
      },
      "typeVersion": 1
    },
    {
      "id": "6dcfa347-8f40-417b-a606-f834f42c5a90",
      "name": "便签8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        480,
        176
      ],
      "parameters": {
        "color": 5,
        "width": 416,
        "height": 496,
        "content": "## 提示:托管您自己的 Redis 数据库"
      },
      "typeVersion": 1
    },
    {
      "id": "70123410-0500-44ea-8347-8de053540373",
      "name": "### 替换 Airtable 连接",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1296,
        -1312
      ],
      "parameters": {
        "width": 768,
        "height": 992,
        "content": "## 您的个人 YouTube 视频 RSS 源!"
      },
      "typeVersion": 1
    },
    {
      "id": "a40e110b-ada6-4960-ac8f-da452f22eb83",
      "name": "设置频道",
      "type": "n8n-nodes-base.set",
      "position": [
        -320,
        -32
      ],
      "parameters": {
        "mode": "raw",
        "options": {},
        "jsonOutput": "{\n  \"channels\": [\n  {\n    \"name\": \"n8n\",\n    \"id\": \"UCiHVTkJtWSdc9N3h0nUGWLg\"\n  },\n  {\n    \"name\": \"NetworkChuck\",\n    \"id\": \"UC9x0AN7BWHpCDHSm9NiJFJQ\"\n  },\n  {\n    \"name\": \"David Bombal\",\n    \"id\": \"UCP7WmQ_U4GB3K51Od9QvM0w\"\n  }\n]\n}\n"
      },
      "typeVersion": 3.4
    },
    {
      "id": "8b7fe325-4f5a-48bd-8ec9-26981eaa01a6",
      "name": "合并 RSS 项",
      "type": "n8n-nodes-base.merge",
      "position": [
        2752,
        -256
      ],
      "parameters": {},
      "typeVersion": 3.2
    }
  ],
  "connections": {
    "RSS Webhook": {
      "main": [
        [
          {
            "node": "Set Channels",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Video ID": {
      "main": [
        [
          {
            "node": "Get Video Details",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Channels": {
      "main": [
        [
          {
            "node": "Make Each Channel One Item",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Sort by Date": {
      "main": [
        [
          {
            "node": "Build RSS Feed",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build RSS Feed": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge RSS Items": {
      "main": [
        [
          {
            "node": "Sort by Date",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Video in Cache?": {
      "main": [
        [
          {
            "node": "Get Cached RSS Items",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Get Video ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create RSS Items": {
      "main": [
        [
          {
            "node": "Get Fields to Cache",
            "type": "main",
            "index": 0
          },
          {
            "node": "Get New RSS Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get New RSS Items": {
      "main": [
        [
          {
            "node": "Merge RSS Items",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Get Video Details": {
      "main": [
        [
          {
            "node": "Extract Short Description",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Fields to Cache": {
      "main": [
        [
          {
            "node": "Cache Video Info",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Cached RSS Items": {
      "main": [
        [
          {
            "node": "Merge RSS Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get relevant RSS fields": {
      "main": [
        [
          {
            "node": "Create RSS Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Short Description": {
      "main": [
        [
          {
            "node": "Get relevant RSS fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Video Info From Cache": {
      "main": [
        [
          {
            "node": "Video in Cache?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Make Each Channel One Item": {
      "main": [
        [
          {
            "node": "RSS Read YouTube Channel Feeds",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Manual trigger for testing": {
      "main": [
        [
          {
            "node": "Set Channels",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "RSS Read YouTube Channel Feeds": {
      "main": [
        [
          {
            "node": "Filter Out Shorts and Old Videos",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter Out Shorts and Old Videos": {
      "main": [
        [
          {
            "node": "Get Video Info From Cache",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。

这个工作流适合什么场景?

高级 - 个人效率

需要付费吗?

本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。

工作流信息
难度等级
高级
节点数量31
分类1
节点类型14
难度说明

适合高级用户,包含 16+ 个节点的复杂工作流

外部链接
在 n8n.io 查看

分享此工作流