mirror of
https://github.com/Wanxp/obsidian-douban.git
synced 2026-04-04 16:48:44 +08:00
fix custom variables
This commit is contained in:
parent
4bf64965bb
commit
331ff38cd9
26
README.md
26
README.md
@ -30,19 +30,19 @@
|
||||
- 阅读其它语言的介绍请点击 [English](./doc/README.en.md) | [简体中文](./README.md)
|
||||
|
||||
## 功能
|
||||
- [x] 同步个人看过的电影
|
||||
- [x] 同步个人阅读过的书籍
|
||||
- [x] 同步个人听过的音乐
|
||||
- [x] 导入电影
|
||||
- [x] 导入电视剧
|
||||
- [x] 导入书籍
|
||||
- [x] 导入音乐
|
||||
- [x] 导入日记
|
||||
- [x] 导入游戏
|
||||
- [x] 导入个人的评论,评论时间,阅读状态,个人评分
|
||||
- [x] 支持保存封面至本地
|
||||
- [x] 支持自定义参数
|
||||
- [ ] 广播
|
||||
- ☑️ 同步个人看过的电影
|
||||
- ☑️ 同步个人阅读过的书籍
|
||||
- ☑️ 同步个人听过的音乐
|
||||
- ☑️ 导入电影
|
||||
- ☑️ 导入电视剧
|
||||
- ☑️ 导入书籍
|
||||
- ☑️ 导入音乐
|
||||
- ☑️ 导入日记
|
||||
- ☑️ 导入游戏
|
||||
- ☑️ 导入个人的评论,评论时间,阅读状态,个人评分
|
||||
- ☑️ 支持保存封面至本地
|
||||
- ☑️ 支持自定义参数
|
||||
- ❌ 广播
|
||||
|
||||
## 拓展
|
||||
1. 结合Timeline插件 __构建个人观影时间线__,请参照[结合timeline插件实现时间线效果](./doc/Obsidian-Douban-TimeLine.md))
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
{
|
||||
"id": "obsidian-douban-plugin",
|
||||
"name": "Douban",
|
||||
"version": "1.9.3",
|
||||
"version": "1.9.4",
|
||||
"minAppVersion": "0.12.0",
|
||||
"description": "This is a plugin that can import movies/books/musics/notes/games info data from Douban for Obsidian .",
|
||||
"author": "Wanxp",
|
||||
|
||||
6028
package-lock.json
generated
6028
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "obsidian-douban-plugin",
|
||||
"version": "1.9.3",
|
||||
"version": "1.9.4",
|
||||
"description": "This is a plugin for Obsidian (https://obsidian.md) that can import data from Douban (https://www.douban.com/).",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
|
||||
@ -99,7 +99,7 @@ export enum TemplateKey {
|
||||
}
|
||||
|
||||
export enum SupportType {
|
||||
ALL = "All",
|
||||
ALL = "all",
|
||||
MOVIE = 'movie',
|
||||
BOOK = 'book',
|
||||
MUSIC = 'music',
|
||||
|
||||
@ -361,8 +361,8 @@ export default abstract class DoubanAbstractLoadHandler<T extends DoubanSubject>
|
||||
}
|
||||
customProperties.filter(customProperty => customProperty.name &&
|
||||
customProperty.field
|
||||
&& (customProperty.field == SupportType.ALL ||
|
||||
customProperty.field == this.getSupportType())).forEach(customProperty => {
|
||||
&& (customProperty.field.toLowerCase() == SupportType.ALL ||
|
||||
customProperty.field.toLowerCase() == this.getSupportType())).forEach(customProperty => {
|
||||
resultContent = resultContent.replaceAll(`{{${customProperty.name}}}`, customProperty.value);
|
||||
});
|
||||
return resultContent;
|
||||
|
||||
@ -3,17 +3,14 @@ import DoubanAbstractLoadHandler from "./DoubanAbstractLoadHandler";
|
||||
import DoubanPlugin from "../../../main";
|
||||
import SchemaOrg from "src/org/wanxp/utils/SchemaOrg";
|
||||
import DoubanSubject from '../model/DoubanSubject';
|
||||
import DoubanMovieSubject from '../model/DoubanMovieSubject';
|
||||
import StringUtil from "../../../utils/StringUtil";
|
||||
import HandleContext from "../model/HandleContext";
|
||||
import {PersonNameMode, SupportType, TemplateKey} from "../../../constant/Constsant";
|
||||
import {PropertyName, SupportType} from "../../../constant/Constsant";
|
||||
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 DoubanTheaterLoadHandler extends DoubanAbstractLoadHandler<DoubanMovieSubject> {
|
||||
import {TITLE_ALIASES_SPECIAL_CHAR_REG_G} from "../../../utils/YamlUtil";
|
||||
import DoubanTheaterSubject from "../model/DoubanTheaterSubject";
|
||||
|
||||
export default class DoubanTheaterLoadHandler extends DoubanAbstractLoadHandler<DoubanTheaterSubject> {
|
||||
constructor(doubanPlugin: DoubanPlugin) {
|
||||
super(doubanPlugin);
|
||||
}
|
||||
@ -22,22 +19,18 @@ export default class DoubanTheaterLoadHandler extends DoubanAbstractLoadHandler<
|
||||
return SupportType.THEATER;
|
||||
}
|
||||
|
||||
getHighQuantityImageUrl(fileName:string):string{
|
||||
getHighQuantityImageUrl(fileName: string): string {
|
||||
return `https://img9.doubanio.com/view/photo/l/public/${fileName}`;
|
||||
}
|
||||
|
||||
parseText(beforeContent: string, extract: DoubanMovieSubject, context: HandleContext): string {
|
||||
const {settings} = context;
|
||||
parseText(beforeContent: string, extract: DoubanTheaterSubject, context: HandleContext): string {
|
||||
return beforeContent
|
||||
.replaceAll("{{originalTitle}}", extract.originalTitle ? extract.originalTitle : "")
|
||||
.replaceAll("{{director}}", this.handleArray( extract.director.map(SchemaOrg.getPersonName).map(name => super.getPersonName(name, context)).filter(c => c), context))
|
||||
.replaceAll("{{actor}}", this.handleArray( extract.actor.map(SchemaOrg.getPersonName).map(name => super.getPersonName(name, context)).filter(c => c), context))
|
||||
.replaceAll("{{author}}", this.handleArray( extract.author.map(SchemaOrg.getPersonName).map(name => super.getPersonName(name, context)).filter(c => c), context))
|
||||
.replaceAll("{{aliases}}", this.handleArray( extract.aliases.map(a=>a.replace(TITLE_ALIASES_SPECIAL_CHAR_REG_G, '_')), context))
|
||||
.replaceAll("{{country}}",this.handleArray( extract.country, context))
|
||||
.replaceAll("{{language}}",this.handleArray( extract.language, context))
|
||||
.replaceAll("{{IMDb}}", extract.IMDb ?? "")
|
||||
.replaceAll("{{time}}", extract.time ?? "")
|
||||
.replaceAll("{{director}}", this.handleArray(extract.director.map(SchemaOrg.getPersonName).map(name => super.getPersonName(name, context)).filter(c => c), context))
|
||||
.replaceAll("{{actor}}", this.handleArray(extract.actor.map(SchemaOrg.getPersonName).map(name => super.getPersonName(name, context)).filter(c => c), context))
|
||||
.replaceAll("{{author}}", this.handleArray(extract.author.map(SchemaOrg.getPersonName).map(name => super.getPersonName(name, context)).filter(c => c), context))
|
||||
.replaceAll("{{aliases}}", this.handleArray(extract.aliases.map(a => a.replace(TITLE_ALIASES_SPECIAL_CHAR_REG_G, '_')), context))
|
||||
.replaceAll("{{language}}", this.handleArray(extract.language, context))
|
||||
;
|
||||
}
|
||||
|
||||
@ -45,105 +38,27 @@ export default class DoubanTheaterLoadHandler extends DoubanAbstractLoadHandler<
|
||||
return extract && extract.type && (extract.type.contains("舞台剧") || extract.type.contains("舞剧") || extract.type.contains("Theater") || extract.type.contains("theater"));
|
||||
}
|
||||
|
||||
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 tagsStr = html('div#interest_sect_level > div.a_stars > span.color_gray').text().trim();
|
||||
let tags = tagsStr ? tagsStr.replace('标签:', '').trim().split(' ') : null;
|
||||
let stateWord = html('div#interest_sect_level > div.a_stars > span.mr10').text().trim();
|
||||
let stateWord = html('#interest_sect_level > h2').text().trim();
|
||||
let collectionDateStr = html('div#interest_sect_level > div.a_stars > span.mr10 > span.collection_date').text().trim();
|
||||
let userState1 = DoubanAbstractLoadHandler.getUserState(stateWord);
|
||||
let component = html('div#interest_sect_level > div.a_stars > span.color_gray').next().next().text().trim();
|
||||
|
||||
|
||||
let component = this.getPropertyValue(html, PropertyName.comment);
|
||||
const userState: UserStateSubject = {
|
||||
tags: tags,
|
||||
rate: rate?Number(rate):null,
|
||||
rate: rate ? Number(rate) : null,
|
||||
state: userState1,
|
||||
collectionDate: collectionDateStr?moment(collectionDateStr, 'YYYY-MM-DD').toDate():null,
|
||||
collectionDate: collectionDateStr ? moment(collectionDateStr, 'YYYY-MM-DD').toDate() : null,
|
||||
comment: component
|
||||
}
|
||||
return {data: html, userState: userState};
|
||||
}
|
||||
|
||||
|
||||
parseSubjectFromHtml(html: CheerioAPI, context: HandleContext): DoubanMovieSubject {
|
||||
const movie:DoubanMovieSubject = html('script')
|
||||
.get()
|
||||
.filter(scd => "application/ld+json" == html(scd).attr("type"))
|
||||
.map(i => {
|
||||
let item = html(i).text();
|
||||
item = super.html_decode(item);
|
||||
let obj = JSON.parse(item.replace(/[\r\n\s+]/g, ''));
|
||||
let idPattern = /(\d){5,10}/g;
|
||||
let id = idPattern.exec(obj.url);
|
||||
let name = obj.name;
|
||||
let title = super.getTitleNameByMode(name, PersonNameMode.CH_NAME, context)??name;
|
||||
let originalTitle = super.getTitleNameByMode(name, PersonNameMode.EN_NAME, context) ?? name;
|
||||
|
||||
const result: DoubanMovieSubject = {
|
||||
id: id ? id[0] : '',
|
||||
title: title,
|
||||
type: this.getSupportType(),
|
||||
score: obj.aggregateRating ? obj.aggregateRating.ratingValue : undefined,
|
||||
originalTitle: originalTitle,
|
||||
desc: obj.description,
|
||||
url: "https://movie.douban.com" + obj.url,
|
||||
director: obj.director,
|
||||
author: obj.author,
|
||||
actor: obj.actor,
|
||||
aggregateRating: obj.aggregateRating,
|
||||
datePublished: obj.datePublished ? new Date(obj.datePublished) : undefined,
|
||||
image: obj.image,
|
||||
imageUrl: obj.image,
|
||||
genre: obj.genre,
|
||||
publisher: '',
|
||||
aliases: [""],
|
||||
language: [""],
|
||||
country: [],
|
||||
time: null,
|
||||
IMDb: null,
|
||||
parseSubjectFromHtml(html: CheerioAPI, context: HandleContext): DoubanTheaterSubject {
|
||||
const obj: DoubanTheaterSubject = new DoubanTheaterSubject();
|
||||
obj.id = this.getPropertyValue(html, PropertyName.id);
|
||||
return obj;
|
||||
}
|
||||
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");
|
||||
|
||||
let valueMap = new Map<string, any>();
|
||||
|
||||
publish.map((index, info) => {
|
||||
let key = html(info).text().trim();
|
||||
let value;
|
||||
if (key.indexOf('又名') >= 0 || key.indexOf('语言') >= 0 || key.indexOf('制片国家') >= 0) {
|
||||
// value = html(info.next.next).text().trim();
|
||||
let vas = html(info.next).text().trim();
|
||||
value = vas.split("/").map((v) => v.trim());
|
||||
} else if(key.indexOf('片长') >= 0) {
|
||||
value = html(info.next.next).text().trim()
|
||||
} else {
|
||||
value = html(info.next).text().trim();
|
||||
}
|
||||
valueMap.set(MovieKeyValueMap.get(key), value);
|
||||
})
|
||||
|
||||
movie.country = valueMap.has('country') ? valueMap.get('country') : [];
|
||||
movie.language = valueMap.has('language') ? valueMap.get('language') : [];
|
||||
movie.time = valueMap.has('time') ? valueMap.get('time') : "";
|
||||
movie.aliases = valueMap.has('aliases') ? valueMap.get('aliases') : [];
|
||||
movie.IMDb = valueMap.has('IMDb') ? valueMap.get('IMDb') : "";
|
||||
return movie;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
const MovieKeyValueMap: Map<string, string> = new Map(
|
||||
[['制片国家/地区:', 'country'],
|
||||
['语言:', 'language'],
|
||||
['片长:', 'time'],
|
||||
['又名:', 'aliases'],
|
||||
['IMDb:', 'IMDb']
|
||||
]
|
||||
);
|
||||
|
||||
@ -38,6 +38,7 @@
|
||||
"1.9.0": "0.12.0",
|
||||
"1.9.1": "0.12.0",
|
||||
"1.9.2": "0.12.0",
|
||||
"1.9.3": "0.12.0"
|
||||
"1.9.3": "0.12.0",
|
||||
"1.9.4": "0.12.0"
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user