yt-dlx
Version:
Effortless Audio-Video Downloader And Streamer!
60 lines • 2.83 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = playlist_data;
const colors_1 = __importDefault(require("colors"));
const zod_1 = require("zod");
const youtubei_1 = require("youtubei");
const YouTubeId_1 = __importDefault(require("../../../utils/YouTubeId"));
const ZodSchema = zod_1.z.object({ playlistLink: zod_1.z.string().min(2), verbose: zod_1.z.boolean().optional() });
async function playlistVideos({ playlistId }) {
try {
const youtube = new youtubei_1.Client();
const playlistVideosData = await youtube.getPlaylist(playlistId);
if (!playlistVideosData) {
throw new Error(`${colors_1.default.red("@error: ")} Unable to fetch playlist data.`);
}
const result = playlistVideosData.videos.items.map((item) => ({ id: item.id, title: item.title, isLive: item.isLive, duration: item.duration, thumbnails: item.thumbnails }));
return { id: playlistVideosData.id, title: playlistVideosData.title, videoCount: playlistVideosData.videoCount, result };
}
catch (error) {
throw new Error(`${colors_1.default.red("@error: ")} ${error.message}`);
}
}
async function playlist_data({ playlistLink, verbose }) {
try {
ZodSchema.parse({ playlistLink, verbose });
const playlistId = await (0, YouTubeId_1.default)(playlistLink);
if (!playlistId) {
throw new Error(`${colors_1.default.red("@error: ")} Incorrect playlist link provided.`);
}
const metaData = await playlistVideos({ playlistId });
if (!metaData) {
throw new Error(`${colors_1.default.red("@error: ")} Unable to retrieve playlist information.`);
}
if (verbose)
console.log(colors_1.default.green("@info:"), "❣️ Thank you for using yt-dlx. Consider 🌟starring the GitHub repo https://github.com/yt-dlx.");
return { data: metaData };
}
catch (error) {
if (error instanceof zod_1.ZodError) {
const errorMessage = `${colors_1.default.red("@error:")} Argument validation failed: ${error.errors.map(e => `${e.path.join(".")}: ${e.message}`).join(", ")}`;
console.error(errorMessage);
throw new Error(errorMessage);
}
else if (error instanceof Error) {
console.error(error.message);
throw error;
}
else {
const unexpectedError = `${colors_1.default.red("@error:")} An unexpected error occurred: ${String(error)}`;
console.error(unexpectedError);
throw new Error(unexpectedError);
}
}
finally {
}
}
//# sourceMappingURL=Single.js.map