Your First FeaturePack
Create a loadable FeaturePack from scratch.
Use http_pack as a template to create a Pack that handles a custom protocol.
Create the directory
Create a new directory under features/:
cp -r features/http_pack features/my_packRemove unnecessary files and keep pack.py.
Define the Pack class
from app.models.pack import FeaturePack, TaskParser
class MyPack(FeaturePack):
packId = "my_pack"
parsers = [MyParser]packId is globally unique. parsers lists all Parser instances provided by this Pack.
Implement the Parser
from app.models.task import Task, TaskOptions
from urllib.parse import urlparse
class MyParser(TaskParser):
priority = 40 # Lower number = checked first
def match(self, options: TaskOptions) -> bool:
return urlparse(options.url).hostname == "example.com"
async def parse(self, options: TaskOptions) -> Task:
# Build and return a Task
task = HttpTask(
name="example.zip",
url=options.url,
fileSize=0,
outputFolder=options.outputFolder,
)
task.addStep(HttpTaskStep(...))
return task- When
match()returnsTrue, this Parser takes over the URL. parse()parses the URL into an executable Task.- The lower
priorityis, the earlier it is checked. The HTTP fallback Parser is 100.
Add manifest.toml
Create manifest.toml under features/my_pack/:
[pack]
entry = "pack.py"
class = "MyPack"
dependencies = ["http_pack"]entry- the entry file nameclass- the Pack class name in the entry filedependencies- names of other Pack directories it depends on (loaded in topological order, dependencies first)
At startup, FeatureService.load() automatically scans the features/ directory, reads each subdirectory's manifest.toml, and loads it. No manual registration is required.
Test
Start the app and paste an example.com link. If the Parser matches correctly, a confirmation window appears.
Complete API: API Reference. More capabilities (Card, BinaryRuntime, PackPage): Capabilities Guide.