filter duplicate recordings based on showId

This commit is contained in:
Luke Pulverenti
2016-11-24 11:29:23 -05:00
parent 8bc4d49c89
commit 9606a2a710
10 changed files with 79 additions and 38 deletions

View File

@@ -100,7 +100,8 @@ namespace Emby.Server.Implementations.HttpServer
responseHeaders = new Dictionary<string, string>();
}
if (addCachePrevention)
string expires;
if (addCachePrevention && !responseHeaders.TryGetValue("Expires", out expires))
{
responseHeaders["Expires"] = "-1";
}

View File

@@ -645,6 +645,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
existingTimer.SeasonNumber = updatedTimer.SeasonNumber;
existingTimer.ShortOverview = updatedTimer.ShortOverview;
existingTimer.StartDate = updatedTimer.StartDate;
existingTimer.ShowId = updatedTimer.ShowId;
}
public Task<ImageStream> GetChannelImageAsync(string channelId, CancellationToken cancellationToken)
@@ -1836,6 +1837,39 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
return seriesTimer.SkipEpisodesInLibrary && IsProgramAlreadyInLibrary(timer);
}
private void HandleDuplicateShowIds(List<TimerInfo> timers)
{
foreach (var timer in timers.Skip(1))
{
// TODO: Get smarter, prefer HD, etc
timer.Status = RecordingStatus.Cancelled;
_timerProvider.Update(timer);
}
}
private void SearchForDuplicateShowIds(List<TimerInfo> timers)
{
var groups = timers.ToLookup(i => i.ShowId ?? string.Empty).ToList();
foreach (var group in groups)
{
if (string.IsNullOrWhiteSpace(group.Key))
{
continue;
}
var groupTimers = group.ToList();
if (groupTimers.Count < 2)
{
continue;
}
HandleDuplicateShowIds(groupTimers);
}
}
private async Task UpdateTimersForSeriesTimer(List<ProgramInfo> epgData, SeriesTimerInfo seriesTimer, bool deleteInvalidTimers)
{
var allTimers = GetTimersForSeries(seriesTimer, epgData)
@@ -1843,6 +1877,8 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
var registration = await _liveTvManager.GetRegistrationInfo("seriesrecordings").ConfigureAwait(false);
var enabledTimersForSeries = new List<TimerInfo>();
if (registration.IsValid)
{
foreach (var timer in allTimers)
@@ -1855,6 +1891,10 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
{
timer.Status = RecordingStatus.Cancelled;
}
else
{
enabledTimersForSeries.Add(timer);
}
_timerProvider.Add(timer);
}
else
@@ -1870,6 +1910,11 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
existingTimer.Status = RecordingStatus.Cancelled;
}
if (existingTimer.Status != RecordingStatus.Cancelled)
{
enabledTimersForSeries.Add(existingTimer);
}
existingTimer.SeriesTimerId = seriesTimer.Id;
_timerProvider.Update(existingTimer);
}
@@ -1877,6 +1922,8 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
}
}
SearchForDuplicateShowIds(enabledTimersForSeries);
if (deleteInvalidTimers)
{
var allTimerIds = allTimers
@@ -1901,8 +1948,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
}
}
private IEnumerable<TimerInfo> GetTimersForSeries(SeriesTimerInfo seriesTimer,
IEnumerable<ProgramInfo> allPrograms)
private IEnumerable<TimerInfo> GetTimersForSeries(SeriesTimerInfo seriesTimer, IEnumerable<ProgramInfo> allPrograms)
{
if (seriesTimer == null)
{

View File

@@ -31,6 +31,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
timer.Name = parent.Name;
timer.Overview = parent.Overview;
timer.SeriesTimerId = seriesTimer.Id;
timer.ShowId = parent.ShowId;
CopyProgramInfoToTimerInfo(parent, timer);

View File

@@ -124,12 +124,14 @@ namespace Emby.Server.Implementations.LiveTv.Listings
private ProgramInfo GetProgramInfo(XmlTvProgram p, ListingsProviderInfo info)
{
var episodeTitle = p.Episode == null ? null : p.Episode.Title;
var programInfo = new ProgramInfo
{
ChannelId = p.ChannelId,
EndDate = GetDate(p.EndDate),
EpisodeNumber = p.Episode == null ? null : p.Episode.Episode,
EpisodeTitle = p.Episode == null ? null : p.Episode.Title,
EpisodeTitle = episodeTitle,
Genres = p.Categories,
Id = String.Format("{0}_{1:O}", p.ChannelId, p.StartDate), // Construct an id from the channel and start date,
StartDate = GetDate(p.StartDate),
@@ -149,7 +151,8 @@ namespace Emby.Server.Implementations.LiveTv.Listings
HasImage = p.Icon != null && !String.IsNullOrEmpty(p.Icon.Source),
OfficialRating = p.Rating != null && !String.IsNullOrEmpty(p.Rating.Value) ? p.Rating.Value : null,
CommunityRating = p.StarRating.HasValue ? p.StarRating.Value : (float?)null,
SeriesId = p.Episode != null ? p.Title.GetMD5().ToString("N") : null
SeriesId = p.Episode != null ? p.Title.GetMD5().ToString("N") : null,
ShowId = ((p.Title ?? string.Empty) + (episodeTitle ?? string.Empty)).GetMD5().ToString("N")
};
if (programInfo.IsMovie)