Merge pull request #220 from ltctceplrm/tmdb-seasons
Added season search for TmdbAPI
This commit is contained in:
commit
cb36559d38
16 changed files with 23751 additions and 13 deletions
|
|
@ -120,6 +120,7 @@ Now you select the result you want, and the plugin will cast its magic, creating
|
||||||
| ---------------------------------------------------- | ------------------------------------------------------------------------------------------------- | ----------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ |
|
| ---------------------------------------------------- | ------------------------------------------------------------------------------------------------- | ----------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ |
|
||||||
| [Jikan](https://jikan.moe/) | Jikan is an API that uses [My Anime List](https://myanimelist.net) and offers metadata for anime. | series, movies, specials, OVAs, manga, manwha, novels | No | 60 per minute and 3 per second | Yes |
|
| [Jikan](https://jikan.moe/) | Jikan is an API that uses [My Anime List](https://myanimelist.net) and offers metadata for anime. | series, movies, specials, OVAs, manga, manwha, novels | No | 60 per minute and 3 per second | Yes |
|
||||||
| [OMDb](https://www.omdbapi.com/) | OMDb is an API that offers metadata for movies, series, and games. | series, movies, games | Yes, you can get a free key here [here](https://www.omdbapi.com/apikey.aspx) | 1000 per day | No |
|
| [OMDb](https://www.omdbapi.com/) | OMDb is an API that offers metadata for movies, series, and games. | series, movies, games | Yes, you can get a free key here [here](https://www.omdbapi.com/apikey.aspx) | 1000 per day | No |
|
||||||
|
| [TMDB](https://www.themoviedb.org/) | TMDB is a API that offers community editable metadata for movies and series. | series, movies | Yes, by making an account [here](https://www.themoviedb.org/signup) and getting your `API Key` (**not** `API Read Access Token`) [here](https://www.themoviedb.org/settings/api) | 50 per second | Yes |
|
||||||
| [MusicBrainz](https://musicbrainz.org/) | MusicBrainz is an API that offers information about music releases. | music releases | No | 50 per second | No |
|
| [MusicBrainz](https://musicbrainz.org/) | MusicBrainz is an API that offers information about music releases. | music releases | No | 50 per second | No |
|
||||||
| [Wikipedia](https://en.wikipedia.org/wiki/Main_Page) | The Wikipedia API allows access to all Wikipedia articles. | wiki articles | No | None | No |
|
| [Wikipedia](https://en.wikipedia.org/wiki/Main_Page) | The Wikipedia API allows access to all Wikipedia articles. | wiki articles | No | None | No |
|
||||||
| [Steam](https://store.steampowered.com/) | The Steam API offers information on all Steam games. | games | No | 10000 per day | No |
|
| [Steam](https://store.steampowered.com/) | The Steam API offers information on all Steam games. | games | No | 10000 per day | No |
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,9 @@ async function fetchSchema() {
|
||||||
|
|
||||||
// https://github.com/internetarchive/openlibrary-api/blob/main/swagger.yaml
|
// https://github.com/internetarchive/openlibrary-api/blob/main/swagger.yaml
|
||||||
await $('bun openapi-typescript ./src/api/schemas/OpenLibrary.json -o ./src/api/schemas/OpenLibrary.ts');
|
await $('bun openapi-typescript ./src/api/schemas/OpenLibrary.json -o ./src/api/schemas/OpenLibrary.ts');
|
||||||
|
|
||||||
|
// https://developer.themoviedb.org/openapi
|
||||||
|
await $('bun openapi-typescript https://developer.themoviedb.org/openapi/tmdb-api.json -o ./src/api/schemas/TMDB.ts');
|
||||||
}
|
}
|
||||||
|
|
||||||
await fetchSchema();
|
await fetchSchema();
|
||||||
|
|
|
||||||
158
src/api/apis/TMDBMovieAPI.ts
Normal file
158
src/api/apis/TMDBMovieAPI.ts
Normal file
|
|
@ -0,0 +1,158 @@
|
||||||
|
import createClient from 'openapi-fetch';
|
||||||
|
import type MediaDbPlugin from '../../main';
|
||||||
|
import type { MediaTypeModel } from '../../models/MediaTypeModel';
|
||||||
|
import { MovieModel } from '../../models/MovieModel';
|
||||||
|
import { MediaType } from '../../utils/MediaType';
|
||||||
|
import { APIModel } from '../APIModel';
|
||||||
|
import type { paths } from '../schemas/TMDB';
|
||||||
|
|
||||||
|
export class TMDBMovieAPI extends APIModel {
|
||||||
|
plugin: MediaDbPlugin;
|
||||||
|
typeMappings: Map<string, string>;
|
||||||
|
apiDateFormat: string = 'YYYY-MM-DD';
|
||||||
|
|
||||||
|
constructor(plugin: MediaDbPlugin) {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.apiName = 'TMDBMovieAPI';
|
||||||
|
this.apiDescription = 'A community built Movie DB.';
|
||||||
|
this.apiUrl = 'https://www.themoviedb.org/';
|
||||||
|
this.types = [MediaType.Movie];
|
||||||
|
this.typeMappings = new Map<string, string>();
|
||||||
|
this.typeMappings.set('movie', 'movie');
|
||||||
|
}
|
||||||
|
|
||||||
|
async searchByTitle(title: string): Promise<MediaTypeModel[]> {
|
||||||
|
console.log(`MDB | api "${this.apiName}" queried by Title`);
|
||||||
|
|
||||||
|
if (!this.plugin.settings.TMDBKey) {
|
||||||
|
throw new Error(`MDB | API key for ${this.apiName} missing.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const client = createClient<paths>({ baseUrl: 'https://api.themoviedb.org' });
|
||||||
|
const response = await client.GET('/3/search/movie', {
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${this.plugin.settings.TMDBKey}`,
|
||||||
|
},
|
||||||
|
params: {
|
||||||
|
query: {
|
||||||
|
query: encodeURIComponent(title),
|
||||||
|
include_adult: this.plugin.settings.sfwFilter ? false : true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
fetch: fetch,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.response.status === 401) {
|
||||||
|
throw Error(`MDB | Authentication for ${this.apiName} failed. Check the API key.`);
|
||||||
|
}
|
||||||
|
if (response.response.status !== 200) {
|
||||||
|
throw Error(`MDB | Received status code ${response.response.status} from ${this.apiName}.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = response.data;
|
||||||
|
|
||||||
|
if (!data) {
|
||||||
|
throw Error(`MDB | No data received from ${this.apiName}.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.total_results === 0 || !data.results) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
// console.debug(data.results);
|
||||||
|
|
||||||
|
const ret: MediaTypeModel[] = [];
|
||||||
|
|
||||||
|
for (const result of data.results) {
|
||||||
|
ret.push(
|
||||||
|
new MovieModel({
|
||||||
|
type: 'movie',
|
||||||
|
title: result.original_title,
|
||||||
|
englishTitle: result.title,
|
||||||
|
year: result.release_date ? new Date(result.release_date).getFullYear().toString() : 'unknown',
|
||||||
|
dataSource: this.apiName,
|
||||||
|
id: result.id.toString(),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
async getById(id: string): Promise<MediaTypeModel> {
|
||||||
|
console.log(`MDB | api "${this.apiName}" queried by ID`);
|
||||||
|
|
||||||
|
if (!this.plugin.settings.TMDBKey) {
|
||||||
|
throw Error(`MDB | API key for ${this.apiName} missing.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const client = createClient<paths>({ baseUrl: 'https://api.themoviedb.org' });
|
||||||
|
const response = await client.GET('/3/movie/{movie_id}', {
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${this.plugin.settings.TMDBKey}`,
|
||||||
|
},
|
||||||
|
params: {
|
||||||
|
path: { movie_id: parseInt(id) },
|
||||||
|
query: {
|
||||||
|
append_to_response: 'credits',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
fetch: fetch,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.response.status === 401) {
|
||||||
|
throw Error(`MDB | Authentication for ${this.apiName} failed. Check the API key.`);
|
||||||
|
}
|
||||||
|
if (response.response.status !== 200) {
|
||||||
|
throw Error(`MDB | Received status code ${response.response.status} from ${this.apiName}.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = response.data;
|
||||||
|
|
||||||
|
if (!result) {
|
||||||
|
throw Error(`MDB | No data received from ${this.apiName}.`);
|
||||||
|
}
|
||||||
|
// console.debug(result);
|
||||||
|
|
||||||
|
return new MovieModel({
|
||||||
|
type: 'movie',
|
||||||
|
title: result.title,
|
||||||
|
englishTitle: result.title,
|
||||||
|
year: result.release_date ? new Date(result.release_date).getFullYear().toString() : 'unknown',
|
||||||
|
premiere: this.plugin.dateFormatter.format(result.release_date, this.apiDateFormat) ?? 'unknown',
|
||||||
|
dataSource: this.apiName,
|
||||||
|
url: `https://www.themoviedb.org/movie/${result.id}`,
|
||||||
|
id: result.id.toString(),
|
||||||
|
|
||||||
|
plot: result.overview ?? '',
|
||||||
|
genres: result.genres?.map((g: any) => g.name) ?? [],
|
||||||
|
// TMDB's spec allows for 'append_to_response' but doesn't seem to account for it in the type
|
||||||
|
// @ts-ignore
|
||||||
|
writer: result.credits.crew?.filter((c: any) => c.job === 'Screenplay').map((c: any) => c.name) ?? [],
|
||||||
|
// @ts-ignore
|
||||||
|
director: result.credits.crew?.filter((c: any) => c.job === 'Director').map((c: any) => c.name) ?? [],
|
||||||
|
studio: result.production_companies?.map((s: any) => s.name) ?? [],
|
||||||
|
|
||||||
|
duration: result.runtime?.toString() ?? 'unknown',
|
||||||
|
onlineRating: result.vote_average,
|
||||||
|
// @ts-ignore
|
||||||
|
actors: result.credits.cast.map((c: any) => c.name).slice(0, 5) ?? [],
|
||||||
|
image: `https://image.tmdb.org/t/p/w780${result.poster_path}`,
|
||||||
|
|
||||||
|
released: ['Released'].includes(result.status!),
|
||||||
|
streamingServices: [],
|
||||||
|
|
||||||
|
userData: {
|
||||||
|
watched: false,
|
||||||
|
lastWatched: '',
|
||||||
|
personalRating: 0,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
getDisabledMediaTypes(): MediaType[] {
|
||||||
|
return this.plugin.settings.TMDBMovieAPI_disabledMediaTypes;
|
||||||
|
}
|
||||||
|
}
|
||||||
269
src/api/apis/TMDBSeasonAPI.ts
Normal file
269
src/api/apis/TMDBSeasonAPI.ts
Normal file
|
|
@ -0,0 +1,269 @@
|
||||||
|
import createClient from 'openapi-fetch';
|
||||||
|
import type MediaDbPlugin from '../../main';
|
||||||
|
import type { MediaTypeModel } from '../../models/MediaTypeModel';
|
||||||
|
import { MediaType } from '../../utils/MediaType';
|
||||||
|
import { APIModel } from '../APIModel';
|
||||||
|
import { SeasonModel } from '../../models/SeasonModel';
|
||||||
|
import type { paths } from '../schemas/TMDB';
|
||||||
|
|
||||||
|
export class TMDBSeasonAPI extends APIModel {
|
||||||
|
plugin: MediaDbPlugin;
|
||||||
|
typeMappings: Map<string, string>;
|
||||||
|
apiDateFormat: string = 'YYYY-MM-DD';
|
||||||
|
|
||||||
|
constructor(plugin: MediaDbPlugin) {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.apiName = 'TMDBSeasonAPI';
|
||||||
|
this.apiDescription = 'A community built Series DB (seasons).';
|
||||||
|
this.apiUrl = 'https://www.themoviedb.org/';
|
||||||
|
this.types = [MediaType.Season];
|
||||||
|
this.typeMappings = new Map<string, string>();
|
||||||
|
this.typeMappings.set('tv', 'season');
|
||||||
|
}
|
||||||
|
|
||||||
|
async searchByTitle(title: string): Promise<MediaTypeModel[]> {
|
||||||
|
console.log(`MDB | api "${this.apiName}" queried by Title`);
|
||||||
|
|
||||||
|
if (!this.plugin.settings.TMDBKey) {
|
||||||
|
throw new Error(`MDB | API key for ${this.apiName} missing.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const client = createClient<paths>({ baseUrl: 'https://api.themoviedb.org' });
|
||||||
|
const searchResponse = await client.GET('/3/search/tv', {
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${this.plugin.settings.TMDBKey}`,
|
||||||
|
},
|
||||||
|
params: {
|
||||||
|
query: {
|
||||||
|
query: encodeURIComponent(title),
|
||||||
|
include_adult: this.plugin.settings.sfwFilter ? false : true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
fetch: fetch,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (searchResponse.response.status === 401) {
|
||||||
|
throw Error(`MDB | Authentication for ${this.apiName} failed. Check the API key.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (searchResponse.response.status !== 200) {
|
||||||
|
throw Error(`MDB | Received status code ${searchResponse.response.status} from ${this.apiName}.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const searchData = searchResponse.data;
|
||||||
|
|
||||||
|
if (!searchData?.results || searchData.total_results === 0) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
const ret: MediaTypeModel[] = [];
|
||||||
|
|
||||||
|
for (const result of searchData.results) {
|
||||||
|
if (ret.length >= 20) break;
|
||||||
|
|
||||||
|
// Fetch series details to get the total number of seasons
|
||||||
|
let totalSeasons = 0;
|
||||||
|
try {
|
||||||
|
const detailsResponse = await client.GET('/3/tv/{series_id}', {
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${this.plugin.settings.TMDBKey}`,
|
||||||
|
},
|
||||||
|
params: {
|
||||||
|
path: { series_id: result.id ?? 0 },
|
||||||
|
},
|
||||||
|
fetch: fetch,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (detailsResponse.response.status === 200 && detailsResponse.data) {
|
||||||
|
const detailsData = detailsResponse.data;
|
||||||
|
if (Array.isArray(detailsData.seasons)) {
|
||||||
|
totalSeasons = detailsData.seasons.length;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch {}
|
||||||
|
|
||||||
|
ret.push(
|
||||||
|
new SeasonModel({
|
||||||
|
title: `${result.name ?? result.original_name ?? ''}`,
|
||||||
|
englishTitle: result.name ?? result.original_name ?? '',
|
||||||
|
year: result.first_air_date ? new Date(result.first_air_date).getFullYear().toString() : 'unknown',
|
||||||
|
dataSource: this.apiName,
|
||||||
|
id: result.id?.toString() ?? '',
|
||||||
|
seasonTitle: result.name ?? result.original_name ?? '',
|
||||||
|
seasonNumber: totalSeasons,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch all seasons for a given series
|
||||||
|
async getSeasonsForSeries(tvId: string): Promise<SeasonModel[]> {
|
||||||
|
if (!this.plugin.settings.TMDBKey) {
|
||||||
|
throw new Error(`MDB | API key for ${this.apiName} missing.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const client = createClient<paths>({ baseUrl: 'https://api.themoviedb.org' });
|
||||||
|
const seriesResponse = await client.GET('/3/tv/{series_id}', {
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${this.plugin.settings.TMDBKey}`,
|
||||||
|
},
|
||||||
|
params: {
|
||||||
|
path: { series_id: parseInt(tvId) },
|
||||||
|
},
|
||||||
|
fetch: fetch,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (seriesResponse.response.status === 401) {
|
||||||
|
throw Error(`MDB | Authentication for ${this.apiName} failed. Check the API key.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (seriesResponse.response.status !== 200) {
|
||||||
|
throw Error(`MDB | Received status code ${seriesResponse.response.status} from ${this.apiName}.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const seriesData = seriesResponse.data;
|
||||||
|
const seriesName = seriesData?.name ?? '';
|
||||||
|
|
||||||
|
const ret: SeasonModel[] = [];
|
||||||
|
|
||||||
|
if (Array.isArray(seriesData?.seasons)) {
|
||||||
|
for (const season of seriesData.seasons) {
|
||||||
|
const seasonNumber = season.season_number ?? 0;
|
||||||
|
const titleText = `${seriesName} - Season ${seasonNumber}`;
|
||||||
|
|
||||||
|
ret.push(
|
||||||
|
new SeasonModel({
|
||||||
|
title: titleText,
|
||||||
|
englishTitle: titleText,
|
||||||
|
year: season.air_date ? new Date(season.air_date).getFullYear().toString() : 'unknown',
|
||||||
|
dataSource: this.apiName,
|
||||||
|
id: `${tvId}/season/${seasonNumber}`,
|
||||||
|
seasonTitle: season.name ?? titleText,
|
||||||
|
seasonNumber: seasonNumber,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
async getById(id: string): Promise<MediaTypeModel> {
|
||||||
|
console.log(`MDB | api "${this.apiName}" queried by ID`);
|
||||||
|
|
||||||
|
if (!this.plugin.settings.TMDBKey) {
|
||||||
|
throw Error(`MDB | API key for ${this.apiName} missing.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Expect season ids like "12345/season/2"
|
||||||
|
const m = /^(\d+)\/season\/(\d+)$/.exec(id);
|
||||||
|
if (!m) {
|
||||||
|
throw Error(`MDB | Invalid season id "${id}". Expected format "<series_id>/season/<season_number>".`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const tvId = m[1];
|
||||||
|
const seasonNumber = m[2];
|
||||||
|
|
||||||
|
const client = createClient<paths>({ baseUrl: 'https://api.themoviedb.org' });
|
||||||
|
|
||||||
|
// Fetch season details
|
||||||
|
const seasonResponse = await client.GET('/3/tv/{series_id}/season/{season_number}', {
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${this.plugin.settings.TMDBKey}`,
|
||||||
|
},
|
||||||
|
params: {
|
||||||
|
path: {
|
||||||
|
series_id: parseInt(tvId),
|
||||||
|
season_number: parseInt(seasonNumber),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
fetch: fetch,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (seasonResponse.response.status === 401) {
|
||||||
|
throw Error(`MDB | Authentication for ${this.apiName} failed. Check the API key.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (seasonResponse.response.status !== 200) {
|
||||||
|
throw Error(`MDB | Received status code ${seasonResponse.response.status} from ${this.apiName}.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const seasonData = seasonResponse.data;
|
||||||
|
if (!seasonData) {
|
||||||
|
throw Error(`MDB | No data received from ${this.apiName}.`);
|
||||||
|
}
|
||||||
|
// Fetch parent series to build consistent titles and inherit fields
|
||||||
|
const seriesResponse = await client.GET('/3/tv/{series_id}', {
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${this.plugin.settings.TMDBKey}`,
|
||||||
|
},
|
||||||
|
params: {
|
||||||
|
path: { series_id: parseInt(tvId) },
|
||||||
|
query: {
|
||||||
|
append_to_response: 'credits',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
fetch: fetch,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (seriesResponse.response.status === 401) {
|
||||||
|
throw Error(`MDB | Authentication for ${this.apiName} failed. Check the API key.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (seriesResponse.response.status !== 200) {
|
||||||
|
throw Error(`MDB | Received status code ${seriesResponse.response.status} from ${this.apiName}.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const seriesData = seriesResponse.data;
|
||||||
|
|
||||||
|
if (!seriesData) {
|
||||||
|
throw Error(`MDB | No data received from ${this.apiName}.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const seriesName = seriesData?.name ?? '';
|
||||||
|
const airDate = seasonData.air_date ?? '';
|
||||||
|
const titleText = `${seriesName} - Season ${seasonData.season_number}`;
|
||||||
|
|
||||||
|
// Get airedTo as the air_date of the last episode, if available
|
||||||
|
let airedTo = 'unknown';
|
||||||
|
if (Array.isArray(seasonData.episodes) && seasonData.episodes.length > 0) {
|
||||||
|
const lastEp = seasonData.episodes[seasonData.episodes.length - 1];
|
||||||
|
if (lastEp?.air_date) airedTo = lastEp.air_date;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new SeasonModel({
|
||||||
|
title: titleText,
|
||||||
|
englishTitle: titleText,
|
||||||
|
year: airDate ? new Date(airDate).getFullYear().toString() : 'unknown',
|
||||||
|
dataSource: this.apiName,
|
||||||
|
url: `https://www.themoviedb.org/tv/${tvId}/season/${seasonData.season_number}`,
|
||||||
|
id: `${tvId}/season/${seasonData.season_number}`,
|
||||||
|
seasonTitle: seasonData.name ?? titleText,
|
||||||
|
seasonNumber: seasonData.season_number ?? Number(seasonNumber),
|
||||||
|
episodes: Array.isArray(seasonData.episodes) ? seasonData.episodes.length : 0,
|
||||||
|
airedFrom: this.plugin.dateFormatter.format(airDate, this.apiDateFormat) ?? 'unknown',
|
||||||
|
airedTo: airedTo,
|
||||||
|
plot: seasonData.overview ?? '',
|
||||||
|
image: seasonData.poster_path ? `https://image.tmdb.org/t/p/w780${seasonData.poster_path}` : '',
|
||||||
|
genres: seriesData.genres?.map(g => g.name ?? '').filter(name => name !== '') ?? [],
|
||||||
|
writer: seriesData.created_by?.map(c => c.name ?? '').filter(name => name !== '') ?? [],
|
||||||
|
studio: seriesData.production_companies?.map(s => s.name ?? '').filter(name => name !== '') ?? [],
|
||||||
|
duration: seriesData.episode_run_time?.[0]?.toString() ?? '',
|
||||||
|
onlineRating: seasonData.vote_average ?? 0,
|
||||||
|
// @ts-ignore - append_to_response credits not reflected in base schema
|
||||||
|
actors: seriesData.credits?.cast?.map((c: any) => c.name).slice(0, 5) ?? [],
|
||||||
|
released: ['Returning Series', 'Cancelled', 'Ended'].includes(seriesData.status ?? ''),
|
||||||
|
streamingServices: [],
|
||||||
|
airing: ['Returning Series'].includes(seriesData.status ?? ''),
|
||||||
|
userData: { watched: false, lastWatched: '', personalRating: 0 },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
getDisabledMediaTypes(): MediaType[] {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
157
src/api/apis/TMDBSeriesAPI.ts
Normal file
157
src/api/apis/TMDBSeriesAPI.ts
Normal file
|
|
@ -0,0 +1,157 @@
|
||||||
|
import createClient from 'openapi-fetch';
|
||||||
|
import type MediaDbPlugin from '../../main';
|
||||||
|
import type { MediaTypeModel } from '../../models/MediaTypeModel';
|
||||||
|
import { SeriesModel } from '../../models/SeriesModel';
|
||||||
|
import { MediaType } from '../../utils/MediaType';
|
||||||
|
import { APIModel } from '../APIModel';
|
||||||
|
import type { paths } from '../schemas/TMDB';
|
||||||
|
|
||||||
|
export class TMDBSeriesAPI extends APIModel {
|
||||||
|
plugin: MediaDbPlugin;
|
||||||
|
typeMappings: Map<string, string>;
|
||||||
|
apiDateFormat: string = 'YYYY-MM-DD';
|
||||||
|
|
||||||
|
constructor(plugin: MediaDbPlugin) {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.apiName = 'TMDBSeriesAPI';
|
||||||
|
this.apiDescription = 'A community built Series DB.';
|
||||||
|
this.apiUrl = 'https://www.themoviedb.org/';
|
||||||
|
this.types = [MediaType.Series];
|
||||||
|
this.typeMappings = new Map<string, string>();
|
||||||
|
this.typeMappings.set('tv', 'series');
|
||||||
|
}
|
||||||
|
|
||||||
|
async searchByTitle(title: string): Promise<MediaTypeModel[]> {
|
||||||
|
console.log(`MDB | api "${this.apiName}" queried by Title`);
|
||||||
|
|
||||||
|
if (!this.plugin.settings.TMDBKey) {
|
||||||
|
throw new Error(`MDB | API key for ${this.apiName} missing.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const client = createClient<paths>({ baseUrl: 'https://api.themoviedb.org' });
|
||||||
|
const response = await client.GET('/3/search/tv', {
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${this.plugin.settings.TMDBKey}`,
|
||||||
|
},
|
||||||
|
params: {
|
||||||
|
query: {
|
||||||
|
query: encodeURIComponent(title),
|
||||||
|
include_adult: this.plugin.settings.sfwFilter ? false : true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
fetch: fetch,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.response.status === 401) {
|
||||||
|
throw Error(`MDB | Authentication for ${this.apiName} failed. Check the API key.`);
|
||||||
|
}
|
||||||
|
if (response.response.status !== 200) {
|
||||||
|
throw Error(`MDB | Received status code ${response.response.status} from ${this.apiName}.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = response.data;
|
||||||
|
|
||||||
|
if (!data) {
|
||||||
|
throw Error(`MDB | No data received from ${this.apiName}.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.total_results === 0 || !data.results) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
// console.debug(data.results);
|
||||||
|
|
||||||
|
const ret: MediaTypeModel[] = [];
|
||||||
|
|
||||||
|
for (const result of data.results) {
|
||||||
|
ret.push(
|
||||||
|
new SeriesModel({
|
||||||
|
type: 'series',
|
||||||
|
title: result.original_name,
|
||||||
|
englishTitle: result.name,
|
||||||
|
year: result.first_air_date ? new Date(result.first_air_date).getFullYear().toString() : 'unknown',
|
||||||
|
dataSource: this.apiName,
|
||||||
|
id: result.id.toString(),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
async getById(id: string): Promise<MediaTypeModel> {
|
||||||
|
console.log(`MDB | api "${this.apiName}" queried by ID`);
|
||||||
|
|
||||||
|
if (!this.plugin.settings.TMDBKey) {
|
||||||
|
throw Error(`MDB | API key for ${this.apiName} missing.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const client = createClient<paths>({ baseUrl: 'https://api.themoviedb.org' });
|
||||||
|
const response = await client.GET('/3/tv/{series_id}', {
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${this.plugin.settings.TMDBKey}`,
|
||||||
|
},
|
||||||
|
params: {
|
||||||
|
path: { series_id: parseInt(id) },
|
||||||
|
query: {
|
||||||
|
append_to_response: 'credits',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
fetch: fetch,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.response.status === 401) {
|
||||||
|
throw Error(`MDB | Authentication for ${this.apiName} failed. Check the API key.`);
|
||||||
|
}
|
||||||
|
if (response.response.status !== 200) {
|
||||||
|
throw Error(`MDB | Received status code ${response.response.status} from ${this.apiName}.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = response.data;
|
||||||
|
|
||||||
|
if (!result) {
|
||||||
|
throw Error(`MDB | No data received from ${this.apiName}.`);
|
||||||
|
}
|
||||||
|
// console.debug(result);
|
||||||
|
|
||||||
|
return new SeriesModel({
|
||||||
|
type: 'series',
|
||||||
|
title: result.original_name,
|
||||||
|
englishTitle: result.name,
|
||||||
|
year: result.first_air_date ? new Date(result.first_air_date).getFullYear().toString() : 'unknown',
|
||||||
|
dataSource: this.apiName,
|
||||||
|
url: `https://www.themoviedb.org/tv/${result.id}`,
|
||||||
|
id: result.id.toString(),
|
||||||
|
|
||||||
|
plot: result.overview ?? '',
|
||||||
|
genres: result.genres?.map((g: any) => g.name) ?? [],
|
||||||
|
writer: result.created_by?.map((c: any) => c.name) ?? [],
|
||||||
|
studio: result.production_companies?.map((s: any) => s.name) ?? [],
|
||||||
|
episodes: result.number_of_episodes,
|
||||||
|
duration: result.episode_run_time?.[0]?.toString() ?? 'unknown',
|
||||||
|
onlineRating: result.vote_average,
|
||||||
|
// TMDB's spec allows for 'append_to_response' but doesn't seem to account for it in the type
|
||||||
|
// @ts-ignore
|
||||||
|
actors: result.credits?.cast.map((c: any) => c.name).slice(0, 5) ?? [],
|
||||||
|
image: result.poster_path ? `https://image.tmdb.org/t/p/w780${result.poster_path}` : null,
|
||||||
|
|
||||||
|
released: ['Returning Series', 'Cancelled', 'Ended'].includes(result.status!),
|
||||||
|
streamingServices: [],
|
||||||
|
airing: ['Returning Series'].includes(result.status!),
|
||||||
|
airedFrom: this.plugin.dateFormatter.format(result.first_air_date, this.apiDateFormat) ?? 'unknown',
|
||||||
|
airedTo: ['Returning Series'].includes(result.status!) ? 'unknown' : (this.plugin.dateFormatter.format(result.last_air_date, this.apiDateFormat) ?? 'unknown'),
|
||||||
|
|
||||||
|
userData: {
|
||||||
|
watched: false,
|
||||||
|
lastWatched: '',
|
||||||
|
personalRating: 0,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
getDisabledMediaTypes(): MediaType[] {
|
||||||
|
return this.plugin.settings.TMDBSeriesAPI_disabledMediaTypes;
|
||||||
|
}
|
||||||
|
}
|
||||||
22832
src/api/schemas/TMDB.ts
Normal file
22832
src/api/schemas/TMDB.ts
Normal file
File diff suppressed because it is too large
Load diff
96
src/main.ts
96
src/main.ts
|
|
@ -13,8 +13,12 @@ import { MusicBrainzAPI } from './api/apis/MusicBrainzAPI';
|
||||||
import { OMDbAPI } from './api/apis/OMDbAPI';
|
import { OMDbAPI } from './api/apis/OMDbAPI';
|
||||||
import { OpenLibraryAPI } from './api/apis/OpenLibraryAPI';
|
import { OpenLibraryAPI } from './api/apis/OpenLibraryAPI';
|
||||||
import { SteamAPI } from './api/apis/SteamAPI';
|
import { SteamAPI } from './api/apis/SteamAPI';
|
||||||
|
import { TMDBSeriesAPI } from './api/apis/TMDBSeriesAPI';
|
||||||
|
import { TMDBSeasonAPI } from './api/apis/TMDBSeasonAPI';
|
||||||
|
import { TMDBMovieAPI } from './api/apis/TMDBMovieAPI';
|
||||||
import { WikipediaAPI } from './api/apis/WikipediaAPI';
|
import { WikipediaAPI } from './api/apis/WikipediaAPI';
|
||||||
import { ConfirmOverwriteModal } from './modals/ConfirmOverwriteModal';
|
import { ConfirmOverwriteModal } from './modals/ConfirmOverwriteModal';
|
||||||
|
import { MediaDbSeasonSelectModal } from './modals/MediaDbSeasonSelectModal';
|
||||||
import type { MediaTypeModel } from './models/MediaTypeModel';
|
import type { MediaTypeModel } from './models/MediaTypeModel';
|
||||||
import { PropertyMapper } from './settings/PropertyMapper';
|
import { PropertyMapper } from './settings/PropertyMapper';
|
||||||
import { PropertyMapping, PropertyMappingModel } from './settings/PropertyMapping';
|
import { PropertyMapping, PropertyMappingModel } from './settings/PropertyMapping';
|
||||||
|
|
@ -56,6 +60,9 @@ export default class MediaDbPlugin extends Plugin {
|
||||||
this.apiManager.registerAPI(new WikipediaAPI(this));
|
this.apiManager.registerAPI(new WikipediaAPI(this));
|
||||||
this.apiManager.registerAPI(new MusicBrainzAPI(this));
|
this.apiManager.registerAPI(new MusicBrainzAPI(this));
|
||||||
this.apiManager.registerAPI(new SteamAPI(this));
|
this.apiManager.registerAPI(new SteamAPI(this));
|
||||||
|
this.apiManager.registerAPI(new TMDBSeriesAPI(this));
|
||||||
|
this.apiManager.registerAPI(new TMDBSeasonAPI(this));
|
||||||
|
this.apiManager.registerAPI(new TMDBMovieAPI(this));
|
||||||
this.apiManager.registerAPI(new BoardGameGeekAPI(this));
|
this.apiManager.registerAPI(new BoardGameGeekAPI(this));
|
||||||
this.apiManager.registerAPI(new OpenLibraryAPI(this));
|
this.apiManager.registerAPI(new OpenLibraryAPI(this));
|
||||||
this.apiManager.registerAPI(new ComicVineAPI(this));
|
this.apiManager.registerAPI(new ComicVineAPI(this));
|
||||||
|
|
@ -212,14 +219,38 @@ export default class MediaDbPlugin extends Plugin {
|
||||||
const proceed: boolean = false;
|
const proceed: boolean = false;
|
||||||
|
|
||||||
while (!proceed) {
|
while (!proceed) {
|
||||||
selectResults =
|
if (types.length === 1 && types[0] === 'season') {
|
||||||
(await this.modalHelper.openSelectModal({ elements: apiSearchResults }, async selectModalData => {
|
selectResults =
|
||||||
return await this.queryDetails(selectModalData.selected);
|
(await this.modalHelper.openSelectModal(
|
||||||
})) ?? [];
|
{
|
||||||
|
elements: apiSearchResults,
|
||||||
|
description: 'Select one search result to proceed.',
|
||||||
|
submitButtonText: 'Ok',
|
||||||
|
},
|
||||||
|
async selectModalData => {
|
||||||
|
return selectModalData.selected;
|
||||||
|
},
|
||||||
|
)) ?? [];
|
||||||
|
} else {
|
||||||
|
selectResults =
|
||||||
|
(await this.modalHelper.openSelectModal(
|
||||||
|
{
|
||||||
|
elements: apiSearchResults,
|
||||||
|
},
|
||||||
|
async selectModalData => {
|
||||||
|
return await this.queryDetails(selectModalData.selected);
|
||||||
|
},
|
||||||
|
)) ?? [];
|
||||||
|
}
|
||||||
if (!selectResults || selectResults.length < 1) {
|
if (!selectResults || selectResults.length < 1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Only show the season select modal if the user searches for seasons
|
||||||
|
if (await this.handleSeasonSelectModal(types, selectResults)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const confirmed = await this.modalHelper.openPreviewModal({ elements: selectResults }, async previewModalData => {
|
const confirmed = await this.modalHelper.openPreviewModal({ elements: selectResults }, async previewModalData => {
|
||||||
return previewModalData.confirmed;
|
return previewModalData.confirmed;
|
||||||
});
|
});
|
||||||
|
|
@ -232,6 +263,63 @@ export default class MediaDbPlugin extends Plugin {
|
||||||
await this.createMediaDbNotes(selectResults!);
|
await this.createMediaDbNotes(selectResults!);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Season select modal
|
||||||
|
private async handleSeasonSelectModal(types: string[], selectResults: MediaTypeModel[]): Promise<boolean> {
|
||||||
|
if (types.length === 1 && types[0] === 'season' && selectResults.length === 1 && selectResults[0].dataSource === 'TMDBSeasonAPI') {
|
||||||
|
// Use static import for the modal
|
||||||
|
const tmdbSeasonAPI = this.apiManager.getApiByName('TMDBSeasonAPI') as import('./api/apis/TMDBSeasonAPI').TMDBSeasonAPI;
|
||||||
|
if (!tmdbSeasonAPI) {
|
||||||
|
new Notice('TMDBSeasonAPI not found.');
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// Fetch all seasons for the selected series
|
||||||
|
const allSeasons = await tmdbSeasonAPI.getSeasonsForSeries(selectResults[0].id);
|
||||||
|
if (!allSeasons || allSeasons.length === 0) {
|
||||||
|
new Notice('No seasons found for this series.');
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// Pass the original series title from the search result
|
||||||
|
const seriesName = selectResults[0]?.englishTitle || selectResults[0]?.title || '';
|
||||||
|
const modal = new MediaDbSeasonSelectModal(
|
||||||
|
this,
|
||||||
|
allSeasons.map(s => ({
|
||||||
|
season_number: s.seasonNumber,
|
||||||
|
name: s.seasonTitle || s.title,
|
||||||
|
episode_count: s.episodes || 0,
|
||||||
|
air_date: s.year,
|
||||||
|
poster_path: s.image,
|
||||||
|
})),
|
||||||
|
true,
|
||||||
|
seriesName,
|
||||||
|
);
|
||||||
|
const selectedSeasons: any[] = await new Promise(resolve => {
|
||||||
|
modal.setSubmitCallback(resolve);
|
||||||
|
modal.open();
|
||||||
|
});
|
||||||
|
if (!selectedSeasons || selectedSeasons.length === 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// Fetch full metadata for each selected season and create the note
|
||||||
|
await Promise.all(
|
||||||
|
selectedSeasons.map(async season => {
|
||||||
|
const orig = allSeasons.find(s => s.seasonNumber === season.season_number);
|
||||||
|
if (orig) {
|
||||||
|
// Fetch full metadata using getById
|
||||||
|
const tmdbSeasonAPI = this.apiManager.getApiByName('TMDBSeasonAPI') as import('./api/apis/TMDBSeasonAPI').TMDBSeasonAPI;
|
||||||
|
if (tmdbSeasonAPI) {
|
||||||
|
const fullMeta = await tmdbSeasonAPI.getById(orig.id);
|
||||||
|
await this.createMediaDbNotes([fullMeta]);
|
||||||
|
} else {
|
||||||
|
await this.createMediaDbNotes([orig]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
async createEntryWithAdvancedSearchModal(): Promise<void> {
|
async createEntryWithAdvancedSearchModal(): Promise<void> {
|
||||||
const apiSearchResults = await this.modalHelper.openAdvancedSearchModal({}, async advancedSearchModalData => {
|
const apiSearchResults = await this.modalHelper.openAdvancedSearchModal({}, async advancedSearchModalData => {
|
||||||
return await this.apiManager.query(advancedSearchModalData.query, advancedSearchModalData.apis);
|
return await this.apiManager.query(advancedSearchModalData.query, advancedSearchModalData.apis);
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import type MediaDbPlugin from '../main';
|
import type MediaDbPlugin from '../main';
|
||||||
import type { MediaTypeModel } from '../models/MediaTypeModel';
|
import type { MediaTypeModel } from '../models/MediaTypeModel';
|
||||||
import type { SelectModalData, SelectModalOptions } from '../utils/ModalHelper';
|
import type { SelectModalData, SelectModalOptions } from '../utils/ModalHelper';
|
||||||
import { SELECT_MODAL_OPTIONS_DEFAULT } from '../utils/ModalHelper';
|
import { SELECTMODALOPTIONSDEFAULT } from '../utils/ModalHelper';
|
||||||
import { SelectModal } from './SelectModal';
|
import { SelectModal } from './SelectModal';
|
||||||
|
|
||||||
export class MediaDbSearchResultModal extends SelectModal<MediaTypeModel> {
|
export class MediaDbSearchResultModal extends SelectModal<MediaTypeModel> {
|
||||||
|
|
@ -13,18 +13,17 @@ export class MediaDbSearchResultModal extends SelectModal<MediaTypeModel> {
|
||||||
submitCallback?: (res: SelectModalData) => void;
|
submitCallback?: (res: SelectModalData) => void;
|
||||||
closeCallback?: (err?: Error) => void;
|
closeCallback?: (err?: Error) => void;
|
||||||
skipCallback?: () => void;
|
skipCallback?: () => void;
|
||||||
|
submitButtonText: string;
|
||||||
|
|
||||||
constructor(plugin: MediaDbPlugin, selectModalOptions: SelectModalOptions) {
|
constructor(plugin: MediaDbPlugin, selectModalOptions: SelectModalOptions) {
|
||||||
selectModalOptions = Object.assign({}, SELECT_MODAL_OPTIONS_DEFAULT, selectModalOptions);
|
selectModalOptions = Object.assign({}, SELECTMODALOPTIONSDEFAULT, selectModalOptions);
|
||||||
super(plugin.app, selectModalOptions.elements ?? [], selectModalOptions.multiSelect);
|
super(plugin.app, selectModalOptions.elements ?? [], selectModalOptions.multiSelect);
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
|
|
||||||
this.title = selectModalOptions.modalTitle ?? '';
|
this.title = selectModalOptions.modalTitle ?? '';
|
||||||
this.description = 'Select one or multiple search results.';
|
this.description = selectModalOptions.description ?? 'Select one or multiple search results.';
|
||||||
this.addSkipButton = selectModalOptions.skipButton ?? false;
|
this.addSkipButton = selectModalOptions.skipButton ?? false;
|
||||||
|
this.submitButtonText = selectModalOptions.submitButtonText ?? 'Ok';
|
||||||
this.busy = false;
|
this.busy = false;
|
||||||
|
|
||||||
this.sendCallback = false;
|
this.sendCallback = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
50
src/modals/MediaDbSeasonSelectModal.ts
Normal file
50
src/modals/MediaDbSeasonSelectModal.ts
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
import type MediaDbPlugin from '../main';
|
||||||
|
import { SelectModal } from './SelectModal';
|
||||||
|
|
||||||
|
export interface SeasonSelectModalElement {
|
||||||
|
season_number: number;
|
||||||
|
name: string;
|
||||||
|
air_date?: string;
|
||||||
|
poster_path?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class MediaDbSeasonSelectModal extends SelectModal<SeasonSelectModalElement> {
|
||||||
|
plugin: MediaDbPlugin;
|
||||||
|
submitCallback?: (selectedSeasons: SeasonSelectModalElement[]) => void;
|
||||||
|
closeCallback?: (err?: Error) => void;
|
||||||
|
seriesName?: string;
|
||||||
|
|
||||||
|
constructor(plugin: MediaDbPlugin, seasons: SeasonSelectModalElement[], multiSelect = true, seriesName?: string) {
|
||||||
|
super(plugin.app, seasons, multiSelect);
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.seriesName = seriesName;
|
||||||
|
this.title = `Select seasons for${seriesName ? ` ${seriesName}` : ''}`;
|
||||||
|
this.description = 'Select one or more seasons to create notes for.';
|
||||||
|
this.submitButtonText = 'Create Entry';
|
||||||
|
}
|
||||||
|
|
||||||
|
renderElement(season: SeasonSelectModalElement, el: HTMLElement): void {
|
||||||
|
el.createEl('div', { text: `${season.name}` });
|
||||||
|
if (season.air_date) {
|
||||||
|
el.createEl('small', { text: `Air date: ${season.air_date}` });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
submit(): void {
|
||||||
|
const selected = this.selectModalElements.filter(x => x.isActive()).map(x => x.value);
|
||||||
|
this.submitCallback?.(selected);
|
||||||
|
this.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
skip(): void {
|
||||||
|
this.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
setSubmitCallback(cb: (selectedSeasons: SeasonSelectModalElement[]) => void): void {
|
||||||
|
this.submitCallback = cb;
|
||||||
|
}
|
||||||
|
|
||||||
|
setCloseCallback(cb: (err?: Error) => void): void {
|
||||||
|
this.closeCallback = cb;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -12,6 +12,7 @@ export abstract class SelectModal<T> extends Modal {
|
||||||
cancelButton?: ButtonComponent;
|
cancelButton?: ButtonComponent;
|
||||||
skipButton?: ButtonComponent;
|
skipButton?: ButtonComponent;
|
||||||
submitButton?: ButtonComponent;
|
submitButton?: ButtonComponent;
|
||||||
|
submitButtonText: string;
|
||||||
|
|
||||||
elementWrapper?: HTMLDivElement;
|
elementWrapper?: HTMLDivElement;
|
||||||
|
|
||||||
|
|
@ -25,6 +26,7 @@ export abstract class SelectModal<T> extends Modal {
|
||||||
this.title = '';
|
this.title = '';
|
||||||
this.description = '';
|
this.description = '';
|
||||||
this.addSkipButton = false;
|
this.addSkipButton = false;
|
||||||
|
this.submitButtonText = 'Ok';
|
||||||
this.cancelButton = undefined;
|
this.cancelButton = undefined;
|
||||||
this.skipButton = undefined;
|
this.skipButton = undefined;
|
||||||
this.submitButton = undefined;
|
this.submitButton = undefined;
|
||||||
|
|
@ -115,7 +117,7 @@ export abstract class SelectModal<T> extends Modal {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
bottomSettingRow.addButton(btn => {
|
bottomSettingRow.addButton(btn => {
|
||||||
btn.setButtonText('Ok');
|
btn.setButtonText(this.submitButtonText);
|
||||||
btn.setCta();
|
btn.setCta();
|
||||||
btn.onClick(() => this.submit());
|
btn.onClick(() => this.submit());
|
||||||
btn.buttonEl.addClass('media-db-plugin-button');
|
btn.buttonEl.addClass('media-db-plugin-button');
|
||||||
|
|
|
||||||
80
src/models/SeasonModel.ts
Normal file
80
src/models/SeasonModel.ts
Normal file
|
|
@ -0,0 +1,80 @@
|
||||||
|
import { MediaType } from '../utils/MediaType';
|
||||||
|
import type { ModelToData } from '../utils/Utils';
|
||||||
|
import { mediaDbTag, migrateObject } from '../utils/Utils';
|
||||||
|
import { MediaTypeModel } from './MediaTypeModel';
|
||||||
|
|
||||||
|
export type SeasonData = ModelToData<SeasonModel>;
|
||||||
|
|
||||||
|
export class SeasonModel extends MediaTypeModel {
|
||||||
|
seasonNumber: number;
|
||||||
|
seasonTitle: string;
|
||||||
|
episodes: number;
|
||||||
|
|
||||||
|
plot: string;
|
||||||
|
genres: string[];
|
||||||
|
writer: string[];
|
||||||
|
studio: string[];
|
||||||
|
duration: string;
|
||||||
|
onlineRating: number;
|
||||||
|
actors: string[];
|
||||||
|
image: string;
|
||||||
|
|
||||||
|
released: boolean;
|
||||||
|
streamingServices: string[];
|
||||||
|
airing: boolean;
|
||||||
|
airedFrom: string;
|
||||||
|
airedTo: string;
|
||||||
|
|
||||||
|
userData: {
|
||||||
|
watched: boolean;
|
||||||
|
lastWatched: string;
|
||||||
|
personalRating: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
constructor(obj: SeasonData) {
|
||||||
|
super();
|
||||||
|
this.seasonTitle = '';
|
||||||
|
this.seasonNumber = 0;
|
||||||
|
this.episodes = 0;
|
||||||
|
this.plot = '';
|
||||||
|
this.genres = [];
|
||||||
|
this.writer = [];
|
||||||
|
this.studio = [];
|
||||||
|
this.duration = '';
|
||||||
|
this.onlineRating = 0;
|
||||||
|
this.actors = [];
|
||||||
|
this.image = '';
|
||||||
|
|
||||||
|
this.released = false;
|
||||||
|
this.streamingServices = [];
|
||||||
|
this.airing = false;
|
||||||
|
this.airedFrom = '';
|
||||||
|
this.airedTo = '';
|
||||||
|
|
||||||
|
this.userData = {
|
||||||
|
watched: false,
|
||||||
|
lastWatched: '',
|
||||||
|
personalRating: 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
migrateObject(this, obj, this);
|
||||||
|
|
||||||
|
if (!obj.hasOwnProperty('userData')) {
|
||||||
|
migrateObject(this.userData, obj, this.userData);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.type = this.getMediaType();
|
||||||
|
}
|
||||||
|
|
||||||
|
getTags(): string[] {
|
||||||
|
return [mediaDbTag, 'tv', 'season'];
|
||||||
|
}
|
||||||
|
|
||||||
|
getMediaType(): MediaType {
|
||||||
|
return MediaType.Season;
|
||||||
|
}
|
||||||
|
|
||||||
|
getSummary(): string {
|
||||||
|
return this.seasonNumber + ' seasons';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -13,6 +13,7 @@ import { FolderSuggest } from './suggesters/FolderSuggest';
|
||||||
|
|
||||||
export interface MediaDbPluginSettings {
|
export interface MediaDbPluginSettings {
|
||||||
OMDbKey: string;
|
OMDbKey: string;
|
||||||
|
TMDBKey: string;
|
||||||
MobyGamesKey: string;
|
MobyGamesKey: string;
|
||||||
GiantBombKey: string;
|
GiantBombKey: string;
|
||||||
ComicVineKey: string;
|
ComicVineKey: string;
|
||||||
|
|
@ -24,6 +25,9 @@ export interface MediaDbPluginSettings {
|
||||||
useDefaultFrontMatter: boolean;
|
useDefaultFrontMatter: boolean;
|
||||||
enableTemplaterIntegration: boolean;
|
enableTemplaterIntegration: boolean;
|
||||||
OMDbAPI_disabledMediaTypes: MediaType[];
|
OMDbAPI_disabledMediaTypes: MediaType[];
|
||||||
|
TMDBSeriesAPI_disabledMediaTypes: MediaType[];
|
||||||
|
TMDBSeasonAPI_disabledMediaTypes: MediaType[];
|
||||||
|
TMDBMovieAPI_disabledMediaTypes: MediaType[];
|
||||||
MALAPI_disabledMediaTypes: MediaType[];
|
MALAPI_disabledMediaTypes: MediaType[];
|
||||||
MALAPIManga_disabledMediaTypes: MediaType[];
|
MALAPIManga_disabledMediaTypes: MediaType[];
|
||||||
ComicVineAPI_disabledMediaTypes: MediaType[];
|
ComicVineAPI_disabledMediaTypes: MediaType[];
|
||||||
|
|
@ -36,6 +40,7 @@ export interface MediaDbPluginSettings {
|
||||||
OpenLibraryAPI_disabledMediaTypes: MediaType[];
|
OpenLibraryAPI_disabledMediaTypes: MediaType[];
|
||||||
movieTemplate: string;
|
movieTemplate: string;
|
||||||
seriesTemplate: string;
|
seriesTemplate: string;
|
||||||
|
seasonTemplate: string;
|
||||||
mangaTemplate: string;
|
mangaTemplate: string;
|
||||||
gameTemplate: string;
|
gameTemplate: string;
|
||||||
wikiTemplate: string;
|
wikiTemplate: string;
|
||||||
|
|
@ -45,6 +50,7 @@ export interface MediaDbPluginSettings {
|
||||||
|
|
||||||
movieFileNameTemplate: string;
|
movieFileNameTemplate: string;
|
||||||
seriesFileNameTemplate: string;
|
seriesFileNameTemplate: string;
|
||||||
|
seasonFileNameTemplate: string;
|
||||||
mangaFileNameTemplate: string;
|
mangaFileNameTemplate: string;
|
||||||
gameFileNameTemplate: string;
|
gameFileNameTemplate: string;
|
||||||
wikiFileNameTemplate: string;
|
wikiFileNameTemplate: string;
|
||||||
|
|
@ -54,6 +60,7 @@ export interface MediaDbPluginSettings {
|
||||||
|
|
||||||
moviePropertyConversionRules: string;
|
moviePropertyConversionRules: string;
|
||||||
seriesPropertyConversionRules: string;
|
seriesPropertyConversionRules: string;
|
||||||
|
seasonPropertyConversionRules: string;
|
||||||
mangaPropertyConversionRules: string;
|
mangaPropertyConversionRules: string;
|
||||||
gamePropertyConversionRules: string;
|
gamePropertyConversionRules: string;
|
||||||
wikiPropertyConversionRules: string;
|
wikiPropertyConversionRules: string;
|
||||||
|
|
@ -63,6 +70,7 @@ export interface MediaDbPluginSettings {
|
||||||
|
|
||||||
movieFolder: string;
|
movieFolder: string;
|
||||||
seriesFolder: string;
|
seriesFolder: string;
|
||||||
|
seasonFolder: string;
|
||||||
mangaFolder: string;
|
mangaFolder: string;
|
||||||
gameFolder: string;
|
gameFolder: string;
|
||||||
wikiFolder: string;
|
wikiFolder: string;
|
||||||
|
|
@ -77,6 +85,7 @@ export interface MediaDbPluginSettings {
|
||||||
|
|
||||||
const DEFAULT_SETTINGS: MediaDbPluginSettings = {
|
const DEFAULT_SETTINGS: MediaDbPluginSettings = {
|
||||||
OMDbKey: '',
|
OMDbKey: '',
|
||||||
|
TMDBKey: '',
|
||||||
MobyGamesKey: '',
|
MobyGamesKey: '',
|
||||||
GiantBombKey: '',
|
GiantBombKey: '',
|
||||||
ComicVineKey: '',
|
ComicVineKey: '',
|
||||||
|
|
@ -88,6 +97,9 @@ const DEFAULT_SETTINGS: MediaDbPluginSettings = {
|
||||||
useDefaultFrontMatter: true,
|
useDefaultFrontMatter: true,
|
||||||
enableTemplaterIntegration: false,
|
enableTemplaterIntegration: false,
|
||||||
OMDbAPI_disabledMediaTypes: [],
|
OMDbAPI_disabledMediaTypes: [],
|
||||||
|
TMDBSeriesAPI_disabledMediaTypes: [],
|
||||||
|
TMDBSeasonAPI_disabledMediaTypes: [],
|
||||||
|
TMDBMovieAPI_disabledMediaTypes: [],
|
||||||
MALAPI_disabledMediaTypes: [],
|
MALAPI_disabledMediaTypes: [],
|
||||||
MALAPIManga_disabledMediaTypes: [],
|
MALAPIManga_disabledMediaTypes: [],
|
||||||
ComicVineAPI_disabledMediaTypes: [],
|
ComicVineAPI_disabledMediaTypes: [],
|
||||||
|
|
@ -100,6 +112,7 @@ const DEFAULT_SETTINGS: MediaDbPluginSettings = {
|
||||||
OpenLibraryAPI_disabledMediaTypes: [],
|
OpenLibraryAPI_disabledMediaTypes: [],
|
||||||
movieTemplate: '',
|
movieTemplate: '',
|
||||||
seriesTemplate: '',
|
seriesTemplate: '',
|
||||||
|
seasonTemplate: '',
|
||||||
mangaTemplate: '',
|
mangaTemplate: '',
|
||||||
gameTemplate: '',
|
gameTemplate: '',
|
||||||
wikiTemplate: '',
|
wikiTemplate: '',
|
||||||
|
|
@ -109,6 +122,7 @@ const DEFAULT_SETTINGS: MediaDbPluginSettings = {
|
||||||
|
|
||||||
movieFileNameTemplate: '{{ title }} ({{ year }})',
|
movieFileNameTemplate: '{{ title }} ({{ year }})',
|
||||||
seriesFileNameTemplate: '{{ title }} ({{ year }})',
|
seriesFileNameTemplate: '{{ title }} ({{ year }})',
|
||||||
|
seasonFileNameTemplate: '{{ title }} ({{ year }})',
|
||||||
mangaFileNameTemplate: '{{ title }} ({{ year }})',
|
mangaFileNameTemplate: '{{ title }} ({{ year }})',
|
||||||
gameFileNameTemplate: '{{ title }} ({{ year }})',
|
gameFileNameTemplate: '{{ title }} ({{ year }})',
|
||||||
wikiFileNameTemplate: '{{ title }}',
|
wikiFileNameTemplate: '{{ title }}',
|
||||||
|
|
@ -118,6 +132,7 @@ const DEFAULT_SETTINGS: MediaDbPluginSettings = {
|
||||||
|
|
||||||
moviePropertyConversionRules: '',
|
moviePropertyConversionRules: '',
|
||||||
seriesPropertyConversionRules: '',
|
seriesPropertyConversionRules: '',
|
||||||
|
seasonPropertyConversionRules: '',
|
||||||
mangaPropertyConversionRules: '',
|
mangaPropertyConversionRules: '',
|
||||||
gamePropertyConversionRules: '',
|
gamePropertyConversionRules: '',
|
||||||
wikiPropertyConversionRules: '',
|
wikiPropertyConversionRules: '',
|
||||||
|
|
@ -127,6 +142,7 @@ const DEFAULT_SETTINGS: MediaDbPluginSettings = {
|
||||||
|
|
||||||
movieFolder: 'Media DB/movies',
|
movieFolder: 'Media DB/movies',
|
||||||
seriesFolder: 'Media DB/series',
|
seriesFolder: 'Media DB/series',
|
||||||
|
seasonFolder: 'Media DB/series',
|
||||||
mangaFolder: 'Media DB/comics',
|
mangaFolder: 'Media DB/comics',
|
||||||
gameFolder: 'Media DB/games',
|
gameFolder: 'Media DB/games',
|
||||||
wikiFolder: 'Media DB/wiki',
|
wikiFolder: 'Media DB/wiki',
|
||||||
|
|
@ -227,6 +243,17 @@ export class MediaDbSettingTab extends PluginSettingTab {
|
||||||
void this.plugin.saveSettings();
|
void this.plugin.saveSettings();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
new Setting(containerEl)
|
||||||
|
.setName('TMDB API key')
|
||||||
|
.setDesc('API key for "https://www.themoviedb.org".')
|
||||||
|
.addText(cb => {
|
||||||
|
cb.setPlaceholder('API key')
|
||||||
|
.setValue(this.plugin.settings.TMDBKey)
|
||||||
|
.onChange(data => {
|
||||||
|
this.plugin.settings.TMDBKey = data;
|
||||||
|
void this.plugin.saveSettings();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
new Setting(containerEl)
|
new Setting(containerEl)
|
||||||
.setName('Moby Games key')
|
.setName('Moby Games key')
|
||||||
|
|
@ -465,6 +492,19 @@ export class MediaDbSettingTab extends PluginSettingTab {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
new Setting(containerEl)
|
||||||
|
.setName('Season folder')
|
||||||
|
.setDesc('Where newly imported seasons should be placed.')
|
||||||
|
.addSearch(cb => {
|
||||||
|
new FolderSuggest(this.app, cb.inputEl);
|
||||||
|
cb.setPlaceholder(DEFAULT_SETTINGS.seasonFolder)
|
||||||
|
.setValue(this.plugin.settings.seriesFolder)
|
||||||
|
.onChange(data => {
|
||||||
|
this.plugin.settings.seasonFolder = data;
|
||||||
|
void this.plugin.saveSettings();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
new Setting(containerEl)
|
new Setting(containerEl)
|
||||||
.setName('Comic and manga folder')
|
.setName('Comic and manga folder')
|
||||||
.setDesc('Where newly imported comics and manga should be placed.')
|
.setDesc('Where newly imported comics and manga should be placed.')
|
||||||
|
|
@ -620,6 +660,19 @@ export class MediaDbSettingTab extends PluginSettingTab {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
new Setting(containerEl)
|
||||||
|
.setName('Season template')
|
||||||
|
.setDesc('Template file to be used when creating a new note for a season.')
|
||||||
|
.addSearch(cb => {
|
||||||
|
new FileSuggest(this.app, cb.inputEl);
|
||||||
|
cb.setPlaceholder('Example: seasonTemplate.md')
|
||||||
|
.setValue(this.plugin.settings.seasonTemplate)
|
||||||
|
.onChange(data => {
|
||||||
|
this.plugin.settings.seasonTemplate = data;
|
||||||
|
void this.plugin.saveSettings();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
new Setting(containerEl)
|
new Setting(containerEl)
|
||||||
.setName('Manga and Comics template')
|
.setName('Manga and Comics template')
|
||||||
.setDesc('Template file to be used when creating a new note for a manga or a comic.')
|
.setDesc('Template file to be used when creating a new note for a manga or a comic.')
|
||||||
|
|
@ -762,6 +815,18 @@ export class MediaDbSettingTab extends PluginSettingTab {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
new Setting(containerEl)
|
||||||
|
.setName('Season file name template')
|
||||||
|
.setDesc('Template for the file name used when creating a new note for a season.')
|
||||||
|
.addText(cb => {
|
||||||
|
cb.setPlaceholder(`Example: ${DEFAULT_SETTINGS.seasonFileNameTemplate}`)
|
||||||
|
.setValue(this.plugin.settings.seasonFileNameTemplate)
|
||||||
|
.onChange(data => {
|
||||||
|
this.plugin.settings.seasonFileNameTemplate = data;
|
||||||
|
void this.plugin.saveSettings();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
new Setting(containerEl)
|
new Setting(containerEl)
|
||||||
.setName('Manga and comic file name template')
|
.setName('Manga and comic file name template')
|
||||||
.setDesc('Template for the file name used when creating a new note for a manga or comic.')
|
.setDesc('Template for the file name used when creating a new note for a manga or comic.')
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
export enum MediaType {
|
export enum MediaType {
|
||||||
Movie = 'movie',
|
Movie = 'movie',
|
||||||
Series = 'series',
|
Series = 'series',
|
||||||
|
Season = 'season',
|
||||||
ComicManga = 'comicManga',
|
ComicManga = 'comicManga',
|
||||||
Game = 'game',
|
Game = 'game',
|
||||||
MusicRelease = 'musicRelease',
|
MusicRelease = 'musicRelease',
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import type { MediaTypeModel } from '../models/MediaTypeModel';
|
||||||
import { MovieModel } from '../models/MovieModel';
|
import { MovieModel } from '../models/MovieModel';
|
||||||
import { MusicReleaseModel } from '../models/MusicReleaseModel';
|
import { MusicReleaseModel } from '../models/MusicReleaseModel';
|
||||||
import { SeriesModel } from '../models/SeriesModel';
|
import { SeriesModel } from '../models/SeriesModel';
|
||||||
|
import { SeasonModel } from '../models/SeasonModel';
|
||||||
import { WikiModel } from '../models/WikiModel';
|
import { WikiModel } from '../models/WikiModel';
|
||||||
import type { MediaDbPluginSettings } from '../settings/Settings';
|
import type { MediaDbPluginSettings } from '../settings/Settings';
|
||||||
import { ILLEGAL_FILENAME_CHARACTERS } from './IllegalFilenameCharactersList';
|
import { ILLEGAL_FILENAME_CHARACTERS } from './IllegalFilenameCharactersList';
|
||||||
|
|
@ -17,6 +18,7 @@ import { replaceTags } from './Utils';
|
||||||
export const MEDIA_TYPES: MediaType[] = [
|
export const MEDIA_TYPES: MediaType[] = [
|
||||||
MediaType.Movie,
|
MediaType.Movie,
|
||||||
MediaType.Series,
|
MediaType.Series,
|
||||||
|
MediaType.Season,
|
||||||
MediaType.ComicManga,
|
MediaType.ComicManga,
|
||||||
MediaType.Game,
|
MediaType.Game,
|
||||||
MediaType.Wiki,
|
MediaType.Wiki,
|
||||||
|
|
@ -40,6 +42,7 @@ export class MediaTypeManager {
|
||||||
this.mediaFileNameTemplateMap = new Map<MediaType, string>();
|
this.mediaFileNameTemplateMap = new Map<MediaType, string>();
|
||||||
this.mediaFileNameTemplateMap.set(MediaType.Movie, settings.movieFileNameTemplate);
|
this.mediaFileNameTemplateMap.set(MediaType.Movie, settings.movieFileNameTemplate);
|
||||||
this.mediaFileNameTemplateMap.set(MediaType.Series, settings.seriesFileNameTemplate);
|
this.mediaFileNameTemplateMap.set(MediaType.Series, settings.seriesFileNameTemplate);
|
||||||
|
this.mediaFileNameTemplateMap.set(MediaType.Season, settings.seasonFileNameTemplate);
|
||||||
this.mediaFileNameTemplateMap.set(MediaType.ComicManga, settings.mangaFileNameTemplate);
|
this.mediaFileNameTemplateMap.set(MediaType.ComicManga, settings.mangaFileNameTemplate);
|
||||||
this.mediaFileNameTemplateMap.set(MediaType.Game, settings.gameFileNameTemplate);
|
this.mediaFileNameTemplateMap.set(MediaType.Game, settings.gameFileNameTemplate);
|
||||||
this.mediaFileNameTemplateMap.set(MediaType.Wiki, settings.wikiFileNameTemplate);
|
this.mediaFileNameTemplateMap.set(MediaType.Wiki, settings.wikiFileNameTemplate);
|
||||||
|
|
@ -50,6 +53,7 @@ export class MediaTypeManager {
|
||||||
this.mediaTemplateMap = new Map<MediaType, string>();
|
this.mediaTemplateMap = new Map<MediaType, string>();
|
||||||
this.mediaTemplateMap.set(MediaType.Movie, settings.movieTemplate);
|
this.mediaTemplateMap.set(MediaType.Movie, settings.movieTemplate);
|
||||||
this.mediaTemplateMap.set(MediaType.Series, settings.seriesTemplate);
|
this.mediaTemplateMap.set(MediaType.Series, settings.seriesTemplate);
|
||||||
|
this.mediaTemplateMap.set(MediaType.Season, settings.seasonTemplate);
|
||||||
this.mediaTemplateMap.set(MediaType.ComicManga, settings.mangaTemplate);
|
this.mediaTemplateMap.set(MediaType.ComicManga, settings.mangaTemplate);
|
||||||
this.mediaTemplateMap.set(MediaType.Game, settings.gameTemplate);
|
this.mediaTemplateMap.set(MediaType.Game, settings.gameTemplate);
|
||||||
this.mediaTemplateMap.set(MediaType.Wiki, settings.wikiTemplate);
|
this.mediaTemplateMap.set(MediaType.Wiki, settings.wikiTemplate);
|
||||||
|
|
@ -62,6 +66,7 @@ export class MediaTypeManager {
|
||||||
this.mediaFolderMap = new Map<MediaType, string>();
|
this.mediaFolderMap = new Map<MediaType, string>();
|
||||||
this.mediaFolderMap.set(MediaType.Movie, settings.movieFolder);
|
this.mediaFolderMap.set(MediaType.Movie, settings.movieFolder);
|
||||||
this.mediaFolderMap.set(MediaType.Series, settings.seriesFolder);
|
this.mediaFolderMap.set(MediaType.Series, settings.seriesFolder);
|
||||||
|
this.mediaFolderMap.set(MediaType.Season, settings.seasonFolder);
|
||||||
this.mediaFolderMap.set(MediaType.ComicManga, settings.mangaFolder);
|
this.mediaFolderMap.set(MediaType.ComicManga, settings.mangaFolder);
|
||||||
this.mediaFolderMap.set(MediaType.Game, settings.gameFolder);
|
this.mediaFolderMap.set(MediaType.Game, settings.gameFolder);
|
||||||
this.mediaFolderMap.set(MediaType.Wiki, settings.wikiFolder);
|
this.mediaFolderMap.set(MediaType.Wiki, settings.wikiFolder);
|
||||||
|
|
@ -138,6 +143,8 @@ export class MediaTypeManager {
|
||||||
return new MovieModel(obj);
|
return new MovieModel(obj);
|
||||||
} else if (mediaType === MediaType.Series) {
|
} else if (mediaType === MediaType.Series) {
|
||||||
return new SeriesModel(obj);
|
return new SeriesModel(obj);
|
||||||
|
} else if (mediaType === MediaType.Season) {
|
||||||
|
return new SeasonModel(obj);
|
||||||
} else if (mediaType === MediaType.ComicManga) {
|
} else if (mediaType === MediaType.ComicManga) {
|
||||||
return new ComicMangaModel(obj);
|
return new ComicMangaModel(obj);
|
||||||
} else if (mediaType === MediaType.Game) {
|
} else if (mediaType === MediaType.Game) {
|
||||||
|
|
|
||||||
|
|
@ -159,12 +159,13 @@ export interface IdSearchModalOptions {
|
||||||
* - skipButton: whether to add a skip button to the modal
|
* - skipButton: whether to add a skip button to the modal
|
||||||
*/
|
*/
|
||||||
export interface SelectModalOptions {
|
export interface SelectModalOptions {
|
||||||
modalTitle?: string;
|
|
||||||
elements?: MediaTypeModel[];
|
elements?: MediaTypeModel[];
|
||||||
multiSelect?: boolean;
|
multiSelect?: boolean;
|
||||||
|
modalTitle?: string;
|
||||||
skipButton?: boolean;
|
skipButton?: boolean;
|
||||||
|
description?: string; // Add this
|
||||||
|
submitButtonText?: string; // Add this too
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Options for the preview modal.
|
* Options for the preview modal.
|
||||||
* - modalTitle: the title of the modal
|
* - modalTitle: the title of the modal
|
||||||
|
|
@ -205,6 +206,15 @@ export const PREVIEW_MODAL_DEFAULT_OPTIONS: PreviewModalOptions = {
|
||||||
elements: [],
|
elements: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const SELECTMODALOPTIONSDEFAULT: SelectModalOptions = {
|
||||||
|
elements: [],
|
||||||
|
multiSelect: true,
|
||||||
|
modalTitle: '',
|
||||||
|
skipButton: false,
|
||||||
|
description: 'Select one or multiple search results.',
|
||||||
|
submitButtonText: 'Ok',
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class providing multiple usefull functions for dealing with the plugins modals.
|
* A class providing multiple usefull functions for dealing with the plugins modals.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
16
src/utils/SeasonModalHelper.ts
Normal file
16
src/utils/SeasonModalHelper.ts
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
import type { App } from 'obsidian';
|
||||||
|
import type { SeasonSelectModalElement } from '../modals/MediaDbSeasonSelectModal';
|
||||||
|
import { MediaDbSeasonSelectModal } from '../modals/MediaDbSeasonSelectModal';
|
||||||
|
|
||||||
|
export async function openSeasonSelectModal(app: App, plugin: any, seasons: SeasonSelectModalElement[]): Promise<SeasonSelectModalElement[] | undefined> {
|
||||||
|
return new Promise(resolve => {
|
||||||
|
const modal = new MediaDbSeasonSelectModal(plugin, seasons, true);
|
||||||
|
modal.setSubmitCallback(selected => {
|
||||||
|
resolve(selected);
|
||||||
|
});
|
||||||
|
modal.setCloseCallback(() => {
|
||||||
|
resolve(undefined);
|
||||||
|
});
|
||||||
|
modal.open();
|
||||||
|
});
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue