commit
c91b608005
|
@ -110,6 +110,7 @@ namespace MediaBrowser.Controller.Entities
|
||||||
|
|
||||||
internal List<Guid> ItemIdsFromPersonFilters { get; set; }
|
internal List<Guid> ItemIdsFromPersonFilters { get; set; }
|
||||||
public int? ParentIndexNumber { get; set; }
|
public int? ParentIndexNumber { get; set; }
|
||||||
|
public int? ParentIndexNumberNotEquals { get; set; }
|
||||||
public int? IndexNumber { get; set; }
|
public int? IndexNumber { get; set; }
|
||||||
public int? MinParentalRating { get; set; }
|
public int? MinParentalRating { get; set; }
|
||||||
public int? MaxParentalRating { get; set; }
|
public int? MaxParentalRating { get; set; }
|
||||||
|
@ -142,6 +143,7 @@ namespace MediaBrowser.Controller.Entities
|
||||||
public bool EnableTotalRecordCount { get; set; }
|
public bool EnableTotalRecordCount { get; set; }
|
||||||
public bool ForceDirect { get; set; }
|
public bool ForceDirect { get; set; }
|
||||||
public Dictionary<string, string> ExcludeProviderIds { get; set; }
|
public Dictionary<string, string> ExcludeProviderIds { get; set; }
|
||||||
|
public string GroupByAncestorOfType { get; set; }
|
||||||
|
|
||||||
public InternalItemsQuery()
|
public InternalItemsQuery()
|
||||||
{
|
{
|
||||||
|
|
|
@ -85,5 +85,6 @@ namespace MediaBrowser.Model.Querying
|
||||||
public const string GameSystem = "GameSystem";
|
public const string GameSystem = "GameSystem";
|
||||||
public const string IsFavoriteOrLiked = "IsFavoriteOrLiked";
|
public const string IsFavoriteOrLiked = "IsFavoriteOrLiked";
|
||||||
public const string DateLastContentAdded = "DateLastContentAdded";
|
public const string DateLastContentAdded = "DateLastContentAdded";
|
||||||
|
public const string SeriesDatePlayed = "SeriesDatePlayed";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Emby.XmlTv.Classes;
|
using Emby.XmlTv.Classes;
|
||||||
|
using MediaBrowser.Common.Extensions;
|
||||||
using MediaBrowser.Common.Net;
|
using MediaBrowser.Common.Net;
|
||||||
using MediaBrowser.Controller.Configuration;
|
using MediaBrowser.Controller.Configuration;
|
||||||
using MediaBrowser.Model.Logging;
|
using MediaBrowser.Model.Logging;
|
||||||
|
@ -68,6 +69,8 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings
|
||||||
Progress = new Progress<Double>()
|
Progress = new Progress<Double>()
|
||||||
|
|
||||||
}).ConfigureAwait(false);
|
}).ConfigureAwait(false);
|
||||||
|
|
||||||
|
Directory.CreateDirectory(Path.GetDirectoryName(cacheFile));
|
||||||
File.Copy(tempFile, cacheFile, true);
|
File.Copy(tempFile, cacheFile, true);
|
||||||
|
|
||||||
return cacheFile;
|
return cacheFile;
|
||||||
|
@ -103,7 +106,8 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings
|
||||||
ImageUrl = p.Icon != null && !String.IsNullOrEmpty(p.Icon.Source) ? p.Icon.Source : null,
|
ImageUrl = p.Icon != null && !String.IsNullOrEmpty(p.Icon.Source) ? p.Icon.Source : null,
|
||||||
HasImage = p.Icon != null && !String.IsNullOrEmpty(p.Icon.Source),
|
HasImage = p.Icon != null && !String.IsNullOrEmpty(p.Icon.Source),
|
||||||
OfficialRating = p.Rating != null && !String.IsNullOrEmpty(p.Rating.Value) ? p.Rating.Value : null,
|
OfficialRating = p.Rating != null && !String.IsNullOrEmpty(p.Rating.Value) ? p.Rating.Value : null,
|
||||||
CommunityRating = p.StarRating.HasValue ? p.StarRating.Value : (float?)null
|
CommunityRating = p.StarRating.HasValue ? p.StarRating.Value : (float?)null,
|
||||||
|
SeriesId = p.IsSeries ? p.Title.GetMD5().ToString("N") : null
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1694,6 +1694,33 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
return " left join UserDataDb.UserData on (select UserDataKey from UserDataKeys where ItemId=Guid order by Priority LIMIT 1)=UserDataDb.UserData.Key";
|
return " left join UserDataDb.UserData on (select UserDataKey from UserDataKeys where ItemId=Guid order by Priority LIMIT 1)=UserDataDb.UserData.Key";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string GetGroupBy(InternalItemsQuery query)
|
||||||
|
{
|
||||||
|
var groups = new List<string>();
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(query.GroupByAncestorOfType))
|
||||||
|
{
|
||||||
|
groups.Add("(Select PresentationUniqueKey from TypedBaseItems B where B.Type = 'MediaBrowser.Controller.Entities.TV.Series' And B.Guid in (Select AncestorId from AncestorIds where ItemId=A.Guid))");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (EnableGroupByPresentationUniqueKey(query))
|
||||||
|
{
|
||||||
|
groups.Add("PresentationUniqueKey");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (groups.Count > 0)
|
||||||
|
{
|
||||||
|
return " Group by " + string.Join(",", groups.ToArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GetFromText()
|
||||||
|
{
|
||||||
|
return " from TypedBaseItems A";
|
||||||
|
}
|
||||||
|
|
||||||
public IEnumerable<BaseItem> GetItemList(InternalItemsQuery query)
|
public IEnumerable<BaseItem> GetItemList(InternalItemsQuery query)
|
||||||
{
|
{
|
||||||
if (query == null)
|
if (query == null)
|
||||||
|
@ -1707,7 +1734,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
|
|
||||||
using (var cmd = _connection.CreateCommand())
|
using (var cmd = _connection.CreateCommand())
|
||||||
{
|
{
|
||||||
cmd.CommandText = "select " + string.Join(",", GetFinalColumnsToSelect(query, _retriveItemColumns, cmd)) + " from TypedBaseItems";
|
cmd.CommandText = "select " + string.Join(",", GetFinalColumnsToSelect(query, _retriveItemColumns, cmd)) + GetFromText();
|
||||||
cmd.CommandText += GetJoinUserDataText(query);
|
cmd.CommandText += GetJoinUserDataText(query);
|
||||||
|
|
||||||
if (EnableJoinUserData(query))
|
if (EnableJoinUserData(query))
|
||||||
|
@ -1723,10 +1750,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
|
|
||||||
cmd.CommandText += whereText;
|
cmd.CommandText += whereText;
|
||||||
|
|
||||||
if (EnableGroupByPresentationUniqueKey(query))
|
cmd.CommandText += GetGroupBy(query);
|
||||||
{
|
|
||||||
cmd.CommandText += " Group by PresentationUniqueKey";
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd.CommandText += GetOrderByText(query);
|
cmd.CommandText += GetOrderByText(query);
|
||||||
|
|
||||||
|
@ -1797,7 +1821,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
|
|
||||||
using (var cmd = _connection.CreateCommand())
|
using (var cmd = _connection.CreateCommand())
|
||||||
{
|
{
|
||||||
cmd.CommandText = "select " + string.Join(",", GetFinalColumnsToSelect(query, _retriveItemColumns, cmd)) + " from TypedBaseItems";
|
cmd.CommandText = "select " + string.Join(",", GetFinalColumnsToSelect(query, _retriveItemColumns, cmd)) + GetFromText();
|
||||||
cmd.CommandText += GetJoinUserDataText(query);
|
cmd.CommandText += GetJoinUserDataText(query);
|
||||||
|
|
||||||
if (EnableJoinUserData(query))
|
if (EnableJoinUserData(query))
|
||||||
|
@ -1817,10 +1841,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
|
|
||||||
cmd.CommandText += whereText;
|
cmd.CommandText += whereText;
|
||||||
|
|
||||||
if (EnableGroupByPresentationUniqueKey(query))
|
cmd.CommandText += GetGroupBy(query);
|
||||||
{
|
|
||||||
cmd.CommandText += " Group by PresentationUniqueKey";
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd.CommandText += GetOrderByText(query);
|
cmd.CommandText += GetOrderByText(query);
|
||||||
|
|
||||||
|
@ -1838,11 +1859,11 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
|
|
||||||
if (EnableGroupByPresentationUniqueKey(query))
|
if (EnableGroupByPresentationUniqueKey(query))
|
||||||
{
|
{
|
||||||
cmd.CommandText += "; select count (distinct PresentationUniqueKey) from TypedBaseItems";
|
cmd.CommandText += "; select count (distinct PresentationUniqueKey)" + GetFromText();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cmd.CommandText += "; select count (guid) from TypedBaseItems";
|
cmd.CommandText += "; select count (guid)" + GetFromText();
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.CommandText += GetJoinUserDataText(query);
|
cmd.CommandText += GetJoinUserDataText(query);
|
||||||
|
@ -1905,7 +1926,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
|
|
||||||
return " ORDER BY " + string.Join(",", query.SortBy.Select(i =>
|
return " ORDER BY " + string.Join(",", query.SortBy.Select(i =>
|
||||||
{
|
{
|
||||||
var columnMap = MapOrderByField(i);
|
var columnMap = MapOrderByField(i, query);
|
||||||
var columnAscending = isAscending;
|
var columnAscending = isAscending;
|
||||||
if (columnMap.Item2)
|
if (columnMap.Item2)
|
||||||
{
|
{
|
||||||
|
@ -1918,7 +1939,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
}).ToArray());
|
}).ToArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Tuple<string, bool> MapOrderByField(string name)
|
private Tuple<string, bool> MapOrderByField(string name, InternalItemsQuery query)
|
||||||
{
|
{
|
||||||
if (string.Equals(name, ItemSortBy.AirTime, StringComparison.OrdinalIgnoreCase))
|
if (string.Equals(name, ItemSortBy.AirTime, StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
|
@ -1977,6 +1998,10 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
{
|
{
|
||||||
return new Tuple<string, bool>("(select value from itemvalues where ItemId=Guid and Type=3 LIMIT 1)", false);
|
return new Tuple<string, bool>("(select value from itemvalues where ItemId=Guid and Type=3 LIMIT 1)", false);
|
||||||
}
|
}
|
||||||
|
if (string.Equals(name, ItemSortBy.SeriesDatePlayed, StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
return new Tuple<string, bool>("(Select MAX(LastPlayedDate) from TypedBaseItems B"+ GetJoinUserDataText(query) + " where B.Guid in (Select ItemId from AncestorIds where AncestorId in (select guid from typedbaseitems c where C.Type = 'MediaBrowser.Controller.Entities.TV.Series' And C.Guid in (Select AncestorId from AncestorIds where ItemId=A.Guid))))", false);
|
||||||
|
}
|
||||||
|
|
||||||
return new Tuple<string, bool>(name, false);
|
return new Tuple<string, bool>(name, false);
|
||||||
}
|
}
|
||||||
|
@ -1994,7 +2019,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
|
|
||||||
using (var cmd = _connection.CreateCommand())
|
using (var cmd = _connection.CreateCommand())
|
||||||
{
|
{
|
||||||
cmd.CommandText = "select " + string.Join(",", GetFinalColumnsToSelect(query, new[] { "guid" }, cmd)) + " from TypedBaseItems";
|
cmd.CommandText = "select " + string.Join(",", GetFinalColumnsToSelect(query, new[] { "guid" }, cmd)) + GetFromText();
|
||||||
cmd.CommandText += GetJoinUserDataText(query);
|
cmd.CommandText += GetJoinUserDataText(query);
|
||||||
|
|
||||||
if (EnableJoinUserData(query))
|
if (EnableJoinUserData(query))
|
||||||
|
@ -2010,10 +2035,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
|
|
||||||
cmd.CommandText += whereText;
|
cmd.CommandText += whereText;
|
||||||
|
|
||||||
if (EnableGroupByPresentationUniqueKey(query))
|
cmd.CommandText += GetGroupBy(query);
|
||||||
{
|
|
||||||
cmd.CommandText += " Group by PresentationUniqueKey";
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd.CommandText += GetOrderByText(query);
|
cmd.CommandText += GetOrderByText(query);
|
||||||
|
|
||||||
|
@ -2070,10 +2092,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
|
|
||||||
cmd.CommandText += whereText;
|
cmd.CommandText += whereText;
|
||||||
|
|
||||||
if (EnableGroupByPresentationUniqueKey(query))
|
cmd.CommandText += GetGroupBy(query);
|
||||||
{
|
|
||||||
cmd.CommandText += " Group by PresentationUniqueKey";
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd.CommandText += GetOrderByText(query);
|
cmd.CommandText += GetOrderByText(query);
|
||||||
|
|
||||||
|
@ -2137,7 +2156,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
|
|
||||||
using (var cmd = _connection.CreateCommand())
|
using (var cmd = _connection.CreateCommand())
|
||||||
{
|
{
|
||||||
cmd.CommandText = "select " + string.Join(",", GetFinalColumnsToSelect(query, new[] { "guid" }, cmd)) + " from TypedBaseItems";
|
cmd.CommandText = "select " + string.Join(",", GetFinalColumnsToSelect(query, new[] { "guid" }, cmd)) + GetFromText();
|
||||||
|
|
||||||
var whereClauses = GetWhereClauses(query, cmd);
|
var whereClauses = GetWhereClauses(query, cmd);
|
||||||
cmd.CommandText += GetJoinUserDataText(query);
|
cmd.CommandText += GetJoinUserDataText(query);
|
||||||
|
@ -2153,10 +2172,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
|
|
||||||
cmd.CommandText += whereText;
|
cmd.CommandText += whereText;
|
||||||
|
|
||||||
if (EnableGroupByPresentationUniqueKey(query))
|
cmd.CommandText += GetGroupBy(query);
|
||||||
{
|
|
||||||
cmd.CommandText += " Group by PresentationUniqueKey";
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd.CommandText += GetOrderByText(query);
|
cmd.CommandText += GetOrderByText(query);
|
||||||
|
|
||||||
|
@ -2174,11 +2190,11 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
|
|
||||||
if (EnableGroupByPresentationUniqueKey(query))
|
if (EnableGroupByPresentationUniqueKey(query))
|
||||||
{
|
{
|
||||||
cmd.CommandText += "; select count (distinct PresentationUniqueKey) from TypedBaseItems";
|
cmd.CommandText += "; select count (distinct PresentationUniqueKey)" + GetFromText();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cmd.CommandText += "; select count (guid) from TypedBaseItems";
|
cmd.CommandText += "; select count (guid)" + GetFromText();
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.CommandText += GetJoinUserDataText(query);
|
cmd.CommandText += GetJoinUserDataText(query);
|
||||||
|
@ -2370,6 +2386,11 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
whereClauses.Add("ParentIndexNumber=@ParentIndexNumber");
|
whereClauses.Add("ParentIndexNumber=@ParentIndexNumber");
|
||||||
cmd.Parameters.Add(cmd, "@ParentIndexNumber", DbType.Int32).Value = query.ParentIndexNumber.Value;
|
cmd.Parameters.Add(cmd, "@ParentIndexNumber", DbType.Int32).Value = query.ParentIndexNumber.Value;
|
||||||
}
|
}
|
||||||
|
if (query.ParentIndexNumberNotEquals.HasValue)
|
||||||
|
{
|
||||||
|
whereClauses.Add("(ParentIndexNumber<>@ParentIndexNumber or ParentIndexNumber is null)");
|
||||||
|
cmd.Parameters.Add(cmd, "@ParentIndexNumber", DbType.Int32).Value = query.ParentIndexNumberNotEquals.Value;
|
||||||
|
}
|
||||||
if (query.MinEndDate.HasValue)
|
if (query.MinEndDate.HasValue)
|
||||||
{
|
{
|
||||||
whereClauses.Add("EndDate>=@MinEndDate");
|
whereClauses.Add("EndDate>=@MinEndDate");
|
||||||
|
|
|
@ -132,10 +132,12 @@ namespace MediaBrowser.Server.Implementations.TV
|
||||||
SortOrder = SortOrder.Ascending,
|
SortOrder = SortOrder.Ascending,
|
||||||
Limit = 1,
|
Limit = 1,
|
||||||
IsPlayed = false,
|
IsPlayed = false,
|
||||||
IsVirtualItem = false
|
IsVirtualItem = false,
|
||||||
|
ParentIndexNumberNotEquals = 0
|
||||||
|
|
||||||
}).Cast<Episode>().FirstOrDefault();
|
}).Cast<Episode>().FirstOrDefault();
|
||||||
|
|
||||||
|
// series is fully played
|
||||||
if (firstUnwatchedEpisode == null)
|
if (firstUnwatchedEpisode == null)
|
||||||
{
|
{
|
||||||
return new Tuple<Episode, DateTime, bool>(null, DateTime.MinValue, true);
|
return new Tuple<Episode, DateTime, bool>(null, DateTime.MinValue, true);
|
||||||
|
@ -148,7 +150,8 @@ namespace MediaBrowser.Server.Implementations.TV
|
||||||
SortBy = new[] { ItemSortBy.DatePlayed },
|
SortBy = new[] { ItemSortBy.DatePlayed },
|
||||||
SortOrder = SortOrder.Descending,
|
SortOrder = SortOrder.Descending,
|
||||||
Limit = 1,
|
Limit = 1,
|
||||||
IsVirtualItem = false
|
IsVirtualItem = false,
|
||||||
|
ParentIndexNumberNotEquals = 0
|
||||||
|
|
||||||
}).FirstOrDefault();
|
}).FirstOrDefault();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user