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-dlpis wrapped in a service module for clean use in your backend. - Use a unified
/process-urlroute 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.
