Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MinigetError: Status code: 410 #1309

Open
MohamedAdany opened this issue Aug 14, 2024 · 2 comments
Open

MinigetError: Status code: 410 #1309

MohamedAdany opened this issue Aug 14, 2024 · 2 comments

Comments

@MohamedAdany
Copy link

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. 
@silvioprog
Copy link

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. 🫤

@BDT-4248
Copy link

BDT-4248 commented Oct 10, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants