DynTube API
  • Welcome!
  • Key Concepts
  • Quick Start
  • Reference
    • Videos
      • Video Upload via File (Server Side)
      • Video Upload via URL (server side)
      • HTML-Form Client Side Video Uploads
      • Get Video Status
      • Get Videos
      • Get Video
      • Update Video
      • Delete Video
      • Download Original Video
      • Get Video for Mobile App/Custom Player
      • Update Video Image
      • Add Video Captions/Chapters/Subtitles
      • Delete Video Captions/Subtitles/Chapters
      • Create Expirable Links
      • Get Collected Emails
      • Setting Up Webhooks
      • Copy call-to-action (CTA) to Videos
      • Token Authentication
    • Projects
      • Create Project
      • Update a Project
      • Get Projects
      • Get a Project
      • Delete a Project
      • Set default CTA for Project
    • Live Streaming
      • Create a Live Stream
      • Update a Live Stream
      • Get Live Streams
      • Get a Live Stream
      • Count Live Streams
      • Live Streams Limit
      • Get Live Streaming Recording
      • Delete a Live Stream
      • Service and Regions for live streams
    • Channels
      • Get Channels
      • Get Channel
      • Delete Channel
    • Subscriptions
      • Create a Plan
      • Create a Member
      • Attach Plan To Member
      • Get Plans
      • Get Members
      • Get Member's Plans
      • Delete a Plan
    • Analytics
      • Use your User Ids in Analytics
      • Get Video Analytics
    • Javascript Events Methods
      • Plain Javascript Events & Methods
      • Control the Player using React
      • Control the Player in Vue.js
    • Developer Resources
      • How to embed DynTube player in Next.Js
      • How to embed the video player in React
      • How to play DynTube videos in React Native
      • ExoPlayer app to play HLS videos
      • How to embed videos & channels dynamically
      • How to Import Vimeo Videos into DynTube
Powered by GitBook
On this page
  1. Reference
  2. Developer Resources

How to Import Vimeo Videos into DynTube

You can utilize the following JavaScript code to seamlessly import your Vimeo videos into DynTube.

import { Vimeo } from '@vimeo/vimeo';
import fetch from 'node-fetch';
import { FormData } from 'formdata-node';

const vimeoClient = new Vimeo("VIMEO_CLIENT", "VIMEO_SECRET", "VIMEO_ACCESS_TOKEN");

async function fetchVimeoVideo(vimeoVideoId) {
  return new Promise((resolve, reject) => {
    vimeoClient.request({
      method: 'GET',
      path: `/videos/${vimeoVideoId}`,
    }, (error, body) => error ? reject(error) : resolve(body));
  });
}

function getMp4Link(video) {
  return video.download?.sort((a, b) => b.width - a.width)
    .find(file => file.type === 'video/mp4')?.link || '';
}

async function uploadToDynTube(videoMp4Link, apiKey) {
  const form = new FormData();
  form.append('url', videoMp4Link);

  const response = await fetch('https://upload.dyntube.com/v1/videos', {
    method: 'POST',
    headers: { 'Authorization': `Bearer ${apiKey}` },
    body: form,
  });

  console.log(await response.text());
}

async function processVimeoVideo(vimeoVideoId, apiKey) {
  try {
    const video = await fetchVimeoVideo(vimeoVideoId);
    const videoMp4Link = getMp4Link(video);

    videoMp4Link
      ? await uploadToDynTube(videoMp4Link, apiKey)
      : console.log('No MP4 link found.');
  } catch (error) {
    console.error(`Error: ${error.message}`);
  }
}

// Usage
processVimeoVideo('[VIMEO_VIDEO_ID]', '[DYNTUBE_API_KEY]');
PreviousHow to embed videos & channels dynamically

Last updated 8 months ago