yt-dlx
Version:
Effortless Audio-Video Downloader And Streamer!
69 lines • 3.29 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = subscriptions_feed;
const colors_1 = __importDefault(require("colors"));
const zod_1 = require("zod");
const TubeLogin_1 = __importDefault(require("../../utils/TubeLogin"));
const sanitizeContentItem_1 = __importDefault(require("../../utils/sanitizeContentItem"));
const ZodSchema = zod_1.z.object({ cookies: zod_1.z.string(), verbose: zod_1.z.boolean().optional() });
async function subscriptions_feed({ cookies, verbose = false }) {
try {
ZodSchema.parse({ cookies, verbose });
if (verbose)
console.log(colors_1.default.green("@info:"), "Fetching subscriptions feed...");
if (!cookies) {
throw new Error(`${colors_1.default.red("@error:")} Cookies not provided!`);
}
const client = await (0, TubeLogin_1.default)(cookies);
if (!client) {
throw new Error(`${colors_1.default.red("@error:")} Could not initialize Tube client.`);
}
const feed = await client.getSubscriptionsFeed();
if (!feed) {
throw new Error(`${colors_1.default.red("@error:")} Failed to fetch subscriptions feed.`);
}
const contents = feed.contents?.map((item) => {
const sanitized = (0, sanitizeContentItem_1.default)(item);
return {
type: sanitized?.type || "",
title: sanitized?.title?.text || "",
videoId: sanitized?.videoId || "",
thumbnails: sanitized?.thumbnails || [],
description: sanitized?.description?.text || "",
authorId: sanitized?.author?.id || "",
authorName: sanitized?.author?.name || "",
authorThumbnails: sanitized?.author?.thumbnails || [],
authorBadges: sanitized?.author?.badges || [],
authorUrl: sanitized?.author?.url || "",
viewCount: sanitized?.view_count?.text || "",
shortViewCount: sanitized?.short_view_count?.text || "",
};
}) || [];
const result = { status: "success", data: { contents } };
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 result;
}
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=SubscriptionsFeed.js.map