is there a youtube API that can assit to add scraped videos URl to a Youtube playlist using a BOT
import { url } from "inspector";
import { Context, Telegraf } from "telegraf";
import { getFilters, Item } from "ytsr";
import { toTitleCase } from "./helpers";
import { SearchResult } from "./interface";
import { youtubeSearch } from "./ytsr";
require("dotenv").config();
if (!process.env.BOT_TOKEN) {
throw new Error("BOT_TOKEN must be in your .env");
}
const bot = new Telegraf(process.env.BOT_TOKEN!);
bot.on("text", async (ctx: Context) => {
const text: string = ctx.message?.text
? ctx.message?.text
: ctx.update.message?.text || "";
console.log("user msg:", text);
let details = text.split(",");
details = details.map((item: string) => {
return item.trim();
});
details = details.filter(Boolean);
console.log(details);
let searchString = details[0];
let type = toTitleCase(details[1] || "");
let feature = details[2];
let duration = details[3];
let sortBy = details[4];
let searchResults = await youtubeSearch(
searchString,
type,
feature,
duration
);
console.log("Our videos ", searchResults);
/*
searchResults?.items.forEach((item: Item, index: number) => {
console.log("res:", item.type);
let message = "";
if (item.type == "playlist") {
message = `Title: ${item.title}`;
message += `\nUrl: ${item.url}`;
message += `\nLength: ${item.length}`;
} else if (item.type == "video") {
message = `Title: ${item.title}`;
message += `\nUrl: ${item.url}`;
message += `\nDuration: ${item.duration}`;
message += `\nIs Live: ${item.isLive}`;
message += `\nViews: ${item.views}`;
}
*/
return ctx.reply(searchResults!);
}
module.exports = function(robot: { logger: { warning: (arg0: string) => void; }; })
{
// OAUTH...
if (process.env.GOOGLE_OAUTH2_API_KEY == null) {
robot.logger.warning("Need GOOGLE_OAUTH2_API_KEY");
return;
}
if (process.env.GOOGLE_OAUTH2_API_SECRET == null) {
robot.logger.warning("Need GOOGLE_OAUTH2_API_SECRET");
return;
}
};
export { bot };
what i have done here is to scrape youtube url on telegram using a bot, after searching a keyword, the results should be filtered through categories such as videos,Features,duration,relevance the end results is a scraped filtred data only the url containing that data is obtained is there a way we can insert the urls into the playlist automatically thus creating a playlist, without needing of me adding videos manualy by hand to create the playlist