mirror of
https://github.com/aleksilassila/reiverr.git
synced 2026-04-23 01:05:13 +02:00
Initial work on getting series working
This commit is contained in:
@@ -2,7 +2,7 @@ import createClient from 'openapi-fetch';
|
||||
import { log, request } from '$lib/utils';
|
||||
import type { paths } from '$lib/apis/radarr/radarr.generated';
|
||||
import type { components } from '$lib/apis/radarr/radarr.generated';
|
||||
import { fetchTmdbMovie } from '$lib/apis/tmdbApi';
|
||||
import { getTmdbMovie } from '$lib/apis/tmdb/tmdbApi';
|
||||
import { PUBLIC_RADARR_API_KEY, PUBLIC_RADARR_BASE_URL } from '$env/static/public';
|
||||
|
||||
export type RadarrMovie = components['schemas']['MovieResource'];
|
||||
@@ -36,9 +36,9 @@ export const getRadarrMovies = (): Promise<RadarrMovie[]> =>
|
||||
params: {}
|
||||
}).then((r) => r.data || []);
|
||||
|
||||
export const requestRadarrMovie = () => request(getRadarrMovie);
|
||||
export const requestRadarrMovie = () => request(getRadarrMovieByTmdbId);
|
||||
|
||||
export const getRadarrMovie = (tmdbId: string): Promise<RadarrMovie | undefined> =>
|
||||
export const getRadarrMovieByTmdbId = (tmdbId: string): Promise<RadarrMovie | undefined> =>
|
||||
RadarrApi.get('/api/v3/movie', {
|
||||
params: {
|
||||
query: {
|
||||
@@ -47,11 +47,9 @@ export const getRadarrMovie = (tmdbId: string): Promise<RadarrMovie | undefined>
|
||||
}
|
||||
}).then((r) => r.data?.find((m) => (m.tmdbId as any) == tmdbId));
|
||||
|
||||
export const requestAddRadarrMovie = () => request(addRadarrMovie);
|
||||
|
||||
export const addRadarrMovie = async (tmdbId: string) => {
|
||||
const tmdbMovie = await fetchTmdbMovie(tmdbId);
|
||||
const radarrMovie = await getMovieByTmdbIdByTmdbId(tmdbId);
|
||||
const tmdbMovie = await getTmdbMovie(tmdbId);
|
||||
const radarrMovie = await lookupRadarrMovieByTmdbId(tmdbId);
|
||||
console.log('fetched movies', tmdbMovie, radarrMovie);
|
||||
|
||||
if (radarrMovie?.id) throw new Error('Movie already exists');
|
||||
@@ -94,15 +92,11 @@ export const cancelDownloadRadarrMovie = async (downloadId: number) => {
|
||||
return deleteResponse.response.ok;
|
||||
};
|
||||
|
||||
export const requestRadarrReleases = () => request(fetchRadarrReleases);
|
||||
|
||||
export const fetchRadarrReleases = (movieId: string) =>
|
||||
RadarrApi.get('/api/v3/release', { params: { query: { movieId: Number(movieId) } } }).then(
|
||||
(r) => r.data
|
||||
);
|
||||
|
||||
export const requestDownloadRadarrMovie = () => request(downloadRadarrMovie);
|
||||
|
||||
export const downloadRadarrMovie = (guid: string) =>
|
||||
RadarrApi.post('/api/v3/release', {
|
||||
params: {},
|
||||
@@ -121,8 +115,6 @@ export const deleteRadarrMovie = (id: number) =>
|
||||
}
|
||||
}).then((res) => res.response.ok);
|
||||
|
||||
export const requestRadarrQueuedById = () => request(getRadarrDownload);
|
||||
|
||||
export const getRadarrDownloads = (): Promise<RadarrDownload[]> =>
|
||||
RadarrApi.get('/api/v3/queue', {
|
||||
params: {
|
||||
@@ -132,10 +124,10 @@ export const getRadarrDownloads = (): Promise<RadarrDownload[]> =>
|
||||
}
|
||||
}).then((r) => (r.data?.records?.filter((record) => record.movie) as RadarrDownload[]) || []);
|
||||
|
||||
export const getRadarrDownload = (id: string) =>
|
||||
getRadarrDownloads().then((downloads) => downloads.find((d) => d.movie.id === Number(id)));
|
||||
export const getRadarrDownloadById = (radarrId: number) =>
|
||||
getRadarrDownloads().then((downloads) => downloads.find((d) => d.movie.id === radarrId));
|
||||
|
||||
const getMovieByTmdbIdByTmdbId = (tmdbId: string) =>
|
||||
const lookupRadarrMovieByTmdbId = (tmdbId: string) =>
|
||||
RadarrApi.get('/api/v3/movie/lookup/tmdb', {
|
||||
params: {
|
||||
query: {
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
import createClient from 'openapi-fetch';
|
||||
import type { paths } from '$lib/apis/sonarr/sonarr.generated';
|
||||
import type { components, paths } from '$lib/apis/sonarr/sonarr.generated';
|
||||
import { PUBLIC_SONARR_API_KEY, PUBLIC_SONARR_BASE_URL } from '$env/static/public';
|
||||
import type { SeriesResource } from '$lib/types';
|
||||
|
||||
export type SonarrSeries = components['schemas']['SeriesResource'];
|
||||
// export type MovieFileResource = components['schemas']['MovieFileResource'];
|
||||
export type SonarrReleaseResource = components['schemas']['ReleaseResource'];
|
||||
export type SonarrDownload = components['schemas']['QueueResource'] & { series: SonarrSeries };
|
||||
export type DiskSpaceInfo = components['schemas']['DiskSpaceResource'];
|
||||
|
||||
export const SonarrApi = createClient<paths>({
|
||||
baseUrl: PUBLIC_SONARR_BASE_URL,
|
||||
@@ -8,3 +15,32 @@ export const SonarrApi = createClient<paths>({
|
||||
'X-Api-Key': PUBLIC_SONARR_API_KEY
|
||||
}
|
||||
});
|
||||
|
||||
export const getSonarrSeries = (): Promise<SeriesResource[]> =>
|
||||
SonarrApi.get('/api/v3/series', {
|
||||
params: {}
|
||||
}).then((r) => r.data || []);
|
||||
|
||||
export const getSonarrSeriesByTvdbId = (tvdbId: number): Promise<SeriesResource | undefined> =>
|
||||
SonarrApi.get('/api/v3/series', {
|
||||
params: {
|
||||
query: {
|
||||
tvdbId: tvdbId
|
||||
}
|
||||
}
|
||||
}).then((r) => r.data?.find((m) => m.tvdbId === tvdbId));
|
||||
|
||||
export const getSonarrDownloads = (): Promise<SonarrDownload[]> =>
|
||||
SonarrApi.get('/api/v3/queue', {
|
||||
params: {
|
||||
query: {
|
||||
includeSeries: true
|
||||
}
|
||||
}
|
||||
}).then((r) => (r.data?.records?.filter((record) => record.series) as SonarrDownload[]) || []);
|
||||
|
||||
export const getRadarrDownloadById = (sonarrId: number) =>
|
||||
getSonarrDownloads().then((downloads) => downloads.find((d) => d.series.id === sonarrId));
|
||||
|
||||
export const getDiskSpace = (): Promise<DiskSpaceInfo[]> =>
|
||||
SonarrApi.get('/api/v3/diskspace', {}).then((d) => d.data || []);
|
||||
|
||||
19910
src/lib/apis/tmdb/tmdb.generated.d.ts
vendored
Normal file
19910
src/lib/apis/tmdb/tmdb.generated.d.ts
vendored
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,54 @@
|
||||
import axios from 'axios';
|
||||
import { PUBLIC_TMDB_API_KEY } from '$env/static/public';
|
||||
import { request } from '$lib/utils';
|
||||
import type { paths } from './tmdb.generated';
|
||||
import createClient from 'openapi-fetch';
|
||||
|
||||
export const TmdbApiOpen = createClient<paths>({
|
||||
baseUrl: 'https://api.themoviedb.org',
|
||||
headers: {
|
||||
Authorization: `Bearer ${PUBLIC_TMDB_API_KEY}`
|
||||
}
|
||||
});
|
||||
|
||||
export const getTmdbMovie = async (tmdbId: number) =>
|
||||
await TmdbApiOpen.get('/3/movie/{movie_id}', {
|
||||
params: {
|
||||
path: {
|
||||
movie_id: tmdbId
|
||||
}
|
||||
}
|
||||
}).then((res) => res.data);
|
||||
|
||||
export const getTmdbPopularMovies = () =>
|
||||
TmdbApiOpen.get('/3/movie/popular', {
|
||||
params: {}
|
||||
}).then((res) => res.data?.results || []);
|
||||
|
||||
export const getTmdbIdFromTvdbId = async (tvdbId: number) =>
|
||||
TmdbApiOpen.get('/3/find/{external_id}', {
|
||||
params: {
|
||||
path: {
|
||||
external_id: String(tvdbId)
|
||||
},
|
||||
query: {
|
||||
external_source: 'tvdb_id'
|
||||
}
|
||||
}
|
||||
})
|
||||
.then((res) => res.data?.tv_results?.[0])
|
||||
.then((res: any) => res?.id as number | undefined);
|
||||
|
||||
export const getTmdbSeriesImages = async (tmdbId: number) =>
|
||||
TmdbApiOpen.get('/3/tv/{series_id}/images', {
|
||||
params: {
|
||||
path: {
|
||||
series_id: tmdbId
|
||||
}
|
||||
}
|
||||
}).then((res) => res.data);
|
||||
|
||||
// Deprecated hereon forward
|
||||
|
||||
export const TmdbApi = axios.create({
|
||||
baseURL: 'https://api.themoviedb.org/3',
|
||||
Reference in New Issue
Block a user