This commit is contained in:
Tavares André 2015-07-16 20:19:12 +02:00
commit 8fd5a8af8d
161 changed files with 66055 additions and 64993 deletions

1
.gitignore vendored
View File

@ -210,7 +210,6 @@ $RECYCLE.BIN/
# Packages # Packages
*.egg *.egg
*.egg-info *.egg-info
dist/
build/ build/
eggs/ eggs/
parts/ parts/

View File

@ -340,7 +340,7 @@ namespace MediaBrowser.Api
// We can really reduce the timeout for apps that are using the newer api // We can really reduce the timeout for apps that are using the newer api
if (!string.IsNullOrWhiteSpace(job.PlaySessionId)) if (!string.IsNullOrWhiteSpace(job.PlaySessionId))
{ {
timerDuration = 120000; timerDuration = 300000;
} }
} }

View File

@ -344,9 +344,7 @@ namespace MediaBrowser.Api
return name; return name;
} }
return libraryManager.GetAllPeople() return libraryManager.GetPeopleNames(new InternalPeopleQuery())
.Select(i => i.Name)
.DistinctNames()
.FirstOrDefault(i => .FirstOrDefault(i =>
{ {
i = _dashReplaceChars.Aggregate(i, (current, c) => current.Replace(c, SlugChar)); i = _dashReplaceChars.Aggregate(i, (current, c) => current.Replace(c, SlugChar));

View File

@ -109,6 +109,7 @@
<Compile Include="Reports\Stat\ReportStatGroup.cs" /> <Compile Include="Reports\Stat\ReportStatGroup.cs" />
<Compile Include="Reports\Stat\ReportStatItem.cs" /> <Compile Include="Reports\Stat\ReportStatItem.cs" />
<Compile Include="Reports\Stat\ReportStatResult.cs" /> <Compile Include="Reports\Stat\ReportStatResult.cs" />
<Compile Include="Social\SharingService.cs" />
<Compile Include="StartupWizardService.cs" /> <Compile Include="StartupWizardService.cs" />
<Compile Include="Subtitles\SubtitleService.cs" /> <Compile Include="Subtitles\SubtitleService.cs" />
<Compile Include="Movies\CollectionService.cs" /> <Compile Include="Movies\CollectionService.cs" />

View File

@ -165,7 +165,7 @@ namespace MediaBrowser.Api.Movies
return ToOptimizedResult(result); return ToOptimizedResult(result);
} }
private async Task<ItemsResult> GetSimilarItemsResult(BaseGetSimilarItemsFromItem request, Func<BaseItem, bool> includeInSearch, Func<BaseItem, BaseItem, ILibraryManager, int> getSimilarityScore) private async Task<ItemsResult> GetSimilarItemsResult(BaseGetSimilarItemsFromItem request, Func<BaseItem, bool> includeInSearch, Func<BaseItem, List<PersonInfo>, List<PersonInfo>, BaseItem, int> getSimilarityScore)
{ {
var user = !string.IsNullOrWhiteSpace(request.UserId) ? _userManager.GetUserById(request.UserId) : null; var user = !string.IsNullOrWhiteSpace(request.UserId) ? _userManager.GetUserById(request.UserId) : null;
@ -358,12 +358,15 @@ namespace MediaBrowser.Api.Movies
private IEnumerable<RecommendationDto> GetWithActor(User user, List<BaseItem> allMovies, IEnumerable<string> names, int itemLimit, DtoOptions dtoOptions, RecommendationType type) private IEnumerable<RecommendationDto> GetWithActor(User user, List<BaseItem> allMovies, IEnumerable<string> names, int itemLimit, DtoOptions dtoOptions, RecommendationType type)
{ {
var userId = user.Id;
foreach (var name in names) foreach (var name in names)
{ {
var itemsWithActor = _libraryManager.GetItemIds(new InternalItemsQuery
{
Person = name
});
var items = allMovies var items = allMovies
.Where(i => _libraryManager.GetPeople(i).Any(p => string.Equals(p.Name, name, StringComparison.OrdinalIgnoreCase))) .Where(i => itemsWithActor.Contains(i.Id))
.Take(itemLimit) .Take(itemLimit)
.ToList(); .ToList();
@ -382,8 +385,6 @@ namespace MediaBrowser.Api.Movies
private IEnumerable<RecommendationDto> GetSimilarTo(User user, List<BaseItem> allMovies, IEnumerable<BaseItem> baselineItems, int itemLimit, DtoOptions dtoOptions, RecommendationType type) private IEnumerable<RecommendationDto> GetSimilarTo(User user, List<BaseItem> allMovies, IEnumerable<BaseItem> baselineItems, int itemLimit, DtoOptions dtoOptions, RecommendationType type)
{ {
var userId = user.Id;
foreach (var item in baselineItems) foreach (var item in baselineItems)
{ {
var similar = SimilarItemsHelper var similar = SimilarItemsHelper
@ -406,18 +407,37 @@ namespace MediaBrowser.Api.Movies
private IEnumerable<string> GetActors(IEnumerable<BaseItem> items) private IEnumerable<string> GetActors(IEnumerable<BaseItem> items)
{ {
// Get the two leading actors for all movies var people = _libraryManager.GetPeople(new InternalPeopleQuery
return items {
.SelectMany(i => _libraryManager.GetPeople(i).Where(p => !string.Equals(PersonType.Director, p.Type, StringComparison.OrdinalIgnoreCase)).Take(2)) ExcludePersonTypes = new List<string>
{
PersonType.Director
},
MaxListOrder = 3
});
var itemIds = items.Select(i => i.Id).ToList();
return people
.Where(i => itemIds.Contains(i.ItemId))
.Select(i => i.Name) .Select(i => i.Name)
.DistinctNames(); .DistinctNames();
} }
private IEnumerable<string> GetDirectors(IEnumerable<BaseItem> items) private IEnumerable<string> GetDirectors(IEnumerable<BaseItem> items)
{ {
return items var people = _libraryManager.GetPeople(new InternalPeopleQuery
.Select(i => _libraryManager.GetPeople(i).FirstOrDefault(p => string.Equals(PersonType.Director, p.Type, StringComparison.OrdinalIgnoreCase))) {
.Where(i => i != null) PersonTypes = new List<string>
{
PersonType.Director
}
});
var itemIds = items.Select(i => i.Id).ToList();
return people
.Where(i => itemIds.Contains(i.ItemId))
.Select(i => i.Name) .Select(i => i.Name)
.DistinctNames(); .DistinctNames();
} }

View File

@ -6,6 +6,7 @@ using MediaBrowser.Controller.Net;
using MediaBrowser.Controller.Persistence; using MediaBrowser.Controller.Persistence;
using ServiceStack; using ServiceStack;
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
namespace MediaBrowser.Api.Music namespace MediaBrowser.Api.Music
@ -68,12 +69,13 @@ namespace MediaBrowser.Api.Music
/// Gets the album similarity score. /// Gets the album similarity score.
/// </summary> /// </summary>
/// <param name="item1">The item1.</param> /// <param name="item1">The item1.</param>
/// <param name="item1People">The item1 people.</param>
/// <param name="allPeople">All people.</param>
/// <param name="item2">The item2.</param> /// <param name="item2">The item2.</param>
/// <param name="libraryManager">The library manager.</param>
/// <returns>System.Int32.</returns> /// <returns>System.Int32.</returns>
private int GetAlbumSimilarityScore(BaseItem item1, BaseItem item2, ILibraryManager libraryManager) private int GetAlbumSimilarityScore(BaseItem item1, List<PersonInfo> item1People, List<PersonInfo> allPeople, BaseItem item2)
{ {
var points = SimilarItemsHelper.GetSimiliarityScore(item1, item2, libraryManager); var points = SimilarItemsHelper.GetSimiliarityScore(item1, item1People, allPeople, item2);
var album1 = (MusicAlbum)item1; var album1 = (MusicAlbum)item1;
var album2 = (MusicAlbum)item2; var album2 = (MusicAlbum)item2;

View File

@ -632,7 +632,7 @@ namespace MediaBrowser.Api.Playback
{ {
var maxHeightParam = request.MaxHeight.Value.ToString(UsCulture); var maxHeightParam = request.MaxHeight.Value.ToString(UsCulture);
filters.Add(string.Format("scale=trunc(oh*a*2)/2:min(ih\\,{0})", maxHeightParam)); filters.Add(string.Format("scale=trunc(oh*a/2)*2:min(ih\\,{0})", maxHeightParam));
} }
if (string.Equals(outputVideoCodec, "h264_qsv", StringComparison.OrdinalIgnoreCase)) if (string.Equals(outputVideoCodec, "h264_qsv", StringComparison.OrdinalIgnoreCase))

View File

@ -313,16 +313,17 @@ namespace MediaBrowser.Api.Playback.Hls
{ {
var segmentPath = GetSegmentPath(state, playlist, i); var segmentPath = GetSegmentPath(state, playlist, i);
double length; //double length;
if (SegmentLengths.TryGetValue(Path.GetFileName(segmentPath), out length)) //if (SegmentLengths.TryGetValue(Path.GetFileName(segmentPath), out length))
{ //{
Logger.Debug("Found segment length of {0} for index {1}", length, i); // Logger.Debug("Found segment length of {0} for index {1}", length, i);
startSeconds += length; // startSeconds += length;
} //}
else //else
{ //{
startSeconds += state.SegmentLength; // startSeconds += state.SegmentLength;
} //}
startSeconds += state.SegmentLength;
} }
var position = TimeSpan.FromSeconds(startSeconds).Ticks; var position = TimeSpan.FromSeconds(startSeconds).Ticks;
@ -441,7 +442,7 @@ namespace MediaBrowser.Api.Playback.Hls
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
// If all transcoding has completed, just return immediately // If all transcoding has completed, just return immediately
if (transcodingJob != null && transcodingJob.HasExited) if (transcodingJob != null && transcodingJob.HasExited && File.Exists(segmentPath))
{ {
return GetSegmentResult(segmentPath, segmentIndex, segmentLength, transcodingJob); return GetSegmentResult(segmentPath, segmentIndex, segmentLength, transcodingJob);
} }
@ -463,7 +464,11 @@ namespace MediaBrowser.Api.Playback.Hls
// If it appears in the playlist, it's done // If it appears in the playlist, it's done
if (text.IndexOf(segmentFilename, StringComparison.OrdinalIgnoreCase) != -1) if (text.IndexOf(segmentFilename, StringComparison.OrdinalIgnoreCase) != -1)
{ {
return GetSegmentResult(segmentPath, segmentIndex, segmentLength, transcodingJob); if (File.Exists(segmentPath))
{
return GetSegmentResult(segmentPath, segmentIndex, segmentLength, transcodingJob);
}
break;
} }
} }
} }
@ -564,11 +569,11 @@ namespace MediaBrowser.Api.Playback.Hls
builder.AppendLine("#EXTM3U"); builder.AppendLine("#EXTM3U");
var isLiveStream = (state.RunTimeTicks ?? 0) == 0;
var queryStringIndex = Request.RawUrl.IndexOf('?'); var queryStringIndex = Request.RawUrl.IndexOf('?');
var queryString = queryStringIndex == -1 ? string.Empty : Request.RawUrl.Substring(queryStringIndex); var queryString = queryStringIndex == -1 ? string.Empty : Request.RawUrl.Substring(queryStringIndex);
var isLiveStream = (state.RunTimeTicks ?? 0) == 0;
// Main stream // Main stream
var playlistUrl = isLiveStream ? "live.m3u8" : "main.m3u8"; var playlistUrl = isLiveStream ? "live.m3u8" : "main.m3u8";
playlistUrl += queryString; playlistUrl += queryString;
@ -798,7 +803,7 @@ namespace MediaBrowser.Api.Playback.Hls
var audioTranscodeParams = new List<string>(); var audioTranscodeParams = new List<string>();
audioTranscodeParams.Add("-acodec " + codec); audioTranscodeParams.Add("-acodec " + codec);
if (state.OutputAudioBitrate.HasValue) if (state.OutputAudioBitrate.HasValue)
{ {
audioTranscodeParams.Add("-ab " + state.OutputAudioBitrate.Value.ToString(UsCulture)); audioTranscodeParams.Add("-ab " + state.OutputAudioBitrate.Value.ToString(UsCulture));

View File

@ -68,7 +68,7 @@ namespace MediaBrowser.Api
/// <param name="includeInSearch">The include in search.</param> /// <param name="includeInSearch">The include in search.</param>
/// <param name="getSimilarityScore">The get similarity score.</param> /// <param name="getSimilarityScore">The get similarity score.</param>
/// <returns>ItemsResult.</returns> /// <returns>ItemsResult.</returns>
internal static ItemsResult GetSimilarItemsResult(DtoOptions dtoOptions, IUserManager userManager, IItemRepository itemRepository, ILibraryManager libraryManager, IUserDataManager userDataRepository, IDtoService dtoService, ILogger logger, BaseGetSimilarItemsFromItem request, Func<BaseItem, bool> includeInSearch, Func<BaseItem, BaseItem, ILibraryManager, int> getSimilarityScore) internal static ItemsResult GetSimilarItemsResult(DtoOptions dtoOptions, IUserManager userManager, IItemRepository itemRepository, ILibraryManager libraryManager, IUserDataManager userDataRepository, IDtoService dtoService, ILogger logger, BaseGetSimilarItemsFromItem request, Func<BaseItem, bool> includeInSearch, Func<BaseItem, List<PersonInfo>, List<PersonInfo>, BaseItem, int> getSimilarityScore)
{ {
var user = !string.IsNullOrWhiteSpace(request.UserId) ? userManager.GetUserById(request.UserId) : null; var user = !string.IsNullOrWhiteSpace(request.UserId) ? userManager.GetUserById(request.UserId) : null;
@ -110,12 +110,17 @@ namespace MediaBrowser.Api
/// <param name="inputItems">The input items.</param> /// <param name="inputItems">The input items.</param>
/// <param name="getSimilarityScore">The get similarity score.</param> /// <param name="getSimilarityScore">The get similarity score.</param>
/// <returns>IEnumerable{BaseItem}.</returns> /// <returns>IEnumerable{BaseItem}.</returns>
internal static IEnumerable<BaseItem> GetSimilaritems(BaseItem item, ILibraryManager libraryManager, IEnumerable<BaseItem> inputItems, Func<BaseItem, BaseItem, ILibraryManager, int> getSimilarityScore) internal static IEnumerable<BaseItem> GetSimilaritems(BaseItem item, ILibraryManager libraryManager, IEnumerable<BaseItem> inputItems, Func<BaseItem, List<PersonInfo>, List<PersonInfo>, BaseItem, int> getSimilarityScore)
{ {
var itemId = item.Id; var itemId = item.Id;
inputItems = inputItems.Where(i => i.Id != itemId); inputItems = inputItems.Where(i => i.Id != itemId);
var itemPeople = libraryManager.GetPeople(item);
var allPeople = libraryManager.GetPeople(new InternalPeopleQuery
{
AppearsInItemId = item.Id
});
return inputItems.Select(i => new Tuple<BaseItem, int>(i, getSimilarityScore(item, i, libraryManager))) return inputItems.Select(i => new Tuple<BaseItem, int>(i, getSimilarityScore(item, itemPeople, allPeople, i)))
.Where(i => i.Item2 > 2) .Where(i => i.Item2 > 2)
.OrderByDescending(i => i.Item2) .OrderByDescending(i => i.Item2)
.Select(i => i.Item1); .Select(i => i.Item1);
@ -147,9 +152,11 @@ namespace MediaBrowser.Api
/// Gets the similiarity score. /// Gets the similiarity score.
/// </summary> /// </summary>
/// <param name="item1">The item1.</param> /// <param name="item1">The item1.</param>
/// <param name="item1People">The item1 people.</param>
/// <param name="allPeople">All people.</param>
/// <param name="item2">The item2.</param> /// <param name="item2">The item2.</param>
/// <returns>System.Int32.</returns> /// <returns>System.Int32.</returns>
internal static int GetSimiliarityScore(BaseItem item1, BaseItem item2, ILibraryManager libraryManager) internal static int GetSimiliarityScore(BaseItem item1, List<PersonInfo> item1People, List<PersonInfo> allPeople, BaseItem item2)
{ {
var points = 0; var points = 0;
@ -170,11 +177,13 @@ namespace MediaBrowser.Api
// Find common studios // Find common studios
points += item1.Studios.Where(i => item2.Studios.Contains(i, StringComparer.OrdinalIgnoreCase)).Sum(i => 3); points += item1.Studios.Where(i => item2.Studios.Contains(i, StringComparer.OrdinalIgnoreCase)).Sum(i => 3);
var item2PeopleNames = libraryManager.GetPeople(item2).Select(i => i.Name) var item2PeopleNames = allPeople.Where(i => i.ItemId == item2.Id)
.Select(i => i.Name)
.Where(i => !string.IsNullOrWhiteSpace(i))
.DistinctNames() .DistinctNames()
.ToDictionary(i => i, StringComparer.OrdinalIgnoreCase); .ToDictionary(i => i, StringComparer.OrdinalIgnoreCase);
points += libraryManager.GetPeople(item1).Where(i => item2PeopleNames.ContainsKey(i.Name)).Sum(i => 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)) if (string.Equals(i.Type, PersonType.Director, StringComparison.OrdinalIgnoreCase) || string.Equals(i.Role, PersonType.Director, StringComparison.OrdinalIgnoreCase))
{ {

View File

@ -0,0 +1,164 @@
using MediaBrowser.Common.Extensions;
using MediaBrowser.Controller.Dlna;
using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Net;
using MediaBrowser.Controller.Social;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Social;
using ServiceStack;
using System;
using System.IO;
using System.Threading.Tasks;
namespace MediaBrowser.Api.Social
{
[Route("/Social/Shares/{Id}", "GET", Summary = "Gets a share")]
[Authenticated]
public class GetSocialShareInfo : IReturn<SocialShareInfo>
{
[ApiMember(Name = "Id", Description = "The id of the item", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
public string Id { get; set; }
}
[Route("/Social/Shares/Public/{Id}", "GET", Summary = "Gets a share")]
public class GetPublicSocialShareInfo : IReturn<SocialShareInfo>
{
[ApiMember(Name = "Id", Description = "The id of the item", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
public string Id { get; set; }
}
[Route("/Social/Shares/Public/{Id}/Image", "GET", Summary = "Gets a share")]
public class GetShareImage
{
[ApiMember(Name = "Id", Description = "The id of the item", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
public string Id { get; set; }
}
[Route("/Social/Shares", "POST", Summary = "Creates a share")]
[Authenticated]
public class CreateShare : IReturn<SocialShareInfo>
{
[ApiMember(Name = "ItemId", Description = "The id of the item", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")]
public string ItemId { get; set; }
[ApiMember(Name = "UserId", Description = "The user id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")]
public string UserId { get; set; }
}
[Route("/Social/Shares/{Id}", "DELETE", Summary = "Deletes a share")]
[Authenticated]
public class DeleteShare : IReturnVoid
{
[ApiMember(Name = "Id", Description = "The id of the item", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "DELETE")]
public string Id { get; set; }
}
[Route("/Social/Shares/Public/{Id}/Item", "GET", Summary = "Gets a share")]
public class GetSharedLibraryItem
{
[ApiMember(Name = "Id", Description = "The id of the item", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
public string Id { get; set; }
}
public class SharingService : BaseApiService
{
private readonly ISharingManager _sharingManager;
private readonly ILibraryManager _libraryManager;
private readonly IDlnaManager _dlnaManager;
private readonly IDtoService _dtoService;
public SharingService(ISharingManager sharingManager, IDlnaManager dlnaManager, ILibraryManager libraryManager, IDtoService dtoService)
{
_sharingManager = sharingManager;
_dlnaManager = dlnaManager;
_libraryManager = libraryManager;
_dtoService = dtoService;
}
public object Get(GetSocialShareInfo request)
{
var info = _sharingManager.GetShareInfo(request.Id);
return ToOptimizedResult(info);
}
public object Get(GetSharedLibraryItem request)
{
var info = _sharingManager.GetShareInfo(request.Id);
if (info.ExpirationDate <= DateTime.UtcNow)
{
throw new ResourceNotFoundException();
}
var item = _libraryManager.GetItemById(info.ItemId);
var dto = _dtoService.GetBaseItemDto(item, new DtoOptions());
return ToOptimizedResult(dto);
}
public object Get(GetPublicSocialShareInfo request)
{
var info = _sharingManager.GetShareInfo(request.Id);
if (info.ExpirationDate <= DateTime.UtcNow)
{
throw new ResourceNotFoundException();
}
return ToOptimizedResult(info);
}
public async Task<object> Post(CreateShare request)
{
var info = await _sharingManager.CreateShare(request.ItemId, request.UserId).ConfigureAwait(false);
return ToOptimizedResult(info);
}
public void Delete(DeleteShare request)
{
var task = _sharingManager.DeleteShare(request.Id);
Task.WaitAll(task);
}
public object Get(GetShareImage request)
{
var share = _sharingManager.GetShareInfo(request.Id);
if (share == null)
{
throw new ResourceNotFoundException();
}
if (share.ExpirationDate <= DateTime.UtcNow)
{
throw new ResourceNotFoundException();
}
var item = _libraryManager.GetItemById(share.ItemId);
var image = item.GetImageInfo(ImageType.Primary, 0);
if (image != null)
{
return ToStaticFileResult(image.Path);
}
// Grab a dlna icon if nothing else is available
using (var response = _dlnaManager.GetIcon("logo240.jpg"))
{
using (var ms = new MemoryStream())
{
response.Stream.CopyTo(ms);
ms.Position = 0;
var bytes = ms.ToArray();
return ResultFactory.GetResult(bytes, "image/" + response.Format.ToString().ToLower());
}
}
}
}
}

View File

@ -252,6 +252,11 @@ namespace MediaBrowser.Api.UserLibrary
return (PersonIds ?? string.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); return (PersonIds ?? string.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
} }
public string[] GetItemIds()
{
return (Ids ?? string.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
}
public VideoType[] GetVideoTypes() public VideoType[] GetVideoTypes()
{ {
var val = VideoTypes; var val = VideoTypes;
@ -329,54 +334,12 @@ namespace MediaBrowser.Api.UserLibrary
var result = await GetItemsToSerialize(request, user, parentItem).ConfigureAwait(false); var result = await GetItemsToSerialize(request, user, parentItem).ConfigureAwait(false);
var isFiltered = result.Item2;
var dtoOptions = GetDtoOptions(request); var dtoOptions = GetDtoOptions(request);
if (isFiltered)
{
return new ItemsResult
{
TotalRecordCount = result.Item1.TotalRecordCount,
Items = _dtoService.GetBaseItemDtos(result.Item1.Items, dtoOptions, user).ToArray()
};
}
var items = result.Item1.Items.Where(i => ApplyAdditionalFilters(request, i, user, false, _libraryManager));
// Apply filters
// Run them starting with the ones that are likely to reduce the list the most
foreach (var filter in request.GetFilters().OrderByDescending(f => (int)f))
{
items = ApplyFilter(items, filter, user, _userDataRepository);
}
items = UserViewBuilder.FilterVirtualEpisodes(items,
request.IsMissing,
request.IsVirtualUnaired,
request.IsUnaired);
var internalQuery = GetItemsQuery(request, user);
items = UserViewBuilder.CollapseBoxSetItemsIfNeeded(items, internalQuery, parentItem, user);
items = _libraryManager.Sort(items, user, request.GetOrderBy(), request.SortOrder ?? SortOrder.Ascending);
// This must be the last filter
if (!string.IsNullOrEmpty(request.AdjacentTo))
{
items = UserViewBuilder.FilterForAdjacency(items, request.AdjacentTo);
}
var itemsArray = items.ToList();
var pagedItems = ApplyPaging(request, itemsArray);
var returnItems = _dtoService.GetBaseItemDtos(pagedItems, dtoOptions, user).ToArray();
return new ItemsResult return new ItemsResult
{ {
TotalRecordCount = itemsArray.Count, TotalRecordCount = result.Item1.TotalRecordCount,
Items = returnItems Items = _dtoService.GetBaseItemDtos(result.Item1.Items, dtoOptions, user).ToArray()
}; };
} }
@ -394,45 +357,46 @@ namespace MediaBrowser.Api.UserLibrary
parentItem; parentItem;
// Default list type = children // Default list type = children
IEnumerable<BaseItem> items;
if (!string.IsNullOrEmpty(request.Ids)) if (!string.IsNullOrEmpty(request.Ids))
{ {
var idList = request.Ids.Split(',').ToList(); request.Recursive = true;
var result = await ((Folder)item).GetItems(GetItemsQuery(request, user)).ConfigureAwait(false);
items = idList.Select(i => _libraryManager.GetItemById(i)); return new Tuple<QueryResult<BaseItem>, bool>(result, true);
} }
else if (request.Recursive) if (request.Recursive)
{ {
var result = await ((Folder)item).GetItems(GetItemsQuery(request, user)).ConfigureAwait(false); var result = await ((Folder)item).GetItems(GetItemsQuery(request, user)).ConfigureAwait(false);
return new Tuple<QueryResult<BaseItem>, bool>(result, true); return new Tuple<QueryResult<BaseItem>, bool>(result, true);
} }
else
if (user == null)
{ {
if (user == null) var result = await ((Folder)item).GetItems(GetItemsQuery(request, null)).ConfigureAwait(false);
{
var result = await ((Folder)item).GetItems(GetItemsQuery(request, null)).ConfigureAwait(false);
return new Tuple<QueryResult<BaseItem>, bool>(result, true); return new Tuple<QueryResult<BaseItem>, bool>(result, true);
}
var userRoot = item as UserRootFolder;
if (userRoot == null)
{
var result = await ((Folder)item).GetItems(GetItemsQuery(request, user)).ConfigureAwait(false);
return new Tuple<QueryResult<BaseItem>, bool>(result, true);
}
items = ((Folder)item).GetChildren(user, true);
} }
var userRoot = item as UserRootFolder;
if (userRoot == null)
{
var result = await ((Folder)item).GetItems(GetItemsQuery(request, user)).ConfigureAwait(false);
return new Tuple<QueryResult<BaseItem>, bool>(result, true);
}
IEnumerable<BaseItem> items = ((Folder)item).GetChildren(user, true);
var itemsArray = items.ToArray();
return new Tuple<QueryResult<BaseItem>, bool>(new QueryResult<BaseItem> return new Tuple<QueryResult<BaseItem>, bool>(new QueryResult<BaseItem>
{ {
Items = items.ToArray() Items = itemsArray,
TotalRecordCount = itemsArray.Length
}, false); }, false);
} }
@ -450,7 +414,7 @@ namespace MediaBrowser.Api.UserLibrary
SortBy = request.GetOrderBy(), SortBy = request.GetOrderBy(),
SortOrder = request.SortOrder ?? SortOrder.Ascending, SortOrder = request.SortOrder ?? SortOrder.Ascending,
Filter = i => ApplyAdditionalFilters(request, i, user, true, _libraryManager), Filter = i => ApplyAdditionalFilters(request, i, user, _libraryManager),
Limit = request.Limit, Limit = request.Limit,
StartIndex = request.StartIndex, StartIndex = request.StartIndex,
@ -490,7 +454,12 @@ namespace MediaBrowser.Api.UserLibrary
Years = request.GetYears(), Years = request.GetYears(),
ImageTypes = request.GetImageTypes().ToArray(), ImageTypes = request.GetImageTypes().ToArray(),
VideoTypes = request.GetVideoTypes().ToArray(), VideoTypes = request.GetVideoTypes().ToArray(),
AdjacentTo = request.AdjacentTo AdjacentTo = request.AdjacentTo,
ItemIds = request.GetItemIds(),
MinPlayers = request.MinPlayers,
MaxPlayers = request.MaxPlayers,
MinCommunityRating = request.MinCommunityRating,
MinCriticRating = request.MinCriticRating
}; };
if (!string.IsNullOrWhiteSpace(request.Ids)) if (!string.IsNullOrWhiteSpace(request.Ids))
@ -619,440 +588,8 @@ namespace MediaBrowser.Api.UserLibrary
return items; return items;
} }
private bool ApplyAdditionalFilters(GetItems request, BaseItem i, User user, bool isPreFiltered, ILibraryManager libraryManager) private bool ApplyAdditionalFilters(GetItems request, BaseItem i, User user, ILibraryManager libraryManager)
{ {
var video = i as Video;
if (!isPreFiltered)
{
var mediaTypes = request.GetMediaTypes();
if (mediaTypes.Length > 0)
{
if (!(!string.IsNullOrEmpty(i.MediaType) && mediaTypes.Contains(i.MediaType, StringComparer.OrdinalIgnoreCase)))
{
return false;
}
}
if (request.IsPlayed.HasValue)
{
var val = request.IsPlayed.Value;
if (i.IsPlayed(user) != val)
{
return false;
}
}
// Exclude item types
var excluteItemTypes = request.GetExcludeItemTypes();
if (excluteItemTypes.Length > 0 && excluteItemTypes.Contains(i.GetType().Name, StringComparer.OrdinalIgnoreCase))
{
return false;
}
// Include item types
var includeItemTypes = request.GetIncludeItemTypes();
if (includeItemTypes.Length > 0 && !includeItemTypes.Contains(i.GetType().Name, StringComparer.OrdinalIgnoreCase))
{
return false;
}
if (request.IsInBoxSet.HasValue)
{
var val = request.IsInBoxSet.Value;
if (i.Parents.OfType<BoxSet>().Any() != val)
{
return false;
}
}
// Filter by Video3DFormat
if (request.Is3D.HasValue)
{
var val = request.Is3D.Value;
if (video == null || val != video.Video3DFormat.HasValue)
{
return false;
}
}
if (request.IsHD.HasValue)
{
var val = request.IsHD.Value;
if (video == null || val != video.IsHD)
{
return false;
}
}
if (request.IsUnidentified.HasValue)
{
var val = request.IsUnidentified.Value;
if (i.IsUnidentified != val)
{
return false;
}
}
if (request.IsLocked.HasValue)
{
var val = request.IsLocked.Value;
if (i.IsLocked != val)
{
return false;
}
}
if (request.HasOverview.HasValue)
{
var filterValue = request.HasOverview.Value;
var hasValue = !string.IsNullOrEmpty(i.Overview);
if (hasValue != filterValue)
{
return false;
}
}
if (request.HasImdbId.HasValue)
{
var filterValue = request.HasImdbId.Value;
var hasValue = !string.IsNullOrEmpty(i.GetProviderId(MetadataProviders.Imdb));
if (hasValue != filterValue)
{
return false;
}
}
if (request.HasTmdbId.HasValue)
{
var filterValue = request.HasTmdbId.Value;
var hasValue = !string.IsNullOrEmpty(i.GetProviderId(MetadataProviders.Tmdb));
if (hasValue != filterValue)
{
return false;
}
}
if (request.HasTvdbId.HasValue)
{
var filterValue = request.HasTvdbId.Value;
var hasValue = !string.IsNullOrEmpty(i.GetProviderId(MetadataProviders.Tvdb));
if (hasValue != filterValue)
{
return false;
}
}
if (request.IsYearMismatched.HasValue)
{
var filterValue = request.IsYearMismatched.Value;
if (UserViewBuilder.IsYearMismatched(i, libraryManager) != filterValue)
{
return false;
}
}
if (request.HasOfficialRating.HasValue)
{
var filterValue = request.HasOfficialRating.Value;
var hasValue = !string.IsNullOrEmpty(i.OfficialRating);
if (hasValue != filterValue)
{
return false;
}
}
if (request.IsPlaceHolder.HasValue)
{
var filterValue = request.IsPlaceHolder.Value;
var isPlaceHolder = false;
var hasPlaceHolder = i as ISupportsPlaceHolders;
if (hasPlaceHolder != null)
{
isPlaceHolder = hasPlaceHolder.IsPlaceHolder;
}
if (isPlaceHolder != filterValue)
{
return false;
}
}
if (request.HasSpecialFeature.HasValue)
{
var filterValue = request.HasSpecialFeature.Value;
var movie = i as IHasSpecialFeatures;
if (movie != null)
{
var ok = filterValue
? movie.SpecialFeatureIds.Count > 0
: movie.SpecialFeatureIds.Count == 0;
if (!ok)
{
return false;
}
}
else
{
return false;
}
}
if (request.HasSubtitles.HasValue)
{
var val = request.HasSubtitles.Value;
if (video == null || val != video.HasSubtitles)
{
return false;
}
}
if (request.HasParentalRating.HasValue)
{
var val = request.HasParentalRating.Value;
var rating = i.CustomRating;
if (string.IsNullOrEmpty(rating))
{
rating = i.OfficialRating;
}
if (val)
{
if (string.IsNullOrEmpty(rating))
{
return false;
}
}
else
{
if (!string.IsNullOrEmpty(rating))
{
return false;
}
}
}
if (request.HasTrailer.HasValue)
{
var val = request.HasTrailer.Value;
var trailerCount = 0;
var hasTrailers = i as IHasTrailers;
if (hasTrailers != null)
{
trailerCount = hasTrailers.GetTrailerIds().Count;
}
var ok = val ? trailerCount > 0 : trailerCount == 0;
if (!ok)
{
return false;
}
}
if (request.HasThemeSong.HasValue)
{
var filterValue = request.HasThemeSong.Value;
var themeCount = 0;
var iHasThemeMedia = i as IHasThemeMedia;
if (iHasThemeMedia != null)
{
themeCount = iHasThemeMedia.ThemeSongIds.Count;
}
var ok = filterValue ? themeCount > 0 : themeCount == 0;
if (!ok)
{
return false;
}
}
if (request.HasThemeVideo.HasValue)
{
var filterValue = request.HasThemeVideo.Value;
var themeCount = 0;
var iHasThemeMedia = i as IHasThemeMedia;
if (iHasThemeMedia != null)
{
themeCount = iHasThemeMedia.ThemeVideoIds.Count;
}
var ok = filterValue ? themeCount > 0 : themeCount == 0;
if (!ok)
{
return false;
}
}
// Apply tag filter
var tags = request.GetTags();
if (tags.Length > 0)
{
var hasTags = i as IHasTags;
if (hasTags == null)
{
return false;
}
if (!(tags.Any(v => hasTags.Tags.Contains(v, StringComparer.OrdinalIgnoreCase))))
{
return false;
}
}
// Apply official rating filter
var officialRatings = request.GetOfficialRatings();
if (officialRatings.Length > 0 && !officialRatings.Contains(i.OfficialRating ?? string.Empty))
{
return false;
}
// Apply genre filter
var genres = request.GetGenres();
if (genres.Length > 0 && !(genres.Any(v => i.Genres.Contains(v, StringComparer.OrdinalIgnoreCase))))
{
return false;
}
// Filter by VideoType
var videoTypes = request.GetVideoTypes();
if (videoTypes.Length > 0 && (video == null || !videoTypes.Contains(video.VideoType)))
{
return false;
}
var imageTypes = request.GetImageTypes().ToList();
if (imageTypes.Count > 0)
{
if (!(imageTypes.Any(i.HasImage)))
{
return false;
}
}
// Apply studio filter
var studios = request.GetStudios();
if (studios.Length > 0 && !studios.Any(v => i.Studios.Contains(v, StringComparer.OrdinalIgnoreCase)))
{
return false;
}
// Apply studio filter
var studioIds = request.GetStudioIds();
if (studioIds.Length > 0 && !studioIds.Any(id =>
{
var studioItem = libraryManager.GetItemById(id);
return studioItem != null && i.Studios.Contains(studioItem.Name, StringComparer.OrdinalIgnoreCase);
}))
{
return false;
}
// Apply year filter
var years = request.GetYears();
if (years.Length > 0 && !(i.ProductionYear.HasValue && years.Contains(i.ProductionYear.Value)))
{
return false;
}
// Apply person filter
var personIds = request.GetPersonIds();
if (personIds.Length > 0)
{
var names = personIds
.Select(libraryManager.GetItemById)
.Select(p => p == null ? "-1" : p.Name)
.ToList();
if (!(names.Any(v => libraryManager.GetPeople(i).Select(p => p.Name).Contains(v, StringComparer.OrdinalIgnoreCase))))
{
return false;
}
}
// Apply person filter
if (!string.IsNullOrEmpty(request.Person))
{
var personTypes = request.GetPersonTypes();
if (personTypes.Length == 0)
{
if (!(libraryManager.GetPeople(i).Any(p => string.Equals(p.Name, request.Person, StringComparison.OrdinalIgnoreCase))))
{
return false;
}
}
else
{
var types = personTypes;
var ok = new[] { i }.Any(item =>
libraryManager.GetPeople(item).Any(p =>
p.Name.Equals(request.Person, StringComparison.OrdinalIgnoreCase) && (types.Contains(p.Type, StringComparer.OrdinalIgnoreCase) || types.Contains(p.Role, StringComparer.OrdinalIgnoreCase))));
if (!ok)
{
return false;
}
}
}
}
if (request.MinCommunityRating.HasValue)
{
var val = request.MinCommunityRating.Value;
if (!(i.CommunityRating.HasValue && i.CommunityRating >= val))
{
return false;
}
}
if (request.MinCriticRating.HasValue)
{
var val = request.MinCriticRating.Value;
var hasCriticRating = i as IHasCriticRating;
if (hasCriticRating != null)
{
if (!(hasCriticRating.CriticRating.HasValue && hasCriticRating.CriticRating >= val))
{
return false;
}
}
else
{
return false;
}
}
// Artists // Artists
if (!string.IsNullOrEmpty(request.ArtistIds)) if (!string.IsNullOrEmpty(request.ArtistIds))
{ {
@ -1239,52 +776,6 @@ namespace MediaBrowser.Api.UserLibrary
} }
} }
if (request.MinPlayers.HasValue)
{
var filterValue = request.MinPlayers.Value;
var game = i as Game;
if (game != null)
{
var players = game.PlayersSupported ?? 1;
var ok = players >= filterValue;
if (!ok)
{
return false;
}
}
else
{
return false;
}
}
if (request.MaxPlayers.HasValue)
{
var filterValue = request.MaxPlayers.Value;
var game = i as Game;
if (game != null)
{
var players = game.PlayersSupported ?? 1;
var ok = players <= filterValue;
if (!ok)
{
return false;
}
}
else
{
return false;
}
}
if (request.ParentIndexNumber.HasValue) if (request.ParentIndexNumber.HasValue)
{ {
var filterValue = request.ParentIndexNumber.Value; var filterValue = request.ParentIndexNumber.Value;
@ -1347,29 +838,6 @@ namespace MediaBrowser.Api.UserLibrary
return true; return true;
} }
/// <summary>
/// Applies the paging.
/// </summary>
/// <param name="request">The request.</param>
/// <param name="items">The items.</param>
/// <returns>IEnumerable{BaseItem}.</returns>
private IEnumerable<BaseItem> ApplyPaging(GetItems request, IEnumerable<BaseItem> items)
{
// Start at
if (request.StartIndex.HasValue)
{
items = items.Skip(request.StartIndex.Value);
}
// Return limit
if (request.Limit.HasValue)
{
items = items.Take(request.Limit.Value);
}
return items;
}
} }
/// <summary> /// <summary>

View File

@ -5,7 +5,6 @@ using MediaBrowser.Controller.Net;
using MediaBrowser.Controller.Persistence; using MediaBrowser.Controller.Persistence;
using MediaBrowser.Model.Dto; using MediaBrowser.Model.Dto;
using ServiceStack; using ServiceStack;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -151,18 +150,16 @@ namespace MediaBrowser.Api.UserLibrary
/// <param name="itemsList">The items list.</param> /// <param name="itemsList">The items list.</param>
/// <param name="personTypes">The person types.</param> /// <param name="personTypes">The person types.</param>
/// <returns>IEnumerable{PersonInfo}.</returns> /// <returns>IEnumerable{PersonInfo}.</returns>
private IEnumerable<PersonInfo> GetAllPeople(IEnumerable<BaseItem> itemsList, string[] personTypes) private IEnumerable<PersonInfo> GetAllPeople(IEnumerable<BaseItem> itemsList, IEnumerable<string> personTypes)
{ {
var people = itemsList.SelectMany(i => LibraryManager.GetPeople(i).OrderBy(p => p.SortOrder ?? int.MaxValue).ThenBy(p => p.Type)); var allIds = itemsList.Select(i => i.Id).ToList();
if (personTypes.Length > 0) var allPeople = LibraryManager.GetPeople(new InternalPeopleQuery
{ {
people = people.Where(p => PersonTypes = personTypes.ToList()
personTypes.Contains(p.Type ?? string.Empty, StringComparer.OrdinalIgnoreCase) || });
personTypes.Contains(p.Role ?? string.Empty, StringComparer.OrdinalIgnoreCase));
}
return people; return allPeople.Where(i => allIds.Contains(i.ItemId)).OrderBy(p => p.SortOrder ?? int.MaxValue).ThenBy(p => p.Type);
} }
} }
} }

View File

@ -85,6 +85,13 @@ namespace MediaBrowser.Common.Implementations.Logging
{ {
rule.EnableLoggingForLevel(level); rule.EnableLoggingForLevel(level);
} }
foreach (var lev in rule.Levels.ToArray())
{
if (lev < level)
{
rule.DisableLoggingForLevel(lev);
}
}
} }
} }

View File

@ -195,7 +195,7 @@ namespace MediaBrowser.Common.Implementations.Updates
cacheLength = TimeSpan.FromMinutes(3); cacheLength = TimeSpan.FromMinutes(3);
break; break;
default: default:
cacheLength = TimeSpan.FromHours(3); cacheLength = TimeSpan.FromHours(24);
break; break;
} }

View File

@ -235,6 +235,15 @@ namespace MediaBrowser.Controller.Entities
} }
} }
[IgnoreDataMember]
public virtual bool EnableAlphaNumericSorting
{
get
{
return true;
}
}
/// <summary> /// <summary>
/// This is just a helper for convenience /// This is just a helper for convenience
/// </summary> /// </summary>
@ -439,6 +448,11 @@ namespace MediaBrowser.Controller.Entities
{ {
if (Name == null) return null; //some items may not have name filled in properly if (Name == null) return null; //some items may not have name filled in properly
if (!EnableAlphaNumericSorting)
{
return Name.TrimStart();
}
var sortable = Name.Trim().ToLower(); var sortable = Name.Trim().ToLower();
sortable = ConfigurationManager.Configuration.SortRemoveCharacters.Aggregate(sortable, (current, search) => current.Replace(search.ToLower(), string.Empty)); sortable = ConfigurationManager.Configuration.SortRemoveCharacters.Aggregate(sortable, (current, search) => current.Replace(search.ToLower(), string.Empty));
@ -464,12 +478,37 @@ namespace MediaBrowser.Controller.Entities
return sortable; return sortable;
} }
public Guid ParentId { get; set; }
private Folder _parent;
/// <summary> /// <summary>
/// Gets or sets the parent. /// Gets or sets the parent.
/// </summary> /// </summary>
/// <value>The parent.</value> /// <value>The parent.</value>
[IgnoreDataMember] public Folder Parent
public Folder Parent { get; set; } {
get
{
if (_parent != null)
{
return _parent;
}
if (ParentId != Guid.Empty)
{
return LibraryManager.GetItemById(ParentId) as Folder;
}
return null;
}
set { _parent = value; }
}
public void SetParent(Folder parent)
{
Parent = parent;
ParentId = parent == null ? Guid.Empty : parent.Id;
}
[IgnoreDataMember] [IgnoreDataMember]
public IEnumerable<Folder> Parents public IEnumerable<Folder> Parents

View File

@ -134,7 +134,7 @@ namespace MediaBrowser.Controller.Entities
/// <exception cref="System.InvalidOperationException">Unable to add + item.Name</exception> /// <exception cref="System.InvalidOperationException">Unable to add + item.Name</exception>
public async Task AddChild(BaseItem item, CancellationToken cancellationToken) public async Task AddChild(BaseItem item, CancellationToken cancellationToken)
{ {
item.Parent = this; item.SetParent(this);
if (item.Id == Guid.Empty) if (item.Id == Guid.Empty)
{ {
@ -230,7 +230,7 @@ namespace MediaBrowser.Controller.Entities
{ {
RemoveChildrenInternal(new[] { item }); RemoveChildrenInternal(new[] { item });
item.Parent = null; item.SetParent(null);
return ItemRepository.SaveChildren(Id, ActualChildren.Select(i => i.Id).ToList(), cancellationToken); return ItemRepository.SaveChildren(Id, ActualChildren.Select(i => i.Id).ToList(), cancellationToken);
} }
@ -783,11 +783,11 @@ namespace MediaBrowser.Controller.Entities
return LibraryManager.GetOrAddByReferenceItem(item); return LibraryManager.GetOrAddByReferenceItem(item);
} }
item.Parent = this; item.SetParent(this);
} }
else else
{ {
child.Parent = this; child.SetParent(this);
LibraryManager.RegisterItem(child); LibraryManager.RegisterItem(child);
item = child; item = child;
} }

View File

@ -6,7 +6,7 @@ namespace MediaBrowser.Controller.Entities
/// <summary> /// <summary>
/// Marker interface /// Marker interface
/// </summary> /// </summary>
public interface IItemByName public interface IItemByName : IHasMetadata
{ {
/// <summary> /// <summary>
/// Gets the tagged items. /// Gets the tagged items.

View File

@ -1,4 +1,5 @@
using MediaBrowser.Model.Entities; using System.Collections.Generic;
using MediaBrowser.Model.Entities;
using System; using System;
namespace MediaBrowser.Controller.Entities namespace MediaBrowser.Controller.Entities
@ -42,6 +43,7 @@ namespace MediaBrowser.Controller.Entities
public string Person { get; set; } public string Person { get; set; }
public string[] PersonIds { get; set; } public string[] PersonIds { get; set; }
public string[] ItemIds { get; set; }
public string AdjacentTo { get; set; } public string AdjacentTo { get; set; }
public string[] PersonTypes { get; set; } public string[] PersonTypes { get; set; }
@ -82,9 +84,16 @@ namespace MediaBrowser.Controller.Entities
public bool? IsMovie { get; set; } public bool? IsMovie { get; set; }
public bool? IsSports { get; set; } public bool? IsSports { get; set; }
public bool? IsKids { get; set; } public bool? IsKids { get; set; }
public int? MinPlayers { get; set; }
public int? MaxPlayers { get; set; }
public double? MinCriticRating { get; set; }
public double? MinCommunityRating { get; set; }
public string[] ChannelIds { get; set; } public string[] ChannelIds { get; set; }
internal List<Guid> ItemIdsFromPersonFilters { get; set; }
public InternalItemsQuery() public InternalItemsQuery()
{ {
Tags = new string[] { }; Tags = new string[] { };
@ -102,6 +111,7 @@ namespace MediaBrowser.Controller.Entities
PersonTypes = new string[] { }; PersonTypes = new string[] { };
PersonIds = new string[] { }; PersonIds = new string[] { };
ChannelIds = new string[] { }; ChannelIds = new string[] { };
ItemIds = new string[] { };
} }
} }
} }

View File

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
namespace MediaBrowser.Controller.Entities
{
public class InternalPeopleQuery
{
public Guid ItemId { get; set; }
public List<string> PersonTypes { get; set; }
public List<string> ExcludePersonTypes { get; set; }
public int? MaxListOrder { get; set; }
public Guid AppearsInItemId { get; set; }
public string NameContains { get; set; }
public InternalPeopleQuery()
{
PersonTypes = new List<string>();
ExcludePersonTypes = new List<string>();
}
}
}

View File

@ -55,6 +55,15 @@ namespace MediaBrowser.Controller.Entities
return true; return true;
} }
[IgnoreDataMember]
public override bool EnableAlphaNumericSorting
{
get
{
return false;
}
}
/// <summary> /// <summary>
/// Gets a value indicating whether this instance is owned item. /// Gets a value indicating whether this instance is owned item.
/// </summary> /// </summary>
@ -70,7 +79,12 @@ namespace MediaBrowser.Controller.Entities
public IEnumerable<BaseItem> GetTaggedItems(IEnumerable<BaseItem> inputItems) public IEnumerable<BaseItem> GetTaggedItems(IEnumerable<BaseItem> inputItems)
{ {
return inputItems.Where(GetItemFilter()); var itemsWithPerson = LibraryManager.GetItemIds(new InternalItemsQuery
{
Person = Name
});
return inputItems.Where(i => itemsWithPerson.Contains(i.Id));
} }
@ -94,6 +108,8 @@ namespace MediaBrowser.Controller.Entities
/// </summary> /// </summary>
public class PersonInfo public class PersonInfo
{ {
public Guid ItemId { get; set; }
/// <summary> /// <summary>
/// Gets or sets the name. /// Gets or sets the name.
/// </summary> /// </summary>

View File

@ -1116,6 +1116,11 @@ namespace MediaBrowser.Controller.Entities
return false; return false;
} }
if (request.ItemIds.Length > 0)
{
return false;
}
if (request.Studios.Length > 0) if (request.Studios.Length > 0)
{ {
return false; return false;
@ -1146,6 +1151,26 @@ namespace MediaBrowser.Controller.Entities
return false; return false;
} }
if (request.MinPlayers.HasValue)
{
return false;
}
if (request.MaxPlayers.HasValue)
{
return false;
}
if (request.MinCommunityRating.HasValue)
{
return false;
}
if (request.MinCriticRating.HasValue)
{
return false;
}
return true; return true;
} }
@ -1304,6 +1329,41 @@ namespace MediaBrowser.Controller.Entities
public static bool Filter(BaseItem item, User user, InternalItemsQuery query, IUserDataManager userDataManager, ILibraryManager libraryManager) public static bool Filter(BaseItem item, User user, InternalItemsQuery query, IUserDataManager userDataManager, ILibraryManager libraryManager)
{ {
if (query.ItemIdsFromPersonFilters == null)
{
if (query.PersonIds.Length > 0)
{
var names = query.PersonIds
.Select(libraryManager.GetItemById)
.Select(i => i == null ? null : i.Name)
.Where(i => !string.IsNullOrWhiteSpace(i))
.ToList();
var itemIdList = new List<Guid>();
foreach (var name in names)
{
itemIdList.AddRange(libraryManager.GetItemIds(new InternalItemsQuery
{
Person = name
}));
}
query.ItemIdsFromPersonFilters = itemIdList;
}
// Apply person filter
else if (!string.IsNullOrWhiteSpace(query.Person))
{
var itemIdList = new List<Guid>();
itemIdList.AddRange(libraryManager.GetItemIds(new InternalItemsQuery
{
Person = query.Person,
PersonTypes = query.PersonTypes
}));
query.ItemIdsFromPersonFilters = itemIdList;
}
}
if (query.MediaTypes.Length > 0 && !query.MediaTypes.Contains(item.MediaType ?? string.Empty, StringComparer.OrdinalIgnoreCase)) if (query.MediaTypes.Length > 0 && !query.MediaTypes.Contains(item.MediaType ?? string.Empty, StringComparer.OrdinalIgnoreCase))
{ {
return false; return false;
@ -1691,45 +1751,20 @@ namespace MediaBrowser.Controller.Entities
return false; return false;
} }
// Apply person filter if (query.ItemIds.Length > 0)
if (query.PersonIds.Length > 0)
{ {
var names = query.PersonIds if (!query.ItemIds.Contains(item.Id.ToString("N"), StringComparer.OrdinalIgnoreCase))
.Select(libraryManager.GetItemById)
.Select(i => i == null ? "-1" : i.Name)
.ToList();
if (!(names.Any(
v => libraryManager.GetPeople(item).Select(i => i.Name).Contains(v, StringComparer.OrdinalIgnoreCase))))
{ {
return false; return false;
} }
} }
// Apply person filter // Apply person filter
if (!string.IsNullOrWhiteSpace(query.Person)) if (query.ItemIdsFromPersonFilters != null)
{ {
var personTypes = query.PersonTypes; if (!query.ItemIdsFromPersonFilters.Contains(item.Id))
if (personTypes.Length == 0)
{ {
if (!(libraryManager.GetPeople(item).Any(p => string.Equals(p.Name, query.Person, StringComparison.OrdinalIgnoreCase)))) return false;
{
return false;
}
}
else
{
var types = personTypes;
var ok = new[] { item }.Any(i =>
libraryManager.GetPeople(i).Any(p =>
string.Equals(p.Name, query.Person, StringComparison.OrdinalIgnoreCase) && (types.Contains(p.Type ?? string.Empty, StringComparer.OrdinalIgnoreCase) || types.Contains(p.Role ?? string.Empty, StringComparer.OrdinalIgnoreCase))));
if (!ok)
{
return false;
}
} }
} }
@ -1748,6 +1783,81 @@ namespace MediaBrowser.Controller.Entities
} }
} }
if (query.MinPlayers.HasValue)
{
var filterValue = query.MinPlayers.Value;
var game = item as Game;
if (game != null)
{
var players = game.PlayersSupported ?? 1;
var ok = players >= filterValue;
if (!ok)
{
return false;
}
}
else
{
return false;
}
}
if (query.MaxPlayers.HasValue)
{
var filterValue = query.MaxPlayers.Value;
var game = item as Game;
if (game != null)
{
var players = game.PlayersSupported ?? 1;
var ok = players <= filterValue;
if (!ok)
{
return false;
}
}
else
{
return false;
}
}
if (query.MinCommunityRating.HasValue)
{
var val = query.MinCommunityRating.Value;
if (!(item.CommunityRating.HasValue && item.CommunityRating >= val))
{
return false;
}
}
if (query.MinCriticRating.HasValue)
{
var val = query.MinCriticRating.Value;
var hasCriticRating = item as IHasCriticRating;
if (hasCriticRating != null)
{
if (!(hasCriticRating.CriticRating.HasValue && hasCriticRating.CriticRating >= val))
{
return false;
}
}
else
{
return false;
}
}
return true; return true;
} }

