mirror of
https://github.com/Wanxp/obsidian-douban.git
synced 2026-04-04 16:48:44 +08:00
fix movie/teleplay actor and director name wrong
This commit is contained in:
parent
c49750b848
commit
3b7a2fb3a1
@ -29,6 +29,7 @@ export const DEFAULT_SETTINGS: DoubanPluginSetting = {
|
||||
],
|
||||
loginCookiesContent: '',
|
||||
cacheImage: true,
|
||||
cacheHighQuantityImage: true,
|
||||
attachmentPath: 'assets',
|
||||
syncHandledDataArray: [],
|
||||
}
|
||||
|
||||
@ -23,6 +23,8 @@ import {DoubanUserParameter, UserStateSubject} from "../model/UserStateSubject";
|
||||
import {DoubanSubjectState, DoubanSubjectStateRecords} from "../../../constant/DoubanUserState";
|
||||
import DoubanLoginModel from "../../component/DoubanLoginModel";
|
||||
import DoubanHumanCheckModel from "../../component/DoubanHumanCheckModel";
|
||||
import DoubanMovieSubject from "../model/DoubanMovieSubject";
|
||||
import {Person} from "schema-dts";
|
||||
|
||||
export default abstract class DoubanAbstractLoadHandler<T extends DoubanSubject> implements DoubanSubjectLoadHandler<T> {
|
||||
|
||||
@ -181,6 +183,33 @@ export default abstract class DoubanAbstractLoadHandler<T extends DoubanSubject>
|
||||
return this.getPersonNameByMode(name, context.settings.personNameMode);
|
||||
}
|
||||
|
||||
getPersonName2(originalName: string, chineseName: string, context: HandleContext): string {
|
||||
return this.getPersonNameByMode2(originalName, chineseName, context.settings.personNameMode);
|
||||
}
|
||||
|
||||
|
||||
getPersonNameByMode2(originalName: string, chineseName: string, personNameMode: string): string {
|
||||
if (!originalName || !personNameMode) {
|
||||
return "";
|
||||
}
|
||||
let resultName: string;
|
||||
switch (personNameMode) {
|
||||
case PersonNameMode.CH_NAME:
|
||||
resultName = chineseName;
|
||||
break;
|
||||
case PersonNameMode.EN_NAME:
|
||||
resultName = originalName.trim().replaceAll(chineseName, '').trim();
|
||||
if (!resultName) {
|
||||
resultName = originalName;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
resultName = originalName;
|
||||
}
|
||||
return resultName;
|
||||
}
|
||||
|
||||
|
||||
getPersonNameByMode(name: string, personNameMode: string): string {
|
||||
if (!name || !personNameMode) {
|
||||
return "";
|
||||
@ -423,13 +452,28 @@ export default abstract class DoubanAbstractLoadHandler<T extends DoubanSubject>
|
||||
if (!extract.image || (syncConfig && !syncConfig.cacheImage) || !context.settings.cacheImage) {
|
||||
return;
|
||||
}
|
||||
let image = extract.image;
|
||||
const image = extract.image;
|
||||
const filename = image.split('/').pop();
|
||||
let folder = syncConfig? syncConfig.attachmentPath : context.settings.attachmentPath;
|
||||
if (!folder) {
|
||||
folder = DEFAULT_SETTINGS.attachmentPath;
|
||||
}
|
||||
const {success, filepath} = await context.netFileHandler.downloadFile(image, folder, filename);
|
||||
if (context.settings.cacheHighQuantityImage && context.userComponent.isLogin()) {
|
||||
try {
|
||||
const fileNameSpilt = filename.split('.');
|
||||
const highImage = `https://img9.doubanio.com/view/photo/raw/public/${fileNameSpilt.first()}.jpg`
|
||||
const highFilename = fileNameSpilt.first() + '.jpg';
|
||||
const {success, filepath} = await context.netFileHandler.downloadFile(highImage, folder, highFilename, context);
|
||||
if (success) {
|
||||
extract.image = filepath;
|
||||
return;
|
||||
}
|
||||
}catch (e) {
|
||||
console.error(e);
|
||||
console.error('下载高清封面失败,将会使用普通封面')
|
||||
}
|
||||
}
|
||||
const {success, filepath} = await context.netFileHandler.downloadFile(image, folder, filename, context);
|
||||
if (success) {
|
||||
extract.image = filepath;
|
||||
}
|
||||
@ -447,4 +491,25 @@ export default abstract class DoubanAbstractLoadHandler<T extends DoubanSubject>
|
||||
|
||||
|
||||
}
|
||||
|
||||
handlePersonNameByMeta(html: CheerioAPI, movie: DoubanSubject, context: HandleContext,
|
||||
metaProperty:string, objectProperty:string) {
|
||||
let metaProperties: string[] = html(`head > meta[property='${metaProperty}']`).get()
|
||||
.map((e) => {
|
||||
return html(e).attr('content');
|
||||
});
|
||||
// @ts-ignore
|
||||
movie[objectProperty]
|
||||
// @ts-ignore
|
||||
.filter((p:Person) => p.name)
|
||||
// @ts-ignore
|
||||
.map((p:Person) => {
|
||||
// @ts-ignore
|
||||
const persons = metaProperties.filter((a) => p.name.indexOf(a) >= 0);
|
||||
if (persons) {
|
||||
// @ts-ignore
|
||||
p.name = this.getPersonName2(p.name, persons[0], context);
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,6 +10,7 @@ import {PersonNameMode, SupportType, TemplateKey} from "../../../constant/Consts
|
||||
import {UserStateSubject} from "../model/UserStateSubject";
|
||||
import {moment} from "obsidian";
|
||||
import YamlUtil, {SPECIAL_CHAR_REG, TITLE_ALIASES_SPECIAL_CHAR_REG_G} from "../../../utils/YamlUtil";
|
||||
import { Person } from 'schema-dts';
|
||||
|
||||
export default class DoubanMovieLoadHandler extends DoubanAbstractLoadHandler<DoubanMovieSubject> {
|
||||
|
||||
@ -99,6 +100,9 @@ export default class DoubanMovieLoadHandler extends DoubanAbstractLoadHandler<Do
|
||||
}
|
||||
return result;
|
||||
})[0];
|
||||
this.handlePersonNameByMeta(html, movie, context, 'video:actor', 'actor');
|
||||
this.handlePersonNameByMeta(html, movie, context, 'video:director', 'director');
|
||||
|
||||
let detailDom = html(html("#info").get(0));
|
||||
let publish = detailDom.find("span.pl");
|
||||
|
||||
@ -127,6 +131,7 @@ export default class DoubanMovieLoadHandler extends DoubanAbstractLoadHandler<Do
|
||||
return movie;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
const MovieKeyValueMap: Map<string, string> = new Map(
|
||||
|
||||
@ -102,6 +102,11 @@ export class DoubanTeleplayLoadHandler extends DoubanAbstractLoadHandler<DoubanT
|
||||
}
|
||||
return result;
|
||||
})[0];
|
||||
|
||||
this.handlePersonNameByMeta(html, teleplay, context, 'video:actor', 'actor');
|
||||
this.handlePersonNameByMeta(html, teleplay, context, 'video:director', 'director');
|
||||
|
||||
|
||||
let detailDom = html(html("#info").get(0));
|
||||
let publish = detailDom.find("span.pl");
|
||||
|
||||
|
||||
@ -102,5 +102,18 @@ export function constructAttachmentFileSettingsUI(containerEl: HTMLElement, mana
|
||||
|
||||
if(manager.plugin.settings.cacheImage) {
|
||||
new Setting(containerEl).then(createFolderSelectionSetting({name: '121432', desc: '121433', placeholder: '121434', key: 'attachmentPath', manager: manager}));
|
||||
new Setting(containerEl)
|
||||
.setName(i18nHelper.getMessage('121435'))
|
||||
.setDesc(i18nHelper.getMessage('121436'))
|
||||
.addToggle((toggleComponent) => {
|
||||
toggleComponent
|
||||
.setTooltip(i18nHelper.getMessage('121437'))
|
||||
.setValue(manager.plugin.settings.cacheHighQuantityImage)
|
||||
.onChange(async (value) => {
|
||||
manager.plugin.settings.cacheHighQuantityImage = value;
|
||||
await manager.plugin.saveSettings();
|
||||
constructAttachmentFileSettingsUI(containerEl, manager);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,6 +21,8 @@ export interface DoubanPluginSetting {
|
||||
customProperties: CustomProperty[],
|
||||
loginCookiesContent: string,
|
||||
cacheImage: boolean,
|
||||
cacheHighQuantityImage: boolean,
|
||||
|
||||
attachmentPath: string,
|
||||
syncHandledDataArray: SyncHandledData[],
|
||||
}
|
||||
|
||||
@ -194,6 +194,10 @@ PS: This file could be delete if you want to.
|
||||
'121432': `Attachment folder`,
|
||||
'121433': `Attachment file created from Obsidian-Douban will be placed in this folder, If blank, they will be placed in the default location for this vault.`,
|
||||
'121434': `assets`,
|
||||
'121435': `Save High Definition Cover`,
|
||||
'121436': `High Definition Cover looks better but it will take more space, and you must login douban in this plugin`,
|
||||
'121437': `Please login first, Then this function could be enable`,
|
||||
|
||||
|
||||
|
||||
'121501': `Note folder`,
|
||||
|
||||
@ -206,7 +206,9 @@ export default {
|
||||
'121432': `附件存放位置`,
|
||||
'121433': `保存的附件将会存放至该文件夹中. 如果为空, 笔记将会存放到默认位置(assets) `,
|
||||
'121434': `assets`,
|
||||
|
||||
'121435': `保存高清封面`,
|
||||
'121436': `高清封面图片质量更高清晰度更好,并且需要您在此插件登录豆瓣才能生效,若未登录则默认使用低精度版本封面`,
|
||||
'121437': `登录后此功能才会生效`,
|
||||
|
||||
|
||||
'121501': `笔记存放位置`,
|
||||
|
||||
@ -3,6 +3,7 @@ import {log} from "../utils/Logutil";
|
||||
import {i18nHelper} from "../lang/helper";
|
||||
import FileHandler from "../file/FileHandler";
|
||||
import {FileUtil} from "../utils/FileUtil";
|
||||
import HandleContext from "../douban/data/model/HandleContext";
|
||||
|
||||
export default class NetFileHandler {
|
||||
private fileHandler: FileHandler;
|
||||
@ -11,12 +12,12 @@ export default class NetFileHandler {
|
||||
this.fileHandler = fileHandler;
|
||||
}
|
||||
|
||||
async downloadFile(url: string, folder:string, filename: string): Promise<{ success: boolean, error:string, filepath: string }> {
|
||||
async downloadFile(url: string, folder:string, filename: string, context:HandleContext): Promise<{ success: boolean, error:string, filepath: string }> {
|
||||
const requestUrlParam: RequestUrlParam = {
|
||||
url: url,
|
||||
method: "GET",
|
||||
throw: true,
|
||||
headers: {}
|
||||
headers: {Cookie: context.settings.loginCookiesContent}
|
||||
};
|
||||
const filePath:string = FileUtil.join(folder, filename);
|
||||
return requestUrl(requestUrlParam)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user