@qodestack/dl-yt-playlist
Version:
Download all videos (or audio only) from a YouTube playlist!
284 lines (280 loc) • 10.4 kB
TypeScript
// Generated by dts-bundle-generator v9.5.1
import { youtube_v3 } from '@googleapis/youtube';
import { GaxiosResponse } from 'googleapis-common';
import { BaseIssue, InferInput, InferIssue } from 'valibot';
declare const PlaylistItemSchema: import("valibot").ObjectSchema<{
readonly id: import("valibot").StringSchema<undefined>;
readonly snippet: import("valibot").ObjectSchema<{
readonly resourceId: import("valibot").ObjectSchema<{
readonly videoId: import("valibot").StringSchema<undefined>;
}, undefined>;
readonly title: import("valibot").StringSchema<undefined>;
readonly description: import("valibot").StringSchema<undefined>;
readonly videoOwnerChannelId: import("valibot").OptionalSchema<import("valibot").StringSchema<undefined>, "">;
readonly videoOwnerChannelTitle: import("valibot").OptionalSchema<import("valibot").StringSchema<undefined>, "">;
readonly publishedAt: import("valibot").StringSchema<undefined>;
readonly thumbnails: import("valibot").ObjectSchema<{
readonly maxres: import("valibot").OptionalSchema<import("valibot").ObjectSchema<{
readonly url: import("valibot").StringSchema<undefined>;
}, undefined>, never>;
readonly standard: import("valibot").OptionalSchema<import("valibot").ObjectSchema<{
readonly url: import("valibot").StringSchema<undefined>;
}, undefined>, never>;
readonly high: import("valibot").OptionalSchema<import("valibot").ObjectSchema<{
readonly url: import("valibot").StringSchema<undefined>;
}, undefined>, never>;
readonly medium: import("valibot").OptionalSchema<import("valibot").ObjectSchema<{
readonly url: import("valibot").StringSchema<undefined>;
}, undefined>, never>;
readonly default: import("valibot").OptionalSchema<import("valibot").ObjectSchema<{
readonly url: import("valibot").StringSchema<undefined>;
}, undefined>, never>;
}, undefined>;
}, undefined>;
readonly contentDetails: import("valibot").ObjectSchema<{
readonly videoPublishedAt: import("valibot").OptionalSchema<import("valibot").StringSchema<undefined>, "">;
}, undefined>;
}, undefined>;
declare const VideosListItemSchema: import("valibot").ObjectSchema<{
readonly id: import("valibot").StringSchema<undefined>;
readonly contentDetails: import("valibot").ObjectSchema<{
readonly duration: import("valibot").StringSchema<undefined>;
}, undefined>;
}, undefined>;
declare const YtDlpJsonSchema: import("valibot").ObjectSchema<{
readonly id: import("valibot").StringSchema<undefined>;
readonly title: import("valibot").StringSchema<undefined>;
readonly description: import("valibot").StringSchema<undefined>;
readonly duration: import("valibot").NumberSchema<undefined>;
readonly channel_url: import("valibot").StringSchema<undefined>;
readonly channel_id: import("valibot").StringSchema<undefined>;
readonly upload_date: import("valibot").StringSchema<undefined>;
readonly channel: import("valibot").StringSchema<undefined>;
readonly ext: import("valibot").StringSchema<undefined>;
readonly requested_downloads: import("valibot").SchemaWithPipe<[
import("valibot").ArraySchema<import("valibot").ObjectSchema<{
readonly ext: import("valibot").StringSchema<undefined>;
}, undefined>, undefined>,
import("valibot").MinLengthAction<{
ext: string;
}[], 1, undefined>
]>;
}, undefined>;
declare const VideoSchema: import("valibot").ObjectSchema<{
/** listApi.snippet.resourceId.videoId */
readonly id: import("valibot").StringSchema<undefined>;
/** listApi.id */
readonly playlistItemId: import("valibot").StringSchema<undefined>;
/** listApi.snippet.title */
readonly title: import("valibot").StringSchema<undefined>;
/** listApi.snippet.description */
readonly description: import("valibot").StringSchema<undefined>;
/** listApi.snippet.videoOwnerChannelId */
readonly channelId: import("valibot").StringSchema<undefined>;
/** listApi.snippet.videoOwnerChannelTitle */
readonly channelName: import("valibot").StringSchema<undefined>;
/** listApi.contentDetails.videoPublishedAt */
readonly dateCreated: import("valibot").StringSchema<undefined>;
/** listApi.snippet.publishedAt */
readonly dateAddedToPlaylist: import("valibot").StringSchema<undefined>;
/** listApi.snippet.thumbnails[maxres | standard | high | medium | default].url */
readonly thumbnailUrls: import("valibot").ArraySchema<import("valibot").StringSchema<undefined>, undefined>;
/** videosApi.contentDetails.duration */
readonly durationInSeconds: import("valibot").NumberSchema<undefined>;
/** Constructed from `id` - URL to the video */
readonly url: import("valibot").StringSchema<undefined>;
/** Constructed from `channelId` - URL to the video owner's channel */
readonly channelUrl: import("valibot").NullableSchema<import("valibot").StringSchema<undefined>, never>;
/** Derived from yt-dlp */
readonly audioFileExtension: import("valibot").NullableSchema<import("valibot").StringSchema<undefined>, never>;
/** Derived from yt-dlp */
readonly videoFileExtension: import("valibot").NullableSchema<import("valibot").StringSchema<undefined>, never>;
/** Derived from the listApi missing certain fields */
readonly isUnavailable: import("valibot").BooleanSchema<undefined>;
/** LUFS value, as calculated by ffmpeg */
readonly lufs: import("valibot").NullableSchema<import("valibot").NumberSchema<undefined>, never>;
}, undefined>;
export type Video = InferInput<typeof VideoSchema>;
export type Failure = {
date: number;
} & ({
type: "Bun.write";
file: string;
error: Record<string, unknown>;
} | {
type: "schemaParse";
schemaName: "PlaylistItemSchema";
issues: InferIssue<typeof PlaylistItemSchema>[];
} | {
type: "schemaParse";
schemaName: "VideosListItemSchema";
issues: InferIssue<typeof VideosListItemSchema>[];
} | {
type: "schemaParse";
schemaName: "YtDlpJsonSchema";
issues: InferIssue<typeof YtDlpJsonSchema>[];
} | {
type: "videosListApi";
error: Record<string, unknown>;
ids: string[] | undefined;
} | {
type: "partialVideoNotFound";
id: string;
} | {
type: "ytdlpFailure";
url: string;
template: string;
stderr: string;
} | {
type: "thumbnailDownload";
url: string;
status: number;
statusText: string;
} | {
type: "thumbnailUrlNotAvailable";
urls: string[];
videoId: string;
} | {
type: "lufs";
filePath: string;
errorMessage: string;
} | {
type: "generic";
error: unknown;
context: string;
});
/**
* A function that takes in a list of ids (representing which videos we have
* metadata for from the Playlist API) and returns a filtered list of ids
* representing which videos to download from the Videos API.
*/
export type GetIdsForDownload = (ids: string[]) => string[] | Promise<string[]>;
export type DownloadOptions = {
downloadType: "audio";
audioFormat: string;
directory: string;
/**
* A function that takes in a list of ids (representing which videos we
* have metadata for from the Playlist API) and returns a filtered list of
* ids representing which videos to download from the Videos API.
*
* This function is run _after_ the call for playlist data and _before_
* the call for video data.
*/
getIdsForDownload: GetIdsForDownload;
downloadThumbnails: boolean;
} | {
downloadType: "video";
videoFormat: string;
directory: string;
/**
* A function that takes in a list of ids (representing which videos we
* have metadata for from the Playlist API) and returns a filtered list of
* ids representing which videos to download from the Videos API.
*
* This function is run _after_ the call for playlist data and _before_
* the call for video data.
*/
getIdsForDownload: GetIdsForDownload;
downloadThumbnails: boolean;
} | {
downloadType: "both";
audioFormat: string;
videoFormat: string;
directory: string;
/**
* A function that takes in a list of ids (representing which videos we
* have metadata for from the Playlist API) and returns a filtered list of
* ids representing which videos to download from the Videos API.
*
* This function is run _after_ the call for playlist data and _before_
* the call for video data.
*/
getIdsForDownload: GetIdsForDownload;
downloadThumbnails: boolean;
} | {
downloadType: "none";
};
export type DownloadYouTubePlaylistInput = {
playlistId: string;
youTubeApiKey: string;
maxDurationSeconds?: number;
mostRecentItemsCount?: number;
silent?: boolean;
timeZone?: string;
maxConcurrentYouTubeCalls?: number;
maxConcurrentYtdlpCalls?: number;
} & DownloadOptions;
export type DownloadYouTubePlaylistOutput = {
/**
* The raw responses from the YouTube
* [PlaylistItems API](https://developers.google.com/youtube/v3/docs/playlistItems).
*/
playlistItemListResponses: GaxiosResponse<youtube_v3.Schema$PlaylistItemListResponse>[];
/**
* The raw responses from the YouTube
* [VideosList API](https://developers.google.com/youtube/v3/docs/videos/list).
*/
videoListResponses: (GaxiosResponse<youtube_v3.Schema$VideoListResponse> | null)[];
/**
* Metadata for videos that were downloaded.
*/
videosDownloaded: Video[];
/**
* Metadata for videos that are no longer available due to either being
* deleted or made private.
*/
unavailableVideos: Video[];
/**
* Various failures incurred along the way.
*/
failures: Failure[];
/**
* An object detailing the number of downloads for `audio`, `video`, and
* `thumbnails`.
*/
downloadCount: DownloadCount;
/**
* The number of times the YouTube API was hit.
*/
youTubeFetchCount: number;
};
export type DownloadCount = {
audio: number;
video: number;
thumbnail: number;
};
export type SingleVideo = {
id: string;
title: string;
description: string;
channelId: string;
channelName: string;
duration: number;
url: string;
channelUrl: string;
videoFileExtension: string;
lufs: number | null;
};
export type SingleVideoFailure = {
type: "bunShell";
exitCode: number;
stderr: string;
} | {
type: "schemaParse";
issues: BaseIssue<unknown>[];
} | {
type: "lufs";
errorMessage: string;
};
export type DownloadYouTubeVideoInput = {
videoId: string;
directory: string;
};
export type DownloadYouTubeVideoOutput = {
video: SingleVideo | null;
failures: SingleVideoFailure[];
};
export declare function downloadYouTubeVideo({ videoId, directory, }: DownloadYouTubeVideoInput): Promise<DownloadYouTubeVideoOutput>;
export declare function downloadYouTubePlaylist(options: DownloadYouTubePlaylistInput): Promise<DownloadYouTubePlaylistOutput>;
export {};