diff --git a/src/NzbDrone.Api/Series/SeriesModule.cs b/src/NzbDrone.Api/Series/SeriesModule.cs index cf80835ce..c69bcd5fc 100644 --- a/src/NzbDrone.Api/Series/SeriesModule.cs +++ b/src/NzbDrone.Api/Series/SeriesModule.cs @@ -13,6 +13,7 @@ using NzbDrone.Api.Validation; using NzbDrone.Api.Mapping; using NzbDrone.Core.Tv.Events; using NzbDrone.Core.Validation.Paths; +using NzbDrone.Core.DataAugmentation.Scene; namespace NzbDrone.Api.Series { @@ -27,11 +28,13 @@ namespace NzbDrone.Api.Series private readonly ICommandExecutor _commandExecutor; private readonly ISeriesService _seriesService; private readonly ISeriesStatisticsService _seriesStatisticsService; + private readonly ISceneMappingService _sceneMappingService; private readonly IMapCoversToLocal _coverMapper; public SeriesModule(ICommandExecutor commandExecutor, ISeriesService seriesService, ISeriesStatisticsService seriesStatisticsService, + ISceneMappingService sceneMappingService, IMapCoversToLocal coverMapper, RootFolderValidator rootFolderValidator, PathExistsValidator pathExistsValidator, @@ -44,6 +47,8 @@ namespace NzbDrone.Api.Series _commandExecutor = commandExecutor; _seriesService = seriesService; _seriesStatisticsService = seriesStatisticsService; + _sceneMappingService = sceneMappingService; + _coverMapper = coverMapper; GetResourceAll = AllSeries; @@ -67,6 +72,21 @@ namespace NzbDrone.Api.Series PostValidator.RuleFor(s => s.TvdbId).GreaterThan(0).SetValidator(seriesExistsValidator); } + private void PopulateAlternativeTitles(List resources) + { + foreach (var resource in resources) + { + PopulateAlternativeTitles(resource); + } + } + + private void PopulateAlternativeTitles(SeriesResource resource) + { + var mapping = _sceneMappingService.FindByTvdbid(resource.TvdbId); + if (mapping == null) return; + resource.AlternativeTitles = mapping.Select(x => x.Title).Distinct().ToList(); + } + private SeriesResource GetSeries(int id) { var series = _seriesService.GetSeries(id); @@ -80,6 +100,7 @@ namespace NzbDrone.Api.Series var resource = series.InjectTo(); MapCoversToLocal(resource); FetchAndLinkSeriesStatistics(resource); + PopulateAlternativeTitles(resource); return resource; } @@ -91,6 +112,7 @@ namespace NzbDrone.Api.Series MapCoversToLocal(seriesResources.ToArray()); LinkSeriesStatistics(seriesResources, seriesStats); + PopulateAlternativeTitles(seriesResources); return seriesResources; } diff --git a/src/NzbDrone.Api/Series/SeriesResource.cs b/src/NzbDrone.Api/Series/SeriesResource.cs index 3e09fd3cf..6fdff13df 100644 --- a/src/NzbDrone.Api/Series/SeriesResource.cs +++ b/src/NzbDrone.Api/Series/SeriesResource.cs @@ -15,6 +15,7 @@ namespace NzbDrone.Api.Series //View Only public String Title { get; set; } + public List AlternativeTitles { get; set; } public Int32 SeasonCount { diff --git a/src/NzbDrone.Core/DataAugmentation/Scene/SceneMapping.cs b/src/NzbDrone.Core/DataAugmentation/Scene/SceneMapping.cs index 07bdfc065..a29518718 100644 --- a/src/NzbDrone.Core/DataAugmentation/Scene/SceneMapping.cs +++ b/src/NzbDrone.Core/DataAugmentation/Scene/SceneMapping.cs @@ -5,7 +5,8 @@ namespace NzbDrone.Core.DataAugmentation.Scene { public class SceneMapping : ModelBase { - [JsonProperty("title")] + public string Title { get; set; } + public string ParseTerm { get; set; } [JsonProperty("searchTitle")] diff --git a/src/NzbDrone.Core/DataAugmentation/Scene/SceneMappingRepository.cs b/src/NzbDrone.Core/DataAugmentation/Scene/SceneMappingRepository.cs index b3075e88f..f59e3a64b 100644 --- a/src/NzbDrone.Core/DataAugmentation/Scene/SceneMappingRepository.cs +++ b/src/NzbDrone.Core/DataAugmentation/Scene/SceneMappingRepository.cs @@ -1,12 +1,13 @@ using NzbDrone.Core.Datastore; using NzbDrone.Core.Messaging.Events; +using System.Collections.Generic; namespace NzbDrone.Core.DataAugmentation.Scene { public interface ISceneMappingRepository : IBasicRepository { - + List FindByTvdbid(int tvdbId); } public class SceneMappingRepository : BasicRepository, ISceneMappingRepository @@ -16,5 +17,9 @@ namespace NzbDrone.Core.DataAugmentation.Scene { } + public List FindByTvdbid(int tvdbId) + { + return Query.Where(x => x.TvdbId == tvdbId); + } } } \ No newline at end of file diff --git a/src/NzbDrone.Core/DataAugmentation/Scene/SceneMappingService.cs b/src/NzbDrone.Core/DataAugmentation/Scene/SceneMappingService.cs index bbe1e08a2..42137b1ac 100644 --- a/src/NzbDrone.Core/DataAugmentation/Scene/SceneMappingService.cs +++ b/src/NzbDrone.Core/DataAugmentation/Scene/SceneMappingService.cs @@ -6,6 +6,7 @@ using NzbDrone.Core.Lifecycle; using NzbDrone.Core.Messaging.Commands; using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Parser; +using System.Collections.Generic; namespace NzbDrone.Core.DataAugmentation.Scene { @@ -13,6 +14,7 @@ namespace NzbDrone.Core.DataAugmentation.Scene { string GetSceneName(int tvdbId); Nullable GetTvDbId(string cleanName); + List FindByTvdbid(int tvdbId); } public class SceneMappingService : ISceneMappingService, @@ -24,6 +26,7 @@ namespace NzbDrone.Core.DataAugmentation.Scene private readonly Logger _logger; private readonly ICached _getSceneNameCache; private readonly ICached _gettvdbIdCache; + private readonly ICached> _findbytvdbIdCache; public SceneMappingService(ISceneMappingRepository repository, ISceneMappingProxy sceneMappingProxy, ICacheManager cacheManager, Logger logger) { @@ -32,6 +35,7 @@ namespace NzbDrone.Core.DataAugmentation.Scene _getSceneNameCache = cacheManager.GetCache(GetType(), "scene_name"); _gettvdbIdCache = cacheManager.GetCache(GetType(), "tvdb_id"); + _findbytvdbIdCache = cacheManager.GetCache>(GetType(), "find_tvdb_id"); _logger = logger; } @@ -54,6 +58,11 @@ namespace NzbDrone.Core.DataAugmentation.Scene return mapping.TvdbId; } + public List FindByTvdbid(int tvdbId) + { + return _findbytvdbIdCache.Find(tvdbId.ToString()); + } + private void UpdateMappings() { _logger.Info("Updating Scene mapping"); @@ -68,7 +77,7 @@ namespace NzbDrone.Core.DataAugmentation.Scene foreach (var sceneMapping in mappings) { - sceneMapping.ParseTerm = sceneMapping.ParseTerm.CleanSeriesTitle(); + sceneMapping.ParseTerm = sceneMapping.Title.CleanSeriesTitle(); } _repository.InsertMany(mappings); @@ -92,12 +101,17 @@ namespace NzbDrone.Core.DataAugmentation.Scene _gettvdbIdCache.Clear(); _getSceneNameCache.Clear(); + _findbytvdbIdCache.Clear(); foreach (var sceneMapping in mappings) { _getSceneNameCache.Set(sceneMapping.TvdbId.ToString(), sceneMapping); _gettvdbIdCache.Set(sceneMapping.ParseTerm.CleanSeriesTitle(), sceneMapping); } + foreach (var sceneMapping in mappings.GroupBy(x => x.TvdbId)) + { + _findbytvdbIdCache.Set(sceneMapping.Key.ToString(), sceneMapping.ToList()); + } } diff --git a/src/NzbDrone.Core/Datastore/Migration/048_add_title_to_scenemappings.cs b/src/NzbDrone.Core/Datastore/Migration/048_add_title_to_scenemappings.cs new file mode 100644 index 000000000..89e099605 --- /dev/null +++ b/src/NzbDrone.Core/Datastore/Migration/048_add_title_to_scenemappings.cs @@ -0,0 +1,18 @@ +using NzbDrone.Core.Datastore.Migration.Framework; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using FluentMigrator; + +namespace NzbDrone.Core.Datastore.Migration +{ + [Migration(48)] + public class add_title_to_scenemappings : NzbDroneMigrationBase + { + protected override void MainDbUpgrade() + { + Alter.Table("SceneMappings").AddColumn("Title").AsString().Nullable(); + } + } +} diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index 9ec718804..f7de87066 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -193,6 +193,7 @@ + diff --git a/src/UI/Series/Details/InfoViewTemplate.html b/src/UI/Series/Details/InfoViewTemplate.html index bef8be3df..25d203f5b 100644 --- a/src/UI/Series/Details/InfoViewTemplate.html +++ b/src/UI/Series/Details/InfoViewTemplate.html @@ -1,25 +1,32 @@ -{{qualityProfile qualityProfileId}} -{{network}} -{{runtime}} minutes -{{path}} -{{#if_eq status compare="continuing"}} - Continuing -{{else}} - Ended -{{/if_eq}} +
+ {{qualityProfile qualityProfileId}} + {{network}} + {{runtime}} minutes + {{path}} + {{#if_eq status compare="continuing"}} + Continuing + {{else}} + Ended + {{/if_eq}} - - Trakt + + Trakt - {{#if imdbId}} - IMDB - {{/if}} + {{#if imdbId}} + IMDB + {{/if}} - {{#if tvdbId}} - TVDB - {{/if}} + {{#if tvdbId}} + TVDB + {{/if}} - {{#if tvRageId}} - TVRage - {{/if}} - \ No newline at end of file + {{#if tvRageId}} + TVRage + {{/if}} + +
+
+ {{#each alternativeTitles}} + {{this}} + {{/each}} +
\ No newline at end of file