Skip to main content
Apps that follow creators (a clip tool, a search index over a channel, an archive) need every new upload as a file soon after it’s posted, with nobody pasting links. Importly takes one link per video and rejects channel and playlist pages, so the work is turning the channel into links and sending each one once. This Node script reads the channel’s public feed, sends each new video to POST /import with its captions, and keeps track in SQLite. Run it every 10 to 20 minutes from cron, a scheduled worker or a platform’s cron job: each run saves the imports that finished, then starts the videos that are new. The same script in Python is New channel videos in Python.

The code

import-channel.mjs
Create your key on the API key page (it’s shown once) and keep it on the server. Connect your bucket once before the first run: the steps for S3, R2, B2 and Spaces are in Deliver to your bucket. Without a bucket, leave out store and the storage fields and copy each file from mediaUrl instead.

How it works

The channel’s feed is public and needs no YouTube API key. https://www.youtube.com/feeds/videos.xml?channel_id=<id> is an Atom feed of the channel’s 15 most recent uploads, newest first. Each <entry> has a <yt:videoId>, a title and a publish time, and the script builds a plain watch URL from the id. As long as it runs more often than the channel posts 15 videos, nothing is missed. Shorts are in the same feed, and their entry’s link is a /shorts/ URL. The script skips them by default; set SKIP_SHORTS=0 to import them too. Importly takes Shorts links like any other video. Each video is sent once. The video id is the primary key, so a re-run skips everything already started, finished or failed. A run never waits on a long download: imports still in progress are collected by the next run. The first run starts the 5 newest videos in the feed and the rest follow over the next two runs. To start from today instead, insert the current feed’s ids as completed before the first run. maxCostDollars caps each video. Downloads are $0.002 per MB, so a 10-minute 720p video is about $0.15, and the default of $1.00 covers about an hour of 720p. A longer video fails with `MAX_COST_EXCEEDED` before anything is downloaded and costs only $0.003 for the price check. Raise the cap, or send includeVideo: false for audio only, if the channel posts long streams. includeTranscript: true adds the video’s captions to the same job for $0.003. When a video has no captions, the import still succeeds and `transcript` is `{ "status": "skipped", "reason": "…" }`, so the script stores no text. To get speech-to-text for those, add `transcriptProvider: 'importly'` ($0.01 per minute). See Transcripts inside an import. Live streams show up in the feed while they’re live. They fail with LIVE_NOT_SUPPORTED and nothing is charged; the script sends them again an hour later, up to 3 tries.

What gets stored

A finished job from GET /import/status has the file under result. The script stores the bucket key from s3Storage, the mediaUrl, the transcript text and totalCostInDollars:
mediaUrl expires after 7 days; the copy in your bucket is yours to keep. If the copy to your bucket fails, the import still succeeds and s3StorageError says why. The script saves it in error.

Errors to handle

Every error has a documentationUrl with the fix. See Error handling.

In production

Use a webhook instead of polling. Pass a webhookUrl when you start each import and save the result when Importly calls you back. Keep the status check as a fallback: each job gets one delivery, with no retries. See Webhooks. Running on a host without a persistent disk (serverless functions, most container platforms)? channel.db is gone on the next deploy. Keep the same table in your app’s Postgres or another database; the queries don’t change. To hand each video to a queue worker instead, see BullMQ. Many channels? Loop over their ids in the same run, with a channel_id column in the table. A 429 just moves the rest to the next run, and Batch imports shows a steady sender for larger volumes. An app that imports around the clock shouldn’t stop when credit runs out. Turn on auto top-up, or watch for the low-balance emails.
A 10-minute 720p video with its captions costs about $0.16, and status checks are free. Try it free, no card required. See Pricing & credits.