Skip to content

Commit

Permalink
Merge pull request #1119 from Kiradien/patch-2
Browse files Browse the repository at this point in the history
Fix #1118 - Update FanFictionParser.js
  • Loading branch information
dteviot authored Nov 26, 2023
2 parents b1200d2 + 3c24485 commit 3b67a9c
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions plugin/js/parsers/FanFictionParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,33 @@ class FanFictionParser extends Parser {
return dom;
}

async fetchWebPageContent(webPage)
{
try
{
return await super.fetchWebPageContent(webPage);
}
catch(ex)
{
//Determine if path contains extra parameters. Immediately fail if already shortened.
//Shortened URI is not always ideal solution; apparently related to caching on server.
let regex = /(https?:\/\/(?:www\.)?\w+\.\w+\/s\/\d+\/\d+)\/[a-z\-0-9]+/i
let shortUri = regex.exec(webPage.sourceUrl);
if (shortUri)
{
console.log(`Failed to load URI [${webPage.sourceUrl}] - Attempting alternative. [${shortUri[1]}]`);
//Await throttle timer again for second page fetch.
await this.rateLimitDelay();
webPage.sourceUrl = shortUri[1];
return await super.fetchWebPageContent(webPage);
}
else
{
throw ex;
}
}
}

addTitleToChapter(url, dom) {
let path = url.split("/");
let chapterId = path[path.length - 2];
Expand Down

0 comments on commit 3b67a9c

Please sign in to comment.