[go: up one dir, main page]

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

Adding a korean source #542

Merged
merged 8 commits into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 48 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions scripts/generateSource.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const getLanguageCode = language => {
Chinese: 'cn',
Japanese: 'jp',
Vietnamese: 'vi',
Korean: 'kr',
};

return codes[language];
Expand Down
165 changes: 165 additions & 0 deletions src/sources/kr/Agitoon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
import * as cheerio from 'cheerio';

const sourceId = 145;
const sourceName = 'Agitoon';
const baseUrl = 'https://agit501.xyz/';

const popularNovels = async page => {
const totalPages = 20;
const list_limit = 20 * (page - 1);
const day = new Date().getDay();

const res = await fetch(baseUrl + 'novel/index.update.php', {
headers: {
'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
},
body: `mode=get_data_novel_list_p&novel_menu=3&np_day=${day}&np_rank=1&np_distributor=0&np_genre=00&np_order=1&np_genre_ex_1=00&np_genre_ex_2=00&list_limit=${list_limit}&is_query_first=true`,
method: 'POST',
});

const resJson = await res.json();

const novels = resJson.list.map(novel => {
return {
sourceId,
novelUrl: baseUrl + 'novel/list/' + novel.wr_id,
novelName: novel.wr_subject,
novelCover: baseUrl + novel.np_dir + '/thumbnail/' + novel.np_thumbnail,
};
});

return { totalPages, novels };
};

const parseNovelAndChapters = async novelUrl => {
const novelId = novelUrl.split('/').reverse()[0];

// cheerio
const result = await fetch(novelUrl);
const body = await result.text();

const loadedCheerio = cheerio.load(body, { decodeEntities: false });
const novelName = loadedCheerio('h5.pt-2').text();
const summary = loadedCheerio('.pt-1.mt-1.pb-1.mb-1').text();
const author = loadedCheerio('.post-item-list-cate-v')
.first()
.text()
.split(' : ')
.reverse()[0];
const novelCover =
baseUrl.slice(0, baseUrl.length - 1) +
loadedCheerio('div.col-5.pr-0.pl-0 img').attr('src');
const genresTag = loadedCheerio('.col-7 > .post-item-list-cate > span');
let genres = '';

genresTag.each((_, element) => {
genres += loadedCheerio(element).text();
genres += ', ';
});
genres = genres.slice(0, genres.length - 2);

// normal REST HTTP requests
let chapters = [];

const res = await fetch(baseUrl + 'novel/list.update.php', {
headers: {
'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
},
body: `mode=get_data_novel_list_c&wr_id_p=${novelId}&page_no=1&cnt_list=10000&order_type=Asc`,
method: 'POST',
});

const resJson = await res.json();

chapters = resJson.list.map(chapter => {
return {
chapterId: chapter.wr_id,
chapterName: chapter.wr_subject,
chapterUrl: baseUrl + `novel/view/${chapter.wr_id}/2`,
releaseDate: chapter.wr_datetime,
};
});

const novel = {
sourceId,
sourceName,
novelUrl,
novelName,
novelCover,
summary,
author,
status: '',
genre: genres,
url: novelUrl,
chapters,
};
return novel;
};

const parseChapter = async (novelUrl, chapterUrl) => {
const result = await fetch(chapterUrl);
const body = await result.text();

const loadedCheerio = cheerio.load(body);

const title = loadedCheerio('div > div.col-12 > h2').text();
const contentTag = loadedCheerio('#id_wr_content > p');

let content = '';
contentTag.each((_, element) => {
content += loadedCheerio(element).text();
content += '<br />';
});

// gets rid of the popup thingy
content = content.replace(
'팝업메뉴는 빈공간을 더치하거나 스크룰시 사라집니다',
'',
);

const chapter = {
sourceId,
novelUrl,
chapterUrl,
chapterName: title,
chapterText: content,
};

return chapter;
};

const searchNovels = async searchTerm => {
const rawResults = await fetch('https://agit501.xyz/novel/search.php', {
headers: {
'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
},
body: `mode=get_data_novel_list_p_sch&search_novel=${searchTerm}&list_limit=0`,
method: 'POST',
});

const results = await rawResults.json();

if (!results.list && results.list.length() === 0) {
return [];
}

const novels = results.list.map(result => {
return {
sourceId,
novelUrl: baseUrl + 'novel/list/' + result.wr_id,
novelName: result.wr_subject,
novelCover: baseUrl + result.np_dir + '/thumbnail/' + result.np_thumbnail,
};
});

return novels;
};

const AgitoonScraper = {
popularNovels,
parseNovelAndChapters,
parseChapter,
searchNovels,
};

export default AgitoonScraper;
Loading