Skip to content

Commit

Permalink
Use an agent to support cookies when fetching youtube streams
Browse files Browse the repository at this point in the history
  • Loading branch information
nukeop committed Sep 17, 2024
1 parent 7912564 commit 0a92bb1
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/core/src/rest/Youtube.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export type YoutubeResult = {
}

const baseUrl = 'http://www.youtube.com/watch?v=';
const agent = ytdl.createAgent();

function isValidURL(str) {
const pattern = new RegExp('^(https?:\\/\\/)' + // protocol
Expand Down Expand Up @@ -84,7 +85,7 @@ export async function handleYoutubePlaylist(url: string): Promise<YoutubeResult[
}

async function handleYoutubeVideo(url: string): Promise<YoutubeResult[]> {
return ytdl.getInfo(url)
return ytdl.getInfo(url, { agent })
.then(info => {
if (info.videoDetails) {
const videoDetails = info.videoDetails;
Expand Down Expand Up @@ -166,7 +167,7 @@ export async function trackSearchByString(query: StreamQuery, sourceName?: strin
export const getStreamForId = async (id: string, sourceName: string, useSponsorBlock = true): Promise<StreamData> => {
try {
const videoUrl = baseUrl + id;
const trackInfo = await ytdl.getInfo(videoUrl);
const trackInfo = await ytdl.getInfo(videoUrl, { agent });
const formatInfo = ytdl.chooseFormat(trackInfo.formats, { quality: 'highestaudio' });
const segments = useSponsorBlock ? await SponsorBlock.getSegments(id) : [];

Expand Down

0 comments on commit 0a92bb1

Please sign in to comment.