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

Commit

Permalink
Merge pull request #25 from GameFuzzy/master
Browse files Browse the repository at this point in the history
2.1.9 - Update Madara generic
  • Loading branch information
ConradWeiser authored Jan 31, 2021
2 parents f818f9b + 202a08c commit caf8e5a
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 17 deletions.
5 changes: 5 additions & 0 deletions .run/current Mocha test file.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="current Mocha test file" type="NodeJSConfigurationType" singleton="false" application-parameters="--no-timeouts --trace-warnings --colors $FilePathRelativeToProjectRoot$ --require ts-node/register" path-to-js-file="node_modules/mocha/bin/_mocha" working-dir="$PROJECT_DIR$">
<method v="2" />
</configuration>
</component>
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "paperback-extensions-common",
"version": "2.1.8",
"version": "2.1.9",
"description": "The base methods and structures for a Paperback extension repo",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
47 changes: 33 additions & 14 deletions src/base/Madara.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,29 @@ export abstract class Madara extends Source {
abstract baseUrl: string

/**
* The language code which this source supports
* The language code which this source supports.
*/
abstract languageCode: LanguageCode

/**
* The path that precedes a manga page not including the base URL.
* Eg. for https://www.webtoon.xyz/read/limit-breaker/ it would be 'read'.
* Used in all functions.
*/
sourceTraversalPathName: string = 'manga'

/**
* By default, the homepage of a Madara is not its true homepage.
* Accessing the site directory and sorting by the latest title allows
* functions to step through the multiple pages easier, without a lot of custom
* logic for each source.
*
* This variable holds the latter half of the website path which is required to reach the
* directory page.
* Eg. 'webtoons' for https://www.webtoon.xyz/webtoons/?m_orderby=latest
*/
homePage: string = 'manga'

/**
* Some Madara sources have a different selector which is required in order to parse
* out the popular manga. This defaults to the most common selector
Expand All @@ -37,7 +56,7 @@ export abstract class Madara extends Source {

async getMangaDetails(mangaId: string): Promise<Manga> {
const request = createRequestObject({
url: `${this.baseUrl}/read/${mangaId}`,
url: `${this.baseUrl}/${this.sourceTraversalPathName}/${mangaId}`,
method: 'GET'
})

Expand Down Expand Up @@ -92,15 +111,15 @@ export abstract class Madara extends Source {
let chapters: Chapter[] = []

// Capture the manga title, as this differs from the ID which this function is fed
let realTitle = $('a', $('li.wp-manga-chapter ').first()).attr('href')?.replace(`${this.baseUrl}/read/`, '').replace(/\/chapter.*/, '')
let realTitle = $('a', $('li.wp-manga-chapter ').first()).attr('href')?.replace(`${this.baseUrl}/${this.sourceTraversalPathName}/`, '').replace(/\/chapter.*/, '')

if(!realTitle) {
throw(`Failed to parse the human-readable title for ${mangaId}`)
}

