CTK-WARRIOR / ctk-anime-scraper

scraper to scrap anime from gogoanime
12 stars 2 forks source link

Error when scraping whole anime. #4

Closed xaxa-0x3F closed 3 years ago

xaxa-0x3F commented 3 years ago
(node:2089) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'disableEpisodeFetch' of undefined
    at Object.fetchAnime (/home/runner/ahega0/node_modules/ctk-anime-scraper/src/Functions/fetchAnime.js:22:14)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:2089) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:2089) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

My code:

const animeapi = require('ctk-anime-scraper');
        const { MessageEmbed, MessageAttachment, MessageCollector } = require('discord.js');

        const name = message.content
        .match(/(?:"[^"]*"|^[^"]*$)/)[0]
        .replace(/"/g, "")

        name.replace(" ", "-")

        // const ep = message.content.match(/^\d+|\d+\b|\d+(?=\w)/g)[0];

        const link = await animeapi.search(`${name}`).then((data) => {
            if(!data.length) return console.log("No Anime with this name found")
            animeapi.fetchAnime(data[0].link).then(data => console.log(data))
            console.log(data[0].link);
        });;        
LegendaryEmoji commented 3 years ago

Hello Asuna :wave:

Seems like you get disableEpisodeFetch error when you don't pass options object or don't pass options object with episode related properties

You can fix this by providing a object as options with episode related properties

Properties

#1 - Not getting any episode information (disableEpisodeFetch: true)

const Anime = require("ctk-anime-scraper");

Anime.fetchAnime("https://gogoanime.ai//category/kimetsu-no-yaiba", {
    disableEpisodeFetch: true
}).then(console.log);

#2 - Only getting first or certain episode information (episode: 1)

const Anime = require("ctk-anime-scraper");

Anime.fetchAnime("https://gogoanime.ai//category/kimetsu-no-yaiba", {
    episode: 1
}).then(console.log);

#3 - Using mass_episodes property for getting multiple episodes (mass_episodes: 5)

const Anime = require("ctk-anime-scraper");

Anime.fetchAnime("https://gogoanime.ai//category/kimetsu-no-yaiba", {
    mass_episodes: 5
}).then(console.log);

If you are confused about how to implement disabling episodes fetch in your code, then (changed some code):

const animeapi = require('ctk-anime-scraper');
const { MessageEmbed, MessageAttachment, MessageCollector } = require('discord.js');

const name = message.content.match(/(?:"[^"]*"|^[^"]*$)/)[0].replace(/"/g, "");

name.replace(" ", "-");

// const ep = message.content.match(/^\d+|\d+\b|\d+(?=\w)/g)[0];

const link = await animeapi.search(name).then((data) => {
    if (!data.length) return console.log("No Anime with this name found");
    console.log(data[0].link);
    animeapi.fetchAnime(data[0].link, {
        disableEpisodeFetch: true
    }).then(data => console.log(data))
});
xaxa-0x3F commented 3 years ago

Thank you so much @LegendaryEmoji