View File

@ -420,6 +420,20 @@ namespace MediaBrowser.Controller.Library
/// <returns>List&lt;PersonInfo&gt;.</returns> /// <returns>List&lt;PersonInfo&gt;.</returns>
List<PersonInfo> GetPeople(BaseItem item); List<PersonInfo> GetPeople(BaseItem item);
/// <summary>
/// Gets the people.
/// </summary>
/// <param name="query">The query.</param>
/// <returns>List&lt;PersonInfo&gt;.</returns>
List<PersonInfo> GetPeople(InternalPeopleQuery query);
/// <summary>
/// Gets the people items.
/// </summary>
/// <param name="query">The query.</param>
/// <returns>List&lt;Person&gt;.</returns>
List<Person> GetPeopleItems(InternalPeopleQuery query);
/// <summary> /// <summary>
/// Gets all people names. /// Gets all people names.
/// </summary> /// </summary>
@ -433,5 +447,19 @@ namespace MediaBrowser.Controller.Library
/// <param name="people">The people.</param> /// <param name="people">The people.</param>
/// <returns>Task.</returns> /// <returns>Task.</returns>
Task UpdatePeople(BaseItem item, List<PersonInfo> people); Task UpdatePeople(BaseItem item, List<PersonInfo> people);
/// <summary>
/// Gets the item ids.
/// </summary>
/// <param name="query">The query.</param>
/// <returns>List&lt;Guid&gt;.</returns>
List<Guid> GetItemIds(InternalItemsQuery query);
/// <summary>
/// Gets the people names.
/// </summary>
/// <param name="query">The query.</param>
/// <returns>List&lt;System.String&gt;.</returns>
List<string> GetPeopleNames(InternalPeopleQuery query);
} }
} }

