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:

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

Previewing the Video (before Download)

public/index.html

public/app.js

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

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

Backend Route: /process-url

The /process-url endpoint acts as a gateway to downloading supported video types.

src/routes/processUrl.ts

This route handles the logic to detect the video platform and invokes the corresponding Google Drive download service. If the platform is unsupported, a 400 error is returned. It validates the input, determines the platform, and calls the appropriate service. In this lesson, only Drive links are supported — LinkedIn is covered later in Unit 2.

Note: The video download is not a separate manual step—the /process-url route immediately downloads the video as part of its internal flow. The downloadGoogleDriveVideo() function handles this behind the scenes and also extracts the video's duration so it’s ready for transcription later.

The Google Drive Video Download Service

src/services/googleDriveService.ts

The service below handles the entire process of downloading a video from Google Drive and probing it for metadata (like duration). Let’s walk through the logic step by step.

Step 1: Extract the File ID from the URL

We first try to extract the file ID from the input URL. Google Drive URLs can have two formats:

  • /file/d/FILEID/view
  • open?id=FILEID

This code matches both formats and selects the one that exists. If no valid ID is found, the function rejects with an error.

Step 2: Create a Download Folder and Generate File Paths

Once we have the Drive file ID, we:

  • Build a direct download URL (using the undocumented /uc?export=download&id=... format)
  • Ensure a local downloads/ directory exists
  • Generate a unique .mp4 filename using a UUID (to avoid collisions)
  • Create the full path to where we’ll save the downloaded video
Step 3: Download the Video with curl

We use curl to download the file from Google Drive and save it to filePath. The -L flag follows redirects, and -o writes to the specified output file.

If the download fails, we immediately reject with an error. Otherwise, we move on to the next step.

Step 4: Probe the Video to Get Duration

After downloading, we run ffprobe (a tool from the FFmpeg suite) to get the video’s duration in seconds.

  • -v error: hides warnings
  • -select_streams v:0: selects the first video stream
  • -show_entries format=duration: extracts only the duration value

The result is parsed and returned along with the filename, so the frontend can know how long the video is and prepare for playback or transcription.

Playback in Native Player

public/app.js

Backend Route: /transcribe

Once a video is loaded, the frontend sends the file path to /transcribe, which performs the following steps:

  1. Checks if the video file exists
  2. Uses FFmpeg to clip the first 30 seconds of audio
  3. Converts the audio to mono 16kHz format
  4. Sends it to Whisper for transcription
  5. Deletes the temporary audio file

src/routes/transcribe.ts

This endpoint clips the first 30 seconds of the downloaded video, prepares the audio in the correct format, and sends it to Whisper for transcription. Once done, it cleans up the temporary .mp3 file and returns the transcription to the frontend.

Summary

In this lesson you:

  • Learned about both Drive URL formats and how to extract file IDs
  • Previewed videos using iframe embedding
  • Downloaded videos via /process-url using a backend service
  • Measured video duration using ffprobe
  • Implemented transcription logic via /transcribe using FFmpeg and Whisper

Next, we'll bring in LinkedIn support using yt-dlp to download social video posts.

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