Skip to content

Commit

Permalink
Merge pull request #5 from tidusjar/develop
Browse files Browse the repository at this point in the history
Bring develop up to date with source
  • Loading branch information
anojht authored Apr 18, 2018
2 parents 3de5160 + bd741e0 commit 30b9a7e
Show file tree
Hide file tree
Showing 51 changed files with 468 additions and 154 deletions.
30 changes: 30 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,30 @@

### **New Features**

- Added a new Job. Plex Recently Added, this is a slimmed down version of the Plex Sync job, this will just scan the recently added list and not the whole library. I'd reccomend running this very regulary and the full scan not as regular. [Jamie]

### **Fixes**

- Add web-app-capable for IOS and Android. [Thomas]

- Fixed the bug where the newsletter CRON was not appearing on the job settings page. [Jamie]

- Add base url as a startup argument #2153. [Jamie Rees]

- Fixed a bug with the RefreshMetadata where we would never get TheMovieDBId's if it was missing it. [Jamie]


## v3.0.3173 (2018-04-12)

### **Fixes**

- Removed some early disposition that seemed to be causing errors in the API. [Jamie]


## v3.0.3164 (2018-04-10)

### **New Features**

- Added the ability to send newsletter out to users that are not in Ombi. [Jamie]

- Added the ability to turn off TV or Movies from the newsletter. [Jamie]
Expand Down Expand Up @@ -56,6 +80,12 @@

- Fixed the issue where movies were not appearing in the newsletter for users with Emby #2111. [Jamie]

- The fact that this button has another style really bothers me. [Louis Laureys]

- Fix discord current user count. [Avi]

- Fix broken images and new discord invite. [Avi]


## v3.0.3111 (2018-03-27)

Expand Down
1 change: 1 addition & 0 deletions src/Ombi.Api.Plex/IPlexApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ public interface IPlexApi
Task<PlexContainer> GetAllEpisodes(string authToken, string host, string section, int start, int retCount);
Task<PlexFriends> GetUsers(string authToken);
Task<PlexAccount> GetAccount(string authToken);
Task<PlexMetadata> GetRecentlyAdded(string authToken, string uri, string sectionId);
}
}
4 changes: 2 additions & 2 deletions src/Ombi.Api.Plex/Models/Metadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public class Metadata
public int leafCount { get; set; }
public int viewedLeafCount { get; set; }
public int childCount { get; set; }
public long addedAt { get; set; }
public int updatedAt { get; set; }
//public long addedAt { get; set; }
//public int updatedAt { get; set; }
public Genre[] Genre { get; set; }
//public Role[] Role { get; set; }
public string primaryExtraKey { get; set; }
Expand Down
9 changes: 9 additions & 0 deletions src/Ombi.Api.Plex/PlexApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,15 @@ public async Task<PlexFriends> GetUsers(string authToken)
return await Api.Request<PlexFriends>(request);
}

public async Task<PlexMetadata> GetRecentlyAdded(string authToken, string uri, string sectionId)
{
var request = new Request($"library/sections/{sectionId}/recentlyAdded", uri, HttpMethod.Get);
AddHeaders(request, authToken);
AddLimitHeaders(request, 0, 50);

return await Api.Request<PlexMetadata>(request);
}