View File

@ -166,6 +166,7 @@
<Compile Include="Entities\ImageSourceInfo.cs" /> <Compile Include="Entities\ImageSourceInfo.cs" />
<Compile Include="Entities\IMetadataContainer.cs" /> <Compile Include="Entities\IMetadataContainer.cs" />
<Compile Include="Entities\InternalItemsQuery.cs" /> <Compile Include="Entities\InternalItemsQuery.cs" />
<Compile Include="Entities\InternalPeopleQuery.cs" />
<Compile Include="Entities\ISupportsBoxSetGrouping.cs" /> <Compile Include="Entities\ISupportsBoxSetGrouping.cs" />
<Compile Include="Entities\ISupportsPlaceHolders.cs" /> <Compile Include="Entities\ISupportsPlaceHolders.cs" />
<Compile Include="Entities\ItemImageInfo.cs" /> <Compile Include="Entities\ItemImageInfo.cs" />
@ -329,6 +330,7 @@
<Compile Include="Security\IAuthenticationRepository.cs" /> <Compile Include="Security\IAuthenticationRepository.cs" />
<Compile Include="Security\IEncryptionManager.cs" /> <Compile Include="Security\IEncryptionManager.cs" />
<Compile Include="Session\AuthenticationRequest.cs" /> <Compile Include="Session\AuthenticationRequest.cs" />
<Compile Include="Social\ISharingManager.cs" />
<Compile Include="Subtitles\ISubtitleManager.cs" /> <Compile Include="Subtitles\ISubtitleManager.cs" />
<Compile Include="Subtitles\ISubtitleProvider.cs" /> <Compile Include="Subtitles\ISubtitleProvider.cs" />
<Compile Include="Providers\ItemIdentifier.cs" /> <Compile Include="Providers\ItemIdentifier.cs" />

