Implementing a Google Drive Video Downloader in TypeScript

Implementing Google Drive Downloader

Welcome to the first lesson in this course! In this unit, you'll build a system that allows users to preview, download, and transcribe videos directly from Google Drive URLs.

Heads-up:
Support for LinkedIn video downloads is also present in the codebase via a separate service. You’re welcome to try it now — but we’ll explore it in depth in Unit 2.

Overview

Here’s what you’ll accomplish in this unit:

  • Extract Google Drive File ID from URLs
  • Preview videos in-browser before downloading
  • Download the video using curl
  • Load and display the downloaded video for playback
  • Transcribe the first 30 seconds of audio using Whisper

Understanding Google Drive URL Formats

Google Drive URLs typically follow one of two structures:

  1. Direct file path
    https://drive.google.com/file/d/{fileid}/view

  2. Open ID parameter
    https://drive.google.com/open?id={fileid}

Both of these formats are supported by the application.

The getDriveFileId() function checks for both patterns:

function getDriveFileId(url) {
  // Match format: https://drive.google.com/file/d/FILEID/view
  const fileIdMatch = url.match(/\/file\/d\/([^/]+)/);
  // Match format: https://drive.google.com/open?id=FILEID
  const openIdMatch = url.match(/open\?id=([^&]+)/);
  return fileIdMatch?.[1] || openIdMatch?.[1] || null;
}

This approach ensures maximum compatibility with typical Google Drive sharing links.

Previewing the Video (before Download)

public/index.html

    <div id="previewFrame" class="flex-grow w-full relative overflow-hidden">
        <!-- iframe or video will be injected here -->
    </div>

public/app.js

function embedDriveVideo(fileId) {
  previewFrame.innerHTML = \`
    <div class="video-wrapper">
      <iframe
        src="https://drive.google.com/file/d/\${fileId}/preview"
        frameborder="0"
        allow="autoplay"
        allowfullscreen>
      </iframe>
    </div>
  \`;
}

The embedded iframe provides users a preview of the Drive-hosted video before they download it.

Handling the Load Button (Client Side)

public/app.js

const response = await fetch('/process-url', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ url })
});

When the user clicks "Load", the video URL is posted to /process-url, which in turn invokes the backend downloader service.

Sign up

Join the 1M+ learners on CodeSignal

Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal