Merge pull request #72 from Cyberlane/alternate_titles

Show alternate names in UI
pull/2/head
Mark McDowall 11 years ago
commit f092f9c08b

@ -13,6 +13,7 @@ using NzbDrone.Api.Validation;
using NzbDrone.Api.Mapping; using NzbDrone.Api.Mapping;
using NzbDrone.Core.Tv.Events; using NzbDrone.Core.Tv.Events;
using NzbDrone.Core.Validation.Paths; using NzbDrone.Core.Validation.Paths;
using NzbDrone.Core.DataAugmentation.Scene;
namespace NzbDrone.Api.Series namespace NzbDrone.Api.Series
{ {
@ -27,11 +28,13 @@ namespace NzbDrone.Api.Series
private readonly ICommandExecutor _commandExecutor; private readonly ICommandExecutor _commandExecutor;
private readonly ISeriesService _seriesService; private readonly ISeriesService _seriesService;
private readonly ISeriesStatisticsService _seriesStatisticsService; private readonly ISeriesStatisticsService _seriesStatisticsService;
private readonly ISceneMappingService _sceneMappingService;
private readonly IMapCoversToLocal _coverMapper; private readonly IMapCoversToLocal _coverMapper;
public SeriesModule(ICommandExecutor commandExecutor, public SeriesModule(ICommandExecutor commandExecutor,
ISeriesService seriesService, ISeriesService seriesService,
ISeriesStatisticsService seriesStatisticsService, ISeriesStatisticsService seriesStatisticsService,
ISceneMappingService sceneMappingService,
IMapCoversToLocal coverMapper, IMapCoversToLocal coverMapper,
RootFolderValidator rootFolderValidator, RootFolderValidator rootFolderValidator,
PathExistsValidator pathExistsValidator, PathExistsValidator pathExistsValidator,
@ -44,6 +47,8 @@ namespace NzbDrone.Api.Series
_commandExecutor = commandExecutor; _commandExecutor = commandExecutor;
_seriesService = seriesService; _seriesService = seriesService;
_seriesStatisticsService = seriesStatisticsService; _seriesStatisticsService = seriesStatisticsService;
_sceneMappingService = sceneMappingService;
_coverMapper = coverMapper; _coverMapper = coverMapper;
GetResourceAll = AllSeries; GetResourceAll = AllSeries;
@ -67,6 +72,21 @@ namespace NzbDrone.Api.Series
PostValidator.RuleFor(s => s.TvdbId).GreaterThan(0).SetValidator(seriesExistsValidator); PostValidator.RuleFor(s => s.TvdbId).GreaterThan(0).SetValidator(seriesExistsValidator);
} }
private void PopulateAlternativeTitles(List<SeriesResource> 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) private SeriesResource GetSeries(int id)
{ {
var series = _seriesService.GetSeries(id); var series = _seriesService.GetSeries(id);
@ -80,6 +100,7 @@ namespace NzbDrone.Api.Series
var resource = series.InjectTo<SeriesResource>(); var resource = series.InjectTo<SeriesResource>();
MapCoversToLocal(resource); MapCoversToLocal(resource);
FetchAndLinkSeriesStatistics(resource); FetchAndLinkSeriesStatistics(resource);
PopulateAlternativeTitles(resource);
return resource; return resource;
} }
@ -91,6 +112,7 @@ namespace NzbDrone.Api.Series
MapCoversToLocal(seriesResources.ToArray()); MapCoversToLocal(seriesResources.ToArray());
LinkSeriesStatistics(seriesResources, seriesStats); LinkSeriesStatistics(seriesResources, seriesStats);
PopulateAlternativeTitles(seriesResources);
return seriesResources; return seriesResources;
} }

