node-ytdl-core icon indicating copy to clipboard operation
node-ytdl-core copied to clipboard

MinigetError: Status code: 410

Open MohamedAdany opened this issue 1 year ago • 2 comments

using this package for more than year, suddenly it stopped working and getting this error while trying to get video info, that will be then used to get video captions Error getting info for videoId: hTcRmj-XLEs MinigetError: Status code: 410 at ClientRequest. (/var/task/node_modules/miniget/dist/index.js:206:27) at Object.onceWrapper (node:events:632:26) at ClientRequest.emit (node:events:529:35) at HTTPParser.parserOnIncomingClient (node:_http_client:700:27) at HTTPParser.parserOnHeadersComplete (node:_http_common:119:17) at TLSSocket.socketOnData (node:_http_client:541:22) at TLSSocket.emit (node:events:517:28) at addChunk (node:internal/streams/readable:368:12) at readableAddChunk (node:internal/streams/readable:341:9) at Readable.push (node:internal/streams/readable:278:10) { statusCode: 410 } here is my code try { const { videoId } = body; console.log("got: ", videoId); const format = "xml"; // Default format is XML const clientLang = query.lang || "en"; // Default language is English

        let info;
        try {
          
          info = await ytdl.getInfo(videoId, { lang: clientLang });
         
          
        } catch (error) {
          console.error("Error getting info for videoId:", videoId, error);
          return null;
        }
        if (info) {
          const autoLangCode = detect(info.videoDetails.title);
          console.log("autoLangCode found===> ,clientLang", clientLang, autoLangCode);

          const tracks =
            info.player_response.captions.playerCaptionsTracklistRenderer
              .captionTracks;

          if (tracks && tracks.length) {
            let track = tracks.find(
              (t) => t.languageCode === (clientLang || autoLangCode || "en")
            );

            if (track) {
              const captionLink = `${track.baseUrl}&fmt=${
                format !== "xml" ? format : ""
              }`;

              const xmlData = await new Promise((resolve, reject) => {
                https
                  .get(captionLink, (response) => {
                    let data = "";

                    response.on("data", (chunk) => {
                      data += chunk;
                    });

                    response.on("end", () => {
                      resolve(data);
                    });
                  })
                  .on("error", (error) => {
                    reject(error);
                  });
              });

              const parser = new xml2js.Parser();
              parser.parseString(xmlData, async (err, result) => {
                if (err) {
                  console.error("Error parsing XML:", err);
                } else {
                  const textContent = result.transcript.text.map(
                    (textElement) => textElement._
                  );
                  const processedText = textContent.join(" ");

                  // Send the response based on the selected file format
                  if (selectedFormat === "xml") {
                    res.status(200).send(xmlData);
                  } else if (selectedFormat === "txt") {
                    res.status(200).send(processedText);
                  } else {
                    res
                      .status(400)
                      .json({ error: "Invalid file format selected" });
                  }
                }
              });
            } else {
              res
                .status(404)
                .json({
                  error:
                    "Could not find captions for the specified language",
                });
            }
          } else {
            res
              .status(404)
              .json({ error: "No captions found for this video" });
          }
        } else {
          console.error("No Info found for videoId:", videoId);
        }
      } catch (error) {
        console.error("Error in download-caption process:", error);
        res
          .status(500)
          .json({ error: "Internal Server Error", details: error.message });
      }
      Code is working fine on localhost , bt getting this error on my production server (vercel)
      Please help me resolving this issue asap. 

MohamedAdany avatar Aug 14 '24 19:08 MohamedAdany

Same here, even with a minimal example like this:

const fs = require("fs");
const ytdl = require("ytdl-core");

ytdl("http://www.youtube.com/watch?v=aqz-KE-bpKQ").pipe(
  fs.createWriteStream("video.mp4")
);

It creates an empty file. 🫤

silvioprog avatar Sep 03 '24 03:09 silvioprog

same issue here... cant do anything with this new error now and i use discord-ytdl-core as package

BDT-4248 avatar Oct 10 '24 20:10 BDT-4248