{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "95a5db18-2a99-4533-b0ae-e4e78cdd9256",
      "name": "On form submission",
      "type": "n8n-nodes-base.formTrigger",
      "position": [
        -2592,
        -160
      ],
      "parameters": {
        "options": {},
        "formTitle": "Bilibili Video Downloader",
        "formFields": {
          "values": [
            {
              "fieldLabel": "URL",
              "placeholder": " https://www.bilibili.com/video/.....",
              "requiredField": true
            }
          ]
        },
        "formDescription": "Bilibili Video Downloader"
      },
      "typeVersion": 2.2
    },
    {
      "id": "6c084dc4-1224-457e-a670-ae539db013b9",
      "name": "Google Drive Set Permission",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        -1248,
        -448
      ],
      "parameters": {
        "fileId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $json.id }}"
        },
        "options": {},
        "resource": "file",
        "operation": "share",
        "permissionsUi": {},
        "authentication": "oAuth2"
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "9976f8b9-0b34-4049-99cf-e09b9ce9b093",
      "name": "Check API Response Status",
      "type": "n8n-nodes-base.if",
      "position": [
        -2080,
        -144
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "bcc58e3d-9609-4ec3-adb9-bc6098205818",
              "operator": {
                "type": "number",
                "operation": "equals"
              },
              "leftValue": "={{ $json.statusCode }}",
              "rightValue": 200
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "64c030aa-ae2d-4c27-b2d3-794cf2a7f88f",
      "name": "Download Video File",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -1808,
        -416
      ],
      "parameters": {
        "url": "={{ $json.body.medias[0].resource_url }}",
        "options": {}
      },
      "typeVersion": 4.2
    },
    {
      "id": "28b5ee25-d65e-408f-b41f-82383c400255",
      "name": "Upload Video to Google Drive",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        -1552,
        -448
      ],
      "parameters": {
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": "My Drive"
        },
        "options": {},
        "folderId": {
          "__rl": true,
          "mode": "list",
          "value": "root",
          "cachedResultName": "/ (Root folder)"
        }
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "b7349a5b-8bc1-4a09-993d-5ed40d3e0bf8",
      "name": "Failure Notification Email",
      "type": "n8n-nodes-base.emailSend",
      "position": [
        -1360,
        112
      ],
      "parameters": {
        "html": "Hello,\n\nWe regret to inform you that your Bilibili video download request could not be completed successfully.\n\nThere might have been an issue with the URL provided or a problem with the video processing service.\n\nPlease double-check the IMDB URL and try again. If the problem persists, feel free to contact our support team for assistance.\n\nWe apologize for the inconvenience caused.\n",
        "options": {},
        "subject": "Bilibili Video Download Failed",
        "toEmail": "user@example.com",
        "fromEmail": "user@example.com"
      },
      "credentials": {
        "smtp": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "fee3736c-9a76-4d8c-b37a-4e5da4d1eb61",
      "name": "Success Notification Email with Drive Link",
      "type": "n8n-nodes-base.emailSend",
      "position": [
        -1040,
        -448
      ],
      "parameters": {
        "html": "=Hello,\n\nYour requested Bilibili  video has been successfully downloaded and uploaded to Google Drive. It is now ready for you to access.\n\nYou can download or view the video directly from your Google Drive using the shared link below:\n {{ $('Upload Video to Google Drive').item.json.webContentLink }}\n",
        "options": {},
        "subject": "Your Bilibili Video is Ready and Shared via Google Drive",
        "toEmail": "user@example.com",
        "fromEmail": "user@example.com"
      },
      "credentials": {
        "smtp": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "f3201fd3-9f6d-4d9e-ae95-7e6d5ee20cd4",
      "name": "Processing Delay",
      "type": "n8n-nodes-base.wait",
      "position": [
        -1728,
        96
      ],
      "parameters": {},
      "typeVersion": 1.1
    },
    {
      "id": "74b26075-b51a-42af-b5ef-d8fe5f6ffa98",
      "name": "Fetch Bilibili Video Info from API",
      "type": "n8n-nodes-base.httpRequest",
      "onError": "continueRegularOutput",
      "position": [
        -2368,
        -160
      ],
      "parameters": {
        "url": "https://bilibili-video-downloader.p.rapidapi.com/bili.php",
        "method": "POST",
        "options": {
          "response": {
            "response": {
              "fullResponse": true
            }
          }
        },
        "sendBody": true,
        "contentType": "multipart-form-data",
        "sendHeaders": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "url",
              "value": "={{ $json.URL }}"
            }
          ]
        },
        "headerParameters": {
          "parameters": [
            {
              "name": "x-rapidapi-host",
              "value": "bilibili-video-downloader.p.rapidapi.com"
            },
            {
              "name": "x-rapidapi-key",
              "value": "your key"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "5afc6028-973d-4ffc-99c8-b202b30ac9bb",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2672,
        -256
      ],
      "parameters": {
        "height": 256,
        "content": "Triggers the workflow when a user submits a form containing a Bilibili video URL."
      },
      "typeVersion": 1
    },
    {
      "id": "89e4649e-42cc-4894-a5c5-b990d0d19a6d",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2416,
        -256
      ],
      "parameters": {
        "height": 240,
        "content": "Sends the submitted URL to the Bilibili downloader API to retrieve video details and media links."
      },
      "typeVersion": 1
    },
    {
      "id": "68e63b6d-05fd-4b2e-a96d-3ffe7dcc9c89",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2160,
        -256
      ],
      "parameters": {
        "height": 256,
        "content": "Verifies that the API response returned a 200 status code indicating success."
      },
      "typeVersion": 1
    },
    {
      "id": "ca9b0fc9-56b9-4720-beec-ec86ff4b64fb",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1872,
        -528
      ],
      "parameters": {
        "height": 240,
        "content": "Downloads the Bilibili video file using the resource URL from the API response."
      },
      "typeVersion": 1
    },
    {
      "id": "54b888df-1815-48ff-8b77-4aaf3c32a428",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1600,
        -544
      ],
      "parameters": {
        "height": 240,
        "content": "Uploads the downloaded video file to the connected Google Drive account."
      },
      "typeVersion": 1
    },
    {
      "id": "890fc4ed-03a7-4846-92b9-3662a82512f2",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1328,
        -544
      ],
      "parameters": {
        "height": 240,
        "content": "Sets sharing permissions for the uploaded video file to make it accessible to the user."
      },
      "typeVersion": 1
    },
    {
      "id": "fe2bf49d-45a0-4ee6-ad45-e573b51976ee",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1072,
        -544
      ],
      "parameters": {
        "height": 240,
        "content": "Sends an email to the user with the Google Drive link to the successfully uploaded video."
      },
      "typeVersion": 1
    },
    {
      "id": "20422525-78c9-49f1-8a71-c4e396d9fc77",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1760,
        -16
      ],
      "parameters": {
        "height": 256,
        "content": "Adds a short delay in workflow execution before handling a failed download scenario."
      },
      "typeVersion": 1
    },
    {
      "id": "1c556652-70c7-4186-beff-76ea0c5316ce",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1424,
        0
      ],
      "parameters": {
        "height": 256,
        "content": "Sends an email notifying the user that the video download process failed."
      },
      "typeVersion": 1
    },
    {
      "id": "1ac5c0d8-41af-4a52-859f-d437e3c5c125",
      "name": "Sticky Note9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -3552,
        -528
      ],
      "parameters": {
        "width": 592,
        "height": 1168,
        "content": "# \ud83c\udfac Bilibili Video Downloader\n\nThis workflow allows users to submit a Bilibili video URL, automatically downloads the video via an API, uploads it to Google Drive, and emails the user with the shared link or an error notification.\n\n---\n\n### **\ud83e\udde9 Node Explanations**\n\n**1. On form submission**\n\n> Triggers the workflow when a user submits a form containing a Bilibili video URL.\n\n**2. Fetch Bilibili Video Info from API**\n\n> Sends the submitted URL to the Bilibili downloader API to retrieve video details and media links.\n\n**3. Check API Response Status**\n\n> Verifies if the API returned a successful `200` status response before proceeding.\n\n**4. Download Video File**\n\n> Downloads the Bilibili video file using the provided media URL from the API response.\n\n**5. Upload Video to Google Drive**\n\n> Uploads the downloaded video to the specified Google Drive folder.\n\n**6. Google Drive Set Permission**\n\n> Adjusts sharing settings to make the uploaded video accessible via a public or shareable link.\n\n**7. Success Notification Email with Drive Link**\n\n> Sends an email to the user containing the Google Drive link to the uploaded video.\n\n**8. Processing Delay**\n\n> Introduces a delay before executing the failure notification process.\n\n**9. Failure Notification Email**\n\n> Sends an email alerting the user that the video download or upload process failed.\n"
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Processing Delay": {
      "main": [
        [
          {
            "node": "Failure Notification Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "On form submission": {
      "main": [
        [
          {
            "node": "Fetch Bilibili Video Info from API",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Video File": {
      "main": [
        [
          {
            "node": "Upload Video to Google Drive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check API Response Status": {
      "main": [
        [
          {
            "node": "Download Video File",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Processing Delay",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Drive Set Permission": {
      "main": [
        [
          {
            "node": "Success Notification Email with Drive Link",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload Video to Google Drive": {
      "main": [
        [
          {
            "node": "Google Drive Set Permission",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Bilibili Video Info from API": {
      "main": [
        [
          {
            "node": "Check API Response Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}