Skip to main content
Apps that follow creators, such as a clip tool, a search index over a channel, or an archive, need every new upload as a file soon after it’s posted, without anyone pasting links. Importly takes one link per video and rejects channel and playlist pages, so the job is to turn the channel into links and send each one once. This script reads the channel’s public feed, sends each new video to POST /import with its captions, and records the result in SQLite. Run it from cron or a scheduled worker every 10 to 20 minutes: each run collects the imports that finished and starts the videos that are new.

The code

import_channel.py
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> lists the channel’s 15 most recent uploads, newest first, each with its video id, title and publish time. The script builds a plain watch URL from each id. Run it more often than the channel posts 15 videos and nothing is missed. Shorts are in the same feed, with /shorts/ links. 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 key in SQLite, so a re-run skips everything already started, finished or failed. Unfinished imports are picked up by the next run, so no run waits on a long download. The first run starts the 5 newest videos in the feed; the rest of the feed follows 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 set "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 appear 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. 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.