Implementing LinkedIn Video Downloader with yt-dlp in TypeScript

Welcome to the second unit of the course! In the previous unit, you learned how to extract and preview videos from Google Drive, download them with curl, and transcribe them using FFmpeg and OpenAI Whisper. Now we’re extending our capabilities to support LinkedIn video downloads using yt-dlp — a powerful CLI tool for downloading from social platforms.

What You'll Learn

In this unit, you will:

  • Detect and validate different LinkedIn video URL formats.
  • Understand how yt-dlp is wrapped in a service module for clean use in your backend.
  • Use a unified /process-url route to delegate downloads to either Drive or LinkedIn services.
  • Preview LinkedIn video content and load it into a native player, ready for future transcription.
Recognizing LinkedIn Video URLs

LinkedIn videos often follow these formats:

  • Post-based:
    https://www.linkedin.com/posts/USERNAME_activity-VIDEO_ID
  • Feed-based:
    https://www.linkedin.com/feed/update/urn:li:activity:VIDEO_ID

To identify these, we use the following function in public/app.js:

This function iterates through known LinkedIn post ID patterns and extracts the first valid match. It enables reliable detection of various LinkedIn video link structures.

Previewing LinkedIn Videos in the Browser

We embed the video for preview using an iframe:

This function constructs an iframe URL using the extracted postId. The embedded player helps users verify that they’ve pasted a valid video URL before initiating a download.

Note: LinkedIn does not allow iframe embedding for all posts. Previews will only work for public or embed-enabled posts. Private posts or content shared by other users may not render in the iframe due to LinkedIn's content restrictions. If the preview frame remains blank, the video might still be downloadable using yt-dlp, even if it's not viewable in the browser.

A Unified Route: /process-url

Your backend has a /process-url route, responsible for handling both Google Drive and LinkedIn videos. Remember how in the previous unit we used this route to handle only the Google Drive video downloads? Now this route dynamically delegates the download based on the domain in the URL — keeping your logic modular and scalable.

Here’s how it works in src/routes/processUrl.ts:

Wrapping yt-dlp with downloadLinkedInVideo

Instead of embedding yt-dlp download logic directly in your route, we isolate it in a reusable backend service. Here's the full implementation:

Explanation:

  • Generates a unique filename using randomUUID()
  • Constructs and runs a yt-dlp command to download the LinkedIn video
  • Uses ffprobe to detect video duration
  • Resolves with the filename and duration — ready to be used in the frontend
  • Both the filename and duration are returned to the route handler so the file can be loaded and transcribed.

Why this structure works well:

  • Separation of concerns: Keeps your route logic clean by pushing download responsibilities into a dedicated service.
Summary

In this lesson, you:

  • Detected and extracted LinkedIn post IDs from different URL formats
  • Embedded LinkedIn video previews in the UI
  • Built a unified /process-url route that handles both Google Drive and LinkedIn
  • Isolated LinkedIn video download logic in a service using yt-dlp and ffprobe

With these patterns in place, you’re set up to handle multi-source video downloading cleanly and reliably. Let’s now move on to some hands-on practice!

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