View File

@ -151,9 +151,9 @@ namespace MediaBrowser.Controller.Persistence
/// <summary> /// <summary>
/// Gets the people. /// Gets the people.
/// </summary> /// </summary>
/// <param name="itemId">The item identifier.</param> /// <param name="query">The query.</param>
/// <returns>List&lt;PersonInfo&gt;.</returns> /// <returns>List&lt;PersonInfo&gt;.</returns>
List<PersonInfo> GetPeople(Guid itemId); List<PersonInfo> GetPeople(InternalPeopleQuery query);
/// <summary> /// <summary>
/// Updates the people. /// Updates the people.
@ -162,6 +162,13 @@ namespace MediaBrowser.Controller.Persistence
/// <param name="people">The people.</param> /// <param name="people">The people.</param>
/// <returns>Task.</returns> /// <returns>Task.</returns>
Task UpdatePeople(Guid itemId, List<PersonInfo> people); Task UpdatePeople(Guid itemId, List<PersonInfo> people);
/// <summary>
/// Gets the people names.
/// </summary>
/// <param name="query">The query.</param>
/// <returns>List&lt;System.String&gt;.</returns>
List<string> GetPeopleNames(InternalPeopleQuery query);
} }
} }

View File

@ -0,0 +1,28 @@
using MediaBrowser.Model.Social;
using System.Threading.Tasks;
namespace MediaBrowser.Controller.Social
{
public interface ISharingManager
{
/// <summary>
/// Creates the share.
/// </summary>
/// <param name="itemId">The item identifier.</param>
/// <param name="userId">The user identifier.</param>
/// <returns>Task&lt;SocialShareInfo&gt;.</returns>
Task<SocialShareInfo> CreateShare(string itemId, string userId);
/// <summary>
/// Gets the share information.
/// </summary>
/// <param name="id">The identifier.</param>
/// <returns>SocialShareInfo.</returns>
SocialShareInfo GetShareInfo(string id);
/// <summary>
/// Deletes the share.
/// </summary>
/// <param name="id">The identifier.</param>
/// <returns>Task.</returns>
Task DeleteShare(string id);
}
}

