Fix: AO3 [archive of our own] handling single chapter stories and minor cleanup (#1098)

* Add files via upload

* 2nd

* another change with image

* another change with image

* another change with image

* another change with image

* another change with image

* another change with image

* another change with image

* another change with image

* another change with image

* another change with image

* another change with image

* another change with image

* another change with image

* another change with image

* another change with image

* another change with image

* another change with image

* another change with image

* another change with image

* another change with image

* another change with image

* another change with image

* clean up

* clean up

* fix handling single chapter stories

* fix handling single chapter stories

* fix handling single chapter stories

* fix handling single chapter stories

* fix handling single chapter stories

* fix handling single chapter stories

* fix handling single chapter stories

* fix handling single chapter stories

* fix handling single chapter stories

* fix handling single chapter stories

* fix handling single chapter stories

* fix handling single chapter stories

* fix handling single chapter stories

* fix handling single chapter stories

* fix handling single chapter stories

* fix handling single chapter stories

* fix handling single chapter stories

* fix handling single chapter stories

* fix handling single chapter stories

* fix handling single chapter stories and minor cleanup

* fix handling single chapter stories and minor cleanup

* New source test

* New source test

* fix bugs

* fix bugs

* fix bugs

* bugs fix
This commit is contained in:
Dredd1987
2024-08-07 04:57:12 +03:00
committed by GitHub
parent f10dd1ad10
commit 7497c4dcfc
+79 -16
View File
@@ -7,7 +7,7 @@ import { defaultCover } from '@libs/defaultCover';
class ArchiveOfOurOwn implements Plugin.PluginBase {
id = 'archiveofourown';
name = 'Archive Of Our Own';
version = '1.0.0';
version = '1.0.1';
icon = 'src/en/ao3/icon.png';
site = 'https://archiveofourown.org/';
@@ -144,22 +144,85 @@ class ArchiveOfOurOwn implements Plugin.PluginBase {
.join(',');
novel.summary = `Fandom:\n${fandom}\n\nRating:\n${rating}\n\nWarning:\n${warning}\n\nSummary:\n${summary}\n\nSeries:\n${series}\n\nRelationships:\n${relation}\n\nCharacters:\n${character}\n\nStats:\n${stats}`;
const chapterItems: Plugin.ChapterItem[] = [];
loadedCheerio('#chapter_index select').each((i, selectEl) => {
loadedCheerio(selectEl)
.find('option')
.each((i, el) => {
const chapterName = loadedCheerio(el).text().trim();
const chapterUrlCode = loadedCheerio(el).attr('value')?.trim();
const chapterUrl = `${novelUrl}/chapters/${chapterUrlCode}`;
const releaseTimeText = loadedCheerio('.wrapper dd.published')
.text()
.trim();
const releaseTime = releaseTimeText
? new Date(releaseTimeText).toISOString()
: '';
if (loadedCheerio('#chapter_index select').length > 0) {
loadedCheerio('#chapter_index select').each((i, selectEl) => {
loadedCheerio(selectEl)
.find('option')
.each((i, el) => {
const chapterName = loadedCheerio(el).text().trim();
const chapterUrlCode = loadedCheerio(el).attr('value')?.trim();
const chapterUrl = `${novelUrl}/chapters/${chapterUrlCode}`;
if (chapterUrl) {
chapterItems.push({
name: chapterName,
path: new URL(chapterUrl, this.site).toString(),
});
if (chapterUrl) {
chapterItems.push({
name: chapterName,
path: chapterUrl,
});
}
});
});
}
if (chapterItems.length === 0) {
loadedCheerio('#chapters h3.title').each((i, titleEl) => {
const fullTitleText = loadedCheerio(titleEl).text().trim();
const chapterNameMatch = fullTitleText.match(/:\s*(.*)$/);
let chapterName = chapterNameMatch ? chapterNameMatch[1].trim() : '';
const chapterUrlRaw = loadedCheerio(titleEl)
.find('a')
.attr('href')
?.trim();
const chapterUrlCode = chapterUrlRaw?.match(/\/chapters\/(\d+)/)?.[1];
const chapterUrl = `${novelUrl}/chapters/${chapterUrlCode}`;
if (chapterUrl) {
if (chapterName === '') {
const novelTitle = loadedCheerio('.work .title.heading')
.text()
.trim();
chapterName = novelTitle;
}
chapterItems.push({
name: chapterName,
path: chapterUrl,
releaseTime: releaseTime,
});
}
});
if (chapterItems.length === 0) {
loadedCheerio('.work.navigation.actions li a').each((i, el) => {
const href = loadedCheerio(el).attr('href');
if (href && href.includes('/downloads/')) {
const chapterUrlCodeMatch = href.match(/updated_at=(\d+)/);
const chapterUrlCode = chapterUrlCodeMatch
? chapterUrlCodeMatch[1]
: null;
let chapterName = loadedCheerio('h2.title.heading').text().trim();
const chapterUrl = `${novelUrl}/chapters/${chapterUrlCode}`;
if (chapterUrl) {
if (chapterName === '') {
const novelTitle = loadedCheerio('.work .title.heading')
.text()
.trim();
chapterName = novelTitle;
}
chapterItems.push({
name: chapterName,
path: chapterUrl,
releaseTime: releaseTime,
});
}
}
});
});
}
}
novel.chapters = chapterItems;
return novel;
@@ -434,8 +497,8 @@ class ArchiveOfOurOwn implements Plugin.PluginBase {
},
singlechap: {
value: '',
label: 'Single Chapter',
options: [{ label: 'Days', value: '1' }],
label: 'Single Chapter Stories',
options: [{ label: 'Single Chapter', value: '1' }],
type: FilterTypes.Picker,
},
author: {