Build an extension
Extension let you extend Azot with your own features to create a custom downloading experience.
In this tutorial, you'll compile an extension example from source code and load it into Azot.
What you'll learn
After you've completed this tutorial, you'll be able to:
- Configure an environment for developing Azot extensions.
- Compile an extension from source code.
- Reload an extension after making changes to it.
Prerequisites
To complete this tutorial, you'll need:
- Git installed on your local machine.
- A local development environment for Node.js.
- A code editor, such as Visual Studio Code.
INFO
It is assumed that you are already familiar with JavaScript and TypeScript. Don't worry, you don't need to be an expert. If you need some help with the basics, check out TypeScript's Handbook and Mozilla's JavaScript Guide.
Step 1: Create a new extension project
Run the interactive scaffolder to create a starter project with TypeScript, azot/vitest, AGENTS.md, and a release workflow. Pass --match for Bitmovin so the test URL in Step 3 matches right away:
npx azot@beta init hello-world --match "https://*.bitmovin.com/*"For scripts or coding agents, pass flags and --yes to skip prompts:
npx azot@beta init hello-world --kind provider --match "https://*.bitmovin.com/*" --yes --jsonPrefer a template repository?
You can still clone or fork azot-labs/azot-extension-example if you prefer starting from a GitHub template repository.
Docs for coding agents
The azot npm package bundles the extension docs inside node_modules/azot/docs/ and node_modules/azot/SKILL.md. Online references are also available at /docs/llms.txt and /docs/llms-full.txt.
Step 2: Build the extension
In this step, you'll compile the extension so that Azot can load it.
- Navigate to the extension directory.
cd hello-world- Install dependencies.
npm installInstall azot@beta
The current Azot v5 is published under the beta tag. Plain npm i azot installs an outdated release from the latest tag. When adding Azot to your own project, install the beta:
npm i -D azot@beta- Compile the source code. The following command keeps running in the terminal and rebuilds the extension when you modify the source code.
npm run devNotice that the extension directory now has a dist/main.cjs file that contains a compiled version of the extension. Azot runs extensions as CommonJS, so main in package.json must point to a .cjs or .js file.
Step 3: Test and load the extension
While developing, you can inspect URLs without downloading media and load the folder in developer mode.
Fast local dry-run (no download): test your provider's
list()andresolve()directly from the extension directory:shnpx azot try https://bitmovin.com/demos/stream-test --jsonValidate metadata, bundle, permissions, and
manifest.json:shnpx azot checkCLI: pass
--extensionto a download, or add--dry-run --jsonto run with your Azot session and cookies without downloading bytes:shazot https://bitmovin.com/demos/stream-test --extension . --dry-run --json azot https://bitmovin.com/demos/stream-test --extension .Desktop: turn on Developer Mode in settings, then choose Load from folder in the extensions page. Azot remembers the folder while Developer Mode is on and reloads it automatically whenever
npm run devornpm run buildupdatesdist/ormanifest.json. While loaded, it replaces an installed extension with the same name.
You're now ready to use the extension in Azot. Next, we'll make some changes to the extension.
Step 4: Update the extension info
In this step, you'll rename the extension and describe which URLs it supports.
- Open
package.jsonin your code editor. - Change
nameto a unique identifier, such as "hello-world". The package name is the extension's identity. - Also fill in
description,authorandfundingfields with your information. - Rename the extension folder to match the extension's name.
- Open
main.tsand settitle,iconand the provider'smatchesin code. To show the title and description in the user's language, see Localization:
import { defineExtension, defineProvider } from "azot";
export default defineExtension({
title: "Hello world",
icon: "https://example.com/icon.png",
bitmovin: defineProvider({
matches: ["https://*.bitmovin.com/*"],
async list({ url }) {
return [];
},
}),
});- Run
npx azot manifest. It regeneratesmanifest.jsonfrom the code without a release build.azot buildandazot devregenerate it too,azot devafter every rebuild. Never editmanifest.jsonby hand. - Load the folder again to pick up the changes: run the next download with
--extension /path/to/hello-world, or choose Load from folder again in the desktop app.
Step 5: Update the source code
To let the user interact with your extension, add a prompt for desired stream format when user trying to download video.
Open
main.tsin your code editor.Import helpers from the
azotpackage and updatelist().
import { defineExtension, defineProvider, prompt } from "azot";
export default defineExtension({
title: "Hello world",
bitmovin: defineProvider({
matches: ["https://*.bitmovin.com/*"],
async list({ url }) {
const { format } = await prompt("Choose stream format", {
title: "Stream format",
form: {
format: {
type: "text",
title: "Format",
defaultValue: "dash",
},
},
});
// Injected fetch is cancelled with the operation, no signal needed.
const response = await fetch(`${url}?format=${format}`);
const body = await response.text();
const mpd = body.split("'").find((line) => line.endsWith(".mpd"));
if (!mpd) return [];
return [
{
kind: "video",
title: "Bitmovin Stream Test",
source: { url: mpd },
},
];
},
}),
});In the Azot CLI, run the command with URL that extension can handle.
azot https://bitmovin.com/demos/stream-test --extension /path/to/hello-worldYou can now see download progress after metadata fetching.
For providers, resolve(), sign-in, settings and the other module kinds, see Extension API.
Conclusion
In this tutorial, you've built your first Azot extension using the TypeScript API. You've modified the extension and reloaded it to reflect the changes inside Azot.