View File

@ -49,4 +49,18 @@ namespace MediaBrowser.Controller.Sync
/// <returns>Task&lt;QueryResult&lt;FileMetadata&gt;&gt;.</returns> /// <returns>Task&lt;QueryResult&lt;FileMetadata&gt;&gt;.</returns>
Task<QueryResult<FileMetadata>> GetFiles(FileQuery query, SyncTarget target, CancellationToken cancellationToken); Task<QueryResult<FileMetadata>> GetFiles(FileQuery query, SyncTarget target, CancellationToken cancellationToken);
} }
public interface ISupportsDirectCopy
{
/// <summary>
/// Sends the file.
/// </summary>
/// <param name="path">The path.</param>
/// <param name="pathParts">The path parts.</param>
/// <param name="target">The target.</param>
/// <param name="progress">The progress.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task&lt;SyncedFileInfo&gt;.</returns>
Task<SyncedFileInfo> SendFile(string path, string[] pathParts, SyncTarget target, IProgress<double> progress, CancellationToken cancellationToken);
}
} }

View File

@ -410,18 +410,11 @@ namespace MediaBrowser.Dlna.ContentDirectory
{ {
if (stubType.Value == StubType.People) if (stubType.Value == StubType.People)
{ {
var items = _libraryManager.GetPeople(item).Select(i => var items = _libraryManager.GetPeopleItems(new InternalPeopleQuery
{ {
try ItemId = item.Id
{
return _libraryManager.GetPerson(i.Name);
}
catch
{
return null;
}
}).Where(i => i != null).ToArray(); }).ToArray();
var result = new QueryResult<ServerItem> var result = new QueryResult<ServerItem>
{ {
@ -443,7 +436,7 @@ namespace MediaBrowser.Dlna.ContentDirectory
var person = item as Person; var person = item as Person;
if (person != null) if (person != null)
{ {
return await GetItemsFromPerson(person, user, startIndex, limit).ConfigureAwait(false); return GetItemsFromPerson(person, user, startIndex, limit);
} }
return ApplyPaging(new QueryResult<ServerItem>(), startIndex, limit); return ApplyPaging(new QueryResult<ServerItem>(), startIndex, limit);
@ -486,38 +479,19 @@ namespace MediaBrowser.Dlna.ContentDirectory
}; };
} }
private async Task<QueryResult<ServerItem>> GetItemsFromPerson(Person person, User user, int? startIndex, int? limit) private QueryResult<ServerItem> GetItemsFromPerson(Person person, User user, int? startIndex, int? limit)
{ {
var items = user.RootFolder.GetRecursiveChildren(user, i => i is Movie || i is Series && PeopleHelper.ContainsPerson(_libraryManager.GetPeople(i), person.Name)) var itemsWithPerson = _libraryManager.GetItems(new InternalItemsQuery
.ToList();
var trailerResult = await _channelManager.GetAllMediaInternal(new AllChannelMediaQuery
{ {
ContentTypes = new[] { ChannelMediaContentType.MovieExtra }, Person = person.Name
ExtraTypes = new[] { ExtraType.Trailer },
UserId = user.Id.ToString("N")
}, CancellationToken.None).ConfigureAwait(false); }).Items;
var currentIds = items.Select(i => i.GetProviderId(MetadataProviders.Imdb)) var items = itemsWithPerson
.Where(i => i is Movie || i is Series || i is IChannelItem)
.Where(i => i.IsVisibleStandalone(user))
.ToList(); .ToList();
var trailersToAdd = trailerResult.Items
.Where(i => PeopleHelper.ContainsPerson(_libraryManager.GetPeople(i), person.Name))
.Where(i =>
{
// Try to filter out dupes using imdb id
var imdb = i.GetProviderId(MetadataProviders.Imdb);
if (!string.IsNullOrWhiteSpace(imdb) &&
currentIds.Contains(imdb, StringComparer.OrdinalIgnoreCase))
{
return false;
}
return true;
});
items.AddRange(trailersToAdd);
items = _libraryManager.Sort(items, user, new[] { ItemSortBy.SortName }, SortOrder.Ascending) items = _libraryManager.Sort(items, user, new[] { ItemSortBy.SortName }, SortOrder.Ascending)
.Skip(startIndex ?? 0) .Skip(startIndex ?? 0)
.Take(limit ?? int.MaxValue) .Take(limit ?? int.MaxValue)
@ -569,7 +543,11 @@ namespace MediaBrowser.Dlna.ContentDirectory
private bool EnablePeopleDisplay(BaseItem item) private bool EnablePeopleDisplay(BaseItem item)
{ {
if (_libraryManager.GetPeople(item).Count > 0) if (_libraryManager.GetPeopleNames(new InternalPeopleQuery
{
ItemId = item.Id
}).Count > 0)
{ {
return item is Movie; return item is Movie;
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.7 KiB

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 840 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 8.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

After

Width:  |  Height:  |  Size: 699 B

View File

@ -834,7 +834,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
{ {
var heightParam = request.Height.Value.ToString(UsCulture); var heightParam = request.Height.Value.ToString(UsCulture);
filters.Add(string.Format("scale=trunc(oh*a*2)/2:{0}", heightParam)); filters.Add(string.Format("scale=trunc(oh*a/2)*2:{0}", heightParam));
} }
// If a max width was requested // If a max width was requested
@ -850,7 +850,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
{ {
var maxHeightParam = request.MaxHeight.Value.ToString(UsCulture); var maxHeightParam = request.MaxHeight.Value.ToString(UsCulture);
filters.Add(string.Format("scale=trunc(oh*a*2)/2:min(ih\\,{0})", maxHeightParam)); filters.Add(string.Format("scale=trunc(oh*a/2)*2:min(ih\\,{0})", maxHeightParam));
} }
var output = string.Empty; var output = string.Empty;

View File

@ -439,7 +439,7 @@ namespace MediaBrowser.MediaEncoding.Probing
if (!string.IsNullOrWhiteSpace(artists)) if (!string.IsNullOrWhiteSpace(artists))
{ {
audio.Artists = artists.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries) audio.Artists = SplitArtists(artists, new[] { '/' }, false)
.Distinct(StringComparer.OrdinalIgnoreCase) .Distinct(StringComparer.OrdinalIgnoreCase)
.ToList(); .ToList();
} }
@ -452,7 +452,7 @@ namespace MediaBrowser.MediaEncoding.Probing
} }
else else
{ {
audio.Artists = SplitArtists(artist) audio.Artists = SplitArtists(artist, _nameDelimiters, true)
.Distinct(StringComparer.OrdinalIgnoreCase) .Distinct(StringComparer.OrdinalIgnoreCase)
.ToList(); .ToList();
} }
@ -474,7 +474,7 @@ namespace MediaBrowser.MediaEncoding.Probing
} }
else else
{ {
audio.AlbumArtists = SplitArtists(albumArtist) audio.AlbumArtists = SplitArtists(albumArtist, _nameDelimiters, true)
.Distinct(StringComparer.OrdinalIgnoreCase) .Distinct(StringComparer.OrdinalIgnoreCase)
.ToList(); .ToList();
@ -552,10 +552,13 @@ namespace MediaBrowser.MediaEncoding.Probing
private const string ArtistReplaceValue = " | "; private const string ArtistReplaceValue = " | ";
private IEnumerable<string> SplitArtists(string val) private IEnumerable<string> SplitArtists(string val, char[] delimiters, bool splitFeaturing)
{ {
val = val.Replace(" featuring ", ArtistReplaceValue, StringComparison.OrdinalIgnoreCase) if (splitFeaturing)
.Replace(" feat. ", ArtistReplaceValue, StringComparison.OrdinalIgnoreCase); {
val = val.Replace(" featuring ", ArtistReplaceValue, StringComparison.OrdinalIgnoreCase)
.Replace(" feat. ", ArtistReplaceValue, StringComparison.OrdinalIgnoreCase);
}
var artistsFound = new List<string>(); var artistsFound = new List<string>();
@ -570,11 +573,7 @@ namespace MediaBrowser.MediaEncoding.Probing
} }
} }
// Only use the comma as a delimeter if there are no slashes or pipes. var artists = val.Split(delimiters, StringSplitOptions.RemoveEmptyEntries)
// We want to be careful not to split names that have commas in them
var delimeter = _nameDelimiters;
var artists = val.Split(delimeter, StringSplitOptions.RemoveEmptyEntries)
.Where(i => !string.IsNullOrWhiteSpace(i)) .Where(i => !string.IsNullOrWhiteSpace(i))
.Select(i => i.Trim()); .Select(i => i.Trim());

View File

@ -1076,6 +1076,9 @@
<Compile Include="..\MediaBrowser.Model\Session\UserDataChangeInfo.cs"> <Compile Include="..\MediaBrowser.Model\Session\UserDataChangeInfo.cs">
<Link>Session\UserDataChangeInfo.cs</Link> <Link>Session\UserDataChangeInfo.cs</Link>
</Compile> </Compile>
<Compile Include="..\MediaBrowser.Model\Social\SocialShareInfo.cs">
<Link>Social\SocialShareInfo.cs</Link>
</Compile>
<Compile Include="..\MediaBrowser.Model\Sync\CompleteSyncJobInfo.cs"> <Compile Include="..\MediaBrowser.Model\Sync\CompleteSyncJobInfo.cs">
<Link>Sync\CompleteSyncJobInfo.cs</Link> <Link>Sync\CompleteSyncJobInfo.cs</Link>
</Compile> </Compile>

View File

@ -1032,6 +1032,9 @@
<Compile Include="..\MediaBrowser.Model\Session\UserDataChangeInfo.cs"> <Compile Include="..\MediaBrowser.Model\Session\UserDataChangeInfo.cs">
<Link>Session\UserDataChangeInfo.cs</Link> <Link>Session\UserDataChangeInfo.cs</Link>
</Compile> </Compile>
<Compile Include="..\mediabrowser.model\social\SocialShareInfo.cs">
<Link>Social\SocialShareInfo.cs</Link>
</Compile>
<Compile Include="..\MediaBrowser.Model\Sync\CompleteSyncJobInfo.cs"> <Compile Include="..\MediaBrowser.Model\Sync\CompleteSyncJobInfo.cs">
<Link>Sync\CompleteSyncJobInfo.cs</Link> <Link>Sync\CompleteSyncJobInfo.cs</Link>
</Compile> </Compile>

View File

@ -25,7 +25,7 @@ namespace MediaBrowser.Model.Configuration
/// </summary> /// </summary>
/// <value>The public HTTPS port.</value> /// <value>The public HTTPS port.</value>
public int PublicHttpsPort { get; set; } public int PublicHttpsPort { get; set; }
/// <summary> /// <summary>
/// Gets or sets the HTTP server port number. /// Gets or sets the HTTP server port number.
/// </summary> /// </summary>
@ -49,7 +49,7 @@ namespace MediaBrowser.Model.Configuration
/// </summary> /// </summary>
/// <value><c>true</c> if [enable user specific user views]; otherwise, <c>false</c>.</value> /// <value><c>true</c> if [enable user specific user views]; otherwise, <c>false</c>.</value>
public bool EnableUserSpecificUserViews { get; set; } public bool EnableUserSpecificUserViews { get; set; }
/// <summary> /// <summary>
/// Gets or sets the value pointing to the file system where the ssl certiifcate is located.. /// Gets or sets the value pointing to the file system where the ssl certiifcate is located..
/// </summary> /// </summary>
@ -103,7 +103,7 @@ namespace MediaBrowser.Model.Configuration
/// </summary> /// </summary>
/// <value><c>true</c> if [enable library metadata sub folder]; otherwise, <c>false</c>.</value> /// <value><c>true</c> if [enable library metadata sub folder]; otherwise, <c>false</c>.</value>
public bool EnableLibraryMetadataSubFolder { get; set; } public bool EnableLibraryMetadataSubFolder { get; set; }
/// <summary> /// <summary>
/// Gets or sets the preferred metadata language. /// Gets or sets the preferred metadata language.
/// </summary> /// </summary>
@ -211,6 +211,8 @@ namespace MediaBrowser.Model.Configuration
public AutoOnOff EnableLibraryMonitor { get; set; } public AutoOnOff EnableLibraryMonitor { get; set; }
public int SharingExpirationDays { get; set; }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ServerConfiguration" /> class. /// Initializes a new instance of the <see cref="ServerConfiguration" /> class.
/// </summary> /// </summary>
@ -231,6 +233,7 @@ namespace MediaBrowser.Model.Configuration
EnableUPnP = true; EnableUPnP = true;
SharingExpirationDays = 30;
MinResumePct = 5; MinResumePct = 5;
MaxResumePct = 90; MaxResumePct = 90;

View File

@ -148,6 +148,7 @@ namespace MediaBrowser.Model.Dlna
{ {
if (!conditionProcessor.IsAudioConditionSatisfied(c, audioChannels, audioBitrate)) if (!conditionProcessor.IsAudioConditionSatisfied(c, audioChannels, audioBitrate))
{ {
LogConditionFailure(options.Profile, "AudioCodecProfile", c, item);
all = false; all = false;
break; break;
} }
@ -274,14 +275,21 @@ namespace MediaBrowser.Model.Dlna
{ {
playMethods.Add(PlayMethod.DirectStream); playMethods.Add(PlayMethod.DirectStream);
} }
// The profile describes what the device supports // The profile describes what the device supports
// If device requirements are satisfied then allow both direct stream and direct play // If device requirements are satisfied then allow both direct stream and direct play
if (item.SupportsDirectPlay && IsAudioEligibleForDirectPlay(item, GetBitrateForDirectPlayCheck(item, options))) if (item.SupportsDirectPlay &&
IsAudioEligibleForDirectPlay(item, GetBitrateForDirectPlayCheck(item, options)))
{ {
playMethods.Add(PlayMethod.DirectPlay); playMethods.Add(PlayMethod.DirectPlay);
} }
} }
else
{
_logger.Debug("Profile: {0}, No direct play profiles found for Path: {1}",
options.Profile.Name ?? "Unknown Profile",
item.Path ?? "Unknown path");
}
return playMethods; return playMethods;
} }
@ -354,8 +362,8 @@ namespace MediaBrowser.Model.Dlna
MediaStream videoStream = item.VideoStream; MediaStream videoStream = item.VideoStream;
// TODO: This doesn't accout for situation of device being able to handle media bitrate, but wifi connection not fast enough // TODO: This doesn't accout for situation of device being able to handle media bitrate, but wifi connection not fast enough
bool isEligibleForDirectPlay = IsEligibleForDirectPlay(item, GetBitrateForDirectPlayCheck(item, options), subtitleStream, options); bool isEligibleForDirectPlay = IsEligibleForDirectPlay(item, GetBitrateForDirectPlayCheck(item, options), subtitleStream, options, PlayMethod.DirectPlay);
bool isEligibleForDirectStream = IsEligibleForDirectPlay(item, options.GetMaxBitrate(), subtitleStream, options); bool isEligibleForDirectStream = IsEligibleForDirectPlay(item, options.GetMaxBitrate(), subtitleStream, options, PlayMethod.DirectStream);
_logger.Debug("Profile: {0}, Path: {1}, isEligibleForDirectPlay: {2}, isEligibleForDirectStream: {3}", _logger.Debug("Profile: {0}, Path: {1}, isEligibleForDirectPlay: {2}, isEligibleForDirectStream: {3}",
options.Profile.Name ?? "Unknown Profile", options.Profile.Name ?? "Unknown Profile",
@ -375,7 +383,7 @@ namespace MediaBrowser.Model.Dlna
if (subtitleStream != null) if (subtitleStream != null)
{ {
SubtitleProfile subtitleProfile = GetSubtitleProfile(subtitleStream, options.Profile.SubtitleProfiles, options.Context); SubtitleProfile subtitleProfile = GetSubtitleProfile(subtitleStream, options.Profile.SubtitleProfiles, options.Context, directPlay.Value);
playlistItem.SubtitleDeliveryMethod = subtitleProfile.Method; playlistItem.SubtitleDeliveryMethod = subtitleProfile.Method;
playlistItem.SubtitleFormat = subtitleProfile.Format; playlistItem.SubtitleFormat = subtitleProfile.Format;
@ -405,7 +413,7 @@ namespace MediaBrowser.Model.Dlna
if (subtitleStream != null) if (subtitleStream != null)
{ {
SubtitleProfile subtitleProfile = GetSubtitleProfile(subtitleStream, options.Profile.SubtitleProfiles, options.Context); SubtitleProfile subtitleProfile = GetSubtitleProfile(subtitleStream, options.Profile.SubtitleProfiles, options.Context, PlayMethod.Transcode);
playlistItem.SubtitleDeliveryMethod = subtitleProfile.Method; playlistItem.SubtitleDeliveryMethod = subtitleProfile.Method;
playlistItem.SubtitleFormat = subtitleProfile.Format; playlistItem.SubtitleFormat = subtitleProfile.Format;
@ -698,14 +706,16 @@ namespace MediaBrowser.Model.Dlna
private bool IsEligibleForDirectPlay(MediaSourceInfo item, private bool IsEligibleForDirectPlay(MediaSourceInfo item,
int? maxBitrate, int? maxBitrate,
MediaStream subtitleStream, MediaStream subtitleStream,
VideoOptions options) VideoOptions options,
PlayMethod playMethod)
{ {
if (subtitleStream != null) if (subtitleStream != null)
{ {
SubtitleProfile subtitleProfile = GetSubtitleProfile(subtitleStream, options.Profile.SubtitleProfiles, options.Context); SubtitleProfile subtitleProfile = GetSubtitleProfile(subtitleStream, options.Profile.SubtitleProfiles, options.Context, playMethod);
if (subtitleProfile.Method != SubtitleDeliveryMethod.External && subtitleProfile.Method != SubtitleDeliveryMethod.Embed) if (subtitleProfile.Method != SubtitleDeliveryMethod.External && subtitleProfile.Method != SubtitleDeliveryMethod.Embed)
{ {
_logger.Debug("Not eligible for {0} due to unsupported subtitles", playMethod);
return false; return false;
} }
} }
@ -713,8 +723,25 @@ namespace MediaBrowser.Model.Dlna
return IsAudioEligibleForDirectPlay(item, maxBitrate); return IsAudioEligibleForDirectPlay(item, maxBitrate);
} }
public static SubtitleProfile GetSubtitleProfile(MediaStream subtitleStream, SubtitleProfile[] subtitleProfiles, EncodingContext context) public static SubtitleProfile GetSubtitleProfile(MediaStream subtitleStream, SubtitleProfile[] subtitleProfiles, EncodingContext context, PlayMethod playMethod)
{ {
if (playMethod != PlayMethod.Transcode)
{
// Look for supported embedded subs
foreach (SubtitleProfile profile in subtitleProfiles)
{
if (!profile.SupportsLanguage(subtitleStream.Language))
{
continue;
}
if (profile.Method == SubtitleDeliveryMethod.Embed && subtitleStream.IsTextSubtitleStream == MediaStream.IsTextFormat(profile.Format))
{
return profile;
}
}
}
// Look for an external profile that matches the stream type (text/graphical) // Look for an external profile that matches the stream type (text/graphical)
foreach (SubtitleProfile profile in subtitleProfiles) foreach (SubtitleProfile profile in subtitleProfiles)
{ {
@ -745,10 +772,9 @@ namespace MediaBrowser.Model.Dlna
} }
} }
// Look for supported embedded subs that we can just mux into the output
foreach (SubtitleProfile profile in subtitleProfiles) foreach (SubtitleProfile profile in subtitleProfiles)
{ {
bool requiresConversion = !StringHelper.EqualsIgnoreCase(subtitleStream.Codec, profile.Format);
if (!profile.SupportsLanguage(subtitleStream.Language)) if (!profile.SupportsLanguage(subtitleStream.Language))
{ {
continue; continue;
@ -756,11 +782,6 @@ namespace MediaBrowser.Model.Dlna
if (profile.Method == SubtitleDeliveryMethod.Embed && subtitleStream.IsTextSubtitleStream == MediaStream.IsTextFormat(profile.Format)) if (profile.Method == SubtitleDeliveryMethod.Embed && subtitleStream.IsTextSubtitleStream == MediaStream.IsTextFormat(profile.Format))
{ {
if (!requiresConversion)
{
return profile;
}
return profile; return profile;
} }
} }
@ -774,8 +795,13 @@ namespace MediaBrowser.Model.Dlna
private bool IsAudioEligibleForDirectPlay(MediaSourceInfo item, int? maxBitrate) private bool IsAudioEligibleForDirectPlay(MediaSourceInfo item, int? maxBitrate)
{ {
// Honor the max bitrate setting if (!maxBitrate.HasValue || (item.Bitrate.HasValue && item.Bitrate.Value <= maxBitrate.Value))
return !maxBitrate.HasValue || (item.Bitrate.HasValue && item.Bitrate.Value <= maxBitrate.Value); {
return true;
}
_logger.Debug("Bitrate exceeds DirectPlay limit");
return false;
} }
private void ValidateInput(VideoOptions options) private void ValidateInput(VideoOptions options)

View File

@ -329,7 +329,7 @@ namespace MediaBrowser.Model.Dlna
private SubtitleStreamInfo GetSubtitleStreamInfo(MediaStream stream, string baseUrl, string accessToken, long startPositionTicks, SubtitleProfile[] subtitleProfiles) private SubtitleStreamInfo GetSubtitleStreamInfo(MediaStream stream, string baseUrl, string accessToken, long startPositionTicks, SubtitleProfile[] subtitleProfiles)
{ {
SubtitleProfile subtitleProfile = StreamBuilder.GetSubtitleProfile(stream, subtitleProfiles, Context); SubtitleProfile subtitleProfile = StreamBuilder.GetSubtitleProfile(stream, subtitleProfiles, Context, PlayMethod);
SubtitleStreamInfo info = new SubtitleStreamInfo SubtitleStreamInfo info = new SubtitleStreamInfo
{ {
IsForced = stream.IsForced, IsForced = stream.IsForced,

View File

@ -1,5 +1,4 @@
using System.Collections.Generic; using MediaBrowser.Model.Dlna;
using MediaBrowser.Model.Dlna;
using MediaBrowser.Model.Extensions; using MediaBrowser.Model.Extensions;
using System.Diagnostics; using System.Diagnostics;

View File

@ -379,6 +379,7 @@
<Compile Include="Session\TranscodingInfo.cs" /> <Compile Include="Session\TranscodingInfo.cs" />
<Compile Include="Session\UserDataChangeInfo.cs" /> <Compile Include="Session\UserDataChangeInfo.cs" />
<Compile Include="Devices\ContentUploadHistory.cs" /> <Compile Include="Devices\ContentUploadHistory.cs" />
<Compile Include="Social\SocialShareInfo.cs" />
<Compile Include="Sync\CompleteSyncJobInfo.cs" /> <Compile Include="Sync\CompleteSyncJobInfo.cs" />
<Compile Include="Sync\DeviceFileInfo.cs" /> <Compile Include="Sync\DeviceFileInfo.cs" />
<Compile Include="Sync\ItemFIleInfo.cs" /> <Compile Include="Sync\ItemFIleInfo.cs" />

View File

@ -0,0 +1,16 @@
using System;
namespace MediaBrowser.Model.Social
{
public class SocialShareInfo
{
public string Id { get; set; }
public string Url { get; set; }
public string ItemId { get; set; }
public string UserId { get; set; }
public DateTime ExpirationDate { get; set; }
public string Name { get; set; }
public string ImageUrl { get; set; }
public string Overview { get; set; }
}
}

View File

@ -330,12 +330,11 @@ namespace MediaBrowser.Providers.Manager
protected async Task SaveItem(MetadataResult<TItemType> result, ItemUpdateType reason, CancellationToken cancellationToken) protected async Task SaveItem(MetadataResult<TItemType> result, ItemUpdateType reason, CancellationToken cancellationToken)
{ {
await result.Item.UpdateToRepository(reason, cancellationToken).ConfigureAwait(false);
if (result.Item.SupportsPeople) if (result.Item.SupportsPeople)
{ {
await LibraryManager.UpdatePeople(result.Item as BaseItem, result.People); await LibraryManager.UpdatePeople(result.Item as BaseItem, result.People);
} }
await result.Item.UpdateToRepository(reason, cancellationToken).ConfigureAwait(false);
} }
public bool CanRefresh(IHasMetadata item) public bool CanRefresh(IHasMetadata item)

View File

@ -485,12 +485,11 @@ namespace MediaBrowser.Providers.Manager
// Give it a dummy path just so that it looks like a file system item // Give it a dummy path just so that it looks like a file system item
var dummy = new T() var dummy = new T()
{ {
Path = Path.Combine(_appPaths.InternalMetadataPath, "dummy"), Path = Path.Combine(_appPaths.InternalMetadataPath, "dummy")
// Dummy this up to fool the local trailer check
Parent = new Folder()
}; };
dummy.SetParent(new Folder());
var options = GetMetadataOptions(dummy); var options = GetMetadataOptions(dummy);
var summary = new MetadataPluginSummary var summary = new MetadataPluginSummary
@ -727,12 +726,11 @@ namespace MediaBrowser.Providers.Manager
// Give it a dummy path just so that it looks like a file system item // Give it a dummy path just so that it looks like a file system item
var dummy = new TItemType var dummy = new TItemType
{ {
Path = Path.Combine(_appPaths.InternalMetadataPath, "dummy"), Path = Path.Combine(_appPaths.InternalMetadataPath, "dummy")
// Dummy this up to fool the local trailer check
Parent = new Folder()
}; };
dummy.SetParent(new Folder());
var options = GetMetadataOptions(dummy); var options = GetMetadataOptions(dummy);
var providers = GetMetadataProvidersInternal<TItemType>(dummy, options, searchInfo.IncludeDisabledProviders) var providers = GetMetadataProvidersInternal<TItemType>(dummy, options, searchInfo.IncludeDisabledProviders)

View File

@ -138,7 +138,7 @@ namespace MediaBrowser.Providers.MediaInfo
if (item.IsShortcut) if (item.IsShortcut)
{ {
FetchShortcutInfo(item); FetchShortcutInfo(item);
return Task.FromResult(ItemUpdateType.MetadataEdit); return Task.FromResult(ItemUpdateType.MetadataImport);
} }
var prober = new FFProbeVideoInfo(_logger, _isoManager, _mediaEncoder, _itemRepo, _blurayExaminer, _localization, _appPaths, _json, _encodingManager, _fileSystem, _config, _subtitleManager, _chapterManager, _libraryManager); var prober = new FFProbeVideoInfo(_logger, _isoManager, _mediaEncoder, _itemRepo, _blurayExaminer, _localization, _appPaths, _json, _encodingManager, _fileSystem, _config, _subtitleManager, _chapterManager, _libraryManager);

View File

@ -1,4 +1,5 @@
using MediaBrowser.Common.Net; using System.Globalization;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Channels; using MediaBrowser.Controller.Channels;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Movies; using MediaBrowser.Controller.Entities.Movies;
@ -191,7 +192,20 @@ namespace MediaBrowser.Providers.Movies
var tmdbId = item.GetProviderId(MetadataProviders.Tmdb); var tmdbId = item.GetProviderId(MetadataProviders.Tmdb);
var language = item.GetPreferredMetadataLanguage(); var language = item.GetPreferredMetadataLanguage();
if (string.IsNullOrEmpty(tmdbId)) if (string.IsNullOrWhiteSpace(tmdbId))
{
var imdbId = item.GetProviderId(MetadataProviders.Imdb);
if (!string.IsNullOrWhiteSpace(imdbId))
{
var movieInfo = await MovieDbProvider.Current.FetchMainResult(imdbId, false, language, cancellationToken).ConfigureAwait(false);
if (movieInfo != null)
{
tmdbId = movieInfo.id.ToString(CultureInfo.InvariantCulture);
}
}
}
if (string.IsNullOrWhiteSpace(tmdbId))
{ {
return null; return null;
} }

View File

@ -2,6 +2,7 @@
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Movies; using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.LiveTv;
using MediaBrowser.Controller.Providers; using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Channels; using MediaBrowser.Model.Channels;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
@ -34,6 +35,13 @@ namespace MediaBrowser.Providers.Movies
return true; return true;
} }
// Supports images for tv movies
var tvProgram = item as LiveTvProgram;
if (tvProgram != null && tvProgram.IsMovie)
{
return true;
}
return item is Movie || item is MusicVideo; return item is Movie || item is MusicVideo;
} }
} }

View File

@ -172,7 +172,7 @@ namespace MediaBrowser.Providers.Omdb
result.Item.SetProviderId(MetadataProviders.Imdb, imdbId); result.Item.SetProviderId(MetadataProviders.Imdb, imdbId);
result.HasMetadata = true; result.HasMetadata = true;
await new OmdbProvider(_jsonSerializer, _httpClient).Fetch(result.Item, imdbId, cancellationToken).ConfigureAwait(false); await new OmdbProvider(_jsonSerializer, _httpClient).Fetch(result.Item, imdbId, info.MetadataLanguage, cancellationToken).ConfigureAwait(false);
} }
return result; return result;
@ -211,7 +211,7 @@ namespace MediaBrowser.Providers.Omdb
result.Item.SetProviderId(MetadataProviders.Imdb, imdbId); result.Item.SetProviderId(MetadataProviders.Imdb, imdbId);
result.HasMetadata = true; result.HasMetadata = true;
await new OmdbProvider(_jsonSerializer, _httpClient).Fetch(result.Item, imdbId, cancellationToken).ConfigureAwait(false); await new OmdbProvider(_jsonSerializer, _httpClient).Fetch(result.Item, imdbId, info.MetadataLanguage, cancellationToken).ConfigureAwait(false);
} }
return result; return result;

View File

@ -28,7 +28,7 @@ namespace MediaBrowser.Providers.Omdb
Current = this; Current = this;
} }
public async Task Fetch(BaseItem item, string imdbId, CancellationToken cancellationToken) public async Task Fetch(BaseItem item, string imdbId, string language, CancellationToken cancellationToken)
{ {
if (string.IsNullOrWhiteSpace(imdbId)) if (string.IsNullOrWhiteSpace(imdbId))
{ {
@ -51,7 +51,11 @@ namespace MediaBrowser.Providers.Omdb
{ {
var result = _jsonSerializer.DeserializeFromStream<RootObject>(stream); var result = _jsonSerializer.DeserializeFromStream<RootObject>(stream);
item.Name = result.Title; // Only take the name if the user's language is set to english, since Omdb has no localization
if (string.Equals(language, "en", StringComparison.OrdinalIgnoreCase))
{
item.Name = result.Title;
}
int year; int year;

View File

@ -59,9 +59,13 @@ namespace MediaBrowser.Providers.People
// Avoid implicitly captured closure // Avoid implicitly captured closure
var itemName = item.Name; var itemName = item.Name;
var seriesWithPerson = _libraryManager.RootFolder var seriesWithPerson = _libraryManager.GetItems(new InternalItemsQuery
.GetRecursiveChildren(i => i is Series && !string.IsNullOrEmpty(i.GetProviderId(MetadataProviders.Tvdb)) && _libraryManager.GetPeople(i).Any(p => string.Equals(p.Name, itemName, StringComparison.OrdinalIgnoreCase))) {
.Cast<Series>() IncludeItemTypes = new[] { typeof(Series).Name },
Person = itemName
}).Items.Cast<Series>()
.Where(i => !string.IsNullOrEmpty(i.GetProviderId(MetadataProviders.Tvdb)))
.ToList(); .ToList();
var infos = seriesWithPerson.Select(i => GetImageFromSeriesData(i, item.Name, cancellationToken)) var infos = seriesWithPerson.Select(i => GetImageFromSeriesData(i, item.Name, cancellationToken))

View File

@ -111,10 +111,11 @@ namespace MediaBrowser.Providers.TV
{ {
Name = seasonName, Name = seasonName,
IndexNumber = seasonNumber, IndexNumber = seasonNumber,
Parent = series,
Id = (series.Id + (seasonNumber ?? -1).ToString(_usCulture) + seasonName).GetMBId(typeof(Season)) Id = (series.Id + (seasonNumber ?? -1).ToString(_usCulture) + seasonName).GetMBId(typeof(Season))
}; };
season.SetParent(series);
await series.AddChild(season, cancellationToken).ConfigureAwait(false); await series.AddChild(season, cancellationToken).ConfigureAwait(false);
await season.RefreshMetadata(new MetadataRefreshOptions(), cancellationToken).ConfigureAwait(false); await season.RefreshMetadata(new MetadataRefreshOptions(), cancellationToken).ConfigureAwait(false);

View File

@ -406,10 +406,11 @@ namespace MediaBrowser.Providers.TV
Name = name, Name = name,
IndexNumber = episodeNumber, IndexNumber = episodeNumber,
ParentIndexNumber = seasonNumber, ParentIndexNumber = seasonNumber,
Parent = season,
Id = (series.Id + seasonNumber.ToString(_usCulture) + name).GetMBId(typeof(Episode)) Id = (series.Id + seasonNumber.ToString(_usCulture) + name).GetMBId(typeof(Episode))
}; };
episode.SetParent(season);
await season.AddChild(episode, cancellationToken).ConfigureAwait(false); await season.AddChild(episode, cancellationToken).ConfigureAwait(false);
await episode.RefreshMetadata(new MetadataRefreshOptions await episode.RefreshMetadata(new MetadataRefreshOptions

View File

@ -7,6 +7,7 @@ using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging; using MediaBrowser.Model.Logging;
using MediaBrowser.Providers.Manager; using MediaBrowser.Providers.Manager;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -30,7 +31,14 @@ namespace MediaBrowser.Providers.TV
{ {
var provider = new DummySeasonProvider(ServerConfigurationManager, Logger, _localization, LibraryManager); var provider = new DummySeasonProvider(ServerConfigurationManager, Logger, _localization, LibraryManager);
await provider.Run(item, CancellationToken.None).ConfigureAwait(false); try
{
await provider.Run(item, CancellationToken.None).ConfigureAwait(false);
}
catch (Exception ex)
{
Logger.ErrorException("Error in DummySeasonProvider", ex);
}
} }
} }

View File

@ -75,7 +75,6 @@ namespace MediaBrowser.Server.Implementations.Collections
var collection = new BoxSet var collection = new BoxSet
{ {
Name = name, Name = name,
Parent = parentFolder,
Path = path, Path = path,
IsLocked = options.IsLocked, IsLocked = options.IsLocked,
ProviderIds = options.ProviderIds, ProviderIds = options.ProviderIds,

View File

@ -88,7 +88,7 @@ namespace MediaBrowser.Server.Implementations.Dto
public IEnumerable<BaseItemDto> GetBaseItemDtos(IEnumerable<BaseItem> items, DtoOptions options, User user = null, BaseItem owner = null) public IEnumerable<BaseItemDto> GetBaseItemDtos(IEnumerable<BaseItem> items, DtoOptions options, User user = null, BaseItem owner = null)
{ {
var syncJobItems = GetSyncedItemProgress(options); var syncJobItems = GetSyncedItemProgress(options);
var syncDictionary = syncJobItems.ToDictionary(i => i.ItemId); var syncDictionary = GetSyncedItemProgressDictionary(syncJobItems);
var list = new List<BaseItemDto>(); var list = new List<BaseItemDto>();
@ -120,11 +120,23 @@ namespace MediaBrowser.Server.Implementations.Dto
return list; return list;
} }
private Dictionary<string, SyncedItemProgress> GetSyncedItemProgressDictionary(IEnumerable<SyncedItemProgress> items)
{
var dict = new Dictionary<string, SyncedItemProgress>();
foreach (var item in items)
{
dict[item.ItemId] = item;
}
return dict;
}
public BaseItemDto GetBaseItemDto(BaseItem item, DtoOptions options, User user = null, BaseItem owner = null) public BaseItemDto GetBaseItemDto(BaseItem item, DtoOptions options, User user = null, BaseItem owner = null)
{ {
var syncProgress = GetSyncedItemProgress(options); var syncProgress = GetSyncedItemProgress(options);
var dto = GetBaseItemDtoInternal(item, options, syncProgress.ToDictionary(i => i.ItemId), user, owner); var dto = GetBaseItemDtoInternal(item, options, GetSyncedItemProgressDictionary(syncProgress), user, owner);
var byName = item as IItemByName; var byName = item as IItemByName;
@ -132,13 +144,7 @@ namespace MediaBrowser.Server.Implementations.Dto
{ {
if (options.Fields.Contains(ItemFields.ItemCounts)) if (options.Fields.Contains(ItemFields.ItemCounts))
{ {
var itemFilter = byName.GetItemFilter(); SetItemByNameInfo(item, dto, GetTaggedItems(byName, user), user);
var libraryItems = user != null ?
user.RootFolder.GetRecursiveChildren(user, itemFilter) :
_libraryManager.RootFolder.GetRecursiveChildren(itemFilter);
SetItemByNameInfo(item, dto, libraryItems.ToList(), user);
} }
FillSyncInfo(dto, item, options, user, syncProgress); FillSyncInfo(dto, item, options, user, syncProgress);
@ -150,6 +156,33 @@ namespace MediaBrowser.Server.Implementations.Dto
return dto; return dto;
} }
private List<BaseItem> GetTaggedItems(IItemByName byName, User user)
{
var person = byName as Person;
if (person != null)
{
var items = _libraryManager.GetItems(new InternalItemsQuery
{
Person = byName.Name
}).Items;
if (user != null)
{
return items.Where(i => i.IsVisibleStandalone(user)).ToList();
}
return items.ToList();
}
var itemFilter = byName.GetItemFilter();
return user != null ?
user.RootFolder.GetRecursiveChildren(user, itemFilter).ToList() :
_libraryManager.RootFolder.GetRecursiveChildren(itemFilter).ToList();
}
private SyncedItemProgress[] GetSyncedItemProgress(DtoOptions options) private SyncedItemProgress[] GetSyncedItemProgress(DtoOptions options)
{ {
if (!options.Fields.Contains(ItemFields.SyncInfo)) if (!options.Fields.Contains(ItemFields.SyncInfo))
@ -361,7 +394,7 @@ namespace MediaBrowser.Server.Implementations.Dto
{ {
var syncProgress = GetSyncedItemProgress(options); var syncProgress = GetSyncedItemProgress(options);
var dto = GetBaseItemDtoInternal(item, options, syncProgress.ToDictionary(i => i.ItemId), user); var dto = GetBaseItemDtoInternal(item, options, GetSyncedItemProgressDictionary(syncProgress), user);
if (options.Fields.Contains(ItemFields.ItemCounts)) if (options.Fields.Contains(ItemFields.ItemCounts))
{ {
@ -684,7 +717,7 @@ namespace MediaBrowser.Server.Implementations.Dto
} }
}).Where(i => i != null) }).Where(i => i != null)
.DistinctBy(i => i.Name) .DistinctBy(i => i.Name, StringComparer.OrdinalIgnoreCase)
.ToDictionary(i => i.Name, StringComparer.OrdinalIgnoreCase); .ToDictionary(i => i.Name, StringComparer.OrdinalIgnoreCase);
for (var i = 0; i < people.Count; i++) for (var i = 0; i < people.Count; i++)
@ -736,6 +769,7 @@ namespace MediaBrowser.Server.Implementations.Dto
} }
}) })
.Where(i => i != null) .Where(i => i != null)
.DistinctBy(i => i.Name, StringComparer.OrdinalIgnoreCase)
.ToDictionary(i => i.Name, StringComparer.OrdinalIgnoreCase); .ToDictionary(i => i.Name, StringComparer.OrdinalIgnoreCase);
for (var i = 0; i < studios.Count; i++) for (var i = 0; i < studios.Count; i++)

View File

@ -256,7 +256,15 @@ namespace MediaBrowser.Server.Implementations.EntryPoints.Notifications
NotificationType = type NotificationType = type
}; };
notification.Variables["ItemName"] = item.Name; if (e.Item != null)
{
notification.Variables["ItemName"] = GetItemName(e.Item);
}
else
{
notification.Variables["ItemName"] = item.Name;
}
notification.Variables["UserName"] = user == null ? "Unknown user" : user.Name; notification.Variables["UserName"] = user == null ? "Unknown user" : user.Name;
notification.Variables["AppName"] = e.ClientName; notification.Variables["AppName"] = e.ClientName;
notification.Variables["DeviceName"] = e.DeviceName; notification.Variables["DeviceName"] = e.DeviceName;

View File

@ -104,7 +104,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer
container.Adapter = _containerAdapter; container.Adapter = _containerAdapter;
Plugins.Add(new SwaggerFeature()); Plugins.Add(new SwaggerFeature());
Plugins.Add(new CorsFeature(allowedHeaders: "Content-Type, Authorization, Range, X-MediaBrowser-Token")); Plugins.Add(new CorsFeature(allowedHeaders: "Content-Type, Authorization, Range, X-MediaBrowser-Token, X-Emby-Authorization"));
//Plugins.Add(new AuthFeature(() => new AuthUserSession(), new IAuthProvider[] { //Plugins.Add(new AuthFeature(() => new AuthUserSession(), new IAuthProvider[] {
// new SessionAuthProvider(_containerAdapter.Resolve<ISessionContext>()), // new SessionAuthProvider(_containerAdapter.Resolve<ISessionContext>()),

View File

@ -1,6 +1,6 @@
using MediaBrowser.Model.Logging; using MediaBrowser.Model.Logging;
using System; using System;
using System.Net; using System.Globalization;
using System.Text; using System.Text;
namespace MediaBrowser.Server.Implementations.HttpServer namespace MediaBrowser.Server.Implementations.HttpServer
@ -23,7 +23,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer
//log.AppendLine("Headers: " + string.Join(",", response.Headers.AllKeys.Select(k => k + "=" + response.Headers[k]))); //log.AppendLine("Headers: " + string.Join(",", response.Headers.AllKeys.Select(k => k + "=" + response.Headers[k])));
var responseTime = string.Format(". Response time: {0} ms.", duration.TotalMilliseconds); var responseTime = string.Format(". Response time: {0} ms.", duration.TotalMilliseconds.ToString(CultureInfo.InvariantCulture));
var msg = "HTTP Response " + statusCode + " to " + endPoint + responseTime; var msg = "HTTP Response " + statusCode + " to " + endPoint + responseTime;

View File

@ -170,7 +170,12 @@ namespace MediaBrowser.Server.Implementations.HttpServer.Security
/// <returns>Dictionary{System.StringSystem.String}.</returns> /// <returns>Dictionary{System.StringSystem.String}.</returns>
private Dictionary<string, string> GetAuthorizationDictionary(IServiceRequest httpReq) private Dictionary<string, string> GetAuthorizationDictionary(IServiceRequest httpReq)
{ {
var auth = httpReq.Headers["Authorization"]; var auth = httpReq.Headers["X-Emby-Authorization"];
if (string.IsNullOrWhiteSpace(auth))
{
auth = httpReq.Headers["Authorization"];
}
return GetAuthorization(auth); return GetAuthorization(auth);
} }

View File

@ -71,6 +71,12 @@ namespace MediaBrowser.Server.Implementations.Intros
var candidates = new List<ItemWithTrailer>(); var candidates = new List<ItemWithTrailer>();
var itemPeople = _libraryManager.GetPeople(item);
var allPeople = _libraryManager.GetPeople(new InternalPeopleQuery
{
AppearsInItemId = item.Id
});
if (config.EnableIntrosFromMoviesInLibrary) if (config.EnableIntrosFromMoviesInLibrary)
{ {
var itemsWithTrailers = user.RootFolder var itemsWithTrailers = user.RootFolder
@ -94,6 +100,8 @@ namespace MediaBrowser.Server.Implementations.Intros
Type = ItemWithTrailerType.ItemWithTrailer, Type = ItemWithTrailerType.ItemWithTrailer,
User = user, User = user,
WatchingItem = item, WatchingItem = item,
WatchingItemPeople = itemPeople,
AllPeople = allPeople,
Random = random, Random = random,
LibraryManager = _libraryManager LibraryManager = _libraryManager
})); }));
@ -135,6 +143,8 @@ namespace MediaBrowser.Server.Implementations.Intros
Type = ItemWithTrailerType.ChannelTrailer, Type = ItemWithTrailerType.ChannelTrailer,
User = user, User = user,
WatchingItem = item, WatchingItem = item,
WatchingItemPeople = itemPeople,
AllPeople = allPeople,
Random = random, Random = random,
LibraryManager = _libraryManager LibraryManager = _libraryManager
})); }));
@ -241,7 +251,7 @@ namespace MediaBrowser.Server.Implementations.Intros
return true; return true;
} }
internal static int GetSimiliarityScore(BaseItem item1, BaseItem item2, Random random, ILibraryManager libraryManager) internal static int GetSimiliarityScore(BaseItem item1, List<PersonInfo> item1People, List<PersonInfo> allPeople, BaseItem item2, Random random, ILibraryManager libraryManager)
{ {
var points = 0; var points = 0;
@ -262,11 +272,13 @@ namespace MediaBrowser.Server.Implementations.Intros
// Find common studios // Find common studios
points += item1.Studios.Where(i => item2.Studios.Contains(i, StringComparer.OrdinalIgnoreCase)).Sum(i => 5); points += item1.Studios.Where(i => item2.Studios.Contains(i, StringComparer.OrdinalIgnoreCase)).Sum(i => 5);
var item2PeopleNames = libraryManager.GetPeople(item2).Select(i => i.Name) var item2PeopleNames = allPeople.Where(i => i.ItemId == item2.Id)
.Distinct(StringComparer.OrdinalIgnoreCase) .Select(i => i.Name)
.Where(i => !string.IsNullOrWhiteSpace(i))
.DistinctNames()
.ToDictionary(i => i, StringComparer.OrdinalIgnoreCase); .ToDictionary(i => i, StringComparer.OrdinalIgnoreCase);
points += libraryManager.GetPeople(item1).Where(i => item2PeopleNames.ContainsKey(i.Name)).Sum(i => 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)) if (string.Equals(i.Type, PersonType.Director, StringComparison.OrdinalIgnoreCase) || string.Equals(i.Role, PersonType.Director, StringComparison.OrdinalIgnoreCase))
{ {
@ -341,6 +353,8 @@ namespace MediaBrowser.Server.Implementations.Intros
internal ItemWithTrailerType Type; internal ItemWithTrailerType Type;
internal User User; internal User User;
internal BaseItem WatchingItem; internal BaseItem WatchingItem;
internal List<PersonInfo> WatchingItemPeople;
internal List<PersonInfo> AllPeople;
internal Random Random; internal Random Random;
internal ILibraryManager LibraryManager; internal ILibraryManager LibraryManager;
@ -364,7 +378,7 @@ namespace MediaBrowser.Server.Implementations.Intros
{ {
if (!_score.HasValue) if (!_score.HasValue)
{ {
_score = GetSimiliarityScore(WatchingItem, Item, Random, LibraryManager); _score = GetSimiliarityScore(WatchingItem, WatchingItemPeople, AllPeople, Item, Random, LibraryManager);
} }
return _score.Value; return _score.Value;
} }

View File

@ -345,7 +345,7 @@ namespace MediaBrowser.Server.Implementations.Library
try try
{ {
await UpdateItem(season, ItemUpdateType.MetadataEdit, cancellationToken).ConfigureAwait(false); await UpdateItem(season, ItemUpdateType.MetadataDownload, cancellationToken).ConfigureAwait(false);
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -1108,6 +1108,8 @@ namespace MediaBrowser.Server.Implementations.Library
progress.Report(innerPercent); progress.Report(innerPercent);
}); });
_logger.Debug("Running post-scan task {0}", task.GetType().Name);
try try
{ {
await task.Run(innerProgress, cancellationToken).ConfigureAwait(false); await task.Run(innerProgress, cancellationToken).ConfigureAwait(false);
@ -1223,6 +1225,11 @@ namespace MediaBrowser.Server.Implementations.Library
}; };
} }
public List<Guid> GetItemIds(InternalItemsQuery query)
{
return ItemRepository.GetItemIdsList(query);
}
/// <summary> /// <summary>
/// Gets the intros. /// Gets the intros.
/// </summary> /// </summary>
@ -2057,30 +2064,58 @@ namespace MediaBrowser.Server.Implementations.Library
} }
} }
public List<PersonInfo> GetPeople(InternalPeopleQuery query)
{
return ItemRepository.GetPeople(query);
}
public List<PersonInfo> GetPeople(BaseItem item) public List<PersonInfo> GetPeople(BaseItem item)
{ {
return item.People ?? ItemRepository.GetPeople(item.Id); var people = GetPeople(new InternalPeopleQuery
{
ItemId = item.Id
});
if (people.Count > 0)
{
return people;
}
return item.People ?? new List<PersonInfo>();
}
public List<Person> GetPeopleItems(InternalPeopleQuery query)
{
return ItemRepository.GetPeopleNames(query).Select(i =>
{
try
{
return GetPerson(i);
}
catch (Exception ex)
{
_logger.ErrorException("Error getting person", ex);
return null;
}
}).Where(i => i != null).ToList();
}
public List<string> GetPeopleNames(InternalPeopleQuery query)
{
return ItemRepository.GetPeopleNames(query);
} }
public List<PersonInfo> GetAllPeople() public List<PersonInfo> GetAllPeople()
{ {
return RootFolder.GetRecursiveChildren() return GetPeople(new InternalPeopleQuery())
.SelectMany(GetPeople)
.Where(i => !string.IsNullOrWhiteSpace(i.Name))
.DistinctBy(i => i.Name, StringComparer.OrdinalIgnoreCase) .DistinctBy(i => i.Name, StringComparer.OrdinalIgnoreCase)
.ToList(); .ToList();
} }
public async Task UpdatePeople(BaseItem item, List<PersonInfo> people) public Task UpdatePeople(BaseItem item, List<PersonInfo> people)
{ {
await ItemRepository.UpdatePeople(item.Id, people).ConfigureAwait(false); return ItemRepository.UpdatePeople(item.Id, people);
if (item.People != null)
{
item.People = null;
await item.UpdateToRepository(ItemUpdateType.MetadataEdit, CancellationToken.None).ConfigureAwait(false);
}
} }
} }
} }

