Skip to content
This repository has been archived by the owner on Oct 3, 2024. It is now read-only.

Commit

Permalink
Fix ksk
Browse files Browse the repository at this point in the history
  • Loading branch information
WaltersAsh committed Oct 15, 2023
1 parent 7a9273c commit f25aa10
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 38 deletions.
21 changes: 18 additions & 3 deletions src/Koushoku/Koushoku.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
getPages,
getTags,
isLastPage,
CloudFlareError
} from './KoushokuParser';

export const KoushokuInfo: SourceInfo = {
Expand All @@ -43,7 +44,7 @@ export const KoushokuInfo: SourceInfo = {
type: BadgeColor.RED
}
],
intents: SourceIntents.MANGA_CHAPTERS | SourceIntents.HOMEPAGE_SECTIONS
intents: SourceIntents.MANGA_CHAPTERS | SourceIntents.HOMEPAGE_SECTIONS | SourceIntents.CLOUDFLARE_BYPASS_REQUIRED
};

export class Koushoku implements SearchResultsProviding, MangaProviding, ChapterProviding, HomePageSectionsProviding {
Expand Down Expand Up @@ -91,6 +92,7 @@ export class Koushoku implements SearchResultsProviding, MangaProviding, Chapter
method: 'GET'
});
const responseForRecentlyAdded = await this.requestManager.schedule(requestForRecentlyAdded, 1);
CloudFlareError(responseForRecentlyAdded.status);
const $recentlyAdded = this.cheerio.load(responseForRecentlyAdded.data as string);
const recentlyAddedAlbumsSection = App.createHomeSection({id: 'recent', title: 'Recent Updates',
containsMoreItems: true, type: HomeSectionType.singleRowNormal});
Expand Down Expand Up @@ -118,6 +120,7 @@ export class Koushoku implements SearchResultsProviding, MangaProviding, Chapter
param
});
const response = await this.requestManager.schedule(request, 1);
CloudFlareError(response.status);
const $ = this.cheerio.load(response.data as string);

const albums = getAlbums($);
Expand All @@ -141,7 +144,7 @@ export class Koushoku implements SearchResultsProviding, MangaProviding, Chapter
tags: data.tags,
author: data.artist,
artist: data.artist,
desc: ''
desc: data.desc
})
});
}
Expand Down Expand Up @@ -173,7 +176,7 @@ export class Koushoku implements SearchResultsProviding, MangaProviding, Chapter
let request;
if (query.title) {
request = App.createRequest({
url: `${DOMAIN}/search?page/${searchPage}&q=${encodeURIComponent(query.title)}`,
url: `${DOMAIN}/search?page=${searchPage}&q=${encodeURIComponent(query.title)}`,
method: 'GET'
});
} else {
Expand All @@ -183,6 +186,7 @@ export class Koushoku implements SearchResultsProviding, MangaProviding, Chapter
});
}
const response = await this.requestManager.schedule(request, 1);
CloudFlareError(response.status);
const $ = this.cheerio.load(response.data as string);

const albums = getAlbums($);
Expand All @@ -193,4 +197,15 @@ export class Koushoku implements SearchResultsProviding, MangaProviding, Chapter
metadata
});
}

async getCloudflareBypassRequestAsync(): Promise<Request> {
return App.createRequest({
url: DOMAIN,
method: 'GET',
headers: {
'referer': `${DOMAIN}/`,
'user-agent': await this.requestManager.getDefaultUserAgent()
}
});
}
}
64 changes: 29 additions & 35 deletions src/Koushoku/KoushokuParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ export async function getTags(requestManager: RequestManager, cheerio: CheerioAP
method: 'GET'
});
const data = await requestManager.schedule(request, 1);
CloudFlareError(data.status);
const $ = cheerio.load(data.data as string);
const tagElements = $('main', 'main').children().toArray();

const tagElements = $('div.entry').toArray();
const tags: Tag[] = [];

