-
-
Notifications
You must be signed in to change notification settings - Fork 407
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): radarr api wrapper / send to radarr when requests approved (…
…#93)
- Loading branch information
Showing
4 changed files
with
176 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import Axios, { AxiosInstance } from 'axios'; | ||
|
||
interface RadarrMovieOptions { | ||
title: string; | ||
qualityProfileId: number; | ||
profileId: number; | ||
year: number; | ||
rootFolderPath: string; | ||
tmdbId: number; | ||
monitored?: boolean; | ||
searchNow?: boolean; | ||
} | ||
|
||
interface RadarrMovie { | ||
id: number; | ||
title: string; | ||
isAvailable: boolean; | ||
monitored: boolean; | ||
tmdbId: number; | ||
titleSlug: string; | ||
folderName: string; | ||
path: string; | ||
profileId: number; | ||
qualityProfileId: number; | ||
added: string; | ||
downloaded: boolean; | ||
hasFile: boolean; | ||
} | ||
|
||
interface RadarrRootFolder { | ||
id: number; | ||
path: string; | ||
freeSpace: number; | ||
totalSpace: number; | ||
unmappedFolders: { | ||
name: string; | ||
path: string; | ||
}[]; | ||
} | ||
|
||
interface RadarrProfile { | ||
id: number; | ||
name: string; | ||
} | ||
|
||
class RadarrAPI { | ||
private axios: AxiosInstance; | ||
constructor({ url, apiKey }: { url: string; apiKey: string }) { | ||
this.axios = Axios.create({ | ||
baseURL: url, | ||
params: { | ||
apikey: apiKey, | ||
}, | ||
}); | ||
} | ||
|
||
public getMovies = async (): Promise<RadarrMovie[]> => { | ||
try { | ||
const response = await this.axios.get<RadarrMovie[]>('/movie'); | ||
|
||
return response.data; | ||
} catch (e) { | ||
throw new Error(`[Radarr] Failed to retrieve movies: ${e.message}`); | ||
} | ||
}; | ||
|
||
public getMovie = async ({ id }: { id: number }): Promise<RadarrMovie> => { | ||
try { | ||
const response = await this.axios.get<RadarrMovie>(`/movie/${id}`); | ||
|
||
return response.data; | ||
} catch (e) { | ||
throw new Error(`[Radarr] Failed to retrieve movie: ${e.message}`); | ||
} | ||
}; | ||
|
||
public addMovie = async ( | ||
options: RadarrMovieOptions | ||
): Promise<RadarrMovie> => { | ||
try { | ||
const response = await this.axios.post<RadarrMovie>(`/movie`, { | ||
title: options.title, | ||
qualityProfileId: options.qualityProfileId, | ||
profileId: options.profileId, | ||
titleSlug: options.tmdbId.toString(), | ||
tmdbId: options.tmdbId, | ||
year: options.year, | ||
rootFolderPath: options.rootFolderPath, | ||
monitored: options.monitored, | ||
addOptions: { | ||
searchForMovie: options.searchNow, | ||
}, | ||
}); | ||
|
||
return response.data; | ||
} catch (e) { | ||
throw new Error(`[Radarr] Failed to add movie: ${e.message}`); | ||
} | ||
}; | ||
|
||
public getProfiles = async (): Promise<RadarrProfile[]> => { | ||
try { | ||
const response = await this.axios.get<RadarrProfile[]>(`/profile`); | ||
|
||
return response.data; | ||
} catch (e) { | ||
throw new Error(`[Radarr] Failed to retrieve profiles: ${e.message}`); | ||
} | ||
}; | ||
|
||
public getRootFolders = async (): Promise<RadarrRootFolder[]> => { | ||
try { | ||
const response = await this.axios.get<RadarrRootFolder[]>(`/rootfolder`); | ||
|
||
return response.data; | ||
} catch (e) { | ||
throw new Error(`[Radarr] Failed to retrieve root folders: ${e.message}`); | ||
} | ||
}; | ||
} | ||
|
||
export default RadarrAPI; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters