Added headers to fetchData function

This commit is contained in:
2025-06-10 21:21:58 +09:00
committed by GitHub
parent 394ce9d61d
commit 789a194a72

View File

@@ -5,23 +5,22 @@ import axios from 'axios';
import { find } from 'lodash'; import { find } from 'lodash';
import striptags from 'striptags'; import striptags from 'striptags';
const fetchData = const fetchData = async function fetchData(url) {
typeof fetch === 'function' const { data } = await axios.get(url, {
? async function fetchData(url) { headers: {
const response = await fetch(url); 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Safari/537.36',
return await response.text(); 'Accept-Language': 'en-US,en;q=0.9',
} 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
: async function fetchData(url) { 'Referer': 'https://www.youtube.com',
const { data } = await axios.get(url); 'Origin': 'https://www.youtube.com',
return data; },
}; });
return data;
};
export async function getSubtitles({ export async function getSubtitles({
videoID, videoID,
lang = 'en', lang = 'en',
}: {
videoID: string,
lang: 'en' | 'de' | 'fr' | void,
}) { }) {
const data = await fetchData( const data = await fetchData(
`https://youtube.com/watch?v=${videoID}` `https://youtube.com/watch?v=${videoID}`