parent
e48963487b
commit
f5b9020dc8
16 changed files with 225 additions and 64 deletions
|
|
@ -1,10 +1,11 @@
|
||||||
import { MediaTypeModel } from '../models/MediaTypeModel';
|
import { MediaTypeModel } from '../models/MediaTypeModel';
|
||||||
|
import { MediaType } from '../utils/MediaType';
|
||||||
|
|
||||||
export abstract class APIModel {
|
export abstract class APIModel {
|
||||||
apiName: string;
|
apiName: string;
|
||||||
apiUrl: string;
|
apiUrl: string;
|
||||||
apiDescription: string;
|
apiDescription: string;
|
||||||
types: string[];
|
types: MediaType[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function should query the api and return a list of matches. The matches should be caped at 20.
|
* This function should query the api and return a list of matches. The matches should be caped at 20.
|
||||||
|
|
@ -15,12 +16,11 @@ export abstract class APIModel {
|
||||||
|
|
||||||
abstract getById(id: string): Promise<MediaTypeModel>;
|
abstract getById(id: string): Promise<MediaTypeModel>;
|
||||||
|
|
||||||
hasType(type: string): boolean {
|
hasType(type: MediaType): boolean {
|
||||||
return this.types.contains(type);
|
return this.types.contains(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
// for future use (https://github.com/mProjectsCode/obsidian-media-db-plugin/issues/5)
|
hasTypeOverlap(types: MediaType[]): boolean {
|
||||||
hasTypeOverlap(types: string[]): boolean {
|
|
||||||
for (const type of types) {
|
for (const type of types) {
|
||||||
if (this.hasType(type)) {
|
if (this.hasType(type)) {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,8 @@ import { APIModel } from '../APIModel';
|
||||||
import { MediaTypeModel } from '../../models/MediaTypeModel';
|
import { MediaTypeModel } from '../../models/MediaTypeModel';
|
||||||
import MediaDbPlugin from '../../main';
|
import MediaDbPlugin from '../../main';
|
||||||
import { BoardGameModel } from 'src/models/BoardGameModel';
|
import { BoardGameModel } from 'src/models/BoardGameModel';
|
||||||
import { debugLog } from '../../utils/Utils';
|
|
||||||
import { requestUrl } from 'obsidian';
|
import { requestUrl } from 'obsidian';
|
||||||
|
import { MediaType } from '../../utils/MediaType';
|
||||||
|
|
||||||
export class BoardGameGeekAPI extends APIModel {
|
export class BoardGameGeekAPI extends APIModel {
|
||||||
plugin: MediaDbPlugin;
|
plugin: MediaDbPlugin;
|
||||||
|
|
@ -15,7 +15,7 @@ export class BoardGameGeekAPI extends APIModel {
|
||||||
this.apiName = 'BoardGameGeekAPI';
|
this.apiName = 'BoardGameGeekAPI';
|
||||||
this.apiDescription = 'A free API for BoardGameGeek things.';
|
this.apiDescription = 'A free API for BoardGameGeek things.';
|
||||||
this.apiUrl = 'https://api.geekdo.com/xmlapi';
|
this.apiUrl = 'https://api.geekdo.com/xmlapi';
|
||||||
this.types = ['boardgames'];
|
this.types = [MediaType.BoardGame];
|
||||||
}
|
}
|
||||||
|
|
||||||
async searchByTitle(title: string): Promise<MediaTypeModel[]> {
|
async searchByTitle(title: string): Promise<MediaTypeModel[]> {
|
||||||
|
|
@ -33,13 +33,13 @@ export class BoardGameGeekAPI extends APIModel {
|
||||||
const data = fetchData.text;
|
const data = fetchData.text;
|
||||||
const response = new window.DOMParser().parseFromString(data, 'text/xml');
|
const response = new window.DOMParser().parseFromString(data, 'text/xml');
|
||||||
|
|
||||||
debugLog(response);
|
console.debug(response);
|
||||||
|
|
||||||
let ret: MediaTypeModel[] = [];
|
let ret: MediaTypeModel[] = [];
|
||||||
|
|
||||||
for (const boardgame of Array.from(response.querySelectorAll('boardgame'))) {
|
for (const boardgame of Array.from(response.querySelectorAll('boardgame'))) {
|
||||||
const id = boardgame.attributes.getNamedItem('objectid')!.value;
|
const id = boardgame.attributes.getNamedItem('objectid')!.value;
|
||||||
const title = boardgame.querySelector('name')!.textContent!;
|
const title = boardgame.querySelector('name[primary=true]')?.textContent ?? boardgame.querySelector('name')!.textContent!;
|
||||||
const year = boardgame.querySelector('yearpublished')?.textContent ?? '';
|
const year = boardgame.querySelector('yearpublished')?.textContent ?? '';
|
||||||
|
|
||||||
ret.push(
|
ret.push(
|
||||||
|
|
@ -70,17 +70,22 @@ export class BoardGameGeekAPI extends APIModel {
|
||||||
|
|
||||||
const data = fetchData.text;
|
const data = fetchData.text;
|
||||||
const response = new window.DOMParser().parseFromString(data, 'text/xml');
|
const response = new window.DOMParser().parseFromString(data, 'text/xml');
|
||||||
debugLog(response);
|
console.debug(response);
|
||||||
|
|
||||||
const boardgame = response.querySelector('boardgame')!;
|
const boardgame = response.querySelector('boardgame')!;
|
||||||
const title = boardgame.querySelector('name')!.textContent!;
|
const title = boardgame.querySelector('name[primary=true]')!.textContent!;
|
||||||
const year = boardgame.querySelector('yearpublished')?.textContent ?? '';
|
const year = boardgame.querySelector('yearpublished')?.textContent ?? '';
|
||||||
const image = boardgame.querySelector('image')?.textContent ?? undefined;
|
const image = boardgame.querySelector('image')?.textContent ?? undefined;
|
||||||
const onlineRating = Number.parseFloat(boardgame.querySelector('statistics ratings average')?.textContent ?? '');
|
const onlineRating = Number.parseFloat(boardgame.querySelector('statistics ratings average')?.textContent ?? '0');
|
||||||
const genres = Array.from(boardgame.querySelectorAll('boardgamecategory')).map(n => n!.textContent!);
|
const genres = Array.from(boardgame.querySelectorAll('boardgamecategory')).map(n => n!.textContent!);
|
||||||
|
const complexityRating = Number.parseFloat(boardgame.querySelector('averageweight')?.textContent ?? '0');
|
||||||
|
const minPlayers = Number.parseFloat(boardgame.querySelector('minplayers')?.textContent ?? '0');
|
||||||
|
const maxPlayers = Number.parseFloat(boardgame.querySelector('maxplayers')?.textContent ?? '0');
|
||||||
|
const playtime = (boardgame.querySelector('playingtime')?.textContent ?? 'unknown') + ' minutes';
|
||||||
|
const publishers = Array.from(boardgame.querySelectorAll('boardgamepublisher')).map(n => n!.textContent!);
|
||||||
|
|
||||||
const model = new BoardGameModel({
|
const model = new BoardGameModel({
|
||||||
title,
|
title: title,
|
||||||
englishTitle: title,
|
englishTitle: title,
|
||||||
year: year === '0' ? '' : year,
|
year: year === '0' ? '' : year,
|
||||||
dataSource: this.apiName,
|
dataSource: this.apiName,
|
||||||
|
|
@ -89,7 +94,13 @@ export class BoardGameGeekAPI extends APIModel {
|
||||||
|
|
||||||
genres: genres,
|
genres: genres,
|
||||||
onlineRating: onlineRating,
|
onlineRating: onlineRating,
|
||||||
|
complexityRating: complexityRating,
|
||||||
|
minPlayers: minPlayers,
|
||||||
|
maxPlayers: maxPlayers,
|
||||||
|
playtime: playtime,
|
||||||
|
publishers: publishers,
|
||||||
image: image,
|
image: image,
|
||||||
|
|
||||||
released: true,
|
released: true,
|
||||||
|
|
||||||
userData: {
|
userData: {
|
||||||
|
|
|
||||||
|
|
@ -25,14 +25,14 @@ export class LocGovAPI extends APIModel {
|
||||||
|
|
||||||
const searchUrl = `https://www.loc.gov/search/?q=${encodeURIComponent(title)}&fo=json&c=20`;
|
const searchUrl = `https://www.loc.gov/search/?q=${encodeURIComponent(title)}&fo=json&c=20`;
|
||||||
const fetchData = await fetch(searchUrl);
|
const fetchData = await fetch(searchUrl);
|
||||||
debugLog(fetchData);
|
console.debug(fetchData);
|
||||||
|
|
||||||
if (fetchData.status !== 200) {
|
if (fetchData.status !== 200) {
|
||||||
throw Error(`MDB | Received status code ${fetchData.status} from an API.`);
|
throw Error(`MDB | Received status code ${fetchData.status} from an API.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await fetchData.json();
|
const data = await fetchData.json();
|
||||||
debugLog(data);
|
console.debug(data);
|
||||||
let ret: MediaTypeModel[] = [];
|
let ret: MediaTypeModel[] = [];
|
||||||
|
|
||||||
throw new Error('MDB | Under construction, API implementation not finished');
|
throw new Error('MDB | Under construction, API implementation not finished');
|
||||||
|
|
@ -50,7 +50,7 @@ export class LocGovAPI extends APIModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await fetchData.json();
|
const data = await fetchData.json();
|
||||||
debugLog(data);
|
console.debug(data);
|
||||||
const result = data.data;
|
const result = data.data;
|
||||||
|
|
||||||
const type = this.typeMappings.get(result.type.toLowerCase());
|
const type = this.typeMappings.get(result.type.toLowerCase());
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import { MediaTypeModel } from '../../models/MediaTypeModel';
|
||||||
import { MovieModel } from '../../models/MovieModel';
|
import { MovieModel } from '../../models/MovieModel';
|
||||||
import MediaDbPlugin from '../../main';
|
import MediaDbPlugin from '../../main';
|
||||||
import { SeriesModel } from '../../models/SeriesModel';
|
import { SeriesModel } from '../../models/SeriesModel';
|
||||||
import { debugLog } from '../../utils/Utils';
|
import { MediaType } from '../../utils/MediaType';
|
||||||
|
|
||||||
export class MALAPI extends APIModel {
|
export class MALAPI extends APIModel {
|
||||||
plugin: MediaDbPlugin;
|
plugin: MediaDbPlugin;
|
||||||
|
|
@ -16,7 +16,7 @@ export class MALAPI extends APIModel {
|
||||||
this.apiName = 'MALAPI';
|
this.apiName = 'MALAPI';
|
||||||
this.apiDescription = 'A free API for Anime. Some results may take a long time to load.';
|
this.apiDescription = 'A free API for Anime. Some results may take a long time to load.';
|
||||||
this.apiUrl = 'https://jikan.moe/';
|
this.apiUrl = 'https://jikan.moe/';
|
||||||
this.types = ['movie', 'series', 'anime'];
|
this.types = [MediaType.Movie, MediaType.Series];
|
||||||
this.typeMappings = new Map<string, string>();
|
this.typeMappings = new Map<string, string>();
|
||||||
this.typeMappings.set('movie', 'movie');
|
this.typeMappings.set('movie', 'movie');
|
||||||
this.typeMappings.set('special', 'special');
|
this.typeMappings.set('special', 'special');
|
||||||
|
|
@ -30,13 +30,13 @@ export class MALAPI extends APIModel {
|
||||||
const searchUrl = `https://api.jikan.moe/v4/anime?q=${encodeURIComponent(title)}&limit=20${this.plugin.settings.sfwFilter ? '&sfw' : ''}`;
|
const searchUrl = `https://api.jikan.moe/v4/anime?q=${encodeURIComponent(title)}&limit=20${this.plugin.settings.sfwFilter ? '&sfw' : ''}`;
|
||||||
|
|
||||||
const fetchData = await fetch(searchUrl);
|
const fetchData = await fetch(searchUrl);
|
||||||
debugLog(fetchData);
|
console.debug(fetchData);
|
||||||
if (fetchData.status !== 200) {
|
if (fetchData.status !== 200) {
|
||||||
throw Error(`MDB | Received status code ${fetchData.status} from an API.`);
|
throw Error(`MDB | Received status code ${fetchData.status} from an API.`);
|
||||||
}
|
}
|
||||||
const data = await fetchData.json();
|
const data = await fetchData.json();
|
||||||
|
|
||||||
debugLog(data);
|
console.debug(data);
|
||||||
|
|
||||||
let ret: MediaTypeModel[] = [];
|
let ret: MediaTypeModel[] = [];
|
||||||
|
|
||||||
|
|
@ -85,7 +85,7 @@ export class MALAPI extends APIModel {
|
||||||
async getById(id: string): Promise<MediaTypeModel> {
|
async getById(id: string): Promise<MediaTypeModel> {
|
||||||
console.log(`MDB | api "${this.apiName}" queried by ID`);
|
console.log(`MDB | api "${this.apiName}" queried by ID`);
|
||||||
|
|
||||||
const searchUrl = `https://api.jikan.moe/v4/anime/${encodeURIComponent(id)}`;
|
const searchUrl = `https://api.jikan.moe/v4/anime/${encodeURIComponent(id)}/full`;
|
||||||
const fetchData = await fetch(searchUrl);
|
const fetchData = await fetch(searchUrl);
|
||||||
|
|
||||||
if (fetchData.status !== 200) {
|
if (fetchData.status !== 200) {
|
||||||
|
|
@ -93,7 +93,7 @@ export class MALAPI extends APIModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await fetchData.json();
|
const data = await fetchData.json();
|
||||||
debugLog(data);
|
console.debug(data);
|
||||||
const result = data.data;
|
const result = data.data;
|
||||||
|
|
||||||
const type = this.typeMappings.get(result.type?.toLowerCase());
|
const type = this.typeMappings.get(result.type?.toLowerCase());
|
||||||
|
|
@ -111,10 +111,12 @@ export class MALAPI extends APIModel {
|
||||||
producer: result.studios?.map((x: any) => x.name).join(', ') ?? 'unknown',
|
producer: result.studios?.map((x: any) => x.name).join(', ') ?? 'unknown',
|
||||||
duration: result.duration ?? 'unknown',
|
duration: result.duration ?? 'unknown',
|
||||||
onlineRating: result.score ?? 0,
|
onlineRating: result.score ?? 0,
|
||||||
|
actors: [],
|
||||||
image: result.images?.jpg?.image_url ?? '',
|
image: result.images?.jpg?.image_url ?? '',
|
||||||
|
|
||||||
released: true,
|
released: true,
|
||||||
premiere: new Date(result.aired?.from).toLocaleDateString() ?? 'unknown',
|
premiere: new Date(result.aired?.from).toLocaleDateString() ?? 'unknown',
|
||||||
|
streamingServices: result.streaming?.map((x: any) => x.name) ?? [],
|
||||||
|
|
||||||
userData: {
|
userData: {
|
||||||
watched: false,
|
watched: false,
|
||||||
|
|
@ -140,10 +142,12 @@ export class MALAPI extends APIModel {
|
||||||
producer: result.studios?.map((x: any) => x.name).join(', ') ?? 'unknown',
|
producer: result.studios?.map((x: any) => x.name).join(', ') ?? 'unknown',
|
||||||
duration: result.duration ?? 'unknown',
|
duration: result.duration ?? 'unknown',
|
||||||
onlineRating: result.score ?? 0,
|
onlineRating: result.score ?? 0,
|
||||||
|
actors: [],
|
||||||
image: result.images?.jpg?.image_url ?? '',
|
image: result.images?.jpg?.image_url ?? '',
|
||||||
|
|
||||||
released: true,
|
released: true,
|
||||||
premiere: new Date(result.aired?.from).toLocaleDateString() ?? 'unknown',
|
premiere: new Date(result.aired?.from).toLocaleDateString() ?? 'unknown',
|
||||||
|
streamingServices: result.streaming?.map((x: any) => x.name) ?? [],
|
||||||
|
|
||||||
userData: {
|
userData: {
|
||||||
watched: false,
|
watched: false,
|
||||||
|
|
@ -168,6 +172,7 @@ export class MALAPI extends APIModel {
|
||||||
episodes: result.episodes,
|
episodes: result.episodes,
|
||||||
duration: result.duration ?? 'unknown',
|
duration: result.duration ?? 'unknown',
|
||||||
onlineRating: result.score ?? 0,
|
onlineRating: result.score ?? 0,
|
||||||
|
streamingServices: result.streaming?.map((x: any) => x.name) ?? [],
|
||||||
image: result.images?.jpg?.image_url ?? '',
|
image: result.images?.jpg?.image_url ?? '',
|
||||||
|
|
||||||
released: true,
|
released: true,
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,8 @@ import { MediaTypeModel } from '../../models/MediaTypeModel';
|
||||||
import MediaDbPlugin from '../../main';
|
import MediaDbPlugin from '../../main';
|
||||||
import { requestUrl } from 'obsidian';
|
import { requestUrl } from 'obsidian';
|
||||||
import { MusicReleaseModel } from '../../models/MusicReleaseModel';
|
import { MusicReleaseModel } from '../../models/MusicReleaseModel';
|
||||||
import { contactEmail, debugLog, mediaDbVersion, pluginName } from '../../utils/Utils';
|
import { contactEmail, mediaDbVersion, pluginName } from '../../utils/Utils';
|
||||||
|
import { MediaType } from '../../utils/MediaType';
|
||||||
|
|
||||||
export class MusicBrainzAPI extends APIModel {
|
export class MusicBrainzAPI extends APIModel {
|
||||||
plugin: MediaDbPlugin;
|
plugin: MediaDbPlugin;
|
||||||
|
|
@ -15,7 +16,7 @@ export class MusicBrainzAPI extends APIModel {
|
||||||
this.apiName = 'MusicBrainz API';
|
this.apiName = 'MusicBrainz API';
|
||||||
this.apiDescription = 'Free API for music albums.';
|
this.apiDescription = 'Free API for music albums.';
|
||||||
this.apiUrl = 'https://musicbrainz.org/';
|
this.apiUrl = 'https://musicbrainz.org/';
|
||||||
this.types = ['music'];
|
this.types = [MediaType.MusicRelease];
|
||||||
}
|
}
|
||||||
|
|
||||||
async searchByTitle(title: string): Promise<MediaTypeModel[]> {
|
async searchByTitle(title: string): Promise<MediaTypeModel[]> {
|
||||||
|
|
@ -30,14 +31,14 @@ export class MusicBrainzAPI extends APIModel {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
debugLog(fetchData);
|
console.debug(fetchData);
|
||||||
|
|
||||||
if (fetchData.status !== 200) {
|
if (fetchData.status !== 200) {
|
||||||
throw Error(`MDB | Received status code ${fetchData.status} from an API.`);
|
throw Error(`MDB | Received status code ${fetchData.status} from an API.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await fetchData.json;
|
const data = await fetchData.json;
|
||||||
debugLog(data);
|
console.debug(data);
|
||||||
let ret: MediaTypeModel[] = [];
|
let ret: MediaTypeModel[] = [];
|
||||||
|
|
||||||
for (const result of data['release-groups']) {
|
for (const result of data['release-groups']) {
|
||||||
|
|
@ -76,7 +77,7 @@ export class MusicBrainzAPI extends APIModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await fetchData.json;
|
const data = await fetchData.json;
|
||||||
debugLog(data);
|
console.debug(data);
|
||||||
const result = data;
|
const result = data;
|
||||||
|
|
||||||
const model = new MusicReleaseModel({
|
const model = new MusicReleaseModel({
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import { MovieModel } from '../../models/MovieModel';
|
||||||
import MediaDbPlugin from '../../main';
|
import MediaDbPlugin from '../../main';
|
||||||
import { SeriesModel } from '../../models/SeriesModel';
|
import { SeriesModel } from '../../models/SeriesModel';
|
||||||
import { GameModel } from '../../models/GameModel';
|
import { GameModel } from '../../models/GameModel';
|
||||||
import { debugLog } from '../../utils/Utils';
|
import { MediaType } from '../../utils/MediaType';
|
||||||
|
|
||||||
export class OMDbAPI extends APIModel {
|
export class OMDbAPI extends APIModel {
|
||||||
plugin: MediaDbPlugin;
|
plugin: MediaDbPlugin;
|
||||||
|
|
@ -17,7 +17,7 @@ export class OMDbAPI extends APIModel {
|
||||||
this.apiName = 'OMDbAPI';
|
this.apiName = 'OMDbAPI';
|
||||||
this.apiDescription = 'A free API for Movies, Series and Games.';
|
this.apiDescription = 'A free API for Movies, Series and Games.';
|
||||||
this.apiUrl = 'http://www.omdbapi.com/';
|
this.apiUrl = 'http://www.omdbapi.com/';
|
||||||
this.types = ['movie', 'series'];
|
this.types = [MediaType.Movie, MediaType.Series, MediaType.Game];
|
||||||
this.typeMappings = new Map<string, string>();
|
this.typeMappings = new Map<string, string>();
|
||||||
this.typeMappings.set('movie', 'movie');
|
this.typeMappings.set('movie', 'movie');
|
||||||
this.typeMappings.set('series', 'series');
|
this.typeMappings.set('series', 'series');
|
||||||
|
|
@ -46,7 +46,7 @@ export class OMDbAPI extends APIModel {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
debugLog(data.Search);
|
console.debug(data.Search);
|
||||||
|
|
||||||
let ret: MediaTypeModel[] = [];
|
let ret: MediaTypeModel[] = [];
|
||||||
|
|
||||||
|
|
@ -108,7 +108,7 @@ export class OMDbAPI extends APIModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await fetchData.json();
|
const result = await fetchData.json();
|
||||||
debugLog(result);
|
console.debug(result);
|
||||||
|
|
||||||
if (result.Response === 'False') {
|
if (result.Response === 'False') {
|
||||||
throw Error(`MDB | Received error from ${this.apiName}: ${result.Error}`);
|
throw Error(`MDB | Received error from ${this.apiName}: ${result.Error}`);
|
||||||
|
|
@ -133,9 +133,11 @@ export class OMDbAPI extends APIModel {
|
||||||
producer: result.Director ?? 'unknown',
|
producer: result.Director ?? 'unknown',
|
||||||
duration: result.Runtime ?? 'unknown',
|
duration: result.Runtime ?? 'unknown',
|
||||||
onlineRating: Number.parseFloat(result.imdbRating ?? 0),
|
onlineRating: Number.parseFloat(result.imdbRating ?? 0),
|
||||||
|
actors: result.Actors?.split(', ') ?? [],
|
||||||
image: result.Poster ?? '',
|
image: result.Poster ?? '',
|
||||||
|
|
||||||
released: true,
|
released: true,
|
||||||
|
streamingServices: [],
|
||||||
premiere: new Date(result.Released).toLocaleDateString() ?? 'unknown',
|
premiere: new Date(result.Released).toLocaleDateString() ?? 'unknown',
|
||||||
|
|
||||||
userData: {
|
userData: {
|
||||||
|
|
@ -161,9 +163,11 @@ export class OMDbAPI extends APIModel {
|
||||||
episodes: 0,
|
episodes: 0,
|
||||||
duration: result.Runtime ?? 'unknown',
|
duration: result.Runtime ?? 'unknown',
|
||||||
onlineRating: Number.parseFloat(result.imdbRating ?? 0),
|
onlineRating: Number.parseFloat(result.imdbRating ?? 0),
|
||||||
|
actors: result.Actors?.split(', ') ?? [],
|
||||||
image: result.Poster ?? '',
|
image: result.Poster ?? '',
|
||||||
|
|
||||||
released: true,
|
released: true,
|
||||||
|
streamingServices: [],
|
||||||
airing: false,
|
airing: false,
|
||||||
airedFrom: new Date(result.Released).toLocaleDateString() ?? 'unknown',
|
airedFrom: new Date(result.Released).toLocaleDateString() ?? 'unknown',
|
||||||
airedTo: 'unknown',
|
airedTo: 'unknown',
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ import { APIModel } from '../APIModel';
|
||||||
import { MediaTypeModel } from '../../models/MediaTypeModel';
|
import { MediaTypeModel } from '../../models/MediaTypeModel';
|
||||||
import MediaDbPlugin from '../../main';
|
import MediaDbPlugin from '../../main';
|
||||||
import { GameModel } from '../../models/GameModel';
|
import { GameModel } from '../../models/GameModel';
|
||||||
import { debugLog } from '../../utils/Utils';
|
|
||||||
import { requestUrl } from 'obsidian';
|
import { requestUrl } from 'obsidian';
|
||||||
import { MediaType } from '../../utils/MediaType';
|
import { MediaType } from '../../utils/MediaType';
|
||||||
|
|
||||||
|
|
@ -17,7 +16,7 @@ export class SteamAPI extends APIModel {
|
||||||
this.apiName = 'SteamAPI';
|
this.apiName = 'SteamAPI';
|
||||||
this.apiDescription = 'A free API for all Steam games.';
|
this.apiDescription = 'A free API for all Steam games.';
|
||||||
this.apiUrl = 'http://www.steampowered.com/';
|
this.apiUrl = 'http://www.steampowered.com/';
|
||||||
this.types = ['games'];
|
this.types = [MediaType.Game];
|
||||||
this.typeMappings = new Map<string, string>();
|
this.typeMappings = new Map<string, string>();
|
||||||
this.typeMappings.set('game', 'game');
|
this.typeMappings.set('game', 'game');
|
||||||
}
|
}
|
||||||
|
|
@ -36,7 +35,7 @@ export class SteamAPI extends APIModel {
|
||||||
|
|
||||||
const data = await fetchData.json;
|
const data = await fetchData.json;
|
||||||
|
|
||||||
debugLog(data);
|
console.debug(data);
|
||||||
|
|
||||||
let filteredData = [];
|
let filteredData = [];
|
||||||
|
|
||||||
|
|
@ -79,7 +78,7 @@ export class SteamAPI extends APIModel {
|
||||||
throw Error(`MDB | Received status code ${fetchData.status} from an API.`);
|
throw Error(`MDB | Received status code ${fetchData.status} from an API.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
debugLog(await fetchData.json);
|
console.debug(await fetchData.json);
|
||||||
|
|
||||||
let result: any;
|
let result: any;
|
||||||
for (const [key, value] of Object.entries(await fetchData.json)) {
|
for (const [key, value] of Object.entries(await fetchData.json)) {
|
||||||
|
|
@ -94,7 +93,7 @@ export class SteamAPI extends APIModel {
|
||||||
throw Error(`MDB | API returned invalid data.`);
|
throw Error(`MDB | API returned invalid data.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
debugLog(result);
|
console.debug(result);
|
||||||
|
|
||||||
const model = new GameModel({
|
const model = new GameModel({
|
||||||
type: MediaType.Game,
|
type: MediaType.Game,
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import { APIModel } from '../APIModel';
|
||||||
import { MediaTypeModel } from '../../models/MediaTypeModel';
|
import { MediaTypeModel } from '../../models/MediaTypeModel';
|
||||||
import MediaDbPlugin from '../../main';
|
import MediaDbPlugin from '../../main';
|
||||||
import { WikiModel } from '../../models/WikiModel';
|
import { WikiModel } from '../../models/WikiModel';
|
||||||
import { debugLog } from '../../utils/Utils';
|
import { MediaType } from '../../utils/MediaType';
|
||||||
|
|
||||||
export class WikipediaAPI extends APIModel {
|
export class WikipediaAPI extends APIModel {
|
||||||
plugin: MediaDbPlugin;
|
plugin: MediaDbPlugin;
|
||||||
|
|
@ -14,7 +14,7 @@ export class WikipediaAPI extends APIModel {
|
||||||
this.apiName = 'Wikipedia API';
|
this.apiName = 'Wikipedia API';
|
||||||
this.apiDescription = 'The API behind Wikipedia';
|
this.apiDescription = 'The API behind Wikipedia';
|
||||||
this.apiUrl = 'https://www.wikipedia.com';
|
this.apiUrl = 'https://www.wikipedia.com';
|
||||||
this.types = ['wiki'];
|
this.types = [MediaType.Wiki];
|
||||||
}
|
}
|
||||||
|
|
||||||
async searchByTitle(title: string): Promise<MediaTypeModel[]> {
|
async searchByTitle(title: string): Promise<MediaTypeModel[]> {
|
||||||
|
|
@ -22,14 +22,14 @@ export class WikipediaAPI extends APIModel {
|
||||||
|
|
||||||
const searchUrl = `https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=${encodeURIComponent(title)}&srlimit=20&utf8=&format=json&origin=*`;
|
const searchUrl = `https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=${encodeURIComponent(title)}&srlimit=20&utf8=&format=json&origin=*`;
|
||||||
const fetchData = await fetch(searchUrl);
|
const fetchData = await fetch(searchUrl);
|
||||||
debugLog(fetchData);
|
console.debug(fetchData);
|
||||||
|
|
||||||
if (fetchData.status !== 200) {
|
if (fetchData.status !== 200) {
|
||||||
throw Error(`MDB | Received status code ${fetchData.status} from an API.`);
|
throw Error(`MDB | Received status code ${fetchData.status} from an API.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await fetchData.json();
|
const data = await fetchData.json();
|
||||||
debugLog(data);
|
console.debug(data);
|
||||||
let ret: MediaTypeModel[] = [];
|
let ret: MediaTypeModel[] = [];
|
||||||
|
|
||||||
for (const result of data.query.search) {
|
for (const result of data.query.search) {
|
||||||
|
|
@ -59,7 +59,7 @@ export class WikipediaAPI extends APIModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await fetchData.json();
|
const data = await fetchData.json();
|
||||||
debugLog(data);
|
console.debug(data);
|
||||||
const result: any = Object.entries(data?.query?.pages)[0][1];
|
const result: any = Object.entries(data?.query?.pages)[0][1];
|
||||||
|
|
||||||
const model = new WikiModel({
|
const model = new WikiModel({
|
||||||
|
|
|
||||||
15
src/main.ts
15
src/main.ts
|
|
@ -45,6 +45,7 @@ export default class MediaDbPlugin extends Plugin {
|
||||||
this.addSettingTab(new MediaDbSettingTab(this.app, this));
|
this.addSettingTab(new MediaDbSettingTab(this.app, this));
|
||||||
|
|
||||||
this.mediaTypeManager.updateTemplates(this.settings);
|
this.mediaTypeManager.updateTemplates(this.settings);
|
||||||
|
this.mediaTypeManager.updateFolders(this.settings);
|
||||||
|
|
||||||
// add icon to the left ribbon
|
// add icon to the left ribbon
|
||||||
const ribbonIconEl = this.addRibbonIcon('database', 'Add new Media DB entry', (evt: MouseEvent) => this.createEntryWithAdvancedSearchModal());
|
const ribbonIconEl = this.addRibbonIcon('database', 'Add new Media DB entry', (evt: MouseEvent) => this.createEntryWithAdvancedSearchModal());
|
||||||
|
|
@ -271,6 +272,10 @@ export default class MediaDbPlugin extends Plugin {
|
||||||
|
|
||||||
let fileContent = await this.generateMediaDbNoteContents(mediaTypeModel, options);
|
let fileContent = await this.generateMediaDbNoteContents(mediaTypeModel, options);
|
||||||
|
|
||||||
|
if (!options.folder) {
|
||||||
|
options.folder = await this.mediaTypeManager.getFolder(mediaTypeModel, this.app);
|
||||||
|
}
|
||||||
|
|
||||||
await this.createNote(this.mediaTypeManager.getFileName(mediaTypeModel), fileContent, options);
|
await this.createNote(this.mediaTypeManager.getFileName(mediaTypeModel), fileContent, options);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn(e);
|
console.warn(e);
|
||||||
|
|
@ -368,10 +373,7 @@ export default class MediaDbPlugin extends Plugin {
|
||||||
*/
|
*/
|
||||||
async createNote(fileName: string, fileContent: string, options: CreateNoteOptions) {
|
async createNote(fileName: string, fileContent: string, options: CreateNoteOptions) {
|
||||||
// find and possibly create the folder set in settings or passed in folder
|
// find and possibly create the folder set in settings or passed in folder
|
||||||
const folder = options.folder ?? this.app.vault.getAbstractFileByPath(this.settings.folder);
|
const folder = options.folder ?? this.app.vault.getAbstractFileByPath('/');
|
||||||
if (!folder) {
|
|
||||||
await this.app.vault.createFolder(this.settings.folder);
|
|
||||||
}
|
|
||||||
|
|
||||||
fileName = replaceIllegalFileNameCharactersInString(fileName);
|
fileName = replaceIllegalFileNameCharactersInString(fileName);
|
||||||
const filePath = `${folder.path}/${fileName}.md`;
|
const filePath = `${folder.path}/${fileName}.md`;
|
||||||
|
|
@ -513,8 +515,8 @@ export default class MediaDbPlugin extends Plugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
async createErroredFilesReport(erroredFiles: { filePath: string; error: string }[]): Promise<void> {
|
async createErroredFilesReport(erroredFiles: { filePath: string; error: string }[]): Promise<void> {
|
||||||
const title = `bulk import error report ${dateTimeToString(new Date())}`;
|
const title = `MDB - bulk import error report ${dateTimeToString(new Date())}`;
|
||||||
const filePath = `${this.settings.folder.replace(/\/$/, '')}/${title}.md`;
|
const filePath = `${title}.md`;
|
||||||
|
|
||||||
const table = [['file', 'error']].concat(erroredFiles.map(x => [x.filePath, x.error]));
|
const table = [['file', 'error']].concat(erroredFiles.map(x => [x.filePath, x.error]));
|
||||||
|
|
||||||
|
|
@ -561,6 +563,7 @@ export default class MediaDbPlugin extends Plugin {
|
||||||
|
|
||||||
async saveSettings() {
|
async saveSettings() {
|
||||||
this.mediaTypeManager.updateTemplates(this.settings);
|
this.mediaTypeManager.updateTemplates(this.settings);
|
||||||
|
this.mediaTypeManager.updateFolders(this.settings);
|
||||||
|
|
||||||
await this.saveData(this.settings);
|
await this.saveData(this.settings);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,11 @@ import { MediaType } from '../utils/MediaType';
|
||||||
export class BoardGameModel extends MediaTypeModel {
|
export class BoardGameModel extends MediaTypeModel {
|
||||||
genres: string[];
|
genres: string[];
|
||||||
onlineRating: number;
|
onlineRating: number;
|
||||||
|
complexityRating: number;
|
||||||
|
minPlayers: number;
|
||||||
|
maxPlayers: number;
|
||||||
|
playtime: string;
|
||||||
|
publishers: string[];
|
||||||
image?: string;
|
image?: string;
|
||||||
|
|
||||||
released: boolean;
|
released: boolean;
|
||||||
|
|
@ -19,8 +24,15 @@ export class BoardGameModel extends MediaTypeModel {
|
||||||
|
|
||||||
this.genres = undefined;
|
this.genres = undefined;
|
||||||
this.onlineRating = undefined;
|
this.onlineRating = undefined;
|
||||||
|
this.minPlayers = undefined;
|
||||||
|
this.maxPlayers = undefined;
|
||||||
|
this.playtime = undefined;
|
||||||
|
this.publishers = undefined;
|
||||||
|
this.complexityRating = undefined;
|
||||||
this.image = undefined;
|
this.image = undefined;
|
||||||
|
|
||||||
this.released = undefined;
|
this.released = undefined;
|
||||||
|
|
||||||
this.userData = {
|
this.userData = {
|
||||||
played: undefined,
|
played: undefined,
|
||||||
personalRating: undefined,
|
personalRating: undefined,
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,11 @@ export class MovieModel extends MediaTypeModel {
|
||||||
producer: string;
|
producer: string;
|
||||||
duration: string;
|
duration: string;
|
||||||
onlineRating: number;
|
onlineRating: number;
|
||||||
|
actors: string[];
|
||||||
image: string;
|
image: string;
|
||||||
|
|
||||||
released: boolean;
|
released: boolean;
|
||||||
|
streamingServices: string[];
|
||||||
premiere: string;
|
premiere: string;
|
||||||
|
|
||||||
userData: {
|
userData: {
|
||||||
|
|
@ -25,9 +27,13 @@ export class MovieModel extends MediaTypeModel {
|
||||||
this.producer = undefined;
|
this.producer = undefined;
|
||||||
this.duration = undefined;
|
this.duration = undefined;
|
||||||
this.onlineRating = undefined;
|
this.onlineRating = undefined;
|
||||||
|
this.actors = undefined;
|
||||||
this.image = undefined;
|
this.image = undefined;
|
||||||
|
|
||||||
this.released = undefined;
|
this.released = undefined;
|
||||||
|
this.streamingServices = undefined;
|
||||||
this.premiere = undefined;
|
this.premiere = undefined;
|
||||||
|
|
||||||
this.userData = {
|
this.userData = {
|
||||||
watched: undefined,
|
watched: undefined,
|
||||||
lastWatched: undefined,
|
lastWatched: undefined,
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,11 @@ export class SeriesModel extends MediaTypeModel {
|
||||||
episodes: number;
|
episodes: number;
|
||||||
duration: string;
|
duration: string;
|
||||||
onlineRating: number;
|
onlineRating: number;
|
||||||
|
actors: string[];
|
||||||
image: string;
|
image: string;
|
||||||
|
|
||||||
released: boolean;
|
released: boolean;
|
||||||
|
streamingServices: string[];
|
||||||
airing: boolean;
|
airing: boolean;
|
||||||
airedFrom: string;
|
airedFrom: string;
|
||||||
airedTo: string;
|
airedTo: string;
|
||||||
|
|
@ -38,11 +40,15 @@ export class SeriesModel extends MediaTypeModel {
|
||||||
this.episodes = undefined;
|
this.episodes = undefined;
|
||||||
this.duration = undefined;
|
this.duration = undefined;
|
||||||
this.onlineRating = undefined;
|
this.onlineRating = undefined;
|
||||||
|
this.actors = undefined;
|
||||||
this.image = undefined;
|
this.image = undefined;
|
||||||
|
|
||||||
this.released = undefined;
|
this.released = undefined;
|
||||||
|
this.streamingServices = undefined;
|
||||||
this.airing = undefined;
|
this.airing = undefined;
|
||||||
this.airedFrom = undefined;
|
this.airedFrom = undefined;
|
||||||
this.airedTo = undefined;
|
this.airedTo = undefined;
|
||||||
|
|
||||||
this.userData = {
|
this.userData = {
|
||||||
watched: undefined,
|
watched: undefined,
|
||||||
lastWatched: undefined,
|
lastWatched: undefined,
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ import { MEDIA_TYPES } from '../utils/MediaTypeManager';
|
||||||
import { MediaTypeModel } from '../models/MediaTypeModel';
|
import { MediaTypeModel } from '../models/MediaTypeModel';
|
||||||
|
|
||||||
export interface MediaDbPluginSettings {
|
export interface MediaDbPluginSettings {
|
||||||
folder: string;
|
|
||||||
OMDbKey: string;
|
OMDbKey: string;
|
||||||
sfwFilter: boolean;
|
sfwFilter: boolean;
|
||||||
useCustomYamlStringifier: boolean;
|
useCustomYamlStringifier: boolean;
|
||||||
|
|
@ -36,11 +35,17 @@ export interface MediaDbPluginSettings {
|
||||||
musicReleasePropertyConversionRules: string;
|
musicReleasePropertyConversionRules: string;
|
||||||
boardgamePropertyConversionRules: string;
|
boardgamePropertyConversionRules: string;
|
||||||
|
|
||||||
|
movieFolder: string;
|
||||||
|
seriesFolder: string;
|
||||||
|
gameFolder: string;
|
||||||
|
wikiFolder: string;
|
||||||
|
musicReleaseFolder: string;
|
||||||
|
boardgameFolder: string;
|
||||||
|
|
||||||
propertyMappingModels: PropertyMappingModel[];
|
propertyMappingModels: PropertyMappingModel[];
|
||||||
}
|
}
|
||||||
|
|
||||||
const DEFAULT_SETTINGS: MediaDbPluginSettings = {
|
const DEFAULT_SETTINGS: MediaDbPluginSettings = {
|
||||||
folder: 'Media DB',
|
|
||||||
OMDbKey: '',
|
OMDbKey: '',
|
||||||
sfwFilter: true,
|
sfwFilter: true,
|
||||||
useCustomYamlStringifier: true,
|
useCustomYamlStringifier: true,
|
||||||
|
|
@ -67,6 +72,13 @@ const DEFAULT_SETTINGS: MediaDbPluginSettings = {
|
||||||
musicReleasePropertyConversionRules: '',
|
musicReleasePropertyConversionRules: '',
|
||||||
boardgamePropertyConversionRules: '',
|
boardgamePropertyConversionRules: '',
|
||||||
|
|
||||||
|
movieFolder: 'Media DB/movies',
|
||||||
|
seriesFolder: 'Media DB/series',
|
||||||
|
gameFolder: 'Media DB/games',
|
||||||
|
wikiFolder: 'Media DB/wiki',
|
||||||
|
musicReleaseFolder: 'Media DB/music',
|
||||||
|
boardgameFolder: 'Media DB/boardgames',
|
||||||
|
|
||||||
propertyMappingModels: [],
|
propertyMappingModels: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -111,19 +123,6 @@ export class MediaDbSettingTab extends PluginSettingTab {
|
||||||
|
|
||||||
containerEl.createEl('h2', { text: 'Media DB Plugin Settings' });
|
containerEl.createEl('h2', { text: 'Media DB Plugin Settings' });
|
||||||
|
|
||||||
new Setting(containerEl)
|
|
||||||
.setName('New file location')
|
|
||||||
.setDesc('New media db entries will be placed here.')
|
|
||||||
.addSearch(cb => {
|
|
||||||
new FolderSuggest(this.app, cb.inputEl);
|
|
||||||
cb.setPlaceholder('Example: folder1/folder2')
|
|
||||||
.setValue(this.plugin.settings.folder)
|
|
||||||
.onChange(data => {
|
|
||||||
this.plugin.settings.folder = data;
|
|
||||||
this.plugin.saveSettings();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
new Setting(containerEl)
|
new Setting(containerEl)
|
||||||
.setName('OMDb API key')
|
.setName('OMDb API key')
|
||||||
.setDesc('API key for "www.omdbapi.com".')
|
.setDesc('API key for "www.omdbapi.com".')
|
||||||
|
|
@ -166,6 +165,87 @@ export class MediaDbSettingTab extends PluginSettingTab {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
containerEl.createEl('h3', { text: 'New File Location' });
|
||||||
|
// region new file location
|
||||||
|
new Setting(containerEl)
|
||||||
|
.setName('Movie Folder')
|
||||||
|
.setDesc('Where newly imported movies should be places.')
|
||||||
|
.addSearch(cb => {
|
||||||
|
new FolderSuggest(this.app, cb.inputEl);
|
||||||
|
cb.setPlaceholder(DEFAULT_SETTINGS.movieFolder)
|
||||||
|
.setValue(this.plugin.settings.movieFolder)
|
||||||
|
.onChange(data => {
|
||||||
|
this.plugin.settings.movieFolder = data;
|
||||||
|
this.plugin.saveSettings();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
new Setting(containerEl)
|
||||||
|
.setName('Series Folder')
|
||||||
|
.setDesc('Where newly imported series should be places.')
|
||||||
|
.addSearch(cb => {
|
||||||
|
new FolderSuggest(this.app, cb.inputEl);
|
||||||
|
cb.setPlaceholder(DEFAULT_SETTINGS.seriesFolder)
|
||||||
|
.setValue(this.plugin.settings.seriesFolder)
|
||||||
|
.onChange(data => {
|
||||||
|
this.plugin.settings.seriesFolder = data;
|
||||||
|
this.plugin.saveSettings();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
new Setting(containerEl)
|
||||||
|
.setName('Game Folder')
|
||||||
|
.setDesc('Where newly imported games should be places.')
|
||||||
|
.addSearch(cb => {
|
||||||
|
new FolderSuggest(this.app, cb.inputEl);
|
||||||
|
cb.setPlaceholder(DEFAULT_SETTINGS.gameFolder)
|
||||||
|
.setValue(this.plugin.settings.gameFolder)
|
||||||
|
.onChange(data => {
|
||||||
|
this.plugin.settings.gameFolder = data;
|
||||||
|
this.plugin.saveSettings();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
new Setting(containerEl)
|
||||||
|
.setName('Wiki Folder')
|
||||||
|
.setDesc('Where newly imported wiki articles should be places.')
|
||||||
|
.addSearch(cb => {
|
||||||
|
new FolderSuggest(this.app, cb.inputEl);
|
||||||
|
cb.setPlaceholder(DEFAULT_SETTINGS.wikiFolder)
|
||||||
|
.setValue(this.plugin.settings.wikiFolder)
|
||||||
|
.onChange(data => {
|
||||||
|
this.plugin.settings.wikiFolder = data;
|
||||||
|
this.plugin.saveSettings();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
new Setting(containerEl)
|
||||||
|
.setName('Music Folder')
|
||||||
|
.setDesc('Where newly imported music should be places.')
|
||||||
|
.addSearch(cb => {
|
||||||
|
new FolderSuggest(this.app, cb.inputEl);
|
||||||
|
cb.setPlaceholder(DEFAULT_SETTINGS.musicReleaseFolder)
|
||||||
|
.setValue(this.plugin.settings.musicReleaseFolder)
|
||||||
|
.onChange(data => {
|
||||||
|
this.plugin.settings.musicReleaseFolder = data;
|
||||||
|
this.plugin.saveSettings();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
new Setting(containerEl)
|
||||||
|
.setName('Board Game Folder')
|
||||||
|
.setDesc('Where newly imported board games should be places.')
|
||||||
|
.addSearch(cb => {
|
||||||
|
new FileSuggest(this.app, cb.inputEl);
|
||||||
|
cb.setPlaceholder(DEFAULT_SETTINGS.boardgameFolder)
|
||||||
|
.setValue(this.plugin.settings.boardgameFolder)
|
||||||
|
.onChange(data => {
|
||||||
|
this.plugin.settings.boardgameFolder = data;
|
||||||
|
this.plugin.saveSettings();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
// endregion
|
||||||
|
|
||||||
containerEl.createEl('h3', { text: 'Template Settings' });
|
containerEl.createEl('h3', { text: 'Template Settings' });
|
||||||
// region templates
|
// region templates
|
||||||
new Setting(containerEl)
|
new Setting(containerEl)
|
||||||
|
|
|
||||||
|
|
@ -2,19 +2,21 @@ import { MediaDbPluginSettings } from '../settings/Settings';
|
||||||
import { MediaType } from './MediaType';
|
import { MediaType } from './MediaType';
|
||||||
import { MediaTypeModel } from '../models/MediaTypeModel';
|
import { MediaTypeModel } from '../models/MediaTypeModel';
|
||||||
import { replaceTags } from './Utils';
|
import { replaceTags } from './Utils';
|
||||||
import { App, TFile } from 'obsidian';
|
import { App, TAbstractFile, TFile, TFolder } from 'obsidian';
|
||||||
import { MovieModel } from '../models/MovieModel';
|
import { MovieModel } from '../models/MovieModel';
|
||||||
import { SeriesModel } from '../models/SeriesModel';
|
import { SeriesModel } from '../models/SeriesModel';
|
||||||
import { GameModel } from '../models/GameModel';
|
import { GameModel } from '../models/GameModel';
|
||||||
import { WikiModel } from '../models/WikiModel';
|
import { WikiModel } from '../models/WikiModel';
|
||||||
import { MusicReleaseModel } from '../models/MusicReleaseModel';
|
import { MusicReleaseModel } from '../models/MusicReleaseModel';
|
||||||
import { BoardGameModel } from '../models/BoardGameModel';
|
import { BoardGameModel } from '../models/BoardGameModel';
|
||||||
|
import { awaitExpression } from '@babel/types';
|
||||||
|
|
||||||
export const MEDIA_TYPES: MediaType[] = [MediaType.Movie, MediaType.Series, MediaType.Game, MediaType.Wiki, MediaType.MusicRelease, MediaType.BoardGame];
|
export const MEDIA_TYPES: MediaType[] = [MediaType.Movie, MediaType.Series, MediaType.Game, MediaType.Wiki, MediaType.MusicRelease, MediaType.BoardGame];
|
||||||
|
|
||||||
export class MediaTypeManager {
|
export class MediaTypeManager {
|
||||||
mediaFileNameTemplateMap: Map<MediaType, string>;
|
mediaFileNameTemplateMap: Map<MediaType, string>;
|
||||||
mediaTemplateMap: Map<MediaType, string>;
|
mediaTemplateMap: Map<MediaType, string>;
|
||||||
|
mediaFolderMap: Map<MediaType, string>;
|
||||||
|
|
||||||
constructor() {}
|
constructor() {}
|
||||||
|
|
||||||
|
|
@ -36,6 +38,16 @@ export class MediaTypeManager {
|
||||||
this.mediaTemplateMap.set(MediaType.BoardGame, settings.boardgameTemplate);
|
this.mediaTemplateMap.set(MediaType.BoardGame, settings.boardgameTemplate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateFolders(settings: MediaDbPluginSettings) {
|
||||||
|
this.mediaFolderMap = new Map<MediaType, string>();
|
||||||
|
this.mediaFolderMap.set(MediaType.Movie, settings.movieFolder);
|
||||||
|
this.mediaFolderMap.set(MediaType.Series, settings.seriesFolder);
|
||||||
|
this.mediaFolderMap.set(MediaType.Game, settings.gameFolder);
|
||||||
|
this.mediaFolderMap.set(MediaType.Wiki, settings.wikiFolder);
|
||||||
|
this.mediaFolderMap.set(MediaType.MusicRelease, settings.musicReleaseFolder);
|
||||||
|
this.mediaFolderMap.set(MediaType.BoardGame, settings.boardgameFolder);
|
||||||
|
}
|
||||||
|
|
||||||
getFileName(mediaTypeModel: MediaTypeModel): string {
|
getFileName(mediaTypeModel: MediaTypeModel): string {
|
||||||
return replaceTags(this.mediaFileNameTemplateMap.get(mediaTypeModel.getMediaType()), mediaTypeModel);
|
return replaceTags(this.mediaFileNameTemplateMap.get(mediaTypeModel.getMediaType()), mediaTypeModel);
|
||||||
}
|
}
|
||||||
|
|
@ -61,6 +73,26 @@ export class MediaTypeManager {
|
||||||
return replaceTags(template, mediaTypeModel);
|
return replaceTags(template, mediaTypeModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getFolder(mediaTypeModel: MediaTypeModel, app: App): Promise<TFolder> {
|
||||||
|
let folderPath = this.mediaFolderMap.get(mediaTypeModel.getMediaType());
|
||||||
|
|
||||||
|
if (!folderPath) {
|
||||||
|
folderPath = `/`;
|
||||||
|
}
|
||||||
|
console.log(folderPath);
|
||||||
|
|
||||||
|
if (!(await app.vault.adapter.exists(folderPath))) {
|
||||||
|
await app.vault.createFolder(folderPath);
|
||||||
|
}
|
||||||
|
let folder: TAbstractFile = app.vault.getAbstractFileByPath(folderPath);
|
||||||
|
|
||||||
|
if (!(folder instanceof TFolder)) {
|
||||||
|
throw Error(`Expected ${folder} to be instance of TFolder`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return folder;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Takes an object and a MediaType and turns the object into an instance of a MediaTypeModel corresponding to the MediaType passed in.
|
* Takes an object and a MediaType and turns the object into an instance of a MediaTypeModel corresponding to the MediaType passed in.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import MediaDbPlugin from '../main';
|
||||||
import { MediaDbPreviewModal } from 'src/modals/MediaDbPreviewModal';
|
import { MediaDbPreviewModal } from 'src/modals/MediaDbPreviewModal';
|
||||||
import { CreateNoteOptions } from './Utils';
|
import { CreateNoteOptions } from './Utils';
|
||||||
import { MediaDbSearchModal } from '../modals/MediaDbSearchModal';
|
import { MediaDbSearchModal } from '../modals/MediaDbSearchModal';
|
||||||
|
import { MediaType } from './MediaType';
|
||||||
|
|
||||||
export enum ModalResultCode {
|
export enum ModalResultCode {
|
||||||
SUCCESS,
|
SUCCESS,
|
||||||
|
|
@ -77,7 +78,7 @@ export interface PreviewModalResult {
|
||||||
*/
|
*/
|
||||||
export interface SearchModalData {
|
export interface SearchModalData {
|
||||||
query: string;
|
query: string;
|
||||||
types: string[];
|
types: MediaType[];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -124,7 +125,7 @@ export interface PreviewModalData {
|
||||||
*/
|
*/
|
||||||
export interface SearchModalOptions {
|
export interface SearchModalOptions {
|
||||||
modalTitle?: string;
|
modalTitle?: string;
|
||||||
preselectedTypes?: string[];
|
preselectedTypes?: MediaType[];
|
||||||
prefilledSearchString?: string;
|
prefilledSearchString?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -202,6 +202,7 @@ export class PropertyMappingNameConflictError extends Error {
|
||||||
* - attachTemplate: whether to attach the template (DEFAULT: false)
|
* - attachTemplate: whether to attach the template (DEFAULT: false)
|
||||||
* - attachFie: a file to attach (DEFAULT: undefined)
|
* - attachFie: a file to attach (DEFAULT: undefined)
|
||||||
* - openNote: whether to open the note after creation (DEFAULT: false)
|
* - openNote: whether to open the note after creation (DEFAULT: false)
|
||||||
|
* - folder: folder to put the note in
|
||||||
*/
|
*/
|
||||||
export interface CreateNoteOptions {
|
export interface CreateNoteOptions {
|
||||||
attachTemplate?: boolean;
|
attachTemplate?: boolean;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue