{
  "name": "\u540c\u6b65\u8c46\u74e3\u60f3\u770b\u5217\u8868\u5230 Sonarr",
  "nodes": [
    {
      "parameters": {
        "url": "https://api.themoviedb.org/3/search/tv",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBearerAuth",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "query",
              "value": "={{$('RSS Read').item.json.title.replace(/\\s*\u7b2c.*?\u5b63\\s*/g, '')}}"
            },
            {
              "name": "language",
              "value": "zh-CN"
            }
          ]
        },
        "options": {}
      },
      "name": "Search TMDb",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        432,
        -768
      ],
      "id": "cc25ae71-f665-491f-8c2b-42c6fb3878c7",
      "credentials": {
        "httpBearerAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "number": [
            {
              "value1": "={{ $json.total_results }}",
              "operation": "larger"
            }
          ],
          "string": [
            {
              "value1": "={{ $json.results[0].name }}",
              "value2": "={{$('RSS Read').item.json.title.replace(/\\s*\u7b2c.*?\u5b63\\s*/g, '')}}"
            }
          ]
        }
      },
      "name": "IF TV Show Found",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        656,
        -768
      ],
      "id": "0631c7a8-e280-473e-a8c2-282586b2419d"
    },
    {
      "parameters": {
        "url": "=https://api.themoviedb.org/3/tv/{{$node[\"IF TV Show Found\"].json.results[0].id}}/external_ids",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBearerAuth",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {}
          ]
        },
        "options": {}
      },
      "name": "Get TVDB ID",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        880,
        -768
      ],
      "id": "e77f061d-f0fb-45ba-a521-6ea4e17cb272",
      "credentials": {
        "httpBearerAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "9a508c25-edb2-484b-a9ae-ae03d0141af5",
              "name": "title",
              "value": "={{ $('IF TV Show Found').item.json.results[0].name.replace(/\\s*\u7b2c.*?\u5b63\\s*/g, '') }}",
              "type": "string"
            },
            {
              "id": "1dd1296c-6402-4bb0-b36d-cd6f45dc24de",
              "name": "rootFolderPath",
              "value": "={{ $('Get Sonarr Root Folder').item.json.path }}",
              "type": "string"
            },
            {
              "id": "8c3cfedc-f3db-46ae-9f9d-ce07f49d5492",
              "name": "tvdbId",
              "value": "={{ $('Get TVDB ID').item.json.tvdb_id }}",
              "type": "string"
            },
            {
              "id": "a5f34bd7-4367-4e42-bf55-09e05c784285",
              "name": "qualityProfileId",
              "value": "={{ $('CONFIG').item.json.qualityProfileId }}",
              "type": "string"
            },
            {
              "id": "1e8d306d-d182-4b59-b992-5be2e4d61792",
              "name": "monitored",
              "value": true,
              "type": "boolean"
            },
            {
              "id": "340e779f-6348-4e68-97e8-7503fb4a5a9b",
              "name": "addOptions",
              "value": "{                 \"searchForMissingEpisodes\": true               }",
              "type": "object"
            },
            {
              "id": "735df0dd-d048-4327-a148-dd4531b2776b",
              "name": "seasons",
              "value": "={{ $('Lookup Series Seasons').item.json.seasons.map(season => ({ ...season, monitored: season.seasonNumber === 1 })) }}",
              "type": "array"
            }
          ]
        },
        "options": {}
      },
      "name": "Build Sonarr Payload",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1552,
        -768
      ],
      "id": "4eddbf26-3b63-41c1-b3e2-e46b884a9c6c"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $('CONFIG').item.json[\"sonarrUrl\"]}}/api/v3/series",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify($json) }}",
        "options": {}
      },
      "name": "Add to Sonarr",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        1776,
        -768
      ],
      "id": "220a9590-2f24-4b7e-bdc9-f39546650a0f",
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      },
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "4c2a08c4-bc11-4f3a-a07d-1738beb0f868",
              "name": "rssUrl",
              "value": "http://nas:1200/douban/people/1443365/wish",
              "type": "string"
            },
            {
              "id": "3b226c8f-7036-4f21-96ba-1c6c76c294fc",
              "name": "sonarrUrl",
              "value": "http://nas:8989",
              "type": "string"
            },
            {
              "id": "2be2ee9a-276b-4961-a2cb-d8f88ba42325",
              "name": "qualityProfileId",
              "value": "1",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "name": "CONFIG",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -240,
        -768
      ],
      "id": "de6901ee-8ed7-4a1d-a219-003d360dc157"
    },
    {
      "parameters": {
        "url": "={{$node[\"CONFIG\"].json[\"sonarrUrl\"]}}/api/v3/rootfolder",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {}
      },
      "name": "Get Sonarr Root Folder",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        -16,
        -768
      ],
      "id": "7e215f9f-2115-4ef5-98fe-aff364d7e40d",
      "credentials": {
        "httpCustomAuth": {
          "name": "<your credential>"
        },
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "5f2e5834-4115-446f-b921-c5acccc08cbb",
              "leftValue": "={{ $json.tvdb_id }}",
              "rightValue": "",
              "operator": {
                "type": "number",
                "operation": "notEmpty",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1104,
        -768
      ],
      "id": "21646d70-1c57-4911-9ecc-74d4cac60b51",
      "name": "If TVDb ID Found"
    },
    {
      "parameters": {
        "url": "={{ $('CONFIG').item.json[\"sonarrUrl\"]}}/api/v3/series/lookup",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "term",
              "value": "=tvdb:{{ $('Get TVDB ID').item.json.tvdb_id }}"
            }
          ]
        },
        "options": {}
      },
      "name": "Lookup Series Seasons",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        1328,
        -768
      ],
      "id": "3d3593e1-5ed0-4279-9e88-fc91f29080fd",
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      },
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes"
            }
          ]
        }
      },
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        -464,
        -768
      ],
      "id": "a30e341d-c8d5-4776-8796-47af26b9b6c8",
      "name": "Schedule Trigger"
    },
    {
      "parameters": {
        "url": "={{ $('CONFIG').first().json.rssUrl }}",
        "options": {}
      },
      "type": "n8n-nodes-base.rssFeedRead",
      "typeVersion": 1.2,
      "position": [
        208,
        -768
      ],
      "id": "c97e7f7a-b32b-4341-bd42-77ab96f4cc15",
      "name": "RSS Read"
    }
  ],
  "connections": {
    "Search TMDb": {
      "main": [
        [
          {
            "node": "IF TV Show Found",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF TV Show Found": {
      "main": [
        [
          {
            "node": "Get TVDB ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get TVDB ID": {
      "main": [
        [
          {
            "node": "If TVDb ID Found",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Sonarr Payload": {
      "main": [
        [
          {
            "node": "Add to Sonarr",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "CONFIG": {
      "main": [
        [
          {
            "node": "Get Sonarr Root Folder",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Sonarr Root Folder": {
      "main": [
        [
          {
            "node": "RSS Read",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If TVDb ID Found": {
      "main": [
        [
          {
            "node": "Lookup Series Seasons",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Lookup Series Seasons": {
      "main": [
        [
          {
            "node": "Build Sonarr Payload",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "CONFIG",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "RSS Read": {
      "main": [
        [
          {
            "node": "Search TMDb",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "callerPolicy": "workflowsFromSameOwner"
  },
  "versionId": "1c8a1b7c-2417-4ca4-a82c-2b5aea57e816",
  "id": "DS6mlrAZj8sXbJxl",
  "tags": []
}