Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
sct committed Apr 21, 2021
2 parents 8c782e0 + 1a311d2 commit 24095ea
Show file tree
Hide file tree
Showing 84 changed files with 853 additions and 2,016 deletions.
9 changes: 9 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,15 @@
"contributions": [
"translation"
]
},
{
"login": "Dabu-dot",
"name": "Dabu-dot",
"avatar_url": "https://avatars.githubusercontent.com/u/52525576?v=4",
"profile": "https://github.com/Dabu-dot",
"contributions": [
"translation"
]
}
],
"badgeTemplate": "<a href=\"#contributors-\"><img alt=\"All Contributors\" src=\"https://img.shields.io/badge/all_contributors-<%= contributors.length %>-orange.svg\"/></a>",
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<a href="https://lgtm.com/projects/g/sct/overseerr/context:javascript"><img alt="Language grade: JavaScript" src="https://img.shields.io/lgtm/grade/javascript/g/sct/overseerr.svg?logo=lgtm&logoWidth=18"/></a>
<a href="https://github.com/sct/overseerr/blob/develop/LICENSE"><img alt="GitHub" src="https://img.shields.io/github/license/sct/overseerr"></a>
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
<a href="#contributors-"><img alt="All Contributors" src="https://img.shields.io/badge/all_contributors-49-orange.svg"/></a>
<a href="#contributors-"><img alt="All Contributors" src="https://img.shields.io/badge/all_contributors-50-orange.svg"/></a>
<!-- ALL-CONTRIBUTORS-BADGE:END -->
</p>

Expand Down Expand Up @@ -137,6 +137,9 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<td align="center"><a href="https://nz.linkedin.com/in/jonocairns"><img src="https://avatars.githubusercontent.com/u/182836?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jono Cairns</b></sub></a><br /><a href="https://github.com/sct/overseerr/commits?author=jonocairns" title="Code">💻</a></td>
<td align="center"><a href="https://scias.net/"><img src="https://avatars.githubusercontent.com/u/439655?v=4?s=100" width="100px;" alt=""/><br /><sub><b>DJScias</b></sub></a><br /><a href="#translation-DJScias" title="Translation">🌍</a></td>
</tr>
<tr>
<td align="center"><a href="https://github.com/Dabu-dot"><img src="https://avatars.githubusercontent.com/u/52525576?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Dabu-dot</b></sub></a><br /><a href="#translation-Dabu-dot" title="Translation">🌍</a></td>
</tr>
</table>

<!-- markdownlint-restore -->
Expand Down
6 changes: 3 additions & 3 deletions docs/using-overseerr/settings/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,11 @@ If the hostname or IP address you configured above is not accessible outside you

#### Enable Scan

Tick this box if you would like to scan your Radarr/Sonarr server for existing media/request status. It is recommended that you enable this setting, so that users cannot submit requests for media which has already been requested or is already available.
Enable this setting if you would like to scan your Radarr/Sonarr server for existing media/request status. It is recommended that you enable this setting, so that users cannot submit requests for media which has already been requested or is already available.

#### Disable Auto-Search
#### Enable Automatic Search

If you do not want Radarr/Sonarr to automatically search for media upon submission of a request, you can disable this setting.
Enable this setting to have Radarr/Sonarr to automatically search for media upon approval of a request.

## Notifications

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"license": "MIT",
"dependencies": {
"@headlessui/react": "^1.0.0",
"@heroicons/react": "^1.0.1",
"@supercharge/request-ip": "^1.1.2",
"@svgr/webpack": "^5.5.0",
"@tanem/react-nprogress": "^3.0.62",
Expand Down
41 changes: 36 additions & 5 deletions server/api/servarr/radarr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ class RadarrAPI extends ServarrBase<{ movieId: number }> {
} catch (e) {
logger.error('Error retrieving movie by TMDb ID', {
label: 'Radarr API',
message: e.message,
errorMessage: e.message,
tmdbId: id,
});
throw new Error('Movie not found');
}
Expand All @@ -89,12 +90,13 @@ class RadarrAPI extends ServarrBase<{ movieId: number }> {
'Title already exists and is available. Skipping add and returning success',
{
label: 'Radarr',
movie,
}
);
return movie;
}

