Merge pull request #72 from Cyberlane/alternate_titles

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

@ -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<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)
{
var series = _seriesService.GetSeries(id);
@ -80,6 +100,7 @@ namespace NzbDrone.Api.Series
var resource = series.InjectTo<SeriesResource>();
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;
}

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

@ -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")]

@ -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<SceneMapping>
{
List<SceneMapping> FindByTvdbid(int tvdbId);
}
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.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<int> GetTvDbId(string cleanName);
List<SceneMapping> FindByTvdbid(int tvdbId);
}
public class SceneMappingService : ISceneMappingService,
@ -24,6 +26,7 @@ namespace NzbDrone.Core.DataAugmentation.Scene
private readonly Logger _logger;
private readonly ICached<SceneMapping> _getSceneNameCache;
private readonly ICached<SceneMapping> _gettvdbIdCache;
private readonly ICached<List<SceneMapping>> _findbytvdbIdCache;
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");
_gettvdbIdCache = cacheManager.GetCache<SceneMapping>(GetType(), "tvdb_id");
_findbytvdbIdCache = cacheManager.GetCache<List<SceneMapping>>(GetType(), "find_tvdb_id");
_logger = logger;
}
@ -54,6 +58,11 @@ namespace NzbDrone.Core.DataAugmentation.Scene
return mapping.TvdbId;
}
public List<SceneMapping> 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());
}
}

@ -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 Include="Datastore\Migration\046_fix_nzb_su_url.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\MigrationController.cs" />
<Compile Include="Datastore\Migration\Framework\MigrationExtension.cs" />

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