From 7a9273c80d86df4acb73e586cccaefa6d25d318f Mon Sep 17 00:00:00 2001 From: Justin Joe Date: Sun, 15 Oct 2023 00:21:56 +1300 Subject: [PATCH] Add back ksk with new domain - wip --- src/Koushoku/Koushoku.ts | 85 ++----------------------- src/Koushoku/KoushokuParser.ts | 113 +++++++++------------------------ 2 files changed, 34 insertions(+), 164 deletions(-) diff --git a/src/Koushoku/Koushoku.ts b/src/Koushoku/Koushoku.ts index 6fa9c81..1a909cd 100644 --- a/src/Koushoku/Koushoku.ts +++ b/src/Koushoku/Koushoku.ts @@ -29,7 +29,7 @@ import { } from './KoushokuParser'; export const KoushokuInfo: SourceInfo = { - version: '1.0.4', + version: '2.0.0', name: 'Koushoku', icon: 'icon.png', author: 'WaltersAsh', @@ -87,7 +87,7 @@ export class Koushoku implements SearchResultsProviding, MangaProviding, Chapter async getHomePageSections(sectionCallback: (section: HomeSection) => void): Promise { const requestForRecentlyAdded = App.createRequest({ - url: `${DOMAIN}/browse`, + url: `${DOMAIN}`, method: 'GET' }); const responseForRecentlyAdded = await this.requestManager.schedule(requestForRecentlyAdded, 1); @@ -97,66 +97,6 @@ export class Koushoku implements SearchResultsProviding, MangaProviding, Chapter const recentlyAddedAlbums = getAlbums($recentlyAdded); recentlyAddedAlbumsSection.items = recentlyAddedAlbums; sectionCallback(recentlyAddedAlbumsSection); - - const requestForPopularWeekly = App.createRequest({ - url: `${DOMAIN}/popular/weekly`, - method: 'GET' - }); - const responseForPopularWeekly = await this.requestManager.schedule(requestForPopularWeekly, 1); - const $popularWeekly = this.cheerio.load(responseForPopularWeekly.data as string); - const popularWeeklySection = App.createHomeSection({id: 'popular weekly', title: 'Popular This Week', - containsMoreItems: true, type: HomeSectionType.singleRowNormal}); - const popularWeeklyAlbums = getAlbums($popularWeekly); - popularWeeklySection.items = popularWeeklyAlbums; - sectionCallback(popularWeeklySection); - - const requestForPopularMonthly = App.createRequest({ - url: `${DOMAIN}/popular/monthly`, - method: 'GET' - }); - const responseForPopularMonthly = await this.requestManager.schedule(requestForPopularMonthly, 1); - const $popularMonthly = this.cheerio.load(responseForPopularMonthly.data as string); - const popularMonthlySection = App.createHomeSection({id: 'popular monthly', title: 'Popular This Month', - containsMoreItems: true, type: HomeSectionType.singleRowNormal}); - const popularMonthlyAlbums = getAlbums($popularMonthly); - popularMonthlySection.items = popularMonthlyAlbums; - sectionCallback(popularMonthlySection); - - const requestForRecentDoujin = App.createRequest({ - url: `${DOMAIN}/browse?cat=2&sort=16`, - method: 'GET' - }); - const responseForRecentDoujin = await this.requestManager.schedule(requestForRecentDoujin, 1); - const $recentDoujin = this.cheerio.load(responseForRecentDoujin.data as string); - const recentDoujinSection = App.createHomeSection({id: 'recent doujins', title: 'Recent Doujins', - containsMoreItems: true, type: HomeSectionType.singleRowNormal}); - const recentDoujinAlbums = getAlbums($recentDoujin); - recentDoujinSection.items = recentDoujinAlbums; - sectionCallback(recentDoujinSection); - - const requestForRecentManga = App.createRequest({ - url: `${DOMAIN}/browse?cat=1`, - method: 'GET' - }); - const responseForRecentManga = await this.requestManager.schedule(requestForRecentManga, 1); - const $recentManga = this.cheerio.load(responseForRecentManga.data as string); - const recentMangaSection = App.createHomeSection({id: 'recent manga', title: 'Recent Manga', - containsMoreItems: true, type: HomeSectionType.singleRowNormal}); - const recentMangaAlbums = getAlbums($recentManga); - recentMangaSection.items = recentMangaAlbums; - sectionCallback(recentMangaSection); - - const requestForRecentIllustrations = App.createRequest({ - url: `${DOMAIN}/browse?cat=4`, - method: 'GET' - }); - const responseForRecentIllustrations = await this.requestManager.schedule(requestForRecentIllustrations, 1); - const $recentIllustrations = this.cheerio.load(responseForRecentIllustrations.data as string); - const recentIllustrationsSection = App.createHomeSection({id: 'recent illustrations', title: 'Recent Illustrations', - containsMoreItems: true, type: HomeSectionType.singleRowNormal}); - const recentIllustrationsAlbums = getAlbums($recentIllustrations); - recentIllustrationsSection.items = recentIllustrationsAlbums; - sectionCallback(recentIllustrationsSection); } // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any @@ -166,22 +106,7 @@ export class Koushoku implements SearchResultsProviding, MangaProviding, Chapter let param = ''; switch (homepageSectionId) { case 'recent': - param = `/browse/page/${albumNum}`; - break; - case 'popular weekly': - param = `/popular/weekly/page/${albumNum}`; - break; - case 'popular monthly': - param = `/popular/monthly/page/${albumNum}`; - break; - case 'recent doujins': - param = `/browse/page/${albumNum}?cat=2&sort=16`; - break; - case 'recent manga': - param = `/browse/page/${albumNum}?cat=1`; - break; - case 'recent illustrations': - param = `/browse/page/${albumNum}?cat=4`; + param = `/?page=${albumNum}`; break; default: throw new Error('Requested to getViewMoreItems for a section ID which doesn\'t exist'); @@ -248,12 +173,12 @@ export class Koushoku implements SearchResultsProviding, MangaProviding, Chapter let request; if (query.title) { request = App.createRequest({ - url: `${DOMAIN}/browse/page/${searchPage}?s=${encodeURIComponent(query.title)}`, + url: `${DOMAIN}/search?page/${searchPage}&q=${encodeURIComponent(query.title)}`, method: 'GET' }); } else { request = App.createRequest({ - url: `${DOMAIN}${query.includedTags?.map(x => x.id)}/page/${searchPage}`, + url: `${DOMAIN}/tags/${query.includedTags?.map(x => x.id)}?page=${searchPage}`, method: 'GET' }); } diff --git a/src/Koushoku/KoushokuParser.ts b/src/Koushoku/KoushokuParser.ts index 208e243..4867ec5 100644 --- a/src/Koushoku/KoushokuParser.ts +++ b/src/Koushoku/KoushokuParser.ts @@ -7,25 +7,16 @@ import { import entities = require('entities'); -export const DOMAIN = 'https://ksk.moe'; -const REGEX_PAGE = /[0-9]+(.(jpg|png))/g; +export const DOMAIN = 'https://fakku.cc'; export async function getTags(requestManager: RequestManager, cheerio: CheerioAPI): Promise { const request = App.createRequest({ - url: `${DOMAIN}/tags/page/1`, + url: `${DOMAIN}/tags`, method: 'GET' }); const data = await requestManager.schedule(request, 1); const $ = cheerio.load(data.data as string); const tagElements = $('main', 'main').children().toArray(); - - const request2 = App.createRequest({ - url: `${DOMAIN}/tags/page/2`, - method: 'GET' - }); - const data2 = await requestManager.schedule(request2, 1); - const $$ = cheerio.load(data2.data as string); - const tagElements2 = $$('main', 'main').children().toArray(); const tags: Tag[] = []; @@ -35,25 +26,24 @@ export async function getTags(requestManager: RequestManager, cheerio: CheerioAP tags.push(App.createTag({ id, label })); } - for (const element of tagElements2) { - const id = $$('a', element).attr('href') ?? ''; - const label = $$('span', element).first().text() ?? ''; - tags.push(App.createTag({ id, label })); - } - return tags; } export function getAlbums ($: CheerioStatic): PartialSourceManga[] { const albums: PartialSourceManga[] = []; - const albumGroups = $('article', 'main').toArray(); - + const albumGroups = $('article.entry').toArray(); + for (const album of albumGroups) { 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); + if (!id || !title) { continue; } @@ -113,78 +103,33 @@ export async function getGalleryData(id: string, requestManager: RequestManager, } export async function getPages(id: string, requestManager: RequestManager, cheerio: CheerioAPI): Promise { - const imageId = id.slice(10); const pages: string[] = []; - // Determine page length - const request = App.createRequest({ - url: `${DOMAIN}/${id}`, - method: 'GET' - }); - const data = await requestManager.schedule(request, 1); - const $ = cheerio.load(data.data as string); - const length = parseInt($('span:contains("Pages")').text().split(' ')[0] ?? ''); - const urlPieces = $('img').first().attr('src')?.split('/') ?? ''; - const suffix = urlPieces[urlPieces?.length - 1] ?? ''; - - const pagesRequest = App.createRequest({ - url: `${DOMAIN}/read${id.slice(7)}/1`, + let request = App.createRequest({ + url: `${DOMAIN}/${id}/1`, method: 'GET' }); - const pagesData = await requestManager.schedule(pagesRequest, 1); - const $$ = cheerio.load(pagesData.data as string, {xmlMode: true}); - - // Image format is not guranteed - // const imageFormat = suffix.slice(suffix.length, 3) ? 'jpg' : 'png'; - const pageNumFormat = suffix.split('.')[0]?.length; - - // Extract page nums from script - const pageNums = $$('script[type$=javascript]').last().toString(); - const unsortedPageNumsList = pageNums.matchAll(REGEX_PAGE); - const pageNumsList = [...new Set(Array.from(unsortedPageNumsList, x => x[0]))]; - - if (pageNumFormat === 2 || pageNumFormat === 3) { - for (let i = 0; i < length; i++) { - const imageLink = `${DOMAIN}/resampled/${imageId}/${pageNumsList[i]}`; - pages.push(imageLink); - } - } else { - const urlFormat = urlPieces[urlPieces.length - 1]; - const firstHalf = urlFormat?.split('001')[0] ?? ''; - const lastHalf = urlFormat?.split('001')[1] ?? ''; - - for (let i = 1; i < length + 1; i++) { - // Pages start from 001, 002..010, 011..100, 101... - let pageNumFormat = i < 10 ? `00${i}` : `0${i}`; - if (i > 99) { - pageNumFormat = `${i}`; - } - const finalFormat = firstHalf?.concat(pageNumFormat, lastHalf); - const imageLink = `${DOMAIN}/resampled/${imageId}/${finalFormat}`; - pages.push(imageLink); - } + let data = await requestManager.schedule(request, 1); + 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++) { + request = App.createRequest({ + url: `${DOMAIN}/${id}/${i}`, + method: 'GET' + }); + data = await requestManager.schedule(request, 1); + $ = cheerio.load(data.data as string); + imageLink = $('img', 'main.page').attr('src') ?? ''; + pages.push(imageLink); } return pages; } export const isLastPage = (albums: PartialSourceManga[]): boolean => { - // max albums displayed per page, need to find better way - last page will have 35 albums for popular sections - return albums.length != 35; -}; - -export async function testImageLink(imageLink: string, requestManager: RequestManager): Promise { - const jpgImageLink = imageLink.replace(/.{0,3}$/, '') + 'jpg'; - - const request = App.createRequest({ - url: imageLink, - method: 'GET' - }); - - const status = (await requestManager.schedule(request, 1)).status; - if (status !== 200) { - return jpgImageLink; - } - - return imageLink; -} \ No newline at end of file + return albums.length != 25; +}; \ No newline at end of file