Skip to content

Commit

Permalink
Merge pull request MALSync#1326 from MALSync/fix_bato
Browse files Browse the repository at this point in the history
Better chapter recognition on Bato
  • Loading branch information
henrik9999 authored Oct 2, 2022
2 parents 8e8d71d + 93151de commit 3037ee6
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/pages/bato/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
},
},
},
Expand All @@ -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;
}
36 changes: 36 additions & 0 deletions src/pages/bato/tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
]
}

0 comments on commit 3037ee6

Please sign in to comment.