for (const element of tagElements) {
const id = $('a', element).attr('href') ?? '';
const label = $('span', element).first().text() ?? '';
const id = $('a', element).attr('href')?.slice(6) ?? '';
const label = $('strong', element).first().text() ?? '';
console.log(id);
console.log(label);
tags.push(App.createTag({ id, label }));
}

Expand All @@ -37,12 +39,7 @@ export function getAlbums ($: CheerioStatic): PartialSourceManga[] {
const image = $('img', album).attr('src') ?? '';
const id = $('a', album).attr('href') ?? '';
const title = $('a', album).attr('title') ?? '';
const artist = $('span', album).first().text() ?? '';

console.log('ID ' + id);
console.log('Image ' + image);
console.log('Title ' + title);
console.log('Artist ' + artist);
const artist = $('span', album).last().text() ?? '';

if (!id || !title) {
continue;
Expand All @@ -66,39 +63,28 @@ export async function getGalleryData(id: string, requestManager: RequestManager,
method: 'GET'
});
const data = await requestManager.schedule(request, 1);
CloudFlareError(data.status);
const $ = cheerio.load(data.data as string);

const title = $('h2', 'section#metadata').first().text();
const title = $('h1.title').first().text();
const image = $('img').first().attr('src') ?? 'https://i.imgur.com/GYUxEX8.png';
const artistSection = $('strong:contains("Artist")').parent();
const artist = $('span', artistSection).first().text();

const tagsElement1 = $('strong:contains("Tag")').first().parent();
const tagsElement2 = $('span', tagsElement1).toArray();

const tagsToRender: Tag[] = [];
for (const tag of tagsElement2) {
const label = $(tag).text();
if (label.match(/^\d/)) continue;

if (!label) {
continue;
}
tagsToRender.push({ id: `/tags/${encodeURIComponent(label)}`, label: label });
}
const artist = $('a', 'tr.artists').text();
const magazine = $('a', 'tr.magazines').text();
const pages = $('td', 'tr.pages').last().text();
const created = $('td', 'tr.created').last().text();
const published = $('td', 'tr.published').last().text();
const desc = 'Magazine: ' + magazine + '\n'
+ 'Pages: ' + pages + '\n'
+ 'Created: ' + created + '\n'
+ 'Published: ' + published + '\n';

const tagSections: TagSection[] = [App.createTagSection({
id: '0',
label: 'Tags',
tags: tagsToRender.map(x => App.createTag(x))
})];

return {
id: id,
titles: [entities.decodeHTML(title as string)],
image: image,
artist: artist,
tags: tagSections
desc: desc
};
}

Expand All @@ -110,18 +96,20 @@ export async function getPages(id: string, requestManager: RequestManager, cheer
method: 'GET'
});
let data = await requestManager.schedule(request, 1);
CloudFlareError(data.status);
let $ = cheerio.load(data.data as string);
const lengthText = $('span.total').text();
const length = parseInt(lengthText.substring(0, lengthText.length / 2));
let imageLink = $('img', 'main.page').attr('src') ?? '';
pages.push(imageLink);

for (let i = 1; i < length + 1; i++) {
for (let i = 2; i < length + 1; i++) {
request = App.createRequest({
url: `${DOMAIN}/${id}/${i}`,
method: 'GET'
});
data = await requestManager.schedule(request, 1);
CloudFlareError(data.status);
$ = cheerio.load(data.data as string);
imageLink = $('img', 'main.page').attr('src') ?? '';
pages.push(imageLink);
Expand All @@ -132,4 +120,10 @@ export async function getPages(id: string, requestManager: RequestManager, cheer

export const isLastPage = (albums: PartialSourceManga[]): boolean => {
return albums.length != 25;
};
};

export function CloudFlareError(status: number): void {
if (status == 503 || status == 403) {
throw new Error(`CLOUDFLARE BYPASS ERROR:\nPlease go to the homepage of <${DOMAIN}> and press the cloud icon.`);
}
}

0 comments on commit f25aa10

Please sign in to comment.