From 3750243f1147e0826f8131efa2747b9805edacdf Mon Sep 17 00:00:00 2001 From: Jamie Date: Fri, 24 Aug 2018 23:02:40 +0100 Subject: [PATCH] A lot more lidarr work, i'm done for the day wow... !wip #2313 --- src/Ombi.Api.Lidarr/Models/Statistics.cs | 2 +- src/Ombi.Core/Engine/MusicSearchEngine.cs | 13 +++++-- .../Models/Search/SearchAlbumViewModel.cs | 8 +++- .../Models/Search/SearchArtistViewModel.cs | 2 - .../Rule/Interfaces/SpecificRules.cs | 2 + .../Rule/Rules/Search/ExistingRule.cs | 23 +++++++++-- .../Rule/Rules/Search/LidarrAlbumCacheRule.cs | 36 +++++++++++++++++ .../Rules/Search/LidarrArtistCacheRule.cs | 35 +++++++++++++++++ .../Jobs/Lidarr/LidarrAlbumSync.cs | 9 +++-- src/Ombi.Store/Entities/LidarrAlbumCache.cs | 4 +- src/Ombi.Store/Entities/LidarrArtistCache.cs | 3 -- ...20180824211553_LidarrSyncJobs.Designer.cs} | 14 ++----- ...bs.cs => 20180824211553_LidarrSyncJobs.cs} | 36 +++++++---------- .../Migrations/OmbiContextModelSnapshot.cs | 12 +----- .../app/interfaces/ISearchMusicResult.ts | 9 +++-- .../search/music/albumsearch.component.html | 39 +++++++++++-------- .../app/settings/jobs/jobs.component.ts | 1 + src/Ombi/Properties/launchSettings.json | 4 +- src/Ombi/wwwroot/translations/en.json | 2 + 19 files changed, 167 insertions(+), 87 deletions(-) create mode 100644 src/Ombi.Core/Rule/Rules/Search/LidarrAlbumCacheRule.cs create mode 100644 src/Ombi.Core/Rule/Rules/Search/LidarrArtistCacheRule.cs rename src/Ombi.Store/Migrations/{20180824202308_LidarrSyncJobs.Designer.cs => 20180824211553_LidarrSyncJobs.Designer.cs} (98%) rename src/Ombi.Store/Migrations/{20180824202308_LidarrSyncJobs.cs => 20180824211553_LidarrSyncJobs.cs} (80%) diff --git a/src/Ombi.Api.Lidarr/Models/Statistics.cs b/src/Ombi.Api.Lidarr/Models/Statistics.cs index 0f334fcdd..5d8eb4275 100644 --- a/src/Ombi.Api.Lidarr/Models/Statistics.cs +++ b/src/Ombi.Api.Lidarr/Models/Statistics.cs @@ -7,6 +7,6 @@ public int trackCount { get; set; } public int totalTrackCount { get; set; } public int sizeOnDisk { get; set; } - public decimal percentOfTracks { get; set; } + public decimal percentOfEpisodes { get; set; } } } \ No newline at end of file diff --git a/src/Ombi.Core/Engine/MusicSearchEngine.cs b/src/Ombi.Core/Engine/MusicSearchEngine.cs index b90fca88c..7eba0429d 100644 --- a/src/Ombi.Core/Engine/MusicSearchEngine.cs +++ b/src/Ombi.Core/Engine/MusicSearchEngine.cs @@ -73,7 +73,7 @@ namespace Ombi.Core.Engine var vm = new List(); foreach (var r in result) { - vm.Add(MapIntoArtistVm(r)); + vm.Add(await MapIntoArtistVm(r)); } return vm; @@ -107,7 +107,7 @@ namespace Ombi.Core.Engine return await _lidarrApi.GetArtist(artistId, settings.ApiKey, settings.FullUri); } - private SearchArtistViewModel MapIntoArtistVm(ArtistLookup a) + private async Task MapIntoArtistVm(ArtistLookup a) { var vm = new SearchArtistViewModel { @@ -121,13 +121,16 @@ namespace Ombi.Core.Engine Links = a.links, Overview = a.overview, }; - + var poster = a.images?.FirstOrDefault(x => x.coverType.Equals("poaster")); if (poster == null) { vm.Poster = a.remotePoster; } + + await Rules.StartSpecificRules(vm, SpecificRules.LidarrArtist); + return vm; } @@ -162,6 +165,10 @@ namespace Ombi.Core.Engine vm.Cover = a.remoteCover; } + await Rules.StartSpecificRules(vm, SpecificRules.LidarrAlbum); + + await RunSearchRules(vm); + return vm; } private LidarrSettings _settings; diff --git a/src/Ombi.Core/Models/Search/SearchAlbumViewModel.cs b/src/Ombi.Core/Models/Search/SearchAlbumViewModel.cs index b243c5374..a494a3cb5 100644 --- a/src/Ombi.Core/Models/Search/SearchAlbumViewModel.cs +++ b/src/Ombi.Core/Models/Search/SearchAlbumViewModel.cs @@ -1,8 +1,9 @@ using System; +using Ombi.Store.Entities; namespace Ombi.Core.Models.Search { - public class SearchAlbumViewModel + public class SearchAlbumViewModel : SearchViewModel { public string Title { get; set; } public string ForeignAlbumId { get; set; } @@ -14,6 +15,9 @@ namespace Ombi.Core.Models.Search public string ForeignArtistId { get; set; } public string Cover { get; set; } public string Disk { get; set; } - + public decimal PercentOfTracks { get; set; } + public override RequestType Type => RequestType.Album; + public bool PartiallyAvailable => PercentOfTracks != 100 && PercentOfTracks > 0; + public bool FullyAvailable => PercentOfTracks == 100; } } \ No newline at end of file diff --git a/src/Ombi.Core/Models/Search/SearchArtistViewModel.cs b/src/Ombi.Core/Models/Search/SearchArtistViewModel.cs index da1cc892f..b736df529 100644 --- a/src/Ombi.Core/Models/Search/SearchArtistViewModel.cs +++ b/src/Ombi.Core/Models/Search/SearchArtistViewModel.cs @@ -12,8 +12,6 @@ namespace Ombi.Core.Models.Search public string Poster { get; set; } public string Logo { get; set; } public bool Monitored { get; set; } - public bool Available { get; set; } - public bool Requested { get; set; } public string ArtistType { get; set; } public string CleanName { get; set; } public Link[] Links { get; set; } // Couldn't be bothered to map it diff --git a/src/Ombi.Core/Rule/Interfaces/SpecificRules.cs b/src/Ombi.Core/Rule/Interfaces/SpecificRules.cs index 522ba8a95..d432f87be 100644 --- a/src/Ombi.Core/Rule/Interfaces/SpecificRules.cs +++ b/src/Ombi.Core/Rule/Interfaces/SpecificRules.cs @@ -3,5 +3,7 @@ public enum SpecificRules { CanSendNotification, + LidarrArtist, + LidarrAlbum, } } \ No newline at end of file diff --git a/src/Ombi.Core/Rule/Rules/Search/ExistingRule.cs b/src/Ombi.Core/Rule/Rules/Search/ExistingRule.cs index bd7218145..965fcdfaf 100644 --- a/src/Ombi.Core/Rule/Rules/Search/ExistingRule.cs +++ b/src/Ombi.Core/Rule/Rules/Search/ExistingRule.cs @@ -11,13 +11,15 @@ namespace Ombi.Core.Rule.Rules.Search { public class ExistingRule : BaseSearchRule, IRules { - public ExistingRule(IMovieRequestRepository movie, ITvRequestRepository tv) + public ExistingRule(IMovieRequestRepository movie, ITvRequestRepository tv, IMusicRequestRepository music) { Movie = movie; Tv = tv; + Music = music; } private IMovieRequestRepository Movie { get; } + private IMusicRequestRepository Music { get; } private ITvRequestRepository Tv { get; } public async Task Execute(SearchViewModel obj) @@ -37,7 +39,7 @@ namespace Ombi.Core.Rule.Rules.Search } return Success(); } - else if (obj.Type == RequestType.Album) + if (obj.Type == RequestType.TvShow) { //var tvRequests = Tv.GetRequest(obj.Id); //if (tvRequests != null) // Do we already have a request for this? @@ -50,7 +52,7 @@ namespace Ombi.Core.Rule.Rules.Search // return Task.FromResult(Success()); //} - var request = (SearchTvShowViewModel) obj; + var request = (SearchTvShowViewModel)obj; var tvRequests = Tv.GetRequest(obj.Id); if (tvRequests != null) // Do we already have a request for this? { @@ -96,6 +98,21 @@ namespace Ombi.Core.Rule.Rules.Search return Success(); } + if (obj.Type == RequestType.Album) + { + var album = (SearchAlbumViewModel) obj; + var albumRequest = await Music.GetRequestAsync(album.ForeignAlbumId); + if (albumRequest != null) // Do we already have a request for this? + { + obj.Requested = true; + obj.RequestId = albumRequest.Id; + obj.Approved = albumRequest.Approved; + obj.Available = albumRequest.Available; + + return Success(); + } + return Success(); + } return Success(); } } diff --git a/src/Ombi.Core/Rule/Rules/Search/LidarrAlbumCacheRule.cs b/src/Ombi.Core/Rule/Rules/Search/LidarrAlbumCacheRule.cs new file mode 100644 index 000000000..97a27d47f --- /dev/null +++ b/src/Ombi.Core/Rule/Rules/Search/LidarrAlbumCacheRule.cs @@ -0,0 +1,36 @@ +using System; +using System.Linq; +using System.Threading.Tasks; +using Ombi.Core.Models.Search; +using Ombi.Core.Rule.Interfaces; +using Ombi.Store.Entities; +using Ombi.Store.Repository; + +namespace Ombi.Core.Rule.Rules.Search +{ + public class LidarrAlbumCacheRule : SpecificRule, ISpecificRule + { + public LidarrAlbumCacheRule(IRepository db) + { + _db = db; + } + + private readonly IRepository _db; + + public Task Execute(object objec) + { + var obj = (SearchAlbumViewModel) objec; + // Check if it's in Lidarr + var result = _db.GetAll().FirstOrDefault(x => x.ForeignAlbumId.Equals(obj.ForeignAlbumId, StringComparison.InvariantCultureIgnoreCase)); + if (result != null) + { + obj.PercentOfTracks = result.PercentOfTracks; + obj.Monitored = true; // It's in Lidarr so it's monitored + } + + return Task.FromResult(Success()); + } + + public override SpecificRules Rule => SpecificRules.LidarrAlbum; + } +} \ No newline at end of file diff --git a/src/Ombi.Core/Rule/Rules/Search/LidarrArtistCacheRule.cs b/src/Ombi.Core/Rule/Rules/Search/LidarrArtistCacheRule.cs new file mode 100644 index 000000000..db472a951 --- /dev/null +++ b/src/Ombi.Core/Rule/Rules/Search/LidarrArtistCacheRule.cs @@ -0,0 +1,35 @@ +using System; +using System.Linq; +using System.Threading.Tasks; +using Ombi.Core.Models.Search; +using Ombi.Core.Rule.Interfaces; +using Ombi.Store.Entities; +using Ombi.Store.Repository; + +namespace Ombi.Core.Rule.Rules.Search +{ + public class LidarrArtistCacheRule : SpecificRule, ISpecificRule + { + public LidarrArtistCacheRule(IRepository db) + { + _db = db; + } + + private readonly IRepository _db; + + public Task Execute(object objec) + { + var obj = (SearchArtistViewModel) objec; + // Check if it's in Lidarr + var result = _db.GetAll().FirstOrDefault(x => x.ForeignArtistId.Equals(obj.ForignArtistId, StringComparison.InvariantCultureIgnoreCase)); + if (result != null) + { + obj.Monitored = true; // It's in Lidarr so it's monitored + } + + return Task.FromResult(Success()); + } + + public override SpecificRules Rule => SpecificRules.LidarrArtist; + } +} \ No newline at end of file diff --git a/src/Ombi.Schedule/Jobs/Lidarr/LidarrAlbumSync.cs b/src/Ombi.Schedule/Jobs/Lidarr/LidarrAlbumSync.cs index 031a9e9f5..2eae36206 100644 --- a/src/Ombi.Schedule/Jobs/Lidarr/LidarrAlbumSync.cs +++ b/src/Ombi.Schedule/Jobs/Lidarr/LidarrAlbumSync.cs @@ -48,23 +48,24 @@ namespace Ombi.Schedule.Jobs.Lidarr // Let's remove the old cached data await _ctx.Database.ExecuteSqlCommandAsync("DELETE FROM LidarrAlbumCache"); - var artistCache = new List(); + var albumCache = new List(); foreach (var a in albums) { if (a.id > 0) { - artistCache.Add(new LidarrAlbumCache + albumCache.Add(new LidarrAlbumCache { ArtistId = a.artistId, ForeignAlbumId = a.foreignAlbumId, ReleaseDate = a.releaseDate, TrackCount = a.currentRelease.trackCount, Monitored = a.monitored, - Title = a.title + Title = a.title, + PercentOfTracks = a.statistics?.percentOfEpisodes ?? 0m }); } } - await _ctx.LidarrAlbumCache.AddRangeAsync(artistCache); + await _ctx.LidarrAlbumCache.AddRangeAsync(albumCache); await _ctx.SaveChangesAsync(); } diff --git a/src/Ombi.Store/Entities/LidarrAlbumCache.cs b/src/Ombi.Store/Entities/LidarrAlbumCache.cs index 5fd1ffcdd..15d0a53da 100644 --- a/src/Ombi.Store/Entities/LidarrAlbumCache.cs +++ b/src/Ombi.Store/Entities/LidarrAlbumCache.cs @@ -12,8 +12,6 @@ namespace Ombi.Store.Entities public DateTime ReleaseDate { get; set; } public bool Monitored { get; set; } public string Title { get; set; } - - [ForeignKey(nameof(ArtistId))] - public LidarrArtistCache Artist { get; set; } + public decimal PercentOfTracks { get; set; } } } \ No newline at end of file diff --git a/src/Ombi.Store/Entities/LidarrArtistCache.cs b/src/Ombi.Store/Entities/LidarrArtistCache.cs index 86daebd2b..dd78b4e2c 100644 --- a/src/Ombi.Store/Entities/LidarrArtistCache.cs +++ b/src/Ombi.Store/Entities/LidarrArtistCache.cs @@ -6,12 +6,9 @@ namespace Ombi.Store.Entities [Table("LidarrArtistCache")] public class LidarrArtistCache : Entity { - [ForeignKey(nameof(ArtistId))] public int ArtistId { get; set; } public string ArtistName { get; set; } public string ForeignArtistId { get; set; } public bool Monitored { get; set; } - - public List Albums { get; set; } } } \ No newline at end of file diff --git a/src/Ombi.Store/Migrations/20180824202308_LidarrSyncJobs.Designer.cs b/src/Ombi.Store/Migrations/20180824211553_LidarrSyncJobs.Designer.cs similarity index 98% rename from src/Ombi.Store/Migrations/20180824202308_LidarrSyncJobs.Designer.cs rename to src/Ombi.Store/Migrations/20180824211553_LidarrSyncJobs.Designer.cs index 5929fe0f5..c97886525 100644 --- a/src/Ombi.Store/Migrations/20180824202308_LidarrSyncJobs.Designer.cs +++ b/src/Ombi.Store/Migrations/20180824211553_LidarrSyncJobs.Designer.cs @@ -9,7 +9,7 @@ using Ombi.Store.Context; namespace Ombi.Store.Migrations { [DbContext(typeof(OmbiContext))] - [Migration("20180824202308_LidarrSyncJobs")] + [Migration("20180824211553_LidarrSyncJobs")] partial class LidarrSyncJobs { protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -257,6 +257,8 @@ namespace Ombi.Store.Migrations b.Property("Monitored"); + b.Property("PercentOfTracks"); + b.Property("ReleaseDate"); b.Property("Title"); @@ -265,8 +267,6 @@ namespace Ombi.Store.Migrations b.HasKey("Id"); - b.HasIndex("ArtistId"); - b.ToTable("LidarrAlbumCache"); }); @@ -965,14 +965,6 @@ namespace Ombi.Store.Migrations .HasPrincipalKey("EmbyId"); }); - modelBuilder.Entity("Ombi.Store.Entities.LidarrAlbumCache", b => - { - b.HasOne("Ombi.Store.Entities.LidarrArtistCache", "Artist") - .WithMany("Albums") - .HasForeignKey("ArtistId") - .OnDelete(DeleteBehavior.Cascade); - }); - modelBuilder.Entity("Ombi.Store.Entities.NotificationUserId", b => { b.HasOne("Ombi.Store.Entities.OmbiUser", "User") diff --git a/src/Ombi.Store/Migrations/20180824202308_LidarrSyncJobs.cs b/src/Ombi.Store/Migrations/20180824211553_LidarrSyncJobs.cs similarity index 80% rename from src/Ombi.Store/Migrations/20180824202308_LidarrSyncJobs.cs rename to src/Ombi.Store/Migrations/20180824211553_LidarrSyncJobs.cs index e741b2294..2b843d3e2 100644 --- a/src/Ombi.Store/Migrations/20180824202308_LidarrSyncJobs.cs +++ b/src/Ombi.Store/Migrations/20180824211553_LidarrSyncJobs.cs @@ -8,49 +8,39 @@ namespace Ombi.Store.Migrations protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( - name: "LidarrArtistCache", + name: "LidarrAlbumCache", columns: table => new { Id = table.Column(nullable: false) .Annotation("Sqlite:Autoincrement", true), ArtistId = table.Column(nullable: false), - ArtistName = table.Column(nullable: true), - ForeignArtistId = table.Column(nullable: true), - Monitored = table.Column(nullable: false) + ForeignAlbumId = table.Column(nullable: true), + TrackCount = table.Column(nullable: false), + ReleaseDate = table.Column(nullable: false), + Monitored = table.Column(nullable: false), + Title = table.Column(nullable: true), + PercentOfTracks = table.Column(nullable: false) }, constraints: table => { - table.PrimaryKey("PK_LidarrArtistCache", x => x.Id); + table.PrimaryKey("PK_LidarrAlbumCache", x => x.Id); }); migrationBuilder.CreateTable( - name: "LidarrAlbumCache", + name: "LidarrArtistCache", columns: table => new { Id = table.Column(nullable: false) .Annotation("Sqlite:Autoincrement", true), ArtistId = table.Column(nullable: false), - ForeignAlbumId = table.Column(nullable: true), - TrackCount = table.Column(nullable: false), - ReleaseDate = table.Column(nullable: false), - Monitored = table.Column(nullable: false), - Title = table.Column(nullable: true) + ArtistName = table.Column(nullable: true), + ForeignArtistId = table.Column(nullable: true), + Monitored = table.Column(nullable: false) }, constraints: table => { - table.PrimaryKey("PK_LidarrAlbumCache", x => x.Id); - table.ForeignKey( - name: "FK_LidarrAlbumCache_LidarrArtistCache_ArtistId", - column: x => x.ArtistId, - principalTable: "LidarrArtistCache", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); + table.PrimaryKey("PK_LidarrArtistCache", x => x.Id); }); - - migrationBuilder.CreateIndex( - name: "IX_LidarrAlbumCache_ArtistId", - table: "LidarrAlbumCache", - column: "ArtistId"); } protected override void Down(MigrationBuilder migrationBuilder) diff --git a/src/Ombi.Store/Migrations/OmbiContextModelSnapshot.cs b/src/Ombi.Store/Migrations/OmbiContextModelSnapshot.cs index 893c22edc..0e3d1efea 100644 --- a/src/Ombi.Store/Migrations/OmbiContextModelSnapshot.cs +++ b/src/Ombi.Store/Migrations/OmbiContextModelSnapshot.cs @@ -255,6 +255,8 @@ namespace Ombi.Store.Migrations b.Property("Monitored"); + b.Property("PercentOfTracks"); + b.Property("ReleaseDate"); b.Property("Title"); @@ -263,8 +265,6 @@ namespace Ombi.Store.Migrations b.HasKey("Id"); - b.HasIndex("ArtistId"); - b.ToTable("LidarrAlbumCache"); }); @@ -963,14 +963,6 @@ namespace Ombi.Store.Migrations .HasPrincipalKey("EmbyId"); }); - modelBuilder.Entity("Ombi.Store.Entities.LidarrAlbumCache", b => - { - b.HasOne("Ombi.Store.Entities.LidarrArtistCache", "Artist") - .WithMany("Albums") - .HasForeignKey("ArtistId") - .OnDelete(DeleteBehavior.Cascade); - }); - modelBuilder.Entity("Ombi.Store.Entities.NotificationUserId", b => { b.HasOne("Ombi.Store.Entities.OmbiUser", "User") diff --git a/src/Ombi/ClientApp/app/interfaces/ISearchMusicResult.ts b/src/Ombi/ClientApp/app/interfaces/ISearchMusicResult.ts index 6afd10b19..806beb92f 100644 --- a/src/Ombi/ClientApp/app/interfaces/ISearchMusicResult.ts +++ b/src/Ombi/ClientApp/app/interfaces/ISearchMusicResult.ts @@ -29,6 +29,8 @@ export interface ILink { } export interface ISearchAlbumResult { + id: number; + requestId: number; albumType: string; artistName: string; cover: string; @@ -39,10 +41,11 @@ export interface ISearchAlbumResult { rating: number; releaseDate: Date; title: string; - approved: boolean; + fullyAvailable: boolean; + partiallyAvailable: boolean; requested: boolean; - requestId: number; - available: boolean; + approved: boolean; + subscribed: boolean; // for the UI showSubscribe: boolean; diff --git a/src/Ombi/ClientApp/app/search/music/albumsearch.component.html b/src/Ombi/ClientApp/app/search/music/albumsearch.component.html index cf98c84cc..6b5cc52a9 100644 --- a/src/Ombi/ClientApp/app/search/music/albumsearch.component.html +++ b/src/Ombi/ClientApp/app/search/music/albumsearch.component.html @@ -33,27 +33,32 @@ --> - - - Release Date: {{result.releaseDate | date:'yyyy-MM-dd'}} + + + + + + + + + + + - - {{result.rating}}/10 + + + + - - - - - - - - - - - - + + + Release Date: {{result.releaseDate | date:'yyyy-MM-dd'}} + + + {{result.rating}}/10 + diff --git a/src/Ombi/ClientApp/app/settings/jobs/jobs.component.ts b/src/Ombi/ClientApp/app/settings/jobs/jobs.component.ts index c69d07731..756d6ba89 100644 --- a/src/Ombi/ClientApp/app/settings/jobs/jobs.component.ts +++ b/src/Ombi/ClientApp/app/settings/jobs/jobs.component.ts @@ -34,6 +34,7 @@ export class JobsComponent implements OnInit { refreshMetadata: [x.refreshMetadata, Validators.required], newsletter: [x.newsletter, Validators.required], plexRecentlyAddedSync: [x.plexRecentlyAddedSync, Validators.required], + lidarrArtistSync: [x.lidarrArtistSync, Validators.required], }); }); } diff --git a/src/Ombi/Properties/launchSettings.json b/src/Ombi/Properties/launchSettings.json index 96b1ceb6e..19e5d23af 100644 --- a/src/Ombi/Properties/launchSettings.json +++ b/src/Ombi/Properties/launchSettings.json @@ -3,14 +3,14 @@ "windowsAuthentication": false, "anonymousAuthentication": true, "iisExpress": { - "applicationUrl": "http://localhost:3579/", + "applicationUrl": "http://localhost:3577/", "sslPort": 0 } }, "profiles": { "IIS Express": { "commandName": "IISExpress", - "commandLineArgs": "--host http://*:3579", + "commandLineArgs": "--host http://*:3577", "launchBrowser": true, "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" diff --git a/src/Ombi/wwwroot/translations/en.json b/src/Ombi/wwwroot/translations/en.json index 1d195d251..4fd3ccb1b 100644 --- a/src/Ombi/wwwroot/translations/en.json +++ b/src/Ombi/wwwroot/translations/en.json @@ -12,6 +12,8 @@ "Common": { "ContinueButton": "Continue", "Available": "Available", + "PartiallyAvailable": "Partially Available", + "Monitored": "Monitored", "NotAvailable": "Not Available", "ProcessingRequest": "Processing Request", "PendingApproval": "Pending Approval",