Tutorials

Import video from URL with the DCAST API, from one link to a bulk video import

How to import a video from a URL through the DCAST API: send one link or a list, see which links are refused, and follow each import until the video is ready.

dcast Team
8 min read
Share:
cloud, finger, touch, cloud computing, data store, capacity, network, services, data, disk space, technical, concept, technol
On this page

If you already host video files somewhere, you do not need to download them and push them back up. The DCAST API can import a video from a URL: you give it the address of the file, and a DCAST server fetches the file for you. You can send a single link or a whole list in one request, and this article walks through what you send, what comes back, which links are refused and how you follow each import to the end.

Upload, stream and sell your videos. Start on the free plan β€” no card needed.

Get Started Free

The idea is simple. Instead of sending the bytes of a video yourself, you hand DCAST an address that answers with the file. A DCAST server then fetches the file on your behalf. That removes the slowest and most fragile part of a migration from your side: your own machine no longer has to hold the file open while it travels.

The import is its own operation in the partner API, separate from the ordinary upload request. With the ordinary upload you receive an address and send the file to it yourself with a PUT request. With an import you never touch the file at all. Which one you need depends on where the video lives today: if it sits on your laptop, upload it; if it already sits at a web address, import it.

Access comes through your API key. The import request needs a key that is allowed to write videos, and reading an import back needs a key that is allowed to read videos. Once the key is in place, your own code can run imports without anyone visiting the dashboard. Keep that key on your server and never place it in a page that your visitors load.

The operation you call is the one that creates a video import. For a single file you pass the link with a title, and optionally a description and a visibility. For a batch you pass a list of items, each with its own link and the same optional fields. You can also pass a plain list of addresses when you have nothing but links.

Because every accepted link becomes its own import, a bulk video import is not one big job that succeeds or fails as a whole. It is a set of independent imports that share a batch. The answer to your request is an acceptance, not a completion: it tells you what was taken in and what was turned away, and the downloading happens afterwards.

The answer carries a batch identifier, the list of imports that were accepted, and a list of rejected links. Keep the batch identifier and the import identifiers in your own database next to the source address of each file. When something goes wrong three hours later, you will want to know which of your records each import belongs to without guessing from titles.

The most common mistake is sending a page instead of a file. A link has to point at the video file itself. A watch page of a video site or a file page of a cloud drive is refused with a code saying it is a page, not a file. If you paste the address from your browser bar while watching a video, expect that refusal.

A streaming playlist address is refused as well, because an import takes one complete file. If your video is delivered as a playlist of segments, you need to find or produce the single file behind it before you can import it by link.

One convenience is built in for a popular case. A Dropbox sharing link is turned into its direct download form, so you can paste the link you already have instead of editing it by hand. Whatever host you use, test the address in a fresh browser session before you queue it: it should start downloading the file, not show you a screen.

Internal and private network addresses are refused before anything is fetched. If your files live on a server that is only reachable from inside your own network, DCAST cannot reach them, and the import will not even start. Put the file at an address that is reachable from the public internet, or upload it the ordinary way.

Reading refusals in a list by position

A bad link in a list does not spoil the others. The good links go ahead, and each refused link is named by its position in your list together with a reason code. Position means where the link sat in the list you sent, so your code can map every refusal straight back to your own record without matching strings.

A refused link creates nothing in your library, so there is nothing to clean up. That makes a sensible retry loop easy: read the rejected list, fix the addresses that need fixing, and send only those again as a new request. Do not resend the whole list, or the links that were accepted the first time will be imported a second time.

Each accepted link gets a video card in your library before the first byte is fetched, with the title you gave it. So the moment your request is answered, your library already shows the videos you are waiting for. This is why a clear title in each item is worth the effort: it is the label you and your colleagues will see while the file is still on its way.

Storage space for the file is claimed for your account before the download begins, and a file larger than the space you have left ends as a failed import with the reason. Before you queue a large batch, check how much room your account has, because the room still bounds each file, exactly as it does for any other upload.

Your links are fetched a few at a time, and each link that finishes or fails starts the next one waiting in your queue. You do not need to space your requests out or feed the queue slowly. Send the batch, and the queue moves along as imports finish. Do not promise your own users a delivery time for a given video, though, because how long a single import takes depends on the file and its source.

Track each import and handle failures

To follow one import, call the operation that reads an import by its identifier. It answers for an import that belongs to the owner of your key, and a position that is not yours is answered as not found. Poll it on a sensible interval from your server and store the outcome next to your own record.

A link that cannot be fetched ends as a failed import with its reason, for example that the source answered with an error, and its video card shows the failure too. So a failure is never silent: you can read it on the import, and anyone looking at the library sees it on the card. When you see a failure, check the source address first, since a login page or an expired link is the usual cause.

If the server fetching your file is lost, the import goes back to the queue and starts again on the same video card. You do not need to create a second import for it, and you will not end up with a duplicate card. Treat a slow import as something to watch rather than something to resubmit.

Before you show an imported video on your site, check its status. The video status operation reports the state of the video card, and it is the right gate for your gallery: show a video only when it reports that it is ready, and show a placeholder or nothing otherwise. An accepted import is a promise to try, not proof that a playable video exists.

Prepare your files before a bulk video import

Most failed imports are decided before you send anything. Host your files at addresses that answer with the file itself, without a login page in front of it. A server fetching on your behalf has no session in your browser, so anything that needs you to sign in first will not return a video.

Start with a small trial. Pick a handful of files, import them, and watch the whole path from acceptance to a ready video. You learn which of your addresses behave, and you see what your titles look like in the library. Only then queue the full catalogue. If you migrate from a video site that only offers watch pages, plan on exporting the files first, because a page address will be refused.

Finally, keep your own records simple. Store the source address, the batch identifier, the import identifier and the outcome for every file. With those four things, a bulk video import can be repeated, audited and repaired one link at a time, and your site can build its gallery from the library using the status of each video rather than from hope.

API documentation for this topic

d

dcast Team

Professional video streaming experts helping creators succeed.

Start Your Video Business Today

Upload, stream and sell your videos. Start on the free plan β€” no card needed.

Get Started Free