mirror of
https://github.com/Wanxp/obsidian-douban.git
synced 2026-04-04 16:48:44 +08:00
fix search error
This commit is contained in:
parent
96fe6d6771
commit
1b5b9bb0b3
@ -281,6 +281,36 @@ export const DoubanSearchResultSubjectPreviousPage: DoubanSearchResultSubject =
|
|||||||
url: NavigateType.previous
|
url: NavigateType.previous
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const DoubanSearchGroupPublishResultSubjectPreviousPage: DoubanSearchResultSubject = {
|
||||||
|
cast: "",
|
||||||
|
datePublished: undefined,
|
||||||
|
desc: "",
|
||||||
|
genre: [],
|
||||||
|
id: "",
|
||||||
|
image: "",
|
||||||
|
imageUrl: "",
|
||||||
|
publisher: "",
|
||||||
|
score: 0,
|
||||||
|
title: i18nHelper.getMessage("150106"),
|
||||||
|
type: "navigate",
|
||||||
|
url: NavigateType.previous
|
||||||
|
}
|
||||||
|
|
||||||
|
export const DoubanSearchGroupPublishResultSubjectNextPage: DoubanSearchResultSubject = {
|
||||||
|
cast: "",
|
||||||
|
datePublished: undefined,
|
||||||
|
desc: "",
|
||||||
|
genre: [],
|
||||||
|
id: "",
|
||||||
|
image: "",
|
||||||
|
imageUrl: "",
|
||||||
|
publisher: "",
|
||||||
|
score: 0,
|
||||||
|
title: i18nHelper.getMessage("150105"),
|
||||||
|
type: "navigate",
|
||||||
|
url: NavigateType.next
|
||||||
|
}
|
||||||
|
|
||||||
export const DoubanSearchResultSubjectNextPage: DoubanSearchResultSubject = {
|
export const DoubanSearchResultSubjectNextPage: DoubanSearchResultSubject = {
|
||||||
cast: "",
|
cast: "",
|
||||||
datePublished: undefined,
|
datePublished: undefined,
|
||||||
@ -311,7 +341,7 @@ export const DoubanSearchResultSubjectNextPageNeedLogin: DoubanSearchResultSubje
|
|||||||
url: NavigateType.nextNeedLogin
|
url: NavigateType.nextNeedLogin
|
||||||
}
|
}
|
||||||
|
|
||||||
export const SEARCH_ITEM_PAGE_SIZE: number = 10;
|
export const SEARCH_ITEM_PAGE_SIZE: number = 20;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 豆瓣默认请求头
|
* 豆瓣默认请求头
|
||||||
|
|||||||
@ -144,7 +144,8 @@ export default abstract class DoubanAbstractLoadHandler<T extends DoubanSubject>
|
|||||||
|
|
||||||
abstract support(extract: DoubanSubject): boolean;
|
abstract support(extract: DoubanSubject): boolean;
|
||||||
|
|
||||||
async handle(url: string, context: HandleContext): Promise<T> {
|
async handle(id: string, context: HandleContext): Promise<T> {
|
||||||
|
const url:string = this.getSubjectUrl(id);
|
||||||
context.plugin.settingsManager.debug(`开始请求地址:${url}`)
|
context.plugin.settingsManager.debug(`开始请求地址:${url}`)
|
||||||
context.plugin.settingsManager.debug(`(注意:请勿向任何人透露你的Cookie,此处若需要截图请**打码**)请求header:${context.settings.loginHeadersContent}`)
|
context.plugin.settingsManager.debug(`(注意:请勿向任何人透露你的Cookie,此处若需要截图请**打码**)请求header:${context.settings.loginHeadersContent}`)
|
||||||
return await HttpUtil.httpRequestGet(url, context.plugin.settingsManager.getHeaders(), context.plugin.settingsManager)
|
return await HttpUtil.httpRequestGet(url, context.plugin.settingsManager.getHeaders(), context.plugin.settingsManager)
|
||||||
@ -515,7 +516,7 @@ export default abstract class DoubanAbstractLoadHandler<T extends DoubanSubject>
|
|||||||
|
|
||||||
abstract getHighQuantityImageUrl(fileName:string):string;
|
abstract getHighQuantityImageUrl(fileName:string):string;
|
||||||
|
|
||||||
|
abstract getSubjectUrl(id:string):string;
|
||||||
|
|
||||||
handlePersonNameByMeta(html: CheerioAPI, movie: DoubanSubject, context: HandleContext,
|
handlePersonNameByMeta(html: CheerioAPI, movie: DoubanSubject, context: HandleContext,
|
||||||
metaProperty:string, objectProperty:string) {
|
metaProperty:string, objectProperty:string) {
|
||||||
|
|||||||
@ -23,6 +23,10 @@ export default class DoubanBookLoadHandler extends DoubanAbstractLoadHandler<Dou
|
|||||||
return `https://img9.doubanio.com/view/subject/l/public/${fileName}`;
|
return `https://img9.doubanio.com/view/subject/l/public/${fileName}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getSubjectUrl(id:string):string{
|
||||||
|
return `https://book.douban.com/subject/${id}/`;
|
||||||
|
}
|
||||||
|
|
||||||
parseText(beforeContent: string, extract: DoubanBookSubject, context: HandleContext, textMode: TemplateTextMode): string {
|
parseText(beforeContent: string, extract: DoubanBookSubject, context: HandleContext, textMode: TemplateTextMode): string {
|
||||||
return beforeContent
|
return beforeContent
|
||||||
.replaceAll(DoubanBookParameter.author,
|
.replaceAll(DoubanBookParameter.author,
|
||||||
@ -42,7 +46,7 @@ export default class DoubanBookLoadHandler extends DoubanAbstractLoadHandler<Dou
|
|||||||
}
|
}
|
||||||
|
|
||||||
support(extract: DoubanSubject): boolean {
|
support(extract: DoubanSubject): boolean {
|
||||||
return extract && extract.type && (extract.type.contains("书籍") || extract.type.contains("Book") || extract.type.contains("book"));
|
return extract && extract.type && (extract.type.contains("图书") || extract.type.contains("书籍") || extract.type.contains("Book") || extract.type.contains("book"));
|
||||||
}
|
}
|
||||||
|
|
||||||
handleSpecialAuthorName(authorName: string): string {
|
handleSpecialAuthorName(authorName: string): string {
|
||||||
|
|||||||
@ -22,6 +22,10 @@ export default class DoubanGameLoadHandler extends DoubanAbstractLoadHandler<Dou
|
|||||||
return `https://img9.doubanio.com/lpic/${fileName}`;
|
return `https://img9.doubanio.com/lpic/${fileName}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getSubjectUrl(id:string):string{
|
||||||
|
return `https://www.douban.com/game/${id}/`;
|
||||||
|
}
|
||||||
|
|
||||||
parseText(beforeContent: string, extract: DoubanGameSubject, context: HandleContext): string {
|
parseText(beforeContent: string, extract: DoubanGameSubject, context: HandleContext): string {
|
||||||
const {settings} = context;
|
const {settings} = context;
|
||||||
return beforeContent
|
return beforeContent
|
||||||
|
|||||||
@ -25,6 +25,10 @@ export default class DoubanMovieLoadHandler extends DoubanAbstractLoadHandler<Do
|
|||||||
return `https://img9.doubanio.com/view/photo/l/public/${fileName}`;
|
return `https://img9.doubanio.com/view/photo/l/public/${fileName}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getSubjectUrl(id:string):string{
|
||||||
|
return `https://movie.douban.com/subject/${id}/`;
|
||||||
|
}
|
||||||
|
|
||||||
parseText(beforeContent: string, extract: DoubanMovieSubject, context: HandleContext): string {
|
parseText(beforeContent: string, extract: DoubanMovieSubject, context: HandleContext): string {
|
||||||
const {settings} = context;
|
const {settings} = context;
|
||||||
return beforeContent
|
return beforeContent
|
||||||
|
|||||||
@ -22,6 +22,10 @@ export default class DoubanMusicLoadHandler extends DoubanAbstractLoadHandler<Do
|
|||||||
return `https://img1.doubanio.com/view/subject/m/public/${fileName}`;
|
return `https://img1.doubanio.com/view/subject/m/public/${fileName}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getSubjectUrl(id:string):string{
|
||||||
|
return `https://music.douban.com/subject/${id}/`;
|
||||||
|
}
|
||||||
|
|
||||||
parseText(beforeContent: string, extract: DoubanMusicSubject, context: HandleContext): string {
|
parseText(beforeContent: string, extract: DoubanMusicSubject, context: HandleContext): string {
|
||||||
const {settings} = context;
|
const {settings} = context;
|
||||||
return beforeContent
|
return beforeContent
|
||||||
|
|||||||
@ -23,6 +23,10 @@ export default class DoubanNoteLoadHandler extends DoubanAbstractLoadHandler<Dou
|
|||||||
return ``;
|
return ``;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getSubjectUrl(id:string):string{
|
||||||
|
return `https://www.douban.com/note/${id}/`;
|
||||||
|
}
|
||||||
|
|
||||||
parseText(beforeContent: string, extract: DoubanNoteSubject, context: HandleContext): string {
|
parseText(beforeContent: string, extract: DoubanNoteSubject, context: HandleContext): string {
|
||||||
return beforeContent
|
return beforeContent
|
||||||
.replaceAll("{{authorUrl}}", extract.authorUrl ? extract.authorUrl : "")
|
.replaceAll("{{authorUrl}}", extract.authorUrl ? extract.authorUrl : "")
|
||||||
|
|||||||
@ -28,6 +28,10 @@ export default class DoubanOtherLoadHandler extends DoubanAbstractLoadHandler<Do
|
|||||||
return `https://img9.doubanio.com/view/photo/l/public/${fileName}`;
|
return `https://img9.doubanio.com/view/photo/l/public/${fileName}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getSubjectUrl(id:string):string{
|
||||||
|
return `https://book.douban.com/subject/${id}/`;
|
||||||
|
}
|
||||||
|
|
||||||
parseSubjectFromHtml(data: CheerioAPI, context: HandleContext): DoubanSubject {
|
parseSubjectFromHtml(data: CheerioAPI, context: HandleContext): DoubanSubject {
|
||||||
log.notice(i18nHelper.getMessage('140101'));
|
log.notice(i18nHelper.getMessage('140101'));
|
||||||
return undefined;
|
return undefined;
|
||||||
|
|||||||
@ -42,9 +42,9 @@ export class DoubanSearchChooseItemHandler {
|
|||||||
let doubanSubjectHandlers: DoubanSubjectLoadHandler<DoubanSubject>[] = this._doubanSubjectHandlers
|
let doubanSubjectHandlers: DoubanSubjectLoadHandler<DoubanSubject>[] = this._doubanSubjectHandlers
|
||||||
.filter(h => h.support(searchExtract));
|
.filter(h => h.support(searchExtract));
|
||||||
if (doubanSubjectHandlers && doubanSubjectHandlers.length > 0) {
|
if (doubanSubjectHandlers && doubanSubjectHandlers.length > 0) {
|
||||||
await doubanSubjectHandlers[0].handle(searchExtract.url, context);
|
await doubanSubjectHandlers[0].handle(searchExtract.id, context);
|
||||||
} else {
|
} else {
|
||||||
await this._doubanSubjectHandlerDefault.handle(searchExtract.url, context);
|
await this._doubanSubjectHandlerDefault.handle(searchExtract.id, context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -8,7 +8,6 @@ export default interface DoubanSubjectLoadHandler<T extends DoubanSubject> {
|
|||||||
|
|
||||||
support(extract: DoubanSubject): boolean;
|
support(extract: DoubanSubject): boolean;
|
||||||
|
|
||||||
handle(url: string, context: HandleContext): Promise<T>;
|
handle(id: string, context: HandleContext): Promise<T>;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -47,6 +47,10 @@ export class DoubanTeleplayLoadHandler extends DoubanAbstractLoadHandler<DoubanT
|
|||||||
return `https://img9.doubanio.com/view/photo/l/public/${fileName}`;
|
return `https://img9.doubanio.com/view/photo/l/public/${fileName}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getSubjectUrl(id:string):string{
|
||||||
|
return `https://movie.douban.com/subject/${id}/`;
|
||||||
|
}
|
||||||
|
|
||||||
analysisUser(html: CheerioAPI, context: HandleContext): {data:CheerioAPI , userState: UserStateSubject} {
|
analysisUser(html: CheerioAPI, context: HandleContext): {data:CheerioAPI , userState: UserStateSubject} {
|
||||||
let rate = html('input#n_rating').val();
|
let rate = html('input#n_rating').val();
|
||||||
const rating = html('span#rating');
|
const rating = html('span#rating');
|
||||||
|
|||||||
@ -23,6 +23,10 @@ export default class DoubanTheaterLoadHandler extends DoubanAbstractLoadHandler<
|
|||||||
return `https://img9.doubanio.com/view/photo/l/public/${fileName}`;
|
return `https://img9.doubanio.com/view/photo/l/public/${fileName}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getSubjectUrl(id:string):string{
|
||||||
|
return `https://www.douban.com/location/drama/${id}/`;
|
||||||
|
}
|
||||||
|
|
||||||
parseText(beforeContent: string, extract: DoubanTheaterSubject, context: HandleContext): string {
|
parseText(beforeContent: string, extract: DoubanTheaterSubject, context: HandleContext): string {
|
||||||
return beforeContent
|
return beforeContent
|
||||||
.replaceAll("{{originalTitle}}", extract.originalTitle ? extract.originalTitle : "")
|
.replaceAll("{{originalTitle}}", extract.originalTitle ? extract.originalTitle : "")
|
||||||
|
|||||||
@ -12,7 +12,7 @@ export class SearchPageInfo {
|
|||||||
this._total = total;
|
this._total = total;
|
||||||
this._pageNum = pageNum;
|
this._pageNum = pageNum;
|
||||||
this._pageSize = pageSize;
|
this._pageSize = pageSize;
|
||||||
this._hasNext = ((pageNum + 1) * pageSize) < total;
|
this._hasNext = (pageNum * pageSize) < total;
|
||||||
this._type = type;
|
this._type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -24,6 +24,7 @@ export class SearchPageInfo {
|
|||||||
this._pageSize, this._type);
|
this._pageSize, this._type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public previousPage(): SearchPageInfo {
|
public previousPage(): SearchPageInfo {
|
||||||
if (this._pageNum == 0) {
|
if (this._pageNum == 0) {
|
||||||
return this;
|
return this;
|
||||||
@ -43,12 +44,12 @@ export class SearchPageInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public get hasPrevious() {
|
public get hasPrevious() {
|
||||||
return this._pageNum > 0;
|
return this._pageNum > 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public get start() {
|
public get start() {
|
||||||
return this._pageNum * this._pageSize + 1;
|
return (this._pageNum - 1) * this._pageSize + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public get total() {
|
public get total() {
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
|
DoubanSearchGroupPublishResultSubjectNextPage, DoubanSearchGroupPublishResultSubjectPreviousPage,
|
||||||
DoubanSearchResultSubjectNextPage,
|
DoubanSearchResultSubjectNextPage,
|
||||||
DoubanSearchResultSubjectNextPageNeedLogin,
|
DoubanSearchResultSubjectNextPageNeedLogin,
|
||||||
DoubanSearchResultSubjectPreviousPage,
|
DoubanSearchResultSubjectPreviousPage,
|
||||||
@ -57,12 +58,6 @@ class DoubanFuzzySuggester extends FuzzySuggestModal<DoubanSearchResultSubject>
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(this.isTypeSelect(item)) {
|
|
||||||
if (await this.handleTypeSelect(item)) {
|
|
||||||
this.start();
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.plugin.showStatus(i18nHelper.getMessage('140204', item.title));
|
this.plugin.showStatus(i18nHelper.getMessage('140204', item.title));
|
||||||
this.context.listItem = item;
|
this.context.listItem = item;
|
||||||
if (item) {
|
if (item) {
|
||||||
@ -89,10 +84,10 @@ class DoubanFuzzySuggester extends FuzzySuggestModal<DoubanSearchResultSubject>
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (result) {
|
if (result) {
|
||||||
// const searchPageResult: SearchPage =
|
const searchPageResult: SearchPage =
|
||||||
// await SearcherV2.loadSearchItem(this.searchItem, currentPage.start, SEARCH_ITEM_PAGE_SIZE, this.plugin.settings, this.plugin.settingsManager);
|
await SearcherV2.search(this.searchItem, currentPage.type, currentPage.pageNum, SEARCH_ITEM_PAGE_SIZE, this.plugin.settings, this.plugin.settingsManager);
|
||||||
// this.context.searchPage = new SearchPageInfo(searchPageResult.total, currentPage.pageNum, searchPageResult.pageSize, item.type);
|
this.context.searchPage = searchPageResult;
|
||||||
// this.updatePageResult(searchPageResult);
|
this.updatePageResult(searchPageResult);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -113,24 +108,26 @@ class DoubanFuzzySuggester extends FuzzySuggestModal<DoubanSearchResultSubject>
|
|||||||
const doubanList: DoubanSearchResultSubject[] = searchPage.list;
|
const doubanList: DoubanSearchResultSubject[] = searchPage.list;
|
||||||
if (searchPage.hasNext) {
|
if (searchPage.hasNext) {
|
||||||
if (this.plugin.userComponent.isLogin()) {
|
if (this.plugin.userComponent.isLogin()) {
|
||||||
doubanList.push(DoubanSearchResultSubjectNextPage)
|
if (searchPage.type == SupportType.ALL && searchPage.pageNum == 1) {
|
||||||
|
doubanList.push(DoubanSearchGroupPublishResultSubjectNextPage)
|
||||||
|
}else {
|
||||||
|
doubanList.push(DoubanSearchResultSubjectNextPage)
|
||||||
|
}
|
||||||
}else {
|
}else {
|
||||||
doubanList.push(DoubanSearchResultSubjectNextPageNeedLogin)
|
doubanList.push(DoubanSearchResultSubjectNextPageNeedLogin)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.initTypeSelect(doubanList, searchPage);
|
|
||||||
if (searchPage.hasPrevious) {
|
if (searchPage.hasPrevious) {
|
||||||
doubanList.unshift(DoubanSearchResultSubjectPreviousPage);
|
if (searchPage.type == SupportType.ALL && searchPage.pageNum == 2) {
|
||||||
|
doubanList.unshift(DoubanSearchGroupPublishResultSubjectPreviousPage)
|
||||||
|
}else {
|
||||||
|
doubanList.unshift(DoubanSearchResultSubjectPreviousPage);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.doubanSearchResultExtract = doubanList;
|
this.doubanSearchResultExtract = doubanList;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private initTypeSelect(doubanList: DoubanSearchResultSubject[], searchPage: SearchPage) {
|
|
||||||
if (SupportType.ALL == searchPage.type) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public start(): void {
|
public start(): void {
|
||||||
try {
|
try {
|
||||||
@ -140,29 +137,4 @@ class DoubanFuzzySuggester extends FuzzySuggestModal<DoubanSearchResultSubject>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private isTypeSelect(item: DoubanSearchResultSubject) {
|
|
||||||
return item.type == "type";
|
|
||||||
}
|
|
||||||
|
|
||||||
private async handleTypeSelect(item: DoubanSearchResultSubject) {
|
|
||||||
const {searchPage} = this.context;
|
|
||||||
let currentPage:SearchPageInfo = searchPage;
|
|
||||||
let result:boolean = false;
|
|
||||||
switch (item.url) {
|
|
||||||
case SupportType.ALL:
|
|
||||||
currentPage = searchPage.previousPage();
|
|
||||||
result = true;
|
|
||||||
break;
|
|
||||||
case NavigateType.next:
|
|
||||||
currentPage = searchPage.nextPage();
|
|
||||||
result = true;
|
|
||||||
break;
|
|
||||||
case NavigateType.nextNeedLogin:
|
|
||||||
log.warn(i18nHelper.getMessage("140304"));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (result) {
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,16 +23,6 @@ export class DoubanSearchModal extends Modal {
|
|||||||
contentEl.createEl("h3", {text: i18nHelper.getMessage('110003')});
|
contentEl.createEl("h3", {text: i18nHelper.getMessage('110003')});
|
||||||
const content = contentEl.createDiv("content");
|
const content = contentEl.createDiv("content");
|
||||||
|
|
||||||
const typeSelect = content.createDiv("type-select");
|
|
||||||
const typeSelectInput = new DropdownComponent(typeSelect)
|
|
||||||
.addOptions(SearchTypeRecords)
|
|
||||||
.setValue(SupportType.ALL)
|
|
||||||
.onChange((value:SupportType) => {
|
|
||||||
this.searchType = value;
|
|
||||||
});
|
|
||||||
typeSelect.addClass('obsidian_douban_search_input');
|
|
||||||
|
|
||||||
|
|
||||||
const inputs = content.createDiv("inputs");
|
const inputs = content.createDiv("inputs");
|
||||||
const searchInput = new TextComponent(inputs).onChange((searchTerm) => {
|
const searchInput = new TextComponent(inputs).onChange((searchTerm) => {
|
||||||
this.searchTerm = searchTerm;
|
this.searchTerm = searchTerm;
|
||||||
@ -46,8 +36,14 @@ export class DoubanSearchModal extends Modal {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const typeSelect = content.createDiv("type-select");
|
||||||
|
const typeSelectInput = new DropdownComponent(typeSelect)
|
||||||
|
.addOptions(SearchTypeRecords)
|
||||||
|
.setValue(SupportType.ALL)
|
||||||
|
.onChange((value:SupportType) => {
|
||||||
|
this.searchType = value;
|
||||||
|
});
|
||||||
|
typeSelect.addClass('obsidian_douban_search_input');
|
||||||
|
|
||||||
|
|
||||||
const controls = contentEl.createDiv("controls");
|
const controls = contentEl.createDiv("controls");
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
import {CheerioAPI, load} from "cheerio";
|
import {CheerioAPI, load} from "cheerio";
|
||||||
import DoubanSearchResultSubject from "../model/DoubanSearchResultSubject";
|
import DoubanSearchResultSubject from "../model/DoubanSearchResultSubject";
|
||||||
import {SearchPage} from "../model/SearchPage";
|
import {SearchPage} from "../model/SearchPage";
|
||||||
import {SEARCH_ITEM_PAGE_SIZE, SupportType} from "../../../constant/Constsant";
|
|
||||||
import {log} from "../../../utils/Logutil";
|
import {log} from "../../../utils/Logutil";
|
||||||
|
import {SupportType} from "../../../constant/Constsant";
|
||||||
|
|
||||||
export default class SearchParserHandler {
|
export default class SearchParserHandler {
|
||||||
static parseSearch(dataHtml: CheerioAPI): DoubanSearchResultSubject[] {
|
static parseSearch(dataHtml: CheerioAPI): DoubanSearchResultSubject[] {
|
||||||
@ -36,7 +36,7 @@ export default class SearchParserHandler {
|
|||||||
};
|
};
|
||||||
return result;
|
return result;
|
||||||
})
|
})
|
||||||
};
|
}
|
||||||
|
|
||||||
static parseSearchJson(result: string, type:SupportType, start:number): SearchPage {
|
static parseSearchJson(result: string, type:SupportType, start:number): SearchPage {
|
||||||
log.debug("解析给多页面结果");
|
log.debug("解析给多页面结果");
|
||||||
|
|||||||
@ -17,7 +17,7 @@ export class FistAllPageSearchResultPageParser implements SearchResultPageParser
|
|||||||
return SearchPage.empty(type);
|
return SearchPage.empty(type);
|
||||||
}
|
}
|
||||||
const doubanSearchResultSubjects = SearchParserHandlerV2.itemMapToSearchResult(items);
|
const doubanSearchResultSubjects = SearchParserHandlerV2.itemMapToSearchResult(items);
|
||||||
return new SearchPage(items.length, pageNum, pageSize, type, doubanSearchResultSubjects);
|
return new SearchPage(2000, pageNum, pageSize, type, doubanSearchResultSubjects);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,19 @@
|
|||||||
|
import {SupportType} from "../../../../constant/Constsant";
|
||||||
|
import {SearchResultPageParserInterface} from "./SearchResultPageParserInterface";
|
||||||
|
import {log} from "../../../../utils/Logutil";
|
||||||
|
import {SearchPage} from "../../model/SearchPage";
|
||||||
|
import SearchParserHandler from "../SearchParser";
|
||||||
|
|
||||||
|
export class NotAllPageSearchResultPageParser implements SearchResultPageParserInterface {
|
||||||
|
support(type:SupportType, pageNum:number):boolean {
|
||||||
|
return type != SupportType.ALL;
|
||||||
|
}
|
||||||
|
parse(source:string, type:SupportType, pageNum:number, pageSize:number):SearchPage {
|
||||||
|
log.debug("解析给多页面结果");
|
||||||
|
if (!source) {
|
||||||
|
return new SearchPage(0, 0, 0, type, []);
|
||||||
|
}
|
||||||
|
return SearchParserHandler.parseSearchJson(source, type, pageNum);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -3,6 +3,7 @@ import {FistAllPageSearchResultPageParser} from "./FistAllPageSearchResultPagePa
|
|||||||
import {OtherAllPageSearchResultPageParser} from "./OtherAllPageSearchResultPageParser";
|
import {OtherAllPageSearchResultPageParser} from "./OtherAllPageSearchResultPageParser";
|
||||||
import {SearchPage} from "../../model/SearchPage";
|
import {SearchPage} from "../../model/SearchPage";
|
||||||
import {SupportType} from "../../../../constant/Constsant";
|
import {SupportType} from "../../../../constant/Constsant";
|
||||||
|
import {NotAllPageSearchResultPageParser} from "./NotAllPageSearchResultPageParser";
|
||||||
|
|
||||||
export class SearchResultPageParser {
|
export class SearchResultPageParser {
|
||||||
|
|
||||||
@ -11,6 +12,7 @@ export class SearchResultPageParser {
|
|||||||
constructor() {
|
constructor() {
|
||||||
this.parsers.push(new FistAllPageSearchResultPageParser());
|
this.parsers.push(new FistAllPageSearchResultPageParser());
|
||||||
this.parsers.push(new OtherAllPageSearchResultPageParser());
|
this.parsers.push(new OtherAllPageSearchResultPageParser());
|
||||||
|
this.parsers.push(new NotAllPageSearchResultPageParser());
|
||||||
}
|
}
|
||||||
|
|
||||||
public parse(source:string, type:SupportType, pageNum:number, pageSize:number):SearchPage {
|
public parse(source:string, type:SupportType, pageNum:number, pageSize:number):SearchPage {
|
||||||
|
|||||||
@ -17,7 +17,8 @@ export abstract class AbstractSearchPageFetcher implements SearchPageFetcherInte
|
|||||||
throw new Error("Method not implemented.");
|
throw new Error("Method not implemented.");
|
||||||
}
|
}
|
||||||
fetch(keyword: string, pageNum: number, pageSize: number): Promise<string> {
|
fetch(keyword: string, pageNum: number, pageSize: number): Promise<string> {
|
||||||
const url:string = this.getUrl(keyword, pageNum, pageSize);
|
const start:number = (pageNum - 1) * pageSize;
|
||||||
|
const url:string = this.getUrl(keyword, start, pageSize);
|
||||||
if (!url) {
|
if (!url) {
|
||||||
return Promise.resolve("");
|
return Promise.resolve("");
|
||||||
}
|
}
|
||||||
@ -26,7 +27,8 @@ export abstract class AbstractSearchPageFetcher implements SearchPageFetcherInte
|
|||||||
throw log.error(i18nHelper.getMessage('130101').replace('{0}', e.toString()), e);
|
throw log.error(i18nHelper.getMessage('130101').replace('{0}', e.toString()), e);
|
||||||
}); }
|
}); }
|
||||||
|
|
||||||
abstract getUrl(keyword: string, pageNum: number, pageSize: number):string;
|
abstract getUrl(keyword: string, start: number, pageSize: number):string;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import {AbstractSearchPageFetcher} from "./AbstractSearchPageFetcher";
|
import {AbstractSearchPageFetcher} from "./AbstractSearchPageFetcher";
|
||||||
import { SupportType } from "src/org/wanxp/constant/Constsant";
|
import { SupportType } from "src/org/wanxp/constant/Constsant";
|
||||||
|
|
||||||
export class FistAllPageSearchPageFetcher extends AbstractSearchPageFetcher {
|
export class AllPageSearchPageFetcher extends AbstractSearchPageFetcher {
|
||||||
getUrl(keyword: string, pageNum: number, pageSize: number): string {
|
getUrl(keyword: string, pageNum: number, pageSize: number): string {
|
||||||
return `https://m.douban.com/rexxar/api/v2/search?q=${keyword}&start=${pageNum}&count=${pageSize}`;
|
return `https://m.douban.com/rexxar/api/v2/search?q=${keyword}&start=${pageNum}&count=${pageSize}`;
|
||||||
}
|
}
|
||||||
@ -2,8 +2,8 @@ import {AbstractSearchPageFetcher} from "./AbstractSearchPageFetcher";
|
|||||||
import { SupportType } from "src/org/wanxp/constant/Constsant";
|
import { SupportType } from "src/org/wanxp/constant/Constsant";
|
||||||
|
|
||||||
export class BookPageSearchPageFetcher extends AbstractSearchPageFetcher {
|
export class BookPageSearchPageFetcher extends AbstractSearchPageFetcher {
|
||||||
getUrl(keyword: string, pageNum: number, pageSize: number): string {
|
getUrl(keyword: string, start: number, pageSize: number): string {
|
||||||
return `https://www.douban.com/j/search?q=${keyword}&start=${pageNum * pageSize}&cat=1001`;
|
return `https://www.douban.com/j/search?q=${keyword}&start=${start}&cat=1001`;
|
||||||
}
|
}
|
||||||
support(type: SupportType): boolean {
|
support(type: SupportType): boolean {
|
||||||
return type == SupportType.MOVIE;
|
return type == SupportType.MOVIE;
|
||||||
|
|||||||
@ -2,8 +2,8 @@ import {AbstractSearchPageFetcher} from "./AbstractSearchPageFetcher";
|
|||||||
import { SupportType } from "src/org/wanxp/constant/Constsant";
|
import { SupportType } from "src/org/wanxp/constant/Constsant";
|
||||||
|
|
||||||
export class MoviePageSearchPageFetcher extends AbstractSearchPageFetcher {
|
export class MoviePageSearchPageFetcher extends AbstractSearchPageFetcher {
|
||||||
getUrl(keyword: string, pageNum: number, pageSize: number): string {
|
getUrl(keyword: string, start: number, pageSize: number): string {
|
||||||
return `https://www.douban.com/j/search?q=${keyword}&start=${pageNum * pageSize}&cat=1002`;
|
return `https://www.douban.com/j/search?q=${keyword}&start=${start}&cat=1002`;
|
||||||
}
|
}
|
||||||
support(type: SupportType): boolean {
|
support(type: SupportType): boolean {
|
||||||
return type == SupportType.MOVIE;
|
return type == SupportType.MOVIE;
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import {SearchPageFetcherInterface} from "./SearchPageFetcherInterface";
|
import {SearchPageFetcherInterface} from "./SearchPageFetcherInterface";
|
||||||
import {FistAllPageSearchPageFetcher} from "./FistAllPageSearchPageFetcher";
|
import {AllPageSearchPageFetcher} from "./AllPageSearchPageFetcher";
|
||||||
import SettingsManager from "../../../setting/SettingsManager";
|
import SettingsManager from "../../../setting/SettingsManager";
|
||||||
import {SupportType} from "../../../../constant/Constsant";
|
import {SupportType} from "../../../../constant/Constsant";
|
||||||
import {MoviePageSearchPageFetcher} from "./MoviePageSearchPageFetcher";
|
import {MoviePageSearchPageFetcher} from "./MoviePageSearchPageFetcher";
|
||||||
@ -10,7 +10,7 @@ export class SearchPageFetcher {
|
|||||||
private fetchers:SearchPageFetcherInterface[] = [];
|
private fetchers:SearchPageFetcherInterface[] = [];
|
||||||
|
|
||||||
constructor(settingsManager:SettingsManager) {
|
constructor(settingsManager:SettingsManager) {
|
||||||
this.fetchers.push(new FistAllPageSearchPageFetcher(settingsManager));
|
this.fetchers.push(new AllPageSearchPageFetcher(settingsManager));
|
||||||
this.fetchers.push(new MoviePageSearchPageFetcher(settingsManager));
|
this.fetchers.push(new MoviePageSearchPageFetcher(settingsManager));
|
||||||
this.fetchers.push(new BookPageSearchPageFetcher(settingsManager))
|
this.fetchers.push(new BookPageSearchPageFetcher(settingsManager))
|
||||||
}
|
}
|
||||||
|
|||||||
@ -72,7 +72,7 @@ export abstract class DoubanAbstractSyncHandler<T extends DoubanSubject> implem
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(syncStatus.shouldSync(item.id)) {
|
if(syncStatus.shouldSync(item.id)) {
|
||||||
let subject: DoubanSubject = await this.doubanSubjectLoadHandler.handle(item.url, context);
|
let subject: DoubanSubject = await this.doubanSubjectLoadHandler.handle(item.id, context);
|
||||||
await sleepRange(BasicConst.CALL_DOUBAN_DELAY, BasicConst.CALL_DOUBAN_DELAY + BasicConst.CALL_DOUBAN_DELAY_RANGE);
|
await sleepRange(BasicConst.CALL_DOUBAN_DELAY, BasicConst.CALL_DOUBAN_DELAY + BasicConst.CALL_DOUBAN_DELAY_RANGE);
|
||||||
}else {
|
}else {
|
||||||
syncStatus.unHandle(item.id, item.title);
|
syncStatus.unHandle(item.id, item.title);
|
||||||
|
|||||||
@ -10,6 +10,9 @@ import { UserStateSubject } from '../../data/model/UserStateSubject';
|
|||||||
|
|
||||||
//TODO will support in future version
|
//TODO will support in future version
|
||||||
class DoubanPageBroadcastLoadHandler extends DoubanAbstractLoadHandler<DoubanPageBroadcastSubject> {
|
class DoubanPageBroadcastLoadHandler extends DoubanAbstractLoadHandler<DoubanPageBroadcastSubject> {
|
||||||
|
getSubjectUrl(id: string): string {
|
||||||
|
throw new Error('Method not implemented.');
|
||||||
|
}
|
||||||
getHighQuantityImageUrl(fileName: string): string {
|
getHighQuantityImageUrl(fileName: string): string {
|
||||||
throw new Error('Method not implemented.');
|
throw new Error('Method not implemented.');
|
||||||
}
|
}
|
||||||
|
|||||||
@ -262,8 +262,10 @@ PS: This file could be delete if you want to.
|
|||||||
|
|
||||||
|
|
||||||
'150101': `Choose an item...`,
|
'150101': `Choose an item...`,
|
||||||
|
'150106': `[Previous Page (Item Result)]...`,
|
||||||
'150102': `[Previous Page]...`,
|
'150102': `[Previous Page]...`,
|
||||||
'150103': `[Next Page]...`,
|
'150103': `[Next Page]...`,
|
||||||
|
'150105': `[Next Page (Group Post)]...`,
|
||||||
'150104': `[Next Page (Please Login First)]...`,
|
'150104': `[Next Page (Please Login First)]...`,
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -266,8 +266,10 @@ export default {
|
|||||||
|
|
||||||
'150101': `选择一项内容...`,
|
'150101': `选择一项内容...`,
|
||||||
'121902': `重置为默认值`,
|
'121902': `重置为默认值`,
|
||||||
|
'150106': `[上一页]...(默认查询结果)`,
|
||||||
'150102': `[上一页]...`,
|
'150102': `[上一页]...`,
|
||||||
'150103': `[下一页]...`,
|
'150103': `[下一页]...`,
|
||||||
|
'150105': `[下一页]...(小组帖子结果)`,
|
||||||
'150104': `[下一页]...(请先在插件中登录才能使用此功能)`,
|
'150104': `[下一页]...(请先在插件中登录才能使用此功能)`,
|
||||||
|
|
||||||
//content
|
//content
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user