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

#1368 - Update TapasParser for multi-request #1371

Merged
merged 1 commit into from
Jul 7, 2024
Merged
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
48 changes: 34 additions & 14 deletions plugin/js/parsers/TapasParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,41 @@ class TapasParser extends Parser{
super();
}

async getChapterUrls(dom) {
async getChapterUrls(dom, chapterUrlsUI) {
let pageNum = 1;
let retrieve_count = 20;

let seriesId = dom.querySelector("meta[property='al:android:url']").getAttribute("content").split("/", 4).pop();
let restUrl = `https://tapas.io/series/${seriesId}/episodes?page=1&sort=OLDEST&max_limit=9999`;
let body = (await HttpClient.fetchJson(restUrl)).json.data.body;
let html = new DOMParser().parseFromString(body, "text/html");
return [...html.querySelectorAll("li")]
.filter(li => !li.querySelector(".thumb__overlay--locked, .ico--schedule"))
.map(this.listItemToChapter);
}

listItemToChapter(li) {
return {
sourceUrl: "https://tapas.io" + li.getAttribute("data-href"),
title: li.querySelector("a.info__title").textContent.trim()
};
let chapterList = [];
let chapterResponse = {};

do
{
chapterResponse = await TapasParser.fetchPartialChapterList(seriesId, pageNum++, retrieve_count);
var chapters = TapasParser.parseEpisodeDataToChapterList(chapterResponse.episodes);
chapterUrlsUI.showTocProgress(chapters.map(item => item));
chapterList = chapterList.concat(chapters);
} while (chapterResponse.pagination.has_next && chapterResponse.episodes.length == retrieve_count);

return chapterList;
}

static async fetchPartialChapterList(id, page, retrieve_count)
{
let restUrl = `https://tapas.io/series/${id}/episodes?page=${page}&sort=OLDEST&max_limit=${retrieve_count}`;
let response = await HttpClient.fetchJson(restUrl);
return response.json.data;
}

static parseEpisodeDataToChapterList(episodes)
{
return episodes.filter(item => item.free || item.free_access || item.unlocked)
.map(item => {
return {
sourceUrl:`https://tapas.io/episode/${item.id}`,
title:item.title
};
} );
}

findContent(dom) {
Expand Down
Loading