|
1 | 1 | import { Notice, renderResults } from 'obsidian'; |
2 | 2 | import type MediaDbPlugin from '../../main'; |
3 | 3 | import type { MediaTypeModel } from '../../models/MediaTypeModel'; |
4 | | -import { MovieModel } from '../../models/MovieModel'; |
5 | 4 | import { SeriesModel } from '../../models/SeriesModel'; |
6 | 5 | import { MediaType } from '../../utils/MediaType'; |
7 | 6 | import { APIModel } from '../APIModel'; |
@@ -131,128 +130,3 @@ export class TMDBSeriesAPI extends APIModel { |
131 | 130 | return this.plugin.settings.TMDBSeriesAPI_disabledMediaTypes as MediaType[]; |
132 | 131 | } |
133 | 132 | } |
134 | | - |
135 | | -export class TMDBMovieAPI extends APIModel { |
136 | | - plugin: MediaDbPlugin; |
137 | | - typeMappings: Map<string, string>; |
138 | | - apiDateFormat: string = 'YYYY-MM-DD'; |
139 | | - |
140 | | - constructor(plugin: MediaDbPlugin) { |
141 | | - super(); |
142 | | - |
143 | | - this.plugin = plugin; |
144 | | - this.apiName = 'TMDBMovieAPI'; |
145 | | - this.apiDescription = 'A community built Movie DB.'; |
146 | | - this.apiUrl = 'https://www.themoviedb.org/'; |
147 | | - this.types = [MediaType.Movie]; |
148 | | - this.typeMappings = new Map<string, string>(); |
149 | | - this.typeMappings.set('movie', 'movie'); |
150 | | - } |
151 | | - |
152 | | - async searchByTitle(title: string): Promise<MediaTypeModel[]> { |
153 | | - console.log(`MDB | api "${this.apiName}" queried by Title`); |
154 | | - |
155 | | - if (!this.plugin.settings.TMDBKey) { |
156 | | - throw new Error(`MDB | API key for ${this.apiName} missing.`); |
157 | | - } |
158 | | - |
159 | | - const searchUrl = `https://api.themoviedb.org/3/search/movie?api_key=${this.plugin.settings.TMDBKey}&query=${encodeURIComponent(title)}&include_adult=${this.plugin.settings.sfwFilter ? 'false' : 'true'}`; |
160 | | - const fetchData = await fetch(searchUrl); |
161 | | - |
162 | | - if (fetchData.status === 401) { |
163 | | - throw Error(`MDB | Authentication for ${this.apiName} failed. Check the API key.`); |
164 | | - } |
165 | | - if (fetchData.status !== 200) { |
166 | | - throw Error(`MDB | Received status code ${fetchData.status} from ${this.apiName}.`); |
167 | | - } |
168 | | - |
169 | | - const data = await fetchData.json(); |
170 | | - |
171 | | - if (data.total_results === 0) { |
172 | | - if (data.Error === 'Movie not found!') { |
173 | | - return []; |
174 | | - } |
175 | | - |
176 | | - throw Error(`MDB | Received error from ${this.apiName}: \n${JSON.stringify(data, undefined, 4)}`); |
177 | | - } |
178 | | - if (!data.results) { |
179 | | - return []; |
180 | | - } |
181 | | - |
182 | | - // console.debug(data.results); |
183 | | - |
184 | | - const ret: MediaTypeModel[] = []; |
185 | | - |
186 | | - for (const result of data.results) { |
187 | | - ret.push( |
188 | | - new MovieModel({ |
189 | | - type: 'movie', |
190 | | - title: result.original_title, |
191 | | - englishTitle: result.title, |
192 | | - year: result.release_date ? new Date(result.release_date).getFullYear().toString() : 'unknown', |
193 | | - dataSource: this.apiName, |
194 | | - id: result.id, |
195 | | - }), |
196 | | - ); |
197 | | - } |
198 | | - |
199 | | - return ret; |
200 | | - } |
201 | | - |
202 | | - async getById(id: string): Promise<MediaTypeModel> { |
203 | | - console.log(`MDB | api "${this.apiName}" queried by ID`); |
204 | | - |
205 | | - if (!this.plugin.settings.TMDBKey) { |
206 | | - throw Error(`MDB | API key for ${this.apiName} missing.`); |
207 | | - } |
208 | | - |
209 | | - const searchUrl = `https://api.themoviedb.org/3/movie/${encodeURIComponent(id)}?api_key=${this.plugin.settings.TMDBKey}&append_to_response=credits`; |
210 | | - const fetchData = await fetch(searchUrl); |
211 | | - |
212 | | - if (fetchData.status === 401) { |
213 | | - throw Error(`MDB | Authentication for ${this.apiName} failed. Check the API key.`); |
214 | | - } |
215 | | - if (fetchData.status !== 200) { |
216 | | - throw Error(`MDB | Received status code ${fetchData.status} from ${this.apiName}.`); |
217 | | - } |
218 | | - |
219 | | - const result = await fetchData.json(); |
220 | | - // console.debug(result); |
221 | | - |
222 | | - return new MovieModel({ |
223 | | - type: 'movie', |
224 | | - title: result.title, |
225 | | - englishTitle: result.title, |
226 | | - year: result.release_date ? new Date(result.release_date).getFullYear().toString() : 'unknown', |
227 | | - premiere: this.plugin.dateFormatter.format(result.release_date, this.apiDateFormat) ?? 'unknown', |
228 | | - dataSource: this.apiName, |
229 | | - url: `https://www.themoviedb.org/movie/${result.id}`, |
230 | | - id: result.id, |
231 | | - |
232 | | - plot: result.overview ?? '', |
233 | | - genres: result.genres.map((g: any) => g.name) ?? [], |
234 | | - writer: result.credits.crew.filter((c: any) => c.job === 'Screenplay').map((c: any) => c.name) ?? [], |
235 | | - director: result.credits.crew.filter((c: any) => c.job === 'Director').map((c: any) => c.name) ?? [], |
236 | | - studio: result.production_companies.map((s: any) => s.name) ?? [], |
237 | | - |
238 | | - duration: result.runtime ?? 'unknown', |
239 | | - onlineRating: result.vote_average, |
240 | | - actors: result.credits.cast.map((c: any) => c.name).slice(0, 5) ?? [], |
241 | | - image: `https://image.tmdb.org/t/p/w780${result.poster_path}`, |
242 | | - |
243 | | - released:['Released'].includes(result.status), |
244 | | - streamingServices: [], |
245 | | - |
246 | | - userData: { |
247 | | - watched: false, |
248 | | - lastWatched: '', |
249 | | - personalRating: 0, |
250 | | - }, |
251 | | - }); |
252 | | - |
253 | | - } |
254 | | - |
255 | | - getDisabledMediaTypes(): MediaType[] { |
256 | | - return this.plugin.settings.TMDBMovieAPI_disabledMediaTypes as MediaType[]; |
257 | | - } |
258 | | -} |
0 commit comments