Download YouTube Playlist
Download all videos from a YouTube playlist. You can optionally download the audio and thumbnail images as well.
Prerequisites
You'll need a few things to use this project:
- This project uses Bun! Get that installed or feel free to edit the source code to use Node instead (it'll only be a few adjustments).
- You'll need a YouTube Data API key. Set that to the
API_KEY
env variable. - The yt-dlp command line tool needs to be present on your system. You can easily install it with a tool like Brew.
Usage
The type signature looks like this:
downloadYoutubePlaylist({
playlistId: string
youTubeApiKey: string
directory: string
downloadType: DownloadType
audioFormat?: string
videoFormat?: string
downloadThumbnails?: boolean
maxDurationSeconds?: number
mostRecentItemsCount?: number
silent?: boolean
timeZone?: string
maxConcurrentFetchCalls?: number
maxConcurrentYtdlpCalls?: number
saveRawResponses?: boolean
}): Promise<FailuresObj>
Folder Structure
Downloads will be organized into the following folder structure:
directory-you-provided
/<playlist name>
/video
<title> [<video id>].mp4
...
/audio
<title> [<video id>].mp3
...
/thumbnails
<video id>.jpg
...
metadata.json
youtubePlaylistResponses.json (only if `saveRawResponses` is true)
youtubeVideoResponses.json (only if `saveRawResponses` is true)
/video | This folder will contain all the video files (file extension is dependent upon `audioFormat` option). |
/audio | This folder will contain all the audio files (file extension is dependent upon `videoFormat` option). |
/thumbnails | This folder will contain all the jpg thumbnail files |
metadata.json | This file will contain an array of metadata on each video. See shape below |
youtubePlaylistResponses.json | This file will contain an array of raw responses from YouTube's PlaylistItems: list api. |
youtubeVideoResponses.json | This file will contain an array of raw responses from YouTube's Videos: list api. |
Metadata Shape
Each video will have metadata stored in the metadata.json
file with the following shape:
{
id: string
title: string
description: string
channelId: string
channelName: string
dateCreated: string
dateAddedToPlaylist: string
thumbnailUrl: string | null
durationInSeconds: number
url: string
channelUrl: string | null
audioFileExtension: string | null
videoFileExtension: string | null
isUnavailable: boolean
}