24 lines
626 B
TypeScript
24 lines
626 B
TypeScript
import { YouTube } from "../../deps.ts";
|
|
import { getYoutubeSources } from "./youtube.ts";
|
|
|
|
import { isPlaylist } from "../../../utils.ts";
|
|
|
|
export type LoadSource = typeof loadLocalOrYoutube;
|
|
|
|
export async function loadLocalOrYoutube(query: string, guildId: bigint, added_by?: string) {
|
|
const queries = [];
|
|
|
|
if(isPlaylist(query))
|
|
{
|
|
const playlist = await YouTube.getPlaylist(query);
|
|
for(const video of playlist.videos) {
|
|
const videoId = video.id ? video.id : "";
|
|
queries.push(videoId);
|
|
}
|
|
} else {
|
|
queries.push(query);
|
|
}
|
|
|
|
return getYoutubeSources(guildId, String(added_by), queries);
|
|
}
|