imputnet / cobalt

best way to save what you love
https://cobalt.tools
GNU Affero General Public License v3.0
17.29k stars 1.41k forks source link

fetch url https://www.youtube.com/iframe_api error #840

Closed xuya227939 closed 1 month ago

xuya227939 commented 1 month ago

problem description

Describe your suggestion

I use proxy, but get error

Error

Line:40 🍷 url https://www.youtube.com/iframe_api Fetch error for https://www.youtube.com/iframe_api. Retrying in 2 seconds...

Line:40 🍷 url https://www.youtube.com/sw.js_data Fetch error for https://www.youtube.com/sw.js_data. Retrying in 2 seconds...

Tell me why? Please, Thank you.

Code

const initializeInnertube = async () => {
  const proxyAgent = new HttpsProxyAgent(
    "https://v2sub.com/xxx"
  );
  return await Innertube.create({
    fetch: async (input, init) => {
      const url =
        typeof input === "string"
          ? input
          : input instanceof URL
          ? input.toString()
          : input.url;

      const modifiedInit = {
        ...init,
        method: init?.method || (init?.body ? "POST" : "GET"),
        agent: proxyAgent,
      };
      if (modifiedInit.method === "POST")
        modifiedInit.headers = {
          ...modifiedInit.headers,
          "Content-Type": "application/json",
        };

      const maxRetries = 5;
      let retryCount = 0;
      const fetchWithRetry = async () => {
        try {
          const response = await fetch(url, modifiedInit);
          if (!response.ok) {
            if (response.status === 429) {
              console.warn(
                `Too Many Requests. Retrying in ${delayTime / 1000} seconds...`
              );
            }
            throw new Error(`Failed to fetch ${url}: ${response.statusText}`);
          }
          return response;
        } catch (error) {
          throw new Error(`Fetch error for ${url}: ${error.message}`);
        }
      };

      return fetchWithRetry();
    },
  });
};

your instance configuration

No response

wukko commented 1 month ago

i have no clue how this is related to cobalt in any way, create a new issue describing the issue