Skip to content

Commit

Permalink
Merge pull request #4220 from Ombi-app/develop
Browse files Browse the repository at this point in the history
sync
  • Loading branch information
twanariens authored Jun 8, 2021
2 parents f0d8add + 5e33088 commit 4d8f0a1
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 81 deletions.
12 changes: 12 additions & 0 deletions src/Ombi.Core/Helpers/TvShowRequestBuilderV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ public TvShowRequestBuilderV2(IMovieDbApi movApi)
public async Task<TvShowRequestBuilderV2> GetShowInfo(int id)
{
TheMovieDbRecord = await MovieDbApi.GetTVInfo(id.ToString());

// Remove 'Specials Season'
var firstSeason = TheMovieDbRecord.seasons.OrderBy(x => x.season_number).FirstOrDefault();
if (firstSeason?.season_number == 0)
{
TheMovieDbRecord.seasons.Remove(firstSeason);
}

BackdropPath = TheMovieDbRecord.Images?.Backdrops?.OrderBy(x => x.VoteCount).ThenBy(x => x.VoteAverage).FirstOrDefault()?.FilePath; ;

DateTime.TryParse(TheMovieDbRecord.first_air_date, out var dt);
Expand Down Expand Up @@ -149,6 +157,10 @@ public async Task<TvShowRequestBuilderV2> BuildEpisodes(TvRequestViewModelV2 tv)
else if (tv.FirstSeason)
{
var first = allEpisodes.OrderBy(x => x.season_number).FirstOrDefault();
if (first.season_number == 0)
{
first = allEpisodes.OrderBy(x => x.season_number).Skip(1).FirstOrDefault();
}
var episodesRequests = new List<EpisodeRequests>();
foreach (var ep in allEpisodes)
{
Expand Down
65 changes: 15 additions & 50 deletions src/Ombi.Core/Senders/MovieSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ private async Task<DogNzbMovieAddResult> SendToDogNzb(FullBaseRequest model, Dog

private async Task<SenderResult> SendToRadarr(MovieRequests model, RadarrSettings settings)
{
var v3 = settings.V3;
var qualityToUse = int.Parse(settings.DefaultQualityProfile);

var rootFolderPath = settings.DefaultRootPath;
Expand Down Expand Up @@ -159,30 +158,16 @@ private async Task<SenderResult> SendToRadarr(MovieRequests model, RadarrSetting

List<MovieResponse> movies;
// Check if the movie already exists? Since it could be unmonitored
if (settings.V3)
{
movies = await _radarrV3Api.GetMovies(settings.ApiKey, settings.FullUri);
}
else
{
movies = await _radarrV2Api.GetMovies(settings.ApiKey, settings.FullUri);
}

movies = await _radarrV3Api.GetMovies(settings.ApiKey, settings.FullUri);

var existingMovie = movies.FirstOrDefault(x => x.tmdbId == model.TheMovieDbId);
if (existingMovie == null)
{
RadarrAddMovie result;
if (v3)
{
result = await _radarrV3Api.AddMovie(model.TheMovieDbId, model.Title, model.ReleaseDate.Year,
qualityToUse, rootFolderPath, settings.ApiKey, settings.FullUri, !settings.AddOnly,
settings.MinimumAvailability);
}
else
{
result = await _radarrV2Api.AddMovie(model.TheMovieDbId, model.Title, model.ReleaseDate.Year,
qualityToUse, rootFolderPath, settings.ApiKey, settings.FullUri, !settings.AddOnly,
settings.MinimumAvailability);
}
var result = await _radarrV3Api.AddMovie(model.TheMovieDbId, model.Title, model.ReleaseDate.Year,
qualityToUse, rootFolderPath, settings.ApiKey, settings.FullUri, !settings.AddOnly,
settings.MinimumAvailability);

if (!string.IsNullOrEmpty(result.Error?.message))
{
_log.LogError(LoggingEvents.RadarrCacher, result.Error.message);
Expand All @@ -199,23 +184,12 @@ private async Task<SenderResult> SendToRadarr(MovieRequests model, RadarrSetting
{
// let's set it to monitored and search for it
existingMovie.monitored = true;
if (v3)
{
await _radarrV3Api.UpdateMovie(existingMovie, settings.ApiKey, settings.FullUri);
// Search for it
if (!settings.AddOnly)
{
await _radarrV3Api.MovieSearch(new[] { existingMovie.id }, settings.ApiKey, settings.FullUri);
}
}
else

await _radarrV3Api.UpdateMovie(existingMovie, settings.ApiKey, settings.FullUri);
// Search for it
if (!settings.AddOnly)
{
await _radarrV2Api.UpdateMovie(existingMovie, settings.ApiKey, settings.FullUri);
// Search for it
if (!settings.AddOnly)
{
await _radarrV2Api.MovieSearch(new[] { existingMovie.id }, settings.ApiKey, settings.FullUri);
}
await _radarrV3Api.MovieSearch(new[] { existingMovie.id }, settings.ApiKey, settings.FullUri);
}

return new SenderResult { Success = true, Sent = true };
Expand All @@ -226,18 +200,9 @@ private async Task<SenderResult> SendToRadarr(MovieRequests model, RadarrSetting

private async Task<string> RadarrRootPath(int overrideId, RadarrSettings settings)
{
if (settings.V3)
{
var paths = await _radarrV3Api.GetRootFolders(settings.ApiKey, settings.FullUri);
var selectedPath = paths.FirstOrDefault(x => x.id == overrideId);
return selectedPath?.path ?? string.Empty;
}
else
{
var paths = await _radarrV2Api.GetRootFolders(settings.ApiKey, settings.FullUri);
var selectedPath = paths.FirstOrDefault(x => x.id == overrideId);
return selectedPath?.path ?? string.Empty;
}
var paths = await _radarrV3Api.GetRootFolders(settings.ApiKey, settings.FullUri);
var selectedPath = paths.FirstOrDefault(x => x.id == overrideId);
return selectedPath?.path ?? string.Empty;
}
}
}
6 changes: 4 additions & 2 deletions src/Ombi.Schedule/Jobs/Ombi/NewsletterJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ await _notification.Clients.Clients(NotificationHub.AdminConnectionIds)
var lidarrContent = _lidarrAlbumRepository.GetAll().AsNoTracking().ToList().Where(x => x.FullyAvailable);

var addedLog = _recentlyAddedLog.GetAll();
var addedPlexMovieLogIds = addedLog.Where(x => x.Type == RecentlyAddedType.Plex && x.ContentType == ContentType.Parent).Select(x => x.ContentId).ToHashSet();

var addedPlexMovieLogIds = addedLog.Where(x => x.Type == RecentlyAddedType.Plex && x.ContentType == ContentType.Parent)?.Select(x => x.ContentId)?.ToHashSet() ?? new HashSet<int>();
var addedEmbyMoviesLogIds = addedLog.Where(x => x.Type == RecentlyAddedType.Emby && x.ContentType == ContentType.Parent).Select(x => x.ContentId).ToHashSet();
var addedJellyfinMoviesLogIds = addedLog.Where(x => x.Type == RecentlyAddedType.Jellyfin && x.ContentType == ContentType.Parent).Select(x => x.ContentId).ToHashSet();
var addedAlbumLogIds = addedLog.Where(x => x.Type == RecentlyAddedType.Lidarr && x.ContentType == ContentType.Album).Select(x => x.AlbumId).ToHashSet();
Expand Down Expand Up @@ -170,6 +171,7 @@ await _notification.Clients.Clients(NotificationHub.AdminConnectionIds)

plexContentMoviesToSend = plexContentMoviesToSend.DistinctBy(x => x.Id).ToHashSet();
embyContentMoviesToSend = embyContentMoviesToSend.DistinctBy(x => x.Id).ToHashSet();
jellyfinContentMoviesToSend = jellyfinContentMoviesToSend.DistinctBy(x => x.Id).ToHashSet();

var plexEpisodesToSend =
FilterPlexEpisodes(_plex.GetAllEpisodes().Include(x => x.Series).AsNoTracking(), addedPlexEpisodesLogIds);
Expand Down Expand Up @@ -537,7 +539,7 @@ private async Task<string> BuildHtml(IQueryable<PlexServerContent> plexContentTo
var plexMovies = plexContentToSend.Where(x => x.Type == PlexMediaTypeEntity.Movie);
var embyMovies = embyContentToSend.Where(x => x.Type == EmbyMediaType.Movie);
var jellyfinMovies = jellyfinContentToSend.Where(x => x.Type == JellyfinMediaType.Movie);
if ((plexMovies.Any() || embyMovies.Any()) && !settings.DisableMovies)
if ((plexMovies.Any() || embyMovies.Any()) || jellyfinMovies.Any() && !settings.DisableMovies)
{
sb.Append("<h1 style=\"text-align: center; max-width: 1042px;\">New Movies</h1><br /><br />");
sb.Append(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
public class RadarrSettings : ExternalSettings
{
public bool Enabled { get; set; }
public bool V3 { get; set; }
public string ApiKey { get; set; }
public string DefaultQualityProfile { get; set; }
public string DefaultRootPath { get; set; }
Expand Down
3 changes: 2 additions & 1 deletion src/Ombi.TheMovieDbApi/Models/TvInfo.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using System.Collections.Generic;

namespace Ombi.Api.TheMovieDb.Models
{
Expand Down Expand Up @@ -26,7 +27,7 @@ public class TvInfo
public float popularity { get; set; }
public string poster_path { get; set; }
public Production_Companies[] production_companies { get; set; }
public Season[] seasons { get; set; }
public List<Season> seasons { get; set; }
public string status { get; set; }
public string type { get; set; }
public float vote_average { get; set; }
Expand Down
1 change: 0 additions & 1 deletion src/Ombi/ClientApp/src/app/interfaces/ISettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ export interface IRadarrSettings extends IExternalSettings {
addOnly: boolean;
minimumAvailability: string;
scanForAvailability: boolean;
v3: boolean;
}

export interface ILidarrSettings extends IExternalSettings {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
<div class="md-form-field">
<mat-slide-toggle formControlName="enabled" id="enable">Enable</mat-slide-toggle>
</div>
<div class="md-form-field">
<mat-slide-toggle formControlName="v3">V3</mat-slide-toggle>
</div>
<div class="md-form-field">
<mat-slide-toggle formControlName="scanForAvailability">Scan for Availability</mat-slide-toggle>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ export class RadarrComponent implements OnInit {
port: [x.port, [Validators.required]],
addOnly: [x.addOnly],
minimumAvailability: [x.minimumAvailability, [Validators.required]],
scanForAvailability: [x.scanForAvailability],
v3: [x.v3 ?? true]
scanForAvailability: [x.scanForAvailability]
});

if (x.defaultQualityProfile) {
Expand Down
24 changes: 4 additions & 20 deletions src/Ombi/Controllers/V1/External/RadarrController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@ public RadarrController(IRadarrApi radarr, ISettingsService<RadarrSettings> sett
[PowerUser]
public async Task<IActionResult> GetProfiles([FromBody] RadarrSettings settings)
{
if (settings.V3)
{
return Ok(await _radarrV3Api.GetProfiles(settings.ApiKey, settings.FullUri));
}
return Ok(await _radarrApi.GetProfiles(settings.ApiKey, settings.FullUri));
return Ok(await _radarrV3Api.GetProfiles(settings.ApiKey, settings.FullUri));
}

[HttpGet("enabled")]
Expand All @@ -64,11 +60,7 @@ public async Task<bool> Enabled()
[PowerUser]
public async Task<IEnumerable<RadarrRootFolder>> GetRootFolders([FromBody] RadarrSettings settings)
{
if (settings.V3)
{
return await _radarrV3Api.GetRootFolders(settings.ApiKey, settings.FullUri);
}
return await _radarrApi.GetRootFolders(settings.ApiKey, settings.FullUri);
return await _radarrV3Api.GetRootFolders(settings.ApiKey, settings.FullUri);
}

/// <summary>
Expand All @@ -83,11 +75,7 @@ public async Task<IActionResult> GetProfiles()
var settings = await _radarrSettings.GetSettingsAsync();
if (settings.Enabled)
{
if (settings.V3)
{
return Ok(await _radarrV3Api.GetProfiles(settings.ApiKey, settings.FullUri));
}
return Ok(await _radarrApi.GetProfiles(settings.ApiKey, settings.FullUri));
return Ok(await _radarrV3Api.GetProfiles(settings.ApiKey, settings.FullUri));
}
return null;
}
Expand All @@ -104,11 +92,7 @@ public async Task<IEnumerable<RadarrRootFolder>> GetRootFolders()
var settings = await _radarrSettings.GetSettingsAsync();
if (settings.Enabled)
{
if (settings.V3)
{
return await _radarrV3Api.GetRootFolders(settings.ApiKey, settings.FullUri);
}
return await _radarrApi.GetRootFolders(settings.ApiKey, settings.FullUri);
return await _radarrV3Api.GetRootFolders(settings.ApiKey, settings.FullUri);
}
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Ombi/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
"Ombi": {
"commandName": "Project",
"commandLineArgs": "--host http://localhost:3577",
"commandLineArgs": "--host http://localhost:3577 --demo true",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
Expand Down

0 comments on commit 4d8f0a1

Please sign in to comment.