View File

@ -34,7 +34,7 @@ namespace MediaBrowser.Server.Implementations.Library
// If the resolver didn't specify this // If the resolver didn't specify this
if (parent != null) if (parent != null)
{ {
item.Parent = parent; item.SetParent(parent);
} }
item.Id = libraryManager.GetNewItemId(item.Path, item.GetType()); item.Id = libraryManager.GetNewItemId(item.Path, item.GetType());
@ -68,7 +68,7 @@ namespace MediaBrowser.Server.Implementations.Library
// If the resolver didn't specify this // If the resolver didn't specify this
if (args.Parent != null) if (args.Parent != null)
{ {
item.Parent = args.Parent; item.SetParent(args.Parent);
} }
item.Id = libraryManager.GetNewItemId(item.Path, item.GetType()); item.Id = libraryManager.GetNewItemId(item.Path, item.GetType());

View File

@ -1,13 +1,10 @@
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
using MediaBrowser.Naming.Common;
using MediaBrowser.Naming.Video; using MediaBrowser.Naming.Video;
using MediaBrowser.Server.Implementations.Logging;
using System; using System;
using System.IO; using System.IO;
using System.Linq;
using MediaBrowser.Server.Implementations.Logging;
namespace MediaBrowser.Server.Implementations.Library.Resolvers namespace MediaBrowser.Server.Implementations.Library.Resolvers
{ {

View File

@ -256,10 +256,15 @@ namespace MediaBrowser.Server.Implementations.Library
if (query.IncludePeople) if (query.IncludePeople)
{ {
var itemIds = items.Select(i => i.Id).ToList();
// Find persons // Find persons
var persons = items.SelectMany(i => _libraryManager.GetPeople(i)) var persons = _libraryManager.GetPeople(new InternalPeopleQuery
{
NameContains = searchTerm
})
.Where(i => itemIds.Contains(i.ItemId))
.Select(i => i.Name) .Select(i => i.Name)
.Where(i => !string.IsNullOrWhiteSpace(i))
.Distinct(StringComparer.OrdinalIgnoreCase) .Distinct(StringComparer.OrdinalIgnoreCase)
.ToList(); .ToList();

View File

@ -38,7 +38,7 @@
"HeaderSupportTheTeam": "Support the Emby Team", "HeaderSupportTheTeam": "Support the Emby Team",
"TextEnjoyBonusFeatures": "Enjoy Bonus Features", "TextEnjoyBonusFeatures": "Enjoy Bonus Features",
"TitleLiveTV": "Live TV", "TitleLiveTV": "Live TV",
"ButtonCancelSyncJob": "Cancel sync job", "ButtonCancelSyncJob": "Cancel sync job",
"TitleSync": "Sync", "TitleSync": "Sync",
"HeaderSelectDate": "Select Date", "HeaderSelectDate": "Select Date",
"ButtonDonate": "Donate", "ButtonDonate": "Donate",
@ -811,5 +811,10 @@
"ErrorMessagePasswordNotMatchConfirm": "The password and password confirmation must match.", "ErrorMessagePasswordNotMatchConfirm": "The password and password confirmation must match.",
"ErrorMessageUsernameInUse": "The username is already in use. Please choose a new name and try again.", "ErrorMessageUsernameInUse": "The username is already in use. Please choose a new name and try again.",
"ErrorMessageEmailInUse": "The email address is already in use. Please enter a new email address and try again, or use the forgot password feature.", "ErrorMessageEmailInUse": "The email address is already in use. Please enter a new email address and try again, or use the forgot password feature.",
"MessageThankYouForConnectSignUp": "Thank you for signing up for Emby Connect. An email will be sent to your address with instructions on how to confirm your new account. Please confirm the account and then return here to sign in." "MessageThankYouForConnectSignUp": "Thank you for signing up for Emby Connect. An email will be sent to your address with instructions on how to confirm your new account. Please confirm the account and then return here to sign in.",
"HeaderShare": "Share",
"ButtonShareHelp": "Share a web page containing media information with social media. Media files are never shared publicly.",
"ButtonShare": "Share",
"HeaderConfirm": "Confirm",
"ButtonAdvancedRefresh": "Advanced Refresh"
} }

Some files were not shown because too many files have changed in this diff Show More