koneko-cli
Version:
Your CLI for reading manga from the terminal
42 lines (41 loc) • 1.6 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.searchManga = exports.BASE_URI = void 0;
const axios_1 = __importDefault(require("axios"));
const cheerio_1 = require("cheerio");
exports.BASE_URI = 'https://kakalotmanga.net';
const searchManga = async (query) => {
try {
const response = await axios_1.default.get(`${exports.BASE_URI}/?s=${encodeURIComponent(query)}&post_type=wp-manga`);
const $ = (0, cheerio_1.load)(response.data);
const data = [];
$('div.row.c-tabs-item__content').each((_, el) => {
const element = $(el);
// Get the link and extract the id (slug)
const linkEl = element.find('div.post-title h3.h4 a');
const href = linkEl.attr('href') || '';
let id = '';
const match = href.match(/\/manga\/([^\/?#]+)/i);
if (match)
id = match[1];
// Get title
const title = linkEl.text().trim();
// Get author
let author = 'Unknown Author';
const authorEl = element.find('.mg_author .summary-content a');
if (authorEl.length) {
author = authorEl.text().trim();
}
data.push({ id, title, author });
});
return data;
}
catch (error) {
console.error("Error fetching manga:", error);
return [];
}
};
exports.searchManga = searchManga;