Cotton code
465 lines · 10.4 KB · JSONRaw
{  "format_version": 1,  "id": "fetch",  "name": "Download",  "plural": "Downloads",  "picture": null,  "builtin": false,  "visibility": "owner",  "engine": null,  "columns": [    {      "key": "source",      "name": "Link",      "type": "text",      "required": true,      "placeholder": "A magnet, a .torrent, a file's link or a page"    },    {      "key": "title",      "name": "Title",      "type": "text",      "placeholder": "Filled by the Mac from what it fetches"    },    {      "key": "picture",      "name": "Picture",      "type": "photo",      "readonly": true    },    {      "key": "wants",      "name": "Wants",      "type": "choice",      "choices": [        "video",        "audio",        "files"      ],      "labels": {        "video": "Video",        "audio": "Audio only",        "files": "Files"      }    },    {      "key": "state",      "name": "State",      "type": "choice",      "readonly": true,      "choices": [        "queued",        "fetching",        "landing",        "done",        "failed",        "cancelled"      ],      "labels": {        "queued": "Waiting for the Mac",        "fetching": "Fetching",        "landing": "Landing",        "done": "Done",        "failed": "Failed",        "cancelled": "Cancelled"      },      "default": "queued"    },    {      "key": "source_kind",      "name": "Kind of link",      "type": "choice",      "readonly": true,      "choices": [        "torrent",        "page",        "file"      ],      "labels": {        "torrent": "Torrent",        "page": "Page",        "file": "File"      }    },    {      "key": "progress",      "name": "Fetched",      "type": "number",      "readonly": true,      "units": {        "one": "{n}%",        "other": "{n}%"      }    },    {      "key": "bytes",      "name": "Fetched so far",      "type": "number",      "format": "bytes",      "readonly": true    },    {      "key": "of_bytes",      "name": "Size",      "type": "number",      "format": "bytes",      "readonly": true    },    {      "key": "speed_bps",      "name": "Speed",      "type": "number",      "format": "bytes",      "readonly": true,      "units": {        "one": "{n}/s",        "other": "{n}/s"      }    },    {      "key": "eta_seconds",      "name": "Time left",      "type": "number",      "format": "duration",      "readonly": true    },    {      "key": "files",      "name": "Files",      "type": "number",      "readonly": true    },    {      "key": "landed_count",      "name": "Landed",      "type": "number",      "readonly": true,      "units": {        "one": "{n} record",        "other": "{n} records"      }    },    {      "key": "stage_line",      "name": "Where it is",      "type": "text",      "readonly": true    },    {      "key": "stage",      "name": "Stage",      "type": "choice",      "readonly": true,      "hidden": true,      "choices": [        "converting",        "sending",        "sending_original",        "smaller_copies",        "waiting"      ],      "labels": {        "converting": "Converting · {done} of {of} min",        "sending": "Sending · {done} of {of} files",        "sending_original": "Sending the original · {done} of {of} GB",        "smaller_copies": "Making smaller copies · {done} of {of} min",        "waiting": "Waiting for the server since {since}"      }    },    {      "key": "stage_done",      "name": "Stage done",      "type": "number",      "readonly": true,      "hidden": true    },    {      "key": "stage_of",      "name": "Stage total",      "type": "number",      "readonly": true,      "hidden": true    },    {      "key": "stage_at",      "name": "Stage last moved",      "type": "date",      "format": "calendar-datetime",      "readonly": true,      "hidden": true    },    {      "key": "error",      "name": "Why it failed",      "type": "text",      "readonly": true    },    {      "key": "machine",      "name": "Mac",      "type": "text",      "readonly": true    },    {      "key": "added_on",      "name": "Added",      "type": "date",      "format": "calendar-datetime",      "readonly": true    },    {      "key": "started_on",      "name": "Started",      "type": "date",      "format": "calendar-datetime",      "readonly": true    },    {      "key": "finished_on",      "name": "Finished",      "type": "date",      "format": "calendar-datetime",      "readonly": true    },    {      "key": "again_on",      "name": "Fetched again",      "type": "date",      "format": "calendar-datetime",      "readonly": true,      "hidden": true    },    {      "key": "again_outcome",      "name": "How fetching it again went",      "type": "choice",      "readonly": true,      "hidden": true,      "choices": [        "landed",        "failed",        "cancelled"      ],      "labels": {        "landed": "Landed",        "failed": "Failed",        "cancelled": "Cancelled"      }    },    {      "key": "again_error",      "name": "Why fetching it again failed",      "type": "text",      "readonly": true,      "hidden": true    },    {      "key": "in_hidden",      "name": "In Hidden",      "type": "bool",      "readonly": true,      "hidden": true    }  ],  "seal": {    "clear": [      "picture",      "wants",      "state",      "source_kind",      "progress",      "bytes",      "of_bytes",      "speed_bps",      "eta_seconds",      "files",      "landed_count",      "machine",      "added_on",      "started_on",      "finished_on",      "again_on",      "again_outcome",      "stage_line",      "stage",      "stage_done",      "stage_of",      "stage_at"    ],    "blind": [      "title"    ]  },  "title": "title",  "date": "added_on",  "project": null,  "order": null,  "slip": {    "title": "title",    "subtitle": [      "stage_line",      "state"    ],    "trailing": "progress",    "photo": "picture",    "toggle": null,    "subtitle_first": true  },  "tile": {    "face": "slip-list"  },  "page": [    {      "heading": null,      "columns": [        "picture",        "title",        "state",        "stage_line",        "progress",        "error",        "landed_count"      ]    },    {      "heading": "Fetch",      "columns": [        "source",        "source_kind",        "wants",        "bytes",        "of_bytes",        "speed_bps",        "eta_seconds",        "files",        "machine",        "added_on",        "started_on",        "finished_on"      ]    }  ],  "sort": {    "column": "added_on",    "descending": true  },  "empty": {    "title": "Nothing fetched yet",    "message": "Give Plus a link: a magnet, a .torrent, a file's link or a video page. The Mac fetches it and each file lands in the tool that plays it."  },  "create": {    "label": "Fetch a link",    "doors": [      {        "id": "link",        "label": "Fetch a link",        "object": "parcel",        "act": {          "name": "fetch_add",          "argument": "source",          "lands": "fetch",          "signed_out": "Sign in to fetch links on your Mac"        }      }    ]  },  "instructions": "One row per link the owner wants as an owned file: a magnet, an http(s) link to a .torrent or to a file, or a page any of the sites yt-dlp reads. Make one with create_record { table: fetch, data: { source } } or the fetch_add act; wants is video (the default for a page), audio (the sound alone) or files (the default for a torrent or a file). The Mac fetches it (pnpm fetch:run): it claims the row (state fetching), says its progress, lands every file in the tool that plays it (a video a film, a sound a song, an EPUB or PDF a book, a picture a photo, anything else a document), makes one fetch_file row per record it landed (each linking the record in its own tool) and says done; or failed, with the fetcher's reason in error. cancel stops the Mac's job while the row waits or fetches, retry queues a failed or cancelled row again, and remove takes a done, failed or cancelled row off the list (the records it landed stay in their tools). fetch_again queues a done row once more, its link untouched, so the films it landed come back keeping their originals: again_on is when it was asked, again_outcome how that second fetch went (landed, failed or cancelled; empty while it runs) and again_error the fetcher's reason in one sentence; a second fetch that fails or is cancelled leaves the row done, its landed records still linked. Cotton never strips a lock: a site behind DRM fails and says so. Never write state, progress or the landed links by hand.",  "commands": [    {      "id": "cancel",      "label": "Cancel",      "kind": "update",      "method": "object.act",      "data": {        "act": "fetch_cancel"      },      "bindings": {        "fetch": "$id"      },      "when": {        "state": [          "queued",          "fetching",          "landing"        ]      },      "receipt": "Cancelled {name}",      "object": "cross"    },    {      "id": "retry",      "label": "Try again",      "kind": "update",      "method": "object.act",      "data": {        "act": "fetch_retry"      },      "bindings": {        "fetch": "$id"      },      "when": {        "state": [          "failed",          "cancelled"        ]      },      "receipt": "Fetching {name} again",      "object": "loop"    },    {      "id": "remove",      "label": "Remove",      "kind": "delete",      "verb": "delete_record",      "data": {        "table": "fetch"      },      "bindings": {        "id": "$id"      },      "when": {        "state": [          "done",          "failed",          "cancelled"        ]      },      "confirm": "The files it landed stay in their tools. Undo on the receipt brings it back.",      "receipt": "Removed {name}",      "does": "destroys",      "object": "bin"    }  ],  "card": {    "face": "plain",    "fields": [      {        "slot": "photo",        "column": "picture"      },      {        "slot": "title",        "column": "title"      },      {        "slot": "subtitle",        "column": "state",        "also": [          "stage_line"        ]      },      {        "slot": "body",        "column": "error"      },      {        "slot": "facts",        "column": "progress",        "also": [          "landed_count",          "of_bytes"        ]      }    ]  }}