mangakonekuto
Version:
Your CLI for reading manga from the terminal
51 lines (50 loc) • 2.33 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
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 = (query) => __awaiter(void 0, void 0, void 0, function* () {
try {
const response = yield 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;