diff --git a/src/pages/bato/main.ts b/src/pages/bato/main.ts index 3e5226af88..80d0784410 100644 --- a/src/pages/bato/main.ts +++ b/src/pages/bato/main.ts @@ -26,11 +26,7 @@ export const bato: pageInterface = { if (!selectedOptionText) return NaN; - const chapterTextMatches = selectedOptionText.match(/(ch\.|chapter)\D?\d+/i); - - if (!chapterTextMatches || chapterTextMatches.length === 0) return NaN; - - return Number(chapterTextMatches[0].match(/\d+/)); + return getChapter(selectedOptionText); }, getVolume(url) { const selectedOptionText = j.$('div.nav-epis > select > optgroup > option:selected').text(); @@ -74,11 +70,7 @@ export const bato: pageInterface = { if (!episodeText) return NaN; - const matches = episodeText.match(/(ch\.|chapter)\D?\d+/i); - - if (!matches || matches.length === 0) return NaN; - - return Number(matches[0].match(/\d+/)); + return getChapter(episodeText); }, }, }, @@ -93,3 +85,11 @@ export const bato: pageInterface = { }); }, }; + +function getChapter(text: string) { + const res = /(ch|chapter|episode|ep|chap|chp)\D?(\d+)/i.exec(text); + + if (!res) return NaN; + + return Number(res[2]) || NaN; +} diff --git a/src/pages/bato/tests.json b/src/pages/bato/tests.json index ee5dd8d654..92117663a6 100644 --- a/src/pages/bato/tests.json +++ b/src/pages/bato/tests.json @@ -26,6 +26,42 @@ "105": "https://bato.to/chapter/1405642" } } + }, + { + "url": "https://bato.to/chapter/2063224", + "expected": { + "sync": true, + "title": "The Villainess Turns the Hourglass (Official) [Tapas]", + "identifier": "111571", + "overviewUrl": "https://bato.to/series/111571", + "nextEpUrl": "https://bato.to/chapter/2063244", + "episode": 2, + "uiSelector": false + } + }, + { + "url": "https://bato.to/chapter/2068568", + "expected": { + "sync": true, + "title": "π˜›π˜©π˜¦π˜³π˜¦ 𝘐𝘴 π˜•π˜° π˜—π˜¦π˜³π˜§π˜¦π˜€π˜΅ π˜”π˜’π˜³π˜³π˜ͺ𝘦π˜₯ 𝘊𝘰𝘢𝘱𝘭𝘦 [liliannaclaris]", + "identifier": "107830", + "overviewUrl": "https://bato.to/series/107830", + "nextEpUrl": "", + "episode": 34, + "uiSelector": false + } + }, + { + "url": "https://bato.to/chapter/2066393", + "expected": { + "sync": true, + "title": "TOKO SHINWOO [SUFA]", + "identifier": "110173", + "overviewUrl": "https://bato.to/series/110173", + "nextEpUrl": "https://bato.to/chapter/2067933", + "episode": 21, + "uiSelector": false + } } ] }