// movie exists in radarr but is neither downloaded nor monitored
// movie exists in Radarr but is neither downloaded nor monitored
if (movie.id && !movie.monitored) {
const response = await this.axios.put<RadarrMovie>(`/movie`, {
...movie,
Expand All @@ -115,16 +117,25 @@ class RadarrAPI extends ServarrBase<{ movieId: number }> {

if (response.data.monitored) {
logger.info(
'Found existing title in Radarr and set it to monitored. Returning success',
{ label: 'Radarr' }
'Found existing title in Radarr and set it to monitored.',
{
label: 'Radarr',
movieId: response.data.id,
movieTitle: response.data.title,
}
);
logger.debug('Radarr update details', {
label: 'Radarr',
movie: response.data,
});

if (options.searchNow) {
this.searchMovie(response.data.id);
}

return response.data;
} else {
logger.error('Failed to update existing movie in Radarr', {
logger.error('Failed to update existing movie in Radarr.', {
label: 'Radarr',
options,
});
Expand Down Expand Up @@ -183,6 +194,26 @@ class RadarrAPI extends ServarrBase<{ movieId: number }> {
throw new Error('Failed to add movie to Radarr');
}
};

public async searchMovie(movieId: number): Promise<void> {
logger.info('Executing movie search command', {
label: 'Radarr API',
movieId,
});

try {
await this.runCommand('MoviesSearch', { movieIds: [movieId] });
} catch (e) {
logger.error(
'Something went wrong while executing Radarr movie search.',
{
label: 'Radarr API',
errorMessage: e.message,
movieId,
}
);
}
}
}

export default RadarrAPI;
35 changes: 26 additions & 9 deletions server/api/servarr/sonarr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ class SonarrAPI extends ServarrBase<{ seriesId: number; episodeId: number }> {
} catch (e) {
logger.error('Error retrieving series by series title', {
label: 'Sonarr API',
message: e.message,
errorMessage: e.message,
title,
});
throw new Error('No series found');
}
Expand All @@ -135,7 +136,8 @@ class SonarrAPI extends ServarrBase<{ seriesId: number; episodeId: number }> {
} catch (e) {
logger.error('Error retrieving series by tvdb ID', {
label: 'Sonarr API',
message: e.message,
errorMessage: e.message,
tvdbId: id,
});
throw new Error('Series not found');
}
Expand All @@ -156,25 +158,28 @@ class SonarrAPI extends ServarrBase<{ seriesId: number; episodeId: number }> {
);

if (newSeriesResponse.data.id) {
logger.info('Sonarr accepted request. Updated existing series', {
logger.info('Updated existing series in Sonarr.', {
label: 'Sonarr',
seriesId: newSeriesResponse.data.id,
seriesTitle: newSeriesResponse.data.title,
});
logger.debug('Sonarr update details', {
label: 'Sonarr',
movie: newSeriesResponse.data,
});

if (options.searchNow) {
this.searchSeries(newSeriesResponse.data.id);
}

return newSeriesResponse.data;
} else {
logger.error('Failed to update series in Sonarr', {
label: 'Sonarr',
options,
});
throw new Error('Failed to update series in Sonarr');
}

return newSeriesResponse.data;
}

const createdSeriesResponse = await this.axios.post<SonarrSeries>(
Expand Down Expand Up @@ -223,7 +228,7 @@ class SonarrAPI extends ServarrBase<{ seriesId: number; episodeId: number }> {
logger.error('Something went wrong while adding a series to Sonarr.', {
label: 'Sonarr API',
errorMessage: e.message,
error: e,
options,
response: e?.response?.data,
});
throw new Error('Failed to add series');
Expand All @@ -244,7 +249,7 @@ class SonarrAPI extends ServarrBase<{ seriesId: number; episodeId: number }> {
'Something went wrong while retrieving Sonarr language profiles.',
{
label: 'Sonarr API',
message: e.message,
errorMessage: e.message,
}
);

Expand All @@ -253,11 +258,23 @@ class SonarrAPI extends ServarrBase<{ seriesId: number; episodeId: number }> {
}

public async searchSeries(seriesId: number): Promise<void> {
logger.info('Executing series search command', {
logger.info('Executing series search command.', {
label: 'Sonarr API',
seriesId,
});
await this.runCommand('SeriesSearch', { seriesId });

try {
await this.runCommand('SeriesSearch', { seriesId });
} catch (e) {
logger.error(
'Something went wrong while executing Sonarr series search.',
{
label: 'Sonarr API',
errorMessage: e.message,
seriesId,
}
);
}
}

private buildSeasonList(
Expand Down
26 changes: 20 additions & 6 deletions server/entity/MediaRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ export class MediaRequest {
if (this.type === MediaType.MOVIE) {
const movie = await tmdb.getMovie({ movieId: media.tmdbId });
notificationManager.sendNotification(Notification.MEDIA_PENDING, {
subject: movie.title,
subject: `${movie.title}${
movie.release_date ? ` (${movie.release_date.slice(0, 4)})` : ''
}`,
message: movie.overview,
image: `https://image.tmdb.org/t/p/w600_and_h900_bestv2${movie.poster_path}`,
media,
Expand All @@ -153,7 +155,9 @@ export class MediaRequest {
if (this.type === MediaType.TV) {
const tv = await tmdb.getTvShow({ tvId: media.tmdbId });
notificationManager.sendNotification(Notification.MEDIA_PENDING, {
subject: tv.name,
subject: `${tv.name}${
tv.first_air_date ? ` (${tv.first_air_date.slice(0, 4)})` : ''
}`,
message: tv.overview,
image: `https://image.tmdb.org/t/p/w600_and_h900_bestv2${tv.poster_path}`,
media,
Expand Down Expand Up @@ -210,7 +214,9 @@ export class MediaRequest {
: Notification.MEDIA_APPROVED
: Notification.MEDIA_DECLINED,
{
subject: movie.title,
subject: `${movie.title}${
movie.release_date ? ` (${movie.release_date.slice(0, 4)})` : ''
}`,
message: movie.overview,
image: `https://image.tmdb.org/t/p/w600_and_h900_bestv2${movie.poster_path}`,
notifyUser: autoApproved ? undefined : this.requestedBy,
Expand All @@ -227,7 +233,9 @@ export class MediaRequest {
: Notification.MEDIA_APPROVED
: Notification.MEDIA_DECLINED,
{
subject: tv.name,
subject: `${tv.name}${
tv.first_air_date ? ` (${tv.first_air_date.slice(0, 4)})` : ''
}`,
message: tv.overview,
image: `https://image.tmdb.org/t/p/w600_and_h900_bestv2${tv.poster_path}`,
notifyUser: autoApproved ? undefined : this.requestedBy,
Expand Down Expand Up @@ -492,7 +500,9 @@ export class MediaRequest {
);

notificationManager.sendNotification(Notification.MEDIA_FAILED, {
subject: movie.title,
subject: `${movie.title}${
movie.release_date ? ` (${movie.release_date.slice(0, 4)})` : ''
}`,
message: movie.overview,
media,
image: `https://image.tmdb.org/t/p/w600_and_h900_bestv2${movie.poster_path}`,
Expand Down Expand Up @@ -700,7 +710,11 @@ export class MediaRequest {
);

notificationManager.sendNotification(Notification.MEDIA_FAILED, {
subject: series.name,
subject: `${series.name}${
series.first_air_date
? ` (${series.first_air_date.slice(0, 4)})`
: ''
}`,
message: series.overview,
image: `https://image.tmdb.org/t/p/w600_and_h900_bestv2${series.poster_path}`,
media,
Expand Down
5 changes: 2 additions & 3 deletions server/lib/notifications/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logger from '../../logger';
import { getSettings } from '../settings';
import type { NotificationAgent, NotificationPayload } from './agents/agent';

export enum Notification {
Expand Down Expand Up @@ -45,13 +44,13 @@ class NotificationManager {
type: Notification,
payload: NotificationPayload
): void {
const settings = getSettings().notifications;
logger.info(`Sending notification(s) for ${Notification[type]}`, {
label: 'Notifications',
subject: payload.subject,
});

this.activeAgents.forEach((agent) => {
if (settings.enabled && agent.shouldSend(type)) {
if (agent.shouldSend(type)) {
agent.send(type, payload);
}
});
Expand Down
2 changes: 0 additions & 2 deletions server/lib/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ interface NotificationAgents {
}

interface NotificationSettings {
enabled: boolean;
agents: NotificationAgents;
}

Expand Down Expand Up @@ -234,7 +233,6 @@ class Settings {
initialized: false,
},
notifications: {
enabled: true,
agents: {
email: {
enabled: false,
Expand Down
Loading

0 comments on commit 24095ea

Please sign in to comment.