@ -15,6 +15,7 @@ namespace NzbDrone.Api.Series
//View Only //View Only
public String Title { get; set; } public String Title { get; set; }
public List<String> AlternativeTitles { get; set; }
public Int32 SeasonCount public Int32 SeasonCount
{ {

@ -5,7 +5,8 @@ namespace NzbDrone.Core.DataAugmentation.Scene
{ {
public class SceneMapping : ModelBase public class SceneMapping : ModelBase
{ {
[JsonProperty("title")] public string Title { get; set; }
public string ParseTerm { get; set; } public string ParseTerm { get; set; }
[JsonProperty("searchTitle")] [JsonProperty("searchTitle")]

@ -1,12 +1,13 @@
using NzbDrone.Core.Datastore; using NzbDrone.Core.Datastore;
using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Messaging.Events;
using System.Collections.Generic;
namespace NzbDrone.Core.DataAugmentation.Scene namespace NzbDrone.Core.DataAugmentation.Scene
{ {
public interface ISceneMappingRepository : IBasicRepository<SceneMapping> public interface ISceneMappingRepository : IBasicRepository<SceneMapping>
{ {
List<SceneMapping> FindByTvdbid(int tvdbId);
} }
public class SceneMappingRepository : BasicRepository<SceneMapping>, ISceneMappingRepository public class SceneMappingRepository : BasicRepository<SceneMapping>, ISceneMappingRepository
@ -16,5 +17,9 @@ namespace NzbDrone.Core.DataAugmentation.Scene
{ {
} }
public List<SceneMapping> FindByTvdbid(int tvdbId)
{
return Query.Where(x => x.TvdbId == tvdbId);
}
} }
} }

@ -6,6 +6,7 @@ using NzbDrone.Core.Lifecycle;
using NzbDrone.Core.Messaging.Commands; using NzbDrone.Core.Messaging.Commands;
using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.Parser; using NzbDrone.Core.Parser;
using System.Collections.Generic;
namespace NzbDrone.Core.DataAugmentation.Scene namespace NzbDrone.Core.DataAugmentation.Scene
{ {
@ -13,6 +14,7 @@ namespace NzbDrone.Core.DataAugmentation.Scene
{ {
string GetSceneName(int tvdbId); string GetSceneName(int tvdbId);
Nullable<int> GetTvDbId(string cleanName); Nullable<int> GetTvDbId(string cleanName);
List<SceneMapping> FindByTvdbid(int tvdbId);
} }
public class SceneMappingService : ISceneMappingService, public class SceneMappingService : ISceneMappingService,
@ -24,6 +26,7 @@ namespace NzbDrone.Core.DataAugmentation.Scene
private readonly Logger _logger; private readonly Logger _logger;
private readonly ICached<SceneMapping> _getSceneNameCache; private readonly ICached<SceneMapping> _getSceneNameCache;
private readonly ICached<SceneMapping> _gettvdbIdCache; private readonly ICached<SceneMapping> _gettvdbIdCache;
private readonly ICached<List<SceneMapping>> _findbytvdbIdCache;
public SceneMappingService(ISceneMappingRepository repository, ISceneMappingProxy sceneMappingProxy, ICacheManager cacheManager, Logger logger) public SceneMappingService(ISceneMappingRepository repository, ISceneMappingProxy sceneMappingProxy, ICacheManager cacheManager, Logger logger)
{ {
@ -32,6 +35,7 @@ namespace NzbDrone.Core.DataAugmentation.Scene
_getSceneNameCache = cacheManager.GetCache<SceneMapping>(GetType(), "scene_name"); _getSceneNameCache = cacheManager.GetCache<SceneMapping>(GetType(), "scene_name");
_gettvdbIdCache = cacheManager.GetCache<SceneMapping>(GetType(), "tvdb_id"); _gettvdbIdCache = cacheManager.GetCache<SceneMapping>(GetType(), "tvdb_id");
_findbytvdbIdCache = cacheManager.GetCache<List<SceneMapping>>(GetType(), "find_tvdb_id");
_logger = logger; _logger = logger;
} }
@ -54,6 +58,11 @@ namespace NzbDrone.Core.DataAugmentation.Scene
return mapping.TvdbId; return mapping.TvdbId;
} }
public List<SceneMapping> FindByTvdbid(int tvdbId)
{
return _findbytvdbIdCache.Find(tvdbId.ToString());
}
private void UpdateMappings() private void UpdateMappings()
{ {
_logger.Info("Updating Scene mapping"); _logger.Info("Updating Scene mapping");
@ -68,7 +77,7 @@ namespace NzbDrone.Core.DataAugmentation.Scene
foreach (var sceneMapping in mappings) foreach (var sceneMapping in mappings)
{ {
sceneMapping.ParseTerm = sceneMapping.ParseTerm.CleanSeriesTitle(); sceneMapping.ParseTerm = sceneMapping.Title.CleanSeriesTitle();
} }
_repository.InsertMany(mappings); _repository.InsertMany(mappings);
@ -92,12 +101,17 @@ namespace NzbDrone.Core.DataAugmentation.Scene
_gettvdbIdCache.Clear(); _gettvdbIdCache.Clear();
_getSceneNameCache.Clear(); _getSceneNameCache.Clear();
_findbytvdbIdCache.Clear();
foreach (var sceneMapping in mappings) foreach (var sceneMapping in mappings)
{ {
_getSceneNameCache.Set(sceneMapping.TvdbId.ToString(), sceneMapping); _getSceneNameCache.Set(sceneMapping.TvdbId.ToString(), sceneMapping);
_gettvdbIdCache.Set(sceneMapping.ParseTerm.CleanSeriesTitle(), sceneMapping); _gettvdbIdCache.Set(sceneMapping.ParseTerm.CleanSeriesTitle(), sceneMapping);
} }
foreach (var sceneMapping in mappings.GroupBy(x => x.TvdbId))
{
_findbytvdbIdCache.Set(sceneMapping.Key.ToString(), sceneMapping.ToList());
}
} }

@ -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();
}
}
}

@ -193,6 +193,7 @@
</Compile> </Compile>
<Compile Include="Datastore\Migration\046_fix_nzb_su_url.cs" /> <Compile Include="Datastore\Migration\046_fix_nzb_su_url.cs" />
<Compile Include="Datastore\Migration\047_add_published_date_blacklist_column.cs" /> <Compile Include="Datastore\Migration\047_add_published_date_blacklist_column.cs" />
<Compile Include="Datastore\Migration\048_add_title_to_scenemappings.cs" />
<Compile Include="Datastore\Migration\Framework\MigrationContext.cs" /> <Compile Include="Datastore\Migration\Framework\MigrationContext.cs" />
<Compile Include="Datastore\Migration\Framework\MigrationController.cs" /> <Compile Include="Datastore\Migration\Framework\MigrationController.cs" />
<Compile Include="Datastore\Migration\Framework\MigrationExtension.cs" /> <Compile Include="Datastore\Migration\Framework\MigrationExtension.cs" />

@ -1,25 +1,32 @@
{{qualityProfile qualityProfileId}} <div>
<span class="label label-info">{{network}}</span> {{qualityProfile qualityProfileId}}
<span class="label label-info">{{runtime}} minutes</span> <span class="label label-info">{{network}}</span>
<span class="label label-info">{{path}}</span> <span class="label label-info">{{runtime}} minutes</span>
{{#if_eq status compare="continuing"}} <span class="label label-info">{{path}}</span>
<span class="label label-info">Continuing</span> {{#if_eq status compare="continuing"}}
{{else}} <span class="label label-info">Continuing</span>
<span class="label">Ended</span> {{else}}
{{/if_eq}} <span class="label">Ended</span>
{{/if_eq}}
<span class="pull-right"> <span class="pull-right">
<a href="{{traktUrl}}" class="label label-info">Trakt</a> <a href="{{traktUrl}}" class="label label-info">Trakt</a>
{{#if imdbId}} {{#if imdbId}}
<a href="{{imdbUrl}}" class="label label-info">IMDB</a> <a href="{{imdbUrl}}" class="label label-info">IMDB</a>
{{/if}} {{/if}}
{{#if tvdbId}} {{#if tvdbId}}
<a href="{{tvdbUrl}}" class="label label-info">TVDB</a> <a href="{{tvdbUrl}}" class="label label-info">TVDB</a>
{{/if}} {{/if}}
{{#if tvRageId}} {{#if tvRageId}}
<a href="{{tvRageUrl}}" class="label label-info">TVRage</a> <a href="{{tvRageUrl}}" class="label label-info">TVRage</a>
{{/if}} {{/if}}
</span> </span>
</div>
<div>
{{#each alternativeTitles}}
<span class="label">{{this}}</span>
{{/each}}
</div>
Loading…
Cancel
Save