diff --git a/src/org/wanxp/douban/data/search/parser/AllFirstPageSearchResultPageParser.ts b/src/org/wanxp/douban/data/search/parser/AllFirstPageSearchResultPageParser.ts index 2d9fd6e..2695130 100644 --- a/src/org/wanxp/douban/data/search/parser/AllFirstPageSearchResultPageParser.ts +++ b/src/org/wanxp/douban/data/search/parser/AllFirstPageSearchResultPageParser.ts @@ -3,8 +3,7 @@ import { } from "../../../../constant/Constsant"; import {SearchResultPageParserInterface} from "./SearchResultPageParserInterface"; import {SearchPage} from "../../model/SearchPage"; -import SearchParserHandlerV2 from "../SearchParserV2"; -import StringUtil from "../../../../utils/StringUtil"; +import SearchParserHandler from "../SearchParser"; import {log} from "../../../../utils/Logutil"; export class AllFirstPageSearchResultPageParser implements SearchResultPageParserInterface { @@ -12,22 +11,11 @@ export class AllFirstPageSearchResultPageParser implements SearchResultPageParse return pageNum == 1 && type == SupportType.all; } parse(source:string, type:SupportType, pageNum:number, pageSize:number):SearchPage { - if (!source || StringUtil.notJsonString(source)) { - //TODO 国际化 - log.notice("Obsidian-Douban:查询结果为空,无匹配结果,请尝试登录获取获取更多数据(已登录则忽略)"); - return SearchPage.empty(type); + log.debug("解析给多页面结果"); + if (!source) { + return new SearchPage(0, 0, 0, type, []); } - - const {subjects} = JSON.parse(source); - if (!subjects) { - return SearchPage.empty(type); - } - const {items} = subjects; - if (!items ||items.length == 0) { - return SearchPage.empty(type); - } - const doubanSearchResultSubjects = SearchParserHandlerV2.itemMapToSearchResult(items); - return new SearchPage(2000, pageNum, pageSize, type, doubanSearchResultSubjects); + return SearchParserHandler.parseSearchJson(source, type, pageNum); } diff --git a/src/org/wanxp/douban/data/search/parser/OtherAllPageSearchResultPageParser.ts b/src/org/wanxp/douban/data/search/parser/OtherAllPageSearchResultPageParser.ts index 4a6970a..1c276e6 100644 --- a/src/org/wanxp/douban/data/search/parser/OtherAllPageSearchResultPageParser.ts +++ b/src/org/wanxp/douban/data/search/parser/OtherAllPageSearchResultPageParser.ts @@ -2,7 +2,7 @@ import {SupportType} from "../../../../constant/Constsant"; import {SearchResultPageParserInterface} from "./SearchResultPageParserInterface"; import {log} from "../../../../utils/Logutil"; import {SearchPage} from "../../model/SearchPage"; -import SearchParserHandlerV2 from "../SearchParserV2"; +import SearchParserHandler from "../SearchParser"; export class OtherAllPageSearchResultPageParser implements SearchResultPageParserInterface { support(type:SupportType, pageNum:number):boolean { @@ -10,13 +10,10 @@ export class OtherAllPageSearchResultPageParser implements SearchResultPageParse } parse(source:string, type:SupportType, pageNum:number, pageSize:number):SearchPage { log.debug("解析给多页面结果"); - const {contents} = JSON.parse(source); - if (!contents) { + if (!source) { return new SearchPage(0, 0, 0, type, []); } - const data:{total:number, start:number, count:number, items:any[]} = contents; - const doubanSearchResultSubjects = SearchParserHandlerV2.itemMapToSearchResult(data.items); - return new SearchPage(data.total, pageNum, pageSize, type, doubanSearchResultSubjects); + return SearchParserHandler.parseSearchJson(source, type, pageNum); } } diff --git a/src/org/wanxp/douban/data/search/searcher/AllPageSearchPageFetcher.ts b/src/org/wanxp/douban/data/search/searcher/AllPageSearchPageFetcher.ts index 66dfe89..816cb66 100644 --- a/src/org/wanxp/douban/data/search/searcher/AllPageSearchPageFetcher.ts +++ b/src/org/wanxp/douban/data/search/searcher/AllPageSearchPageFetcher.ts @@ -2,8 +2,8 @@ import {AbstractSearchPageFetcher} from "./AbstractSearchPageFetcher"; import { SupportType } from "src/org/wanxp/constant/Constsant"; export class AllPageSearchPageFetcher extends AbstractSearchPageFetcher { - getUrl(keyword: string, pageNum: number, pageSize: number): string { - return `https://m.douban.com/rexxar/api/v2/search?q=${keyword}&start=${pageNum}&count=${pageSize}`; + getUrl(keyword: string, start: number, pageSize: number): string { + return `https://www.douban.com/j/search?q=${keyword}&start=${start}`; } support(type: SupportType): boolean { return type == SupportType.all; diff --git a/src/org/wanxp/main.ts b/src/org/wanxp/main.ts index 3f8e9bf..33ee153 100644 --- a/src/org/wanxp/main.ts +++ b/src/org/wanxp/main.ts @@ -285,6 +285,7 @@ export default class DoubanPlugin extends Plugin { this.settingsManager = new SettingsManager(this.app, this); // this.fetchOnlineData(this.settingsManager); this.userComponent = new UserComponent(this.settingsManager); + await this.userComponent.login(); this.netFileHandler = new NetFileHandler(this.fileHandler); this.settingTab = new DoubanSettingTab(this.app, this);