[Syosetu] improve novel status parsing and chapter content retrieval (#1350)
* [Syosetu] improve novel status parsing and chapter content retrieval - Improve logic of deciding the novel status - Extract novel genres - Keep text formatting for chapter content by using HTML * [Syosetu] improve novel status parsing and chapter content retrieval Fixed typo * [Syosetu] Conform to Prettier rules
This commit is contained in:
@@ -3,6 +3,7 @@ import { fetchApi } from '@libs/fetch';
|
|||||||
import { Plugin } from '@typings/plugin';
|
import { Plugin } from '@typings/plugin';
|
||||||
import { defaultCover } from '@libs/defaultCover';
|
import { defaultCover } from '@libs/defaultCover';
|
||||||
import { FilterTypes, Filters } from '@libs/filterInputs';
|
import { FilterTypes, Filters } from '@libs/filterInputs';
|
||||||
|
import { NovelStatus } from '@libs/novelStatus';
|
||||||
// const novelStatus = require('@libs/novelStatus');
|
// const novelStatus = require('@libs/novelStatus');
|
||||||
// const isUrlAbsolute = require('@libs/isAbsoluteUrl');
|
// const isUrlAbsolute = require('@libs/isAbsoluteUrl');
|
||||||
// const parseDate = require('@libs/parseDate');
|
// const parseDate = require('@libs/parseDate');
|
||||||
@@ -13,7 +14,7 @@ class Syosetu implements Plugin.PluginBase {
|
|||||||
icon = 'src/jp/syosetu/icon.png';
|
icon = 'src/jp/syosetu/icon.png';
|
||||||
site = 'https://yomou.syosetu.com/';
|
site = 'https://yomou.syosetu.com/';
|
||||||
novelPrefix = 'https://ncode.syosetu.com';
|
novelPrefix = 'https://ncode.syosetu.com';
|
||||||
version = '1.1.1';
|
version = '1.1.2';
|
||||||
headers = {
|
headers = {
|
||||||
'User-Agent':
|
'User-Agent':
|
||||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
|
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
|
||||||
@@ -106,12 +107,17 @@ class Syosetu implements Plugin.PluginBase {
|
|||||||
|
|
||||||
// Parse status
|
// Parse status
|
||||||
let status = 'Unknown';
|
let status = 'Unknown';
|
||||||
if (loadedCheerio('.c-announce').text().includes('連載中')) {
|
if (
|
||||||
status = 'Ongoing';
|
loadedCheerio('.c-announce').text().includes('連載中') ||
|
||||||
|
loadedCheerio('.c-announce').text().includes('未完結')
|
||||||
|
) {
|
||||||
|
status = NovelStatus.Ongoing;
|
||||||
|
} else if (
|
||||||
|
loadedCheerio('.c-announce').text().includes('更新されていません')
|
||||||
|
) {
|
||||||
|
status = NovelStatus.OnHiatus;
|
||||||
} else if (loadedCheerio('.c-announce').text().includes('完結')) {
|
} else if (loadedCheerio('.c-announce').text().includes('完結')) {
|
||||||
status = 'Completed';
|
status = NovelStatus.Completed;
|
||||||
} else if (loadedCheerio('.c-announce').text().includes('約2ヶ月以上')) {
|
|
||||||
status = 'On Hiatus';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create novel object with metadata
|
// Create novel object with metadata
|
||||||
@@ -126,10 +132,14 @@ class Syosetu implements Plugin.PluginBase {
|
|||||||
artist: '',
|
artist: '',
|
||||||
cover: defaultCover,
|
cover: defaultCover,
|
||||||
chapters: [],
|
chapters: [],
|
||||||
|
genres: loadedCheerio('meta[property="og:description"]')
|
||||||
|
.attr('content')
|
||||||
|
?.split(' ')
|
||||||
|
.join(','), // Get genres from meta tag
|
||||||
};
|
};
|
||||||
|
|
||||||
// Get summary if available
|
// Get summary if available
|
||||||
novel.summary = loadedCheerio('#novel_ex').text().trim();
|
novel.summary = loadedCheerio('#novel_ex').html() || '';
|
||||||
|
|
||||||
const chapters: Plugin.ChapterItem[] = [];
|
const chapters: Plugin.ChapterItem[] = [];
|
||||||
|
|
||||||
@@ -208,16 +218,15 @@ class Syosetu implements Plugin.PluginBase {
|
|||||||
decodeEntities: false,
|
decodeEntities: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Get the novel text content and process it
|
// Get the chapter title
|
||||||
const chapterContent = cheerioQuery('.p-novel__body .js-novel-text')
|
const chapterTitle = cheerioQuery('.p-novel__title').html() || '';
|
||||||
.find('p')
|
|
||||||
.map((_, element) => {
|
|
||||||
return cheerioQuery(element).text();
|
|
||||||
})
|
|
||||||
.get()
|
|
||||||
.join('\n');
|
|
||||||
|
|
||||||
return chapterContent || '';
|
// Get the chapter content
|
||||||
|
const chapterContent =
|
||||||
|
cheerioQuery('.p-novel__body .js-novel-text').html() || '';
|
||||||
|
|
||||||
|
// Combine title and content with proper HTML structure
|
||||||
|
return `<h1>${chapterTitle}</h1>${chapterContent}`;
|
||||||
}
|
}
|
||||||
async searchNovels(
|
async searchNovels(
|
||||||
searchTerm: string,
|
searchTerm: string,
|
||||||
|
|||||||
Reference in New Issue
Block a user