553 lines
18 KiB
JSON
553 lines
18 KiB
JSON
{
|
|
"id": "kRZyX9H2uDHHncpE",
|
|
"name": "MAM Transmission Manager",
|
|
"nodes": [
|
|
{
|
|
"parameters": {},
|
|
"id": "start",
|
|
"name": "Start",
|
|
"position": [
|
|
224,
|
|
128
|
|
],
|
|
"type": "n8n-nodes-base.executeWorkflowTrigger",
|
|
"typeVersion": 1
|
|
},
|
|
{
|
|
"parameters": {
|
|
"method": "POST",
|
|
"url": "http://seed-1.dfw.ben.io:9091/transmission/rpc",
|
|
"authentication": "genericCredentialType",
|
|
"genericAuthType": "httpBasicAuth",
|
|
"sendHeaders": true,
|
|
"headerParameters": {
|
|
"parameters": [
|
|
{
|
|
"name": "X-Transmission-Session-Id",
|
|
"value": "={{ $('Merge Session to Files').item.json.headers[\"X-Transmission-Session-Id\"] }}"
|
|
}
|
|
]
|
|
},
|
|
"sendBody": true,
|
|
"specifyBody": "json",
|
|
"jsonBody": "={\n \"method\": \"torrent-add\",\n \"arguments\": {\n \"metainfo\": \"{{ $('Extract from File').item.json.data }}\",\n \"download-dir\": \"/home/seed_/.transmission/downloads/audio\",\n \"paused\": true\n }\n}",
|
|
"options": {
|
|
"response": {
|
|
"response": {
|
|
"fullResponse": true
|
|
}
|
|
}
|
|
}
|
|
},
|
|
"id": "http-add-torrent",
|
|
"name": "Add Torrent to Transmission",
|
|
"position": [
|
|
1792,
|
|
128
|
|
],
|
|
"type": "n8n-nodes-base.httpRequest",
|
|
"typeVersion": 4.2,
|
|
"credentials": {
|
|
"httpBasicAuth": {
|
|
"id": "iymUPilnVhfL3h5D",
|
|
"name": "transmission"
|
|
}
|
|
},
|
|
"onError": "continueRegularOutput"
|
|
},
|
|
{
|
|
"parameters": {
|
|
"jsCode": "const responses = $input.all();\nconst originals = $('Start').all();\nconst mergedPayloads = $('Merge Session Context').all();\n\nfunction getOriginal(index) {\n return originals[index]?.json || originals[0]?.json || {};\n}\n\nfunction getSessionId(index) {\n return mergedPayloads[index]?.json?.session_id || mergedPayloads[0]?.json?.session_id || '';\n}\n\nconst outputs = [];\n\nfor (let i = 0; i < responses.length; i++) {\n const item = responses[i];\n const body = item.json.body || item.json;\n const result = body?.result;\n const args = body?.arguments || {};\n const torrentInfo = args['torrent-added'] || args['torrent-duplicate'];\n const sessionId = getSessionId(i);\n const originalInput = getOriginal(i);\n\n if (item.error || (!torrentInfo && result !== 'duplicate' && result !== 'success')) {\n outputs.push({\n json: {\n status: 'failed',\n error: item.error?.message || result || 'Unknown error adding torrent',\n torrent_id: null,\n session_id: sessionId,\n original_input: originalInput\n }\n });\n continue;\n }\n\n if (!torrentInfo) {\n outputs.push({\n json: {\n status: 'failed',\n error: 'Could not extract torrent info from response',\n torrent_id: null,\n session_id: sessionId,\n original_input: originalInput\n }\n });\n continue;\n }\n\n outputs.push({\n json: {\n status: 'queued',\n torrent_id: torrentInfo.id,\n torrent_hash: torrentInfo.hashString,\n torrent_name: torrentInfo.name,\n session_id: sessionId,\n original_input: originalInput\n }\n });\n}\n\nreturn outputs;"
|
|
},
|
|
"id": "code-extract-torrent-id",
|
|
"name": "Extract Torrent ID",
|
|
"position": [
|
|
2016,
|
|
128
|
|
],
|
|
"type": "n8n-nodes-base.code",
|
|
"typeVersion": 2
|
|
},
|
|
{
|
|
"parameters": {
|
|
"respondWith": "allIncomingItems",
|
|
"options": {}
|
|
},
|
|
"id": "respond-complete",
|
|
"name": "Respond Complete",
|
|
"position": [
|
|
2464,
|
|
128
|
|
],
|
|
"type": "n8n-nodes-base.respondToWebhook",
|
|
"typeVersion": 1
|
|
},
|
|
{
|
|
"parameters": {
|
|
"language": "pythonNative",
|
|
"pythonCode": "# 1. Access the input item\nitem = _items[0]['json']\n\n# 2. Extract the data we need\n# UPDATE: The input key is now 'dl_link', not 'download_link'\ndownload_link = item.get('dl_link')\nsession_id = item.get('session_id')\n\n# 3. Create the Transmission Payload\npayload = {\n \"method\": \"torrent-add\",\n \"arguments\": {\n \"filename\": download_link,\n \"download-dir\": \"/home/seed_/.transmission/downloads/audio\",\n \"paused\": True \n }\n}\n\n# 4. Return the formatted data\nreturn [{\n \"json\": {\n # UPDATE: Map 'title' correctly for any old nodes that need it\n \"title\": item.get('meta_title'),\n \n # NEW: Pass through all metadata for the Postgres Logger\n \"meta_title\": item.get('meta_title'),\n \"meta_series\": item.get('meta_series'),\n \"meta_book_number\": item.get('meta_book_number'),\n \"meta_author\": item.get('meta_author'),\n \"mam_id\": item.get('mam_id'),\n \"dl_link\": download_link,\n \n # Transmission Data\n \"transmission_body\": payload,\n \"headers\": {\n \"X-Transmission-Session-Id\": session_id\n }\n }\n}]"
|
|
},
|
|
"type": "n8n-nodes-base.code",
|
|
"typeVersion": 2,
|
|
"position": [
|
|
896,
|
|
128
|
|
],
|
|
"id": "d6d9f145-6b10-452f-aa08-2dc669c3b4d6",
|
|
"name": "Merge Session to Files"
|
|
},
|
|
{
|
|
"parameters": {
|
|
"mode": "combine",
|
|
"combineBy": "combineByPosition",
|
|
"options": {}
|
|
},
|
|
"type": "n8n-nodes-base.merge",
|
|
"typeVersion": 3.2,
|
|
"position": [
|
|
672,
|
|
128
|
|
],
|
|
"id": "dde23141-d708-48e7-942f-08aa1d749189",
|
|
"name": "Merge Session Context"
|
|
},
|
|
{
|
|
"parameters": {
|
|
"url": "={{ $json.transmission_body.arguments.filename }}",
|
|
"authentication": "genericCredentialType",
|
|
"genericAuthType": "httpHeaderAuth",
|
|
"options": {
|
|
"response": {
|
|
"response": {
|
|
"fullResponse": true,
|
|
"responseFormat": "file"
|
|
}
|
|
}
|
|
}
|
|
},
|
|
"type": "n8n-nodes-base.httpRequest",
|
|
"typeVersion": 4.3,
|
|
"position": [
|
|
1120,
|
|
128
|
|
],
|
|
"id": "acb7d649-a853-44e7-84e8-f82398f3008a",
|
|
"name": "MAM Get File HTTP Request",
|
|
"credentials": {
|
|
"httpBasicAuth": {
|
|
"id": "iymUPilnVhfL3h5D",
|
|
"name": "transmission"
|
|
},
|
|
"httpHeaderAuth": {
|
|
"id": "G8eA8XeS9P5axwJd",
|
|
"name": "mam cookie auth header"
|
|
}
|
|
}
|
|
},
|
|
{
|
|
"parameters": {
|
|
"operation": "binaryToPropery",
|
|
"options": {}
|
|
},
|
|
"type": "n8n-nodes-base.extractFromFile",
|
|
"typeVersion": 1.1,
|
|
"position": [
|
|
1568,
|
|
128
|
|
],
|
|
"id": "acb1b56b-ac9a-41ec-ad60-7ce983b8cdd7",
|
|
"name": "Extract from File"
|
|
},
|
|
{
|
|
"parameters": {
|
|
"language": "pythonNative",
|
|
"pythonCode": "results = []\n\nfor item in _items:\n # 1. Get the binary data from the previous download node\n # n8n stores the file in the 'binary' key. The default property name is usually 'data'.\n # We need the 'data' field inside that, which contains the Base64 string.\n binary_ref = item.get('binary', {}).get('data', {})\n b64_string = binary_ref.get('data')\n\n if b64_string:\n # 2. Create the exact JSON body Transmission expects for file uploads\n # We use \"metainfo\" for the actual file content (Base64)\n payload = {\n \"method\": \"torrent-add\",\n \"arguments\": {\n \"metainfo\": b64_string, \n \"download-dir\": \"/home/seed_/.transmission/downloads/audio\",\n \"paused\": False\n }\n }\n\n # 3. Preserve any existing JSON (like session_id) if it exists, or start fresh\n new_json = item.get('json', {}).copy()\n new_json['transmission_body'] = payload\n \n results.append({\n \"json\": new_json,\n # Pass the binary through just in case, though we don't strictly need it anymore\n \"binary\": item.get('binary', {})\n })\n\nreturn results"
|
|
},
|
|
"type": "n8n-nodes-base.code",
|
|
"typeVersion": 2,
|
|
"position": [
|
|
1344,
|
|
128
|
|
],
|
|
"id": "0b011613-50e9-4612-ac6e-1f6ac0e39ebb",
|
|
"name": "Prepare Transmission Payload"
|
|
},
|
|
{
|
|
"parameters": {
|
|
"workflowId": {
|
|
"__rl": true,
|
|
"value": "NChjOd3ILEmt0FdyAt8qA",
|
|
"mode": "list",
|
|
"cachedResultUrl": "/workflow/NChjOd3ILEmt0FdyAt8qA",
|
|
"cachedResultName": "Transmission: Get Session"
|
|
},
|
|
"workflowInputs": {
|
|
"mappingMode": "defineBelow",
|
|
"value": {
|
|
"server_id": "seed-1.dfw.ben.io"
|
|
},
|
|
"matchingColumns": [
|
|
"server_id"
|
|
],
|
|
"schema": [
|
|
{
|
|
"id": "server_id",
|
|
"displayName": "server_id",
|
|
"required": false,
|
|
"defaultMatch": false,
|
|
"display": true,
|
|
"canBeUsedToMatch": true,
|
|
"type": "string",
|
|
"removed": false
|
|
}
|
|
],
|
|
"attemptToConvertTypes": false,
|
|
"convertFieldsToString": true
|
|
},
|
|
"options": {}
|
|
},
|
|
"type": "n8n-nodes-base.executeWorkflow",
|
|
"typeVersion": 1.3,
|
|
"position": [
|
|
448,
|
|
208
|
|
],
|
|
"id": "175e270a-b1d9-41d0-981a-1f83258443b1",
|
|
"name": "Transmission: Get Session"
|
|
},
|
|
{
|
|
"parameters": {
|
|
"schema": {
|
|
"__rl": true,
|
|
"mode": "list",
|
|
"value": "public"
|
|
},
|
|
"table": {
|
|
"__rl": true,
|
|
"value": "download_history",
|
|
"mode": "list",
|
|
"cachedResultName": "download_history"
|
|
},
|
|
"columns": {
|
|
"mappingMode": "defineBelow",
|
|
"value": {
|
|
"mam_id": "={{ $json.original_input.mam_id }}",
|
|
"torrent_url": "={{ $('Extract Torrent ID').item.json.original_input.dl_link }}",
|
|
"book_id": "={{ null }}",
|
|
"torrent_hash": "={{ $json.torrent_hash }}",
|
|
"filename": "={{ $('Extract Torrent ID').item.json.torrent_name }}",
|
|
"status": "={{ $json.status }}",
|
|
"meta_title": "={{ $json.original_input.meta_title }}",
|
|
"meta_series": "={{ $json.original_input.meta_series }}",
|
|
"meta_book_number": "={{ $json.original_input.meta_book_number }}",
|
|
"meta_author": "={{ $json.original_input.meta_author }}"
|
|
},
|
|
"matchingColumns": [
|
|
"id"
|
|
],
|
|
"schema": [
|
|
{
|
|
"id": "id",
|
|
"displayName": "id",
|
|
"required": false,
|
|
"defaultMatch": true,
|
|
"display": true,
|
|
"type": "string",
|
|
"canBeUsedToMatch": true,
|
|
"removed": false
|
|
},
|
|
{
|
|
"id": "book_id",
|
|
"displayName": "book_id",
|
|
"required": false,
|
|
"defaultMatch": false,
|
|
"display": true,
|
|
"type": "string",
|
|
"canBeUsedToMatch": true
|
|
},
|
|
{
|
|
"id": "torrent_url",
|
|
"displayName": "torrent_url",
|
|
"required": true,
|
|
"defaultMatch": false,
|
|
"display": true,
|
|
"type": "string",
|
|
"canBeUsedToMatch": true
|
|
},
|
|
{
|
|
"id": "torrent_hash",
|
|
"displayName": "torrent_hash",
|
|
"required": true,
|
|
"defaultMatch": false,
|
|
"display": true,
|
|
"type": "string",
|
|
"canBeUsedToMatch": true
|
|
},
|
|
{
|
|
"id": "filename",
|
|
"displayName": "filename",
|
|
"required": true,
|
|
"defaultMatch": false,
|
|
"display": true,
|
|
"type": "string",
|
|
"canBeUsedToMatch": true
|
|
},
|
|
{
|
|
"id": "transmission_path",
|
|
"displayName": "transmission_path",
|
|
"required": false,
|
|
"defaultMatch": false,
|
|
"display": true,
|
|
"type": "string",
|
|
"canBeUsedToMatch": true
|
|
},
|
|
{
|
|
"id": "gateway_path",
|
|
"displayName": "gateway_path",
|
|
"required": false,
|
|
"defaultMatch": false,
|
|
"display": true,
|
|
"type": "string",
|
|
"canBeUsedToMatch": true
|
|
},
|
|
{
|
|
"id": "status",
|
|
"displayName": "status",
|
|
"required": false,
|
|
"defaultMatch": false,
|
|
"display": true,
|
|
"type": "string",
|
|
"canBeUsedToMatch": true
|
|
},
|
|
{
|
|
"id": "downloaded_at",
|
|
"displayName": "downloaded_at",
|
|
"required": false,
|
|
"defaultMatch": false,
|
|
"display": true,
|
|
"type": "dateTime",
|
|
"canBeUsedToMatch": true
|
|
},
|
|
{
|
|
"id": "created_at",
|
|
"displayName": "created_at",
|
|
"required": false,
|
|
"defaultMatch": false,
|
|
"display": true,
|
|
"type": "dateTime",
|
|
"canBeUsedToMatch": true
|
|
},
|
|
{
|
|
"id": "updated_at",
|
|
"displayName": "updated_at",
|
|
"required": false,
|
|
"defaultMatch": false,
|
|
"display": true,
|
|
"type": "dateTime",
|
|
"canBeUsedToMatch": true
|
|
},
|
|
{
|
|
"id": "meta_title",
|
|
"displayName": "meta_title",
|
|
"required": false,
|
|
"defaultMatch": false,
|
|
"display": true,
|
|
"type": "string",
|
|
"canBeUsedToMatch": true
|
|
},
|
|
{
|
|
"id": "meta_series",
|
|
"displayName": "meta_series",
|
|
"required": false,
|
|
"defaultMatch": false,
|
|
"display": true,
|
|
"type": "string",
|
|
"canBeUsedToMatch": true
|
|
},
|
|
{
|
|
"id": "meta_book_number",
|
|
"displayName": "meta_book_number",
|
|
"required": false,
|
|
"defaultMatch": false,
|
|
"display": true,
|
|
"type": "string",
|
|
"canBeUsedToMatch": true
|
|
},
|
|
{
|
|
"id": "meta_author",
|
|
"displayName": "meta_author",
|
|
"required": false,
|
|
"defaultMatch": false,
|
|
"display": true,
|
|
"type": "string",
|
|
"canBeUsedToMatch": true
|
|
},
|
|
{
|
|
"id": "mam_id",
|
|
"displayName": "mam_id",
|
|
"required": false,
|
|
"defaultMatch": false,
|
|
"display": true,
|
|
"type": "number",
|
|
"canBeUsedToMatch": true
|
|
},
|
|
{
|
|
"id": "error_log",
|
|
"displayName": "error_log",
|
|
"required": false,
|
|
"defaultMatch": false,
|
|
"display": true,
|
|
"type": "string",
|
|
"canBeUsedToMatch": true
|
|
}
|
|
],
|
|
"attemptToConvertTypes": false,
|
|
"convertFieldsToString": false
|
|
},
|
|
"options": {}
|
|
},
|
|
"type": "n8n-nodes-base.postgres",
|
|
"typeVersion": 2.6,
|
|
"position": [
|
|
2240,
|
|
128
|
|
],
|
|
"id": "5a79163a-a211-475c-b53e-79d086a4c9a7",
|
|
"name": "Insert rows in a table",
|
|
"credentials": {
|
|
"postgres": {
|
|
"id": "9grzZwW7Br6SzdV8",
|
|
"name": "n8n-media"
|
|
}
|
|
}
|
|
}
|
|
],
|
|
"connections": {
|
|
"Add Torrent to Transmission": {
|
|
"main": [
|
|
[
|
|
{
|
|
"index": 0,
|
|
"node": "Extract Torrent ID",
|
|
"type": "main"
|
|
}
|
|
]
|
|
]
|
|
},
|
|
"Extract Torrent ID": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "Insert rows in a table",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
},
|
|
"Start": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "Transmission: Get Session",
|
|
"type": "main",
|
|
"index": 0
|
|
},
|
|
{
|
|
"node": "Merge Session Context",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
},
|
|
"Merge Session to Files": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "MAM Get File HTTP Request",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
},
|
|
"Merge Session Context": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "Merge Session to Files",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
},
|
|
"MAM Get File HTTP Request": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "Prepare Transmission Payload",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
},
|
|
"Extract from File": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "Add Torrent to Transmission",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
},
|
|
"Prepare Transmission Payload": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "Extract from File",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
},
|
|
"Transmission: Get Session": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "Merge Session Context",
|
|
"type": "main",
|
|
"index": 1
|
|
}
|
|
]
|
|
]
|
|
},
|
|
"Insert rows in a table": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "Respond Complete",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
}
|
|
},
|
|
"settings": {},
|
|
"triggerCount": 0,
|
|
"versionId": "ea21c736-ae26-492b-aa4d-f1096fa4af15",
|
|
"owner": {
|
|
"type": "personal",
|
|
"projectId": "FeLO36wNUAcn61Wj",
|
|
"projectName": "Ben W <admin@ben.io>",
|
|
"personalEmail": "admin@ben.io"
|
|
},
|
|
"parentFolderId": "6tDyZCwqELStb6Ik",
|
|
"isArchived": false
|
|
} |