{
  "name": "Media Encoder Workflow",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours",
              "hoursInterval": 9
            }
          ]
        }
      },
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [-784, -16],
      "id": "trigger-1",
      "name": "Schedule Trigger"
    },
    {
      "parameters": {
        "command": "=bash /mnt/storage/scripts/encode-media.sh"
      },
      "type": "n8n-nodes-base.ssh",
      "typeVersion": 1,
      "position": [-576, -16],
      "id": "ssh-1",
      "name": "Execute Command",
      "credentials": {
        "sshPassword": {
          "id": "cred-ssh-placeholder",
          "name": "SSH Homelab Server"
        }
      },
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "dataTableId": {
          "__rl": true,
          "value": "datatable-placeholder-id",
          "mode": "list",
          "cachedResultName": "Encoded Media",
          "cachedResultUrl": "/projects/example-project/datatables/datatable-placeholder-id"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Files_Converted": "={{ $json.table_row.files_converted }}",
            "Space_Saved": "={{ $json.table_row.space_saved_gb }}",
            "Successful": "={{ $json.table_row.successful }}",
            "Failed": "={{ $json.table_row.failed }}",
            "Skipped": "={{ $json.table_row.skipped }}",
            "Files": "={{ $json.table_row.files }}"
          },
          "schema": [
            { "id": "Files", "displayName": "Files", "type": "string" },
            { "id": "Files_Converted", "displayName": "Files_Converted", "type": "number" },
            { "id": "Space_Saved", "displayName": "Space_Saved", "type": "number" },
            { "id": "Successful", "displayName": "Successful", "type": "number" },
            { "id": "Failed", "displayName": "Failed", "type": "number" },
            { "id": "Skipped", "displayName": "Skipped", "type": "number" }
          ]
        }
      },
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1,
      "position": [-176, -16],
      "id": "datatable-1",
      "name": "Data Table"
    },
    {
      "parameters": {
        "jsCode": "const execOutput = $input.first().json;\nconst stdout = execOutput.stdout || \"\";\n\nlet result;\ntry {\n  const matches = [...stdout.matchAll(/\\{[\\s\\S]*?\\}(?=\\s*\\{|\\s*$)/g)];\n  if (matches.length === 0) throw new Error(\"No JSON found in stdout\");\n  const lastJson = matches[matches.length - 1][0];\n  result = JSON.parse(lastJson);\n} catch (error) {\n  return [{ json: { status: \"error\", message: \"Failed to parse script output\", error: error.message, raw_output: stdout } }];\n}\n\nconst summary = result.summary || {};\nconst filesProcessed = result.files_processed || [];\n\nconst totalActivity = (summary.successful || 0) + (summary.failed || 0) + (summary.skipped || 0);\nif (totalActivity === 0) return [];\n\nconst table_row = {\n  files: filesProcessed.map(f => f.filename).join(\", \") || \"None\",\n  space_saved_gb: ((summary.total_saved_mb || 0) / 1024).toFixed(2),\n  files_converted: summary.successful || 0,\n  successful: summary.successful || 0,\n  failed: summary.failed || 0,\n  skipped: summary.skipped || 0\n};\n\nreturn [{ json: { table_row, summary, files_processed: filesProcessed } }];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [-368, -16],
      "id": "code-1",
      "name": "Parse JSON"
    }
  ],
  "connections": {
    "Schedule Trigger": {
      "main": [[{ "node": "Execute Command", "type": "main", "index": 0 }]]
    },
    "Execute Command": {
      "main": [[{ "node": "Parse JSON", "type": "main", "index": 0 }]]
    },
    "Parse JSON": {
      "main": [[{ "node": "Data Table", "type": "main", "index": 0 }]]
    }
  },
  "active": true,
  "settings": { "executionOrder": "v1" },
  "versionId": "version-placeholder-id",
  "meta": { "instanceId": "instance-placeholder-id" },
  "id": "workflow-placeholder-id",
  "tags": []
}