// For each available chapter..
for(let obj of $('li.wp-manga-chapter ').toArray()) {
let id = $('a', $(obj)).first().attr('href')?.replace(`${this.baseUrl}/read/${realTitle}/`, '').replace('/', '')
let id = $('a', $(obj)).first().attr('href')?.replace(`${this.baseUrl}/${this.sourceTraversalPathName}/${realTitle}/`, '').replace('/', '')
let chapNum = Number($('a', $(obj)).first().text().replace(/\D/g, ''))
let releaseDate = $('i', $(obj)).text()

Expand All @@ -122,7 +141,7 @@ export abstract class Madara extends Source {

async getChapterDetails(mangaId: string, chapterId: string): Promise<ChapterDetails> {
const request = createRequestObject({
url: `${this.baseUrl}/read/${mangaId}/${chapterId}`,
url: `${this.baseUrl}/${this.sourceTraversalPathName}/${mangaId}/${chapterId}`,
method: 'GET',
cookies: [createCookie({name: 'wpmanga-adault', value: "1", domain: this.baseUrl})]
})
Expand Down Expand Up @@ -153,7 +172,7 @@ export abstract class Madara extends Source {

/**
* Different Madara sources might have a slightly different selector which is required to parse out
* each manga object while on a search resulst page. This is the selector
* each manga object while on a search result page. This is the selector
* which is looped over. This may be overridden if required.
*/
searchMangaSelector: string = "div.c-tabs-item__content"
Expand All @@ -172,7 +191,7 @@ export abstract class Madara extends Source {
let results: MangaTile[] = []

for(let obj of $(this.searchMangaSelector).toArray()) {
let id = $('a', $(obj)).attr('href')?.replace(`${this.baseUrl}/read/`, '').replace('/', '')
let id = $('a', $(obj)).attr('href')?.replace(`${this.baseUrl}/${this.sourceTraversalPathName}/`, '').replace('/', '')
let title = createIconText({text: $('a', $(obj)).attr('title') ?? ''})
let image = $('img', $(obj)).attr('data-src')

Expand Down Expand Up @@ -224,7 +243,7 @@ export abstract class Madara extends Source {

// Parse all of the available data
const request = createRequestObject({
url: `${this.baseUrl}/webtoons/?m_orderby=latest`,
url: `${this.baseUrl}/${this.homePage}/?m_orderby=latest`,
method: 'GET',
cookies: [createCookie({name: 'wpmanga-adault', value: "1", domain: this.baseUrl})]
})
Expand All @@ -236,10 +255,10 @@ export abstract class Madara extends Source {
for(let obj of $('div.manga').toArray()) {
let image = $('img', $(obj)).attr('data-src')
let title = $('a', $('h3.h5', $(obj))).text()
let id = $('a', $('h3.h5', $(obj))).attr('href')?.replace(`${this.baseUrl}/webtoon/`, '').replace('/', '')
let id = $('a', $('h3.h5', $(obj))).attr('href')?.replace(`${this.baseUrl}/${this.sourceTraversalPathName}/`, '').replace('/', '')

if(!id || !title || !image) {
throw(`Failed to parse homepage sections for ${this.baseUrl}/webtoon/`)
throw(`Failed to parse homepage sections for ${this.baseUrl}/${this.sourceTraversalPathName}/`)
}

items.push(createMangaTile({
Expand All @@ -248,7 +267,7 @@ export abstract class Madara extends Source {
image: image
}))
}

section.items = items
sectionCallback(section)
}
Expand All @@ -258,7 +277,7 @@ export abstract class Madara extends Source {
let page = metadata.page ?? 0 // Default to page 0

const request = createRequestObject({
url: `${this.baseUrl}/webtoons/page/${page}/?m_orderby=latest`,
url: `${this.baseUrl}/${this.homePage}/page/${page}/?m_orderby=latest`,
method: 'GET',
cookies: [createCookie({name: 'wpmanga-adault', value: "1", domain: this.baseUrl})]
})
Expand All @@ -270,10 +289,10 @@ export abstract class Madara extends Source {
for(let obj of $('div.manga').toArray()) {
let image = $('img', $(obj)).attr('data-src')
let title = $('a', $('h3.h5', $(obj))).text()
let id = $('a', $('h3.h5', $(obj))).attr('href')?.replace(`${this.baseUrl}/read/`, '').replace('/', '')
let id = $('a', $('h3.h5', $(obj))).attr('href')?.replace(`${this.baseUrl}/${this.sourceTraversalPathName}/`, '').replace('/', '')

if(!id || !title || !image) {
throw(`Failed to parse homepage sections for ${this.baseUrl}/webtoon/`)
throw(`Failed to parse homepage sections for ${this.baseUrl}/${this.sourceTraversalPathName}`)
}

items.push(createMangaTile({
Expand Down
3 changes: 2 additions & 1 deletion src/base/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './Source'
export * from './Source'
export * from './Madara'
2 changes: 2 additions & 0 deletions src/base/tests/TestClass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ import { Madara } from "../Madara";
export class TestClass extends Madara {
baseUrl: string = "https://www.webtoon.xyz"
languageCode: LanguageCode = LanguageCode.ENGLISH
sourceTraversalPathName: string = 'read'
homePage: string = 'webtoons'
}

0 comments on commit caf8e5a

Please sign in to comment.