Implementing a LinkedIn Video Downloader with yt-dlp in TypeScript

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:

function getLinkedInPostId(url) {
  const patterns = [
    /activity-(\d+)/, // Matches /posts/..._activity-123456
    /urn:li:activity:(\d+)/, // Matches urn:li:activity:123456
    /urn:li:ugcPost:(\d+)/ // Matches urn:li:ugcPost:123456
  ];
  for (const pattern of patterns) {
    const match = url.match(pattern);
    if (match) return match[1];
  }
  return null;
}

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:

function embedLinkedInPost(postId) {
  previewFrame.innerHTML = \`
    <div class="video-wrapper">
      <iframe
        src="https://www.linkedin.com/embed/feed/update/urn:li:activity:\${postId}"
        frameborder="0"
        allow="autoplay; encrypted-media"
        allowfullscreen>
      </iframe>
    </div>
  \`;
}

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.

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