/// <summary>
/// Adds the required headers and also the authorization header
/// </summary>
Expand Down
7 changes: 5 additions & 2 deletions src/Ombi.Core/Engine/TvRequestEngine.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using AutoMapper;
using Ombi.Api.TvMaze;
using Ombi.Api.TheMovieDb;
using Ombi.Core.Models.Requests;
using Ombi.Core.Models.Search;
using Ombi.Helpers;
Expand All @@ -26,11 +27,12 @@ namespace Ombi.Core.Engine
{
public class TvRequestEngine : BaseMediaEngine, ITvRequestEngine
{
public TvRequestEngine(ITvMazeApi tvApi, IRequestServiceMain requestService, IPrincipal user,
public TvRequestEngine(ITvMazeApi tvApi, IMovieDbApi movApi, IRequestServiceMain requestService, IPrincipal user,
INotificationHelper helper, IRuleEvaluator rule, OmbiUserManager manager,
ITvSender sender, IAuditRepository audit, IRepository<RequestLog> rl, ISettingsService<OmbiSettings> settings, ICacheService cache) : base(user, requestService, rule, manager, cache, settings)
{
TvApi = tvApi;
MovieDbApi = movApi;
NotificationHelper = helper;
TvSender = sender;
Audit = audit;
Expand All @@ -39,6 +41,7 @@ public TvRequestEngine(ITvMazeApi tvApi, IRequestServiceMain requestService, IPr

private INotificationHelper NotificationHelper { get; }
private ITvMazeApi TvApi { get; }
private IMovieDbApi MovieDbApi { get; }
private ITvSender TvSender { get; }
private IAuditRepository Audit { get; }
private readonly IRepository<RequestLog> _requestLog;
Expand All @@ -47,7 +50,7 @@ public async Task<RequestEngineResult> RequestTvShow(TvRequestViewModel tv)
{
var user = await GetUser();

var tvBuilder = new TvShowRequestBuilder(TvApi);
var tvBuilder = new TvShowRequestBuilder(TvApi, MovieDbApi);
(await tvBuilder
.GetShowInfo(tv.TvDbId))
.CreateTvList(tv)
Expand Down
16 changes: 15 additions & 1 deletion src/Ombi.Core/Helpers/TvShowRequestBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
using System.Linq;
using System.Threading.Tasks;
using Ombi.Api.TvMaze;
using Ombi.Api.TheMovieDb;
using Ombi.Api.TvMaze.Models;
using Ombi.Api.TheMovieDb.Models;
using Ombi.Core.Models.Requests;
using Ombi.Core.Models.Search;
using Ombi.Helpers;
Expand All @@ -16,23 +18,35 @@ namespace Ombi.Core.Helpers
public class TvShowRequestBuilder
{

public TvShowRequestBuilder(ITvMazeApi tvApi)
public TvShowRequestBuilder(ITvMazeApi tvApi, IMovieDbApi movApi)
{
TvApi = tvApi;
MovieDbApi = movApi;
}

private ITvMazeApi TvApi { get; }
private IMovieDbApi MovieDbApi { get; }

public ChildRequests ChildRequest { get; set; }
public List<SeasonsViewModel> TvRequests { get; protected set; }
public string PosterPath { get; protected set; }
public DateTime FirstAir { get; protected set; }
public TvRequests NewRequest { get; protected set; }
protected TvMazeShow ShowInfo { get; set; }
protected List<TvSearchResult> Results { get; set; }

public async Task<TvShowRequestBuilder> GetShowInfo(int id)
{
ShowInfo = await TvApi.ShowLookupByTheTvDbId(id);
Results = await MovieDbApi.SearchTv(ShowInfo.name);
foreach (TvSearchResult result in Results) {
if (result.Name == ShowInfo.name)
{
var showIds = await MovieDbApi.GetTvExternals(result.Id);
ShowInfo.externals.imdb = showIds.imdb_id;
break;
}
}

DateTime.TryParse(ShowInfo.premiered, out var dt);

Expand Down
2 changes: 2 additions & 0 deletions src/Ombi.Helpers/OmbiRoles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
{
public static class OmbiRoles
{
// DONT FORGET TO ADD TO IDENTITYCONTROLLER.CREATEROLES AND THE UI!

public const string Admin = nameof(Admin);
public const string AutoApproveMovie = nameof(AutoApproveMovie);
public const string AutoApproveTv = nameof(AutoApproveTv);
Expand Down
13 changes: 13 additions & 0 deletions src/Ombi.Mapping/Profiles/MovieProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@ public MovieProfile()
.ForMember(dest => dest.VoteAverage, opts => opts.MapFrom(src => src.vote_average))
.ForMember(dest => dest.VoteCount, opts => opts.MapFrom(src => src.vote_count));

CreateMap<SearchResult, TvSearchResult>()
.ForMember(dest => dest.BackdropPath, opts => opts.MapFrom(src => src.backdrop_path))
.ForMember(dest => dest.Id, opts => opts.MapFrom(src => src.id))
.ForMember(dest => dest.OriginalLanguage, opts => opts.MapFrom(src => src.original_language))
.ForMember(dest => dest.OriginalName, opts => opts.MapFrom(src => src.original_name))
.ForMember(dest => dest.Overview, opts => opts.MapFrom(src => src.overview))
.ForMember(dest => dest.Popularity, opts => opts.MapFrom(src => src.popularity))
.ForMember(dest => dest.PosterPath, opts => opts.MapFrom(src => src.poster_path))
.ForMember(dest => dest.ReleaseDate, opts => opts.MapFrom(src => src.first_air_date))
.ForMember(dest => dest.Name, opts => opts.MapFrom(src => src.name))
.ForMember(dest => dest.VoteAverage, opts => opts.MapFrom(src => src.vote_average))
.ForMember(dest => dest.VoteCount, opts => opts.MapFrom(src => src.vote_count));

CreateMap<MovieResponse, MovieResponseDto>()
.ForMember(dest => dest.Adult, opts => opts.MapFrom(src => src.adult))
.ForMember(dest => dest.BackdropPath, opts => opts.MapFrom(src => src.backdrop_path))
Expand Down
3 changes: 2 additions & 1 deletion src/Ombi.Schedule/JobSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public void Setup()
RecurringJob.AddOrUpdate(() => _embyContentSync.Start(), JobSettingsHelper.EmbyContent(s));
RecurringJob.AddOrUpdate(() => _sonarrSync.Start(), JobSettingsHelper.Sonarr(s));
RecurringJob.AddOrUpdate(() => _radarrSync.CacheContent(), JobSettingsHelper.Radarr(s));
RecurringJob.AddOrUpdate(() => _plexContentSync.CacheContent(), JobSettingsHelper.PlexContent(s));
RecurringJob.AddOrUpdate(() => _plexContentSync.CacheContent(false), JobSettingsHelper.PlexContent(s));
RecurringJob.AddOrUpdate(() => _plexContentSync.CacheContent(true), JobSettingsHelper.PlexRecentlyAdded(s));
RecurringJob.AddOrUpdate(() => _cpCache.Start(), JobSettingsHelper.CouchPotato(s));
RecurringJob.AddOrUpdate(() => _srSync.Start(), JobSettingsHelper.SickRageSync(s));
RecurringJob.AddOrUpdate(() => _refreshMetadata.Start(), JobSettingsHelper.RefreshMetadata(s));
Expand Down
30 changes: 23 additions & 7 deletions src/Ombi.Schedule/Jobs/Ombi/RefreshMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private async Task StartPlexTv()

if (!hasTheMovieDb)
{
var id = await GetTheMovieDbId(hasTvDbId, hasImdb, show.TvDbId, show.ImdbId, show.Title);
var id = await GetTheMovieDbId(hasTvDbId, hasImdb, show.TvDbId, show.ImdbId, show.Title, false);
show.TheMovieDbId = id;
}

Expand Down Expand Up @@ -120,7 +120,7 @@ private async Task StartEmbyTv()

if (!hasTheMovieDb)
{
var id = await GetTheMovieDbId(hasTvDbId, hasImdb, show.TvDbId, show.ImdbId, show.Title);
var id = await GetTheMovieDbId(hasTvDbId, hasImdb, show.TvDbId, show.ImdbId, show.Title, false);
show.TheMovieDbId = id;
}

Expand Down Expand Up @@ -166,7 +166,7 @@ private async Task StartPlexMovies()
}
if (!hasTheMovieDb)
{
var id = await GetTheMovieDbId(false, hasImdb, string.Empty, movie.ImdbId, movie.Title);
var id = await GetTheMovieDbId(false, hasImdb, string.Empty, movie.ImdbId, movie.Title, true);
movie.TheMovieDbId = id;
_plexRepo.UpdateWithoutSave(movie);
}
Expand Down Expand Up @@ -200,7 +200,7 @@ private async Task StartEmbyMovies()
}
if (!hasTheMovieDb)
{
var id = await GetTheMovieDbId(false, hasImdb, string.Empty, movie.ImdbId, movie.Title);
var id = await GetTheMovieDbId(false, hasImdb, string.Empty, movie.ImdbId, movie.Title, true);
movie.TheMovieDbId = id;
_embyRepo.UpdateWithoutSave(movie);
}
Expand All @@ -215,7 +215,7 @@ private async Task StartEmbyMovies()
await _embyRepo.SaveChangesAsync();
}

private async Task<string> GetTheMovieDbId(bool hasTvDbId, bool hasImdb, string tvdbID, string imdbId, string title)
private async Task<string> GetTheMovieDbId(bool hasTvDbId, bool hasImdb, string tvdbID, string imdbId, string title, bool movie)
{
_log.LogInformation("The Media item {0} does not have a TheMovieDbId, searching for TheMovieDbId", title);
FindResult result = null;
Expand All @@ -230,13 +230,29 @@ private async Task<string> GetTheMovieDbId(bool hasTvDbId, bool hasImdb, string
if (hasImdb && !hasResult)
{
result = await _movieApi.Find(imdbId, ExternalSource.imdb_id);
hasResult = result?.tv_results?.Length > 0;
if (movie)
{
hasResult = result?.movie_results?.Length > 0;
}
else
{
hasResult = result?.tv_results?.Length > 0;

}

_log.LogInformation("Setting Show {0} because we have ImdbId, result: {1}", title, hasResult);
}
if (hasResult)
{
return result.tv_results?[0]?.id.ToString() ?? string.Empty;
if (movie)
{
return result.movie_results?[0]?.id.ToString() ?? string.Empty;
}
else
{

return result.tv_results?[0]?.id.ToString() ?? string.Empty;
}
}
return string.Empty;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Ombi.Schedule/Jobs/Plex/Interfaces/IPlexContentSync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ namespace Ombi.Schedule.Jobs
{
public interface IPlexContentSync : IBaseJob
{
Task CacheContent();
Task CacheContent(bool recentlyAddedSearch = false);
}
}
34 changes: 24 additions & 10 deletions src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public PlexContentSync(ISettingsService<PlexSettings> plex, IPlexApi plexApi, IL
private IPlexContentRepository Repo { get; }
private IPlexEpisodeSync EpisodeSync { get; }

public async Task CacheContent()
public async Task CacheContent(bool recentlyAddedSearch = false)
{
var plexSettings = await Plex.GetSettingsAsync();
if (!plexSettings.Enable)
Expand All @@ -78,7 +78,7 @@ public async Task CacheContent()
Logger.LogInformation("Starting Plex Content Cacher");
try
{
await StartTheCache(plexSettings);
await StartTheCache(plexSettings, recentlyAddedSearch);
}
catch (Exception e)
{
Expand All @@ -89,14 +89,14 @@ public async Task CacheContent()
BackgroundJob.Enqueue(() => EpisodeSync.Start());
}

private async Task StartTheCache(PlexSettings plexSettings)
private async Task StartTheCache(PlexSettings plexSettings, bool recentlyAddedSearch)
{
foreach (var servers in plexSettings.Servers ?? new List<PlexServers>())
{
try
{
Logger.LogInformation("Starting to cache the content on server {0}", servers.Name);
await ProcessServer(servers);
await ProcessServer(servers, recentlyAddedSearch);
}
catch (Exception e)
{
Expand All @@ -105,10 +105,10 @@ private async Task StartTheCache(PlexSettings plexSettings)
}
}

private async Task ProcessServer(PlexServers servers)
private async Task ProcessServer(PlexServers servers, bool recentlyAddedSearch)
{
Logger.LogInformation("Getting all content from server {0}", servers.Name);
var allContent = await GetAllContent(servers);
var allContent = await GetAllContent(servers, recentlyAddedSearch);
Logger.LogInformation("We found {0} items", allContent.Count);

// Let's now process this.
Expand Down Expand Up @@ -388,8 +388,9 @@ private async Task ProcessServer(PlexServers servers)
/// If they have not set the settings then we will monitor them all
/// </summary>
/// <param name="plexSettings">The plex settings.</param>
/// <param name="recentlyAddedSearch"></param>
/// <returns></returns>
private async Task<List<Mediacontainer>> GetAllContent(PlexServers plexSettings)
private async Task<List<Mediacontainer>> GetAllContent(PlexServers plexSettings, bool recentlyAddedSearch)
{
var sections = await PlexApi.GetLibrarySections(plexSettings.PlexAuthToken, plexSettings.FullUri);

Expand All @@ -413,10 +414,23 @@ private async Task<List<Mediacontainer>> GetAllContent(PlexServers plexSettings)
}
}
}
var lib = await PlexApi.GetLibrary(plexSettings.PlexAuthToken, plexSettings.FullUri, dir.key);
if (lib != null)

if (recentlyAddedSearch)
{
libs.Add(lib.MediaContainer);
var container = await PlexApi.GetRecentlyAdded(plexSettings.PlexAuthToken, plexSettings.FullUri,
dir.key);
if (container != null)
{
libs.Add(container.MediaContainer);
}
}
else
{
var lib = await PlexApi.GetLibrary(plexSettings.PlexAuthToken, plexSettings.FullUri, dir.key);
if (lib != null)
{
libs.Add(lib.MediaContainer);
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/Ombi.Settings/Settings/Models/JobSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public class JobSettings : Settings
public string SonarrSync { get; set; }
public string RadarrSync { get; set; }
public string PlexContentSync { get; set; }
public string PlexRecentlyAddedSync { get; set; }
public string CouchPotatoSync { get; set; }
public string AutomaticUpdater { get; set; }
public string UserImporter { get; set; }
Expand Down
Loading

0 comments on commit 30b9a7e

Please sign in to comment.