mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-04-20 09:04:42 +01:00
Merge remote-tracking branch 'upstream/dev' into dev
This commit is contained in:
@@ -63,16 +63,8 @@ namespace MediaBrowser.Server.Implementations.Intros
|
||||
? null
|
||||
: _localization.GetRatingLevel(item.OfficialRating);
|
||||
|
||||
var random = new Random(Environment.TickCount + Guid.NewGuid().GetHashCode());
|
||||
|
||||
var candidates = new List<ItemWithTrailer>();
|
||||
|
||||
var itemPeople = _libraryManager.GetPeople(item);
|
||||
var allPeople = _libraryManager.GetPeople(new InternalPeopleQuery
|
||||
{
|
||||
AppearsInItemId = item.Id
|
||||
});
|
||||
|
||||
var trailerTypes = new List<TrailerType>();
|
||||
|
||||
if (config.EnableIntrosFromMoviesInLibrary)
|
||||
@@ -105,26 +97,25 @@ namespace MediaBrowser.Server.Implementations.Intros
|
||||
var trailerResult = _libraryManager.GetItemList(new InternalItemsQuery
|
||||
{
|
||||
IncludeItemTypes = new[] { typeof(Trailer).Name },
|
||||
TrailerTypes = trailerTypes.ToArray()
|
||||
TrailerTypes = trailerTypes.ToArray(),
|
||||
SimilarTo = item,
|
||||
IsPlayed = config.EnableIntrosForWatchedContent ? (bool?) null : false,
|
||||
MaxParentalRating = config.EnableIntrosParentalControl ? ratingLevel : null,
|
||||
Limit = config.TrailerLimit
|
||||
});
|
||||
|
||||
candidates.AddRange(trailerResult.Select(i => new ItemWithTrailer
|
||||
{
|
||||
Item = i,
|
||||
Type = i.SourceType == SourceType.Channel ? ItemWithTrailerType.ChannelTrailer : ItemWithTrailerType.ItemWithTrailer,
|
||||
User = user,
|
||||
WatchingItem = item,
|
||||
WatchingItemPeople = itemPeople,
|
||||
AllPeople = allPeople,
|
||||
Random = random,
|
||||
LibraryManager = _libraryManager
|
||||
}));
|
||||
}
|
||||
|
||||
return GetResult(item, candidates, config, ratingLevel);
|
||||
return GetResult(item, candidates, config);
|
||||
}
|
||||
|
||||
private IEnumerable<IntroInfo> GetResult(BaseItem item, IEnumerable<ItemWithTrailer> candidates, CinemaModeConfiguration config, int? ratingLevel)
|
||||
private IEnumerable<IntroInfo> GetResult(BaseItem item, IEnumerable<ItemWithTrailer> candidates, CinemaModeConfiguration config)
|
||||
{
|
||||
var customIntros = !string.IsNullOrWhiteSpace(config.CustomIntroPath) ?
|
||||
GetCustomIntros(config) :
|
||||
@@ -134,48 +125,12 @@ namespace MediaBrowser.Server.Implementations.Intros
|
||||
GetMediaInfoIntros(config, item) :
|
||||
new List<IntroInfo>();
|
||||
|
||||
var trailerLimit = config.TrailerLimit;
|
||||
|
||||
// Avoid implicitly captured closure
|
||||
return candidates.Where(i =>
|
||||
{
|
||||
if (config.EnableIntrosParentalControl && !FilterByParentalRating(ratingLevel, i.Item))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!config.EnableIntrosForWatchedContent && i.IsPlayed)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return !IsDuplicate(item, i.Item);
|
||||
})
|
||||
.OrderByDescending(i => i.Score)
|
||||
.ThenBy(i => Guid.NewGuid())
|
||||
.ThenByDescending(i => i.IsPlayed ? 0 : 1)
|
||||
.Select(i => i.IntroInfo)
|
||||
.Take(trailerLimit)
|
||||
return candidates.Select(i => i.IntroInfo)
|
||||
.Concat(customIntros.Take(1))
|
||||
.Concat(mediaInfoIntros);
|
||||
}
|
||||
|
||||
private bool IsDuplicate(BaseItem playingContent, BaseItem test)
|
||||
{
|
||||
var id = playingContent.GetProviderId(MetadataProviders.Imdb);
|
||||
if (!string.IsNullOrWhiteSpace(id) && string.Equals(id, test.GetProviderId(MetadataProviders.Imdb), StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
id = playingContent.GetProviderId(MetadataProviders.Tmdb);
|
||||
if (!string.IsNullOrWhiteSpace(id) && string.Equals(id, test.GetProviderId(MetadataProviders.Tmdb), StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private CinemaModeConfiguration GetOptions()
|
||||
{
|
||||
return _serverConfig.GetConfiguration<CinemaModeConfiguration>("cinemamode");
|
||||
@@ -346,96 +301,6 @@ namespace MediaBrowser.Server.Implementations.Intros
|
||||
return list.Distinct(StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
private bool FilterByParentalRating(int? ratingLevel, BaseItem item)
|
||||
{
|
||||
// Only content rated same or lower
|
||||
if (ratingLevel.HasValue)
|
||||
{
|
||||
var level = string.IsNullOrWhiteSpace(item.OfficialRating)
|
||||
? (int?)null
|
||||
: _localization.GetRatingLevel(item.OfficialRating);
|
||||
|
||||
return level.HasValue && level.Value <= ratingLevel.Value;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
internal static int GetSimiliarityScore(BaseItem item1, List<PersonInfo> item1People, List<PersonInfo> allPeople, BaseItem item2, Random random, ILibraryManager libraryManager)
|
||||
{
|
||||
var points = 0;
|
||||
|
||||
if (!string.IsNullOrEmpty(item1.OfficialRating) && string.Equals(item1.OfficialRating, item2.OfficialRating, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
points += 10;
|
||||
}
|
||||
|
||||
// Find common genres
|
||||
points += item1.Genres.Where(i => item2.Genres.Contains(i, StringComparer.OrdinalIgnoreCase)).Sum(i => 10);
|
||||
|
||||
// Find common tags
|
||||
points += GetTags(item1).Where(i => GetTags(item2).Contains(i, StringComparer.OrdinalIgnoreCase)).Sum(i => 10);
|
||||
|
||||
// Find common keywords
|
||||
points += GetKeywords(item1).Where(i => GetKeywords(item2).Contains(i, StringComparer.OrdinalIgnoreCase)).Sum(i => 10);
|
||||
|
||||
// Find common studios
|
||||
points += item1.Studios.Where(i => item2.Studios.Contains(i, StringComparer.OrdinalIgnoreCase)).Sum(i => 5);
|
||||
|
||||
var item2PeopleNames = allPeople.Where(i => i.ItemId == item2.Id)
|
||||
.Select(i => i.Name)
|
||||
.Where(i => !string.IsNullOrWhiteSpace(i))
|
||||
.DistinctNames()
|
||||
.ToDictionary(i => i, StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
points += item1People.Where(i => item2PeopleNames.ContainsKey(i.Name)).Sum(i =>
|
||||
{
|
||||
if (string.Equals(i.Type, PersonType.Director, StringComparison.OrdinalIgnoreCase) || string.Equals(i.Role, PersonType.Director, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
if (string.Equals(i.Type, PersonType.Actor, StringComparison.OrdinalIgnoreCase) || string.Equals(i.Role, PersonType.Actor, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
if (string.Equals(i.Type, PersonType.Composer, StringComparison.OrdinalIgnoreCase) || string.Equals(i.Role, PersonType.Composer, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
if (string.Equals(i.Type, PersonType.GuestStar, StringComparison.OrdinalIgnoreCase) || string.Equals(i.Role, PersonType.GuestStar, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
if (string.Equals(i.Type, PersonType.Writer, StringComparison.OrdinalIgnoreCase) || string.Equals(i.Role, PersonType.Writer, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
return 1;
|
||||
});
|
||||
|
||||
// Add some randomization so that you're not always seeing the same ones for a given movie
|
||||
points += random.Next(0, 50);
|
||||
|
||||
return points;
|
||||
}
|
||||
|
||||
private static IEnumerable<string> GetTags(BaseItem item)
|
||||
{
|
||||
var hasTags = item as IHasTags;
|
||||
if (hasTags != null)
|
||||
{
|
||||
return hasTags.Tags;
|
||||
}
|
||||
|
||||
return new List<string>();
|
||||
}
|
||||
|
||||
private static IEnumerable<string> GetKeywords(BaseItem item)
|
||||
{
|
||||
return item.Keywords;
|
||||
}
|
||||
|
||||
public IEnumerable<string> GetAllIntroFiles()
|
||||
{
|
||||
return GetCustomIntroFiles(GetOptions(), true, true);
|
||||
@@ -455,39 +320,8 @@ namespace MediaBrowser.Server.Implementations.Intros
|
||||
{
|
||||
internal BaseItem Item;
|
||||
internal ItemWithTrailerType Type;
|
||||
internal User User;
|
||||
internal BaseItem WatchingItem;
|
||||
internal List<PersonInfo> WatchingItemPeople;
|
||||
internal List<PersonInfo> AllPeople;
|
||||
internal Random Random;
|
||||
internal ILibraryManager LibraryManager;
|
||||
|
||||
private bool? _isPlayed;
|
||||
public bool IsPlayed
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!_isPlayed.HasValue)
|
||||
{
|
||||
_isPlayed = Item.IsPlayed(User);
|
||||
}
|
||||
return _isPlayed.Value;
|
||||
}
|
||||
}
|
||||
|
||||
private int? _score;
|
||||
public int Score
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!_score.HasValue)
|
||||
{
|
||||
_score = GetSimiliarityScore(WatchingItem, WatchingItemPeople, AllPeople, Item, Random, LibraryManager);
|
||||
}
|
||||
return _score.Value;
|
||||
}
|
||||
}
|
||||
|
||||
public IntroInfo IntroInfo
|
||||
{
|
||||
get
|
||||
|
||||
@@ -2309,7 +2309,7 @@ namespace MediaBrowser.Server.Implementations.Library
|
||||
|
||||
public IEnumerable<Video> FindTrailers(BaseItem owner, List<FileSystemMetadata> fileSystemChildren, IDirectoryService directoryService)
|
||||
{
|
||||
var files = fileSystemChildren.Where(i => i.IsDirectory)
|
||||
var files = owner.IsInMixedFolder ? new List<FileSystemMetadata>() : fileSystemChildren.Where(i => i.IsDirectory)
|
||||
.Where(i => string.Equals(i.Name, BaseItem.TrailerFolderName, StringComparison.OrdinalIgnoreCase))
|
||||
.SelectMany(i => _fileSystem.GetFiles(i.FullName, false))
|
||||
.ToList();
|
||||
|
||||
@@ -46,11 +46,12 @@
|
||||
<HintPath>..\packages\CommonIO.1.0.0.9\lib\net45\CommonIO.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Emby.XmlTv, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Emby.XmlTv.1.0.0.49\lib\net45\Emby.XmlTv.dll</HintPath>
|
||||
<HintPath>..\packages\Emby.XmlTv.1.0.0.50\lib\net45\Emby.XmlTv.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="INIFileParser">
|
||||
<HintPath>..\packages\ini-parser.2.2.4\lib\net20\INIFileParser.dll</HintPath>
|
||||
<Reference Include="INIFileParser, Version=2.3.0.0, Culture=neutral, PublicKeyToken=79af7b307b65cf3c, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\ini-parser.2.3.0\lib\net20\INIFileParser.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Interfaces.IO">
|
||||
<HintPath>..\packages\Interfaces.IO.1.0.0.5\lib\portable-net45+sl4+wp71+win8+wpa81\Interfaces.IO.dll</HintPath>
|
||||
|
||||
@@ -6,5 +6,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||
public interface IDbConnector
|
||||
{
|
||||
Task<IDbConnection> Connect(string dbPath);
|
||||
void BindSimilarityScoreFunction(IDbConnection connection);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,175 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SQLite;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Model.Logging;
|
||||
|
||||
namespace MediaBrowser.Server.Implementations.Persistence
|
||||
{
|
||||
/// <summary>
|
||||
/// Class SQLiteExtensions
|
||||
/// </summary>
|
||||
public static class SqliteExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Connects to db.
|
||||
/// </summary>
|
||||
/// <param name="dbPath">The db path.</param>
|
||||
/// <param name="logger">The logger.</param>
|
||||
/// <returns>Task{IDbConnection}.</returns>
|
||||
/// <exception cref="System.ArgumentNullException">dbPath</exception>
|
||||
public static async Task<IDbConnection> ConnectToDb(string dbPath, ILogger logger)
|
||||
{
|
||||
if (string.IsNullOrEmpty(dbPath))
|
||||
{
|
||||
throw new ArgumentNullException("dbPath");
|
||||
}
|
||||
|
||||
logger.Info("Sqlite {0} opening {1}", SQLiteConnection.SQLiteVersion, dbPath);
|
||||
|
||||
var connectionstr = new SQLiteConnectionStringBuilder
|
||||
{
|
||||
PageSize = 4096,
|
||||
CacheSize = 2000,
|
||||
SyncMode = SynchronizationModes.Normal,
|
||||
DataSource = dbPath,
|
||||
JournalMode = SQLiteJournalModeEnum.Wal
|
||||
};
|
||||
|
||||
var connection = new SQLiteConnection(connectionstr.ConnectionString);
|
||||
|
||||
await connection.OpenAsync().ConfigureAwait(false);
|
||||
|
||||
return connection;
|
||||
}
|
||||
|
||||
public static void BindGetSimilarityScore(IDbConnection connection, ILogger logger)
|
||||
{
|
||||
var sqlConnection = (SQLiteConnection) connection;
|
||||
SimiliarToFunction.Logger = logger;
|
||||
sqlConnection.BindFunction(new SimiliarToFunction());
|
||||
}
|
||||
|
||||
public static void BindFunction(this SQLiteConnection connection, SQLiteFunction function)
|
||||
{
|
||||
var attributes = function.GetType().GetCustomAttributes(typeof(SQLiteFunctionAttribute), true).Cast<SQLiteFunctionAttribute>().ToArray();
|
||||
if (attributes.Length == 0)
|
||||
{
|
||||
throw new InvalidOperationException("SQLiteFunction doesn't have SQLiteFunctionAttribute");
|
||||
}
|
||||
connection.BindFunction(attributes[0], function);
|
||||
}
|
||||
}
|
||||
|
||||
[SQLiteFunction(Name = "GetSimilarityScore", Arguments = 12, FuncType = FunctionType.Scalar)]
|
||||
public class SimiliarToFunction : SQLiteFunction
|
||||
{
|
||||
internal static ILogger Logger;
|
||||
|
||||
public override object Invoke(object[] args)
|
||||
{
|
||||
var score = 0;
|
||||
|
||||
var inputOfficialRating = args[0] as string;
|
||||
var rowOfficialRating = args[1] as string;
|
||||
if (!string.IsNullOrWhiteSpace(inputOfficialRating) && string.Equals(inputOfficialRating, rowOfficialRating))
|
||||
{
|
||||
score += 10;
|
||||
}
|
||||
|
||||
long? inputYear = args[2] == null ? (long?)null : (long)args[2];
|
||||
long? rowYear = args[3] == null ? (long?)null : (long)args[3];
|
||||
|
||||
if (inputYear.HasValue && rowYear.HasValue)
|
||||
{
|
||||
var diff = Math.Abs(inputYear.Value - rowYear.Value);
|
||||
|
||||
// Add if they came out within the same decade
|
||||
if (diff < 10)
|
||||
{
|
||||
score += 2;
|
||||
}
|
||||
|
||||
// And more if within five years
|
||||
if (diff < 5)
|
||||
{
|
||||
score += 2;
|
||||
}
|
||||
}
|
||||
|
||||
// genres
|
||||
score += GetListScore(args, 4, 5);
|
||||
|
||||
// tags
|
||||
score += GetListScore(args, 6, 7);
|
||||
|
||||
// keywords
|
||||
score += GetListScore(args, 8, 9);
|
||||
|
||||
// studios
|
||||
score += GetListScore(args, 10, 11, 3);
|
||||
|
||||
|
||||
// TODO: People
|
||||
// var item2PeopleNames = allPeople.Where(i => i.ItemId == item2.Id)
|
||||
//.Select(i => i.Name)
|
||||
//.Where(i => !string.IsNullOrWhiteSpace(i))
|
||||
//.DistinctNames()
|
||||
//.ToDictionary(i => i, StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
// points += item1People.Where(i => item2PeopleNames.ContainsKey(i.Name)).Sum(i =>
|
||||
// {
|
||||
// if (string.Equals(i.Type, PersonType.Director, StringComparison.OrdinalIgnoreCase) || string.Equals(i.Role, PersonType.Director, StringComparison.OrdinalIgnoreCase))
|
||||
// {
|
||||
// return 5;
|
||||
// }
|
||||
// if (string.Equals(i.Type, PersonType.Actor, StringComparison.OrdinalIgnoreCase) || string.Equals(i.Role, PersonType.Actor, StringComparison.OrdinalIgnoreCase))
|
||||
// {
|
||||
// return 3;
|
||||
// }
|
||||
// if (string.Equals(i.Type, PersonType.Composer, StringComparison.OrdinalIgnoreCase) || string.Equals(i.Role, PersonType.Composer, StringComparison.OrdinalIgnoreCase))
|
||||
// {
|
||||
// return 3;
|
||||
// }
|
||||
// if (string.Equals(i.Type, PersonType.GuestStar, StringComparison.OrdinalIgnoreCase) || string.Equals(i.Role, PersonType.GuestStar, StringComparison.OrdinalIgnoreCase))
|
||||
// {
|
||||
// return 3;
|
||||
// }
|
||||
// if (string.Equals(i.Type, PersonType.Writer, StringComparison.OrdinalIgnoreCase) || string.Equals(i.Role, PersonType.Writer, StringComparison.OrdinalIgnoreCase))
|
||||
// {
|
||||
// return 2;
|
||||
// }
|
||||
|
||||
// return 1;
|
||||
// });
|
||||
|
||||
// return points;
|
||||
|
||||
//Logger.Debug("Returning score {0}", score);
|
||||
return score;
|
||||
}
|
||||
|
||||
private int GetListScore(object[] args, int index1, int index2, int value = 10)
|
||||
{
|
||||
var score = 0;
|
||||
|
||||
var inputGenres = args[index1] as string;
|
||||
var rowGenres = args[index2] as string;
|
||||
var inputGenreList = string.IsNullOrWhiteSpace(inputGenres) ? new string[] { } : inputGenres.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
var rowGenresList = string.IsNullOrWhiteSpace(rowGenres) ? new string[] { } : rowGenres.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
foreach (var genre in inputGenreList)
|
||||
{
|
||||
if (rowGenresList.Contains(genre, StringComparer.OrdinalIgnoreCase))
|
||||
{
|
||||
score += value;
|
||||
}
|
||||
}
|
||||
|
||||
return score;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Common.Extensions;
|
||||
@@ -258,6 +259,8 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||
new MediaStreamColumns(_connection, Logger).AddColumns();
|
||||
|
||||
DataExtensions.Attach(_connection, Path.Combine(_config.ApplicationPaths.DataPath, "userdata_v2.db"), "UserDataDb");
|
||||
|
||||
dbConnector.BindSimilarityScoreFunction(_connection);
|
||||
}
|
||||
|
||||
private readonly string[] _retriveItemColumns =
|
||||
@@ -1523,6 +1526,11 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||
return false;
|
||||
}
|
||||
|
||||
if (query.SimilarTo != null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (query.SortBy != null && query.SortBy.Length > 0)
|
||||
{
|
||||
if (query.SortBy.Contains(ItemSortBy.IsFavoriteOrLiked, StringComparer.OrdinalIgnoreCase))
|
||||
@@ -1575,7 +1583,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||
return false;
|
||||
}
|
||||
|
||||
private string[] GetFinalColumnsToSelect(InternalItemsQuery query, string[] startColumns)
|
||||
private string[] GetFinalColumnsToSelect(InternalItemsQuery query, string[] startColumns, IDbCommand cmd)
|
||||
{
|
||||
var list = startColumns.ToList();
|
||||
|
||||
@@ -1590,6 +1598,45 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||
list.Add("UserDataDb.UserData.rating");
|
||||
}
|
||||
|
||||
if (query.SimilarTo != null)
|
||||
{
|
||||
var item = query.SimilarTo;
|
||||
|
||||
var builder = new StringBuilder();
|
||||
builder.Append("GetSimilarityScore(");
|
||||
|
||||
builder.Append("@ItemOfficialRating,");
|
||||
builder.Append("OfficialRating,");
|
||||
|
||||
builder.Append("@ItemProductionYear,");
|
||||
builder.Append("ProductionYear,");
|
||||
|
||||
builder.Append("@ItemGenres,");
|
||||
builder.Append("Genres,");
|
||||
|
||||
builder.Append("@ItemTags,");
|
||||
builder.Append("Tags,");
|
||||
|
||||
builder.Append("@ItemKeywords,");
|
||||
builder.Append("(select group_concat((Select Value from ItemValues where ItemId=Guid and Type=5), '|')),");
|
||||
|
||||
builder.Append("@ItemStudios,");
|
||||
builder.Append("Studios");
|
||||
builder.Append(") as SimilarityScore");
|
||||
|
||||
list.Add(builder.ToString());
|
||||
cmd.Parameters.Add(cmd, "@ItemOfficialRating", DbType.String).Value = item.OfficialRating;
|
||||
cmd.Parameters.Add(cmd, "@ItemProductionYear", DbType.Int32).Value = item.ProductionYear ?? -1;
|
||||
cmd.Parameters.Add(cmd, "@ItemGenres", DbType.String).Value = string.Join("|", item.Genres.ToArray());
|
||||
cmd.Parameters.Add(cmd, "@ItemTags", DbType.String).Value = string.Join("|", item.Tags.ToArray());
|
||||
cmd.Parameters.Add(cmd, "@ItemKeywords", DbType.String).Value = string.Join("|", item.Keywords.ToArray());
|
||||
cmd.Parameters.Add(cmd, "@ItemStudios", DbType.String).Value = string.Join("|", item.Studios.ToArray());
|
||||
|
||||
var excludeIds = query.ExcludeItemIds.ToList();
|
||||
excludeIds.Add(item.Id.ToString("N"));
|
||||
query.ExcludeItemIds = excludeIds.ToArray();
|
||||
}
|
||||
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
@@ -1616,7 +1663,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||
|
||||
using (var cmd = _connection.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "select " + string.Join(",", GetFinalColumnsToSelect(query, _retriveItemColumns)) + " from TypedBaseItems";
|
||||
cmd.CommandText = "select " + string.Join(",", GetFinalColumnsToSelect(query, _retriveItemColumns, cmd)) + " from TypedBaseItems";
|
||||
cmd.CommandText += GetJoinUserDataText(query);
|
||||
|
||||
if (EnableJoinUserData(query))
|
||||
@@ -1706,7 +1753,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||
|
||||
using (var cmd = _connection.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "select " + string.Join(",", GetFinalColumnsToSelect(query, _retriveItemColumns)) + " from TypedBaseItems";
|
||||
cmd.CommandText = "select " + string.Join(",", GetFinalColumnsToSelect(query, _retriveItemColumns, cmd)) + " from TypedBaseItems";
|
||||
cmd.CommandText += GetJoinUserDataText(query);
|
||||
|
||||
if (EnableJoinUserData(query))
|
||||
@@ -1789,6 +1836,22 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||
|
||||
private string GetOrderByText(InternalItemsQuery query)
|
||||
{
|
||||
if (query.SimilarTo != null)
|
||||
{
|
||||
if (query.SortBy == null || query.SortBy.Length == 0)
|
||||
{
|
||||
if (query.User != null)
|
||||
{
|
||||
query.SortBy = new[] { "SimilarityScore", "IsUnplayed", "Random" };
|
||||
}
|
||||
else
|
||||
{
|
||||
query.SortBy = new[] { "SimilarityScore", "Random" };
|
||||
}
|
||||
query.SortOrder = SortOrder.Descending;
|
||||
}
|
||||
}
|
||||
|
||||
if (query.SortBy == null || query.SortBy.Length == 0)
|
||||
{
|
||||
return string.Empty;
|
||||
@@ -1862,6 +1925,14 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||
{
|
||||
return new Tuple<string, bool>("(select value from itemvalues where ItemId=Guid and Type=1 LIMIT 1)", false);
|
||||
}
|
||||
if (string.Equals(name, ItemSortBy.OfficialRating, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return new Tuple<string, bool>("ParentalRatingValue", false);
|
||||
}
|
||||
if (string.Equals(name, ItemSortBy.Studio, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return new Tuple<string, bool>("(select value from itemvalues where ItemId=Guid and Type=3 LIMIT 1)", false);
|
||||
}
|
||||
|
||||
return new Tuple<string, bool>(name, false);
|
||||
}
|
||||
@@ -1879,7 +1950,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||
|
||||
using (var cmd = _connection.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "select " + string.Join(",", GetFinalColumnsToSelect(query, new[] { "guid" })) + " from TypedBaseItems";
|
||||
cmd.CommandText = "select " + string.Join(",", GetFinalColumnsToSelect(query, new[] { "guid" }, cmd)) + " from TypedBaseItems";
|
||||
cmd.CommandText += GetJoinUserDataText(query);
|
||||
|
||||
if (EnableJoinUserData(query))
|
||||
@@ -2022,7 +2093,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||
|
||||
using (var cmd = _connection.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "select " + string.Join(",", GetFinalColumnsToSelect(query, new[] { "guid" })) + " from TypedBaseItems";
|
||||
cmd.CommandText = "select " + string.Join(",", GetFinalColumnsToSelect(query, new[] { "guid" }, cmd)) + " from TypedBaseItems";
|
||||
|
||||
var whereClauses = GetWhereClauses(query, cmd);
|
||||
cmd.CommandText += GetJoinUserDataText(query);
|
||||
@@ -2148,24 +2219,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||
}
|
||||
else
|
||||
{
|
||||
if (query.IsMovie.Value)
|
||||
{
|
||||
var typeClauses = new List<string>();
|
||||
var typeIndex = 0;
|
||||
foreach (var type in alternateTypes)
|
||||
{
|
||||
var paramName = "@AlternateType" + typeIndex.ToString(CultureInfo.InvariantCulture);
|
||||
typeClauses.Add("Type=" + paramName);
|
||||
cmd.Parameters.Add(cmd, paramName, DbType.String).Value = type;
|
||||
typeIndex++;
|
||||
}
|
||||
|
||||
whereClauses.Add("(IsMovie=@IsMovie OR " + string.Join(" OR ", typeClauses.ToArray()) + ")");
|
||||
}
|
||||
else
|
||||
{
|
||||
whereClauses.Add("(IsMovie is null OR IsMovie=@IsMovie)");
|
||||
}
|
||||
whereClauses.Add("(IsMovie is null OR IsMovie=@IsMovie)");
|
||||
}
|
||||
cmd.Parameters.Add(cmd, "@IsMovie", DbType.Boolean).Value = query.IsMovie;
|
||||
}
|
||||
@@ -2539,6 +2593,20 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||
whereClauses.Add(clause);
|
||||
}
|
||||
|
||||
if (query.OfficialRatings.Length > 0)
|
||||
{
|
||||
var clauses = new List<string>();
|
||||
var index = 0;
|
||||
foreach (var item in query.OfficialRatings)
|
||||
{
|
||||
clauses.Add("OfficialRating=@OfficialRating" + index);
|
||||
cmd.Parameters.Add(cmd, "@OfficialRating" + index, DbType.String).Value = item;
|
||||
index++;
|
||||
}
|
||||
var clause = "(" + string.Join(" OR ", clauses.ToArray()) + ")";
|
||||
whereClauses.Add(clause);
|
||||
}
|
||||
|
||||
if (query.MinParentalRating.HasValue)
|
||||
{
|
||||
whereClauses.Add("InheritedParentalRatingValue<=@MinParentalRating");
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="CommonIO" version="1.0.0.9" targetFramework="net45" />
|
||||
<package id="Emby.XmlTv" version="1.0.0.49" targetFramework="net45" />
|
||||
<package id="ini-parser" version="2.2.4" targetFramework="net45" />
|
||||
<package id="Emby.XmlTv" version="1.0.0.50" targetFramework="net45" />
|
||||
<package id="ini-parser" version="2.3.0" targetFramework="net45" />
|
||||
<package id="Interfaces.IO" version="1.0.0.5" targetFramework="net45" />
|
||||
<package id="MediaBrowser.Naming" version="1.0.0.50" targetFramework="net45" />
|
||||
<package id="Mono.Nat" version="1.2.24.0" targetFramework="net45" />
|
||||
|
||||
Reference in New Issue
Block a user