add date content added comparer

pull/702/head
Luke Pulverenti 10 years ago
parent 12ba57d423
commit 2fc0686c30

@ -13,6 +13,7 @@ using System.Threading.Tasks;
namespace MediaBrowser.Api.Playback namespace MediaBrowser.Api.Playback
{ {
[Route("/Items/{Id}/MediaInfo", "GET", Summary = "Gets live playback media info for an item")] [Route("/Items/{Id}/MediaInfo", "GET", Summary = "Gets live playback media info for an item")]
[Route("/Items/{Id}/PlaybackInfo", "GET", Summary = "Gets live playback media info for an item")]
public class GetLiveMediaInfo : IReturn<LiveMediaInfoResult> public class GetLiveMediaInfo : IReturn<LiveMediaInfoResult>
{ {
[ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")] [ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]

@ -239,7 +239,7 @@ namespace MediaBrowser.Controller.Entities.Audio
{ {
Id = i.Id.ToString("N"), Id = i.Id.ToString("N"),
Protocol = locationType == LocationType.Remote ? MediaProtocol.Http : MediaProtocol.File, Protocol = locationType == LocationType.Remote ? MediaProtocol.Http : MediaProtocol.File,
MediaStreams = MediaSourceManager.GetMediaStreams(new MediaStreamQuery { ItemId = i.Id }).ToList(), MediaStreams = MediaSourceManager.GetMediaStreams(i.Id).ToList(),
Name = i.Name, Name = i.Name,
Path = enablePathSubstituion ? GetMappedPath(i.Path, locationType) : i.Path, Path = enablePathSubstituion ? GetMappedPath(i.Path, locationType) : i.Path,
RunTimeTicks = i.RunTimeTicks, RunTimeTicks = i.RunTimeTicks,

@ -420,12 +420,17 @@ namespace MediaBrowser.Controller.Entities
return base.GetDeletePaths(); return base.GetDeletePaths();
} }
public virtual IEnumerable<MediaStream> GetMediaStreams() public IEnumerable<MediaStream> GetMediaStreams()
{ {
return MediaSourceManager.GetMediaStreams(new MediaStreamQuery var mediaSource = GetMediaSources(false)
.FirstOrDefault();
if (mediaSource == null)
{ {
ItemId = Id return new List<MediaStream>();
}); }
return mediaSource.MediaStreams;
} }
public virtual MediaStream GetDefaultVideoStream() public virtual MediaStream GetDefaultVideoStream()
@ -474,7 +479,7 @@ namespace MediaBrowser.Controller.Entities
private static MediaSourceInfo GetVersionInfo(bool enablePathSubstitution, Video i, MediaSourceType type) private static MediaSourceInfo GetVersionInfo(bool enablePathSubstitution, Video i, MediaSourceType type)
{ {
var mediaStreams = MediaSourceManager.GetMediaStreams(new MediaStreamQuery { ItemId = i.Id }) var mediaStreams = MediaSourceManager.GetMediaStreams(i.Id)
.ToList(); .ToList();
var locationType = i.LocationType; var locationType = i.LocationType;

@ -1,11 +1,29 @@
using MediaBrowser.Controller.Persistence; using MediaBrowser.Controller.Persistence;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace MediaBrowser.Controller.Library namespace MediaBrowser.Controller.Library
{ {
public interface IMediaSourceManager public interface IMediaSourceManager
{ {
/// <summary>
/// Gets the media streams.
/// </summary>
/// <param name="itemId">The item identifier.</param>
/// <returns>IEnumerable&lt;MediaStream&gt;.</returns>
IEnumerable<MediaStream> GetMediaStreams(Guid itemId);
/// <summary>
/// Gets the media streams.
/// </summary>
/// <param name="mediaSourceId">The media source identifier.</param>
/// <returns>IEnumerable&lt;MediaStream&gt;.</returns>
IEnumerable<MediaStream> GetMediaStreams(string mediaSourceId);
/// <summary>
/// Gets the media streams.
/// </summary>
/// <param name="query">The query.</param>
/// <returns>IEnumerable&lt;MediaStream&gt;.</returns>
IEnumerable<MediaStream> GetMediaStreams(MediaStreamQuery query); IEnumerable<MediaStream> GetMediaStreams(MediaStreamQuery query);
} }
} }

@ -4,6 +4,7 @@ namespace MediaBrowser.Model.Dlna
public enum PlaybackErrorCode public enum PlaybackErrorCode
{ {
NotAllowed = 0, NotAllowed = 0,
NoCompatibleStream = 1 NoCompatibleStream = 1,
RateLimitExceeded = 2
} }
} }

@ -62,8 +62,9 @@ namespace MediaBrowser.Server.Implementations.Drawing
logger.Info("Failed to read image header for {0}. Doing it the slow way.", path); logger.Info("Failed to read image header for {0}. Doing it the slow way.", path);
} }
using (var wand = new MagickWand(path)) using (var wand = new MagickWand())
{ {
wand.PingImage(path);
var img = wand.CurrentImage; var img = wand.CurrentImage;
return new ImageSize return new ImageSize

@ -1,6 +1,7 @@
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Persistence; using MediaBrowser.Controller.Persistence;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -47,5 +48,59 @@ namespace MediaBrowser.Server.Implementations.Library
{ {
return true; return true;
} }
public IEnumerable<MediaStream> GetMediaStreams(string mediaSourceId)
{
var list = GetMediaStreams(new MediaStreamQuery
{
ItemId = new Guid(mediaSourceId)
});
return GetMediaStreamsForItem(list);
}
public IEnumerable<MediaStream> GetMediaStreams(Guid itemId)
{
var list = GetMediaStreams(new MediaStreamQuery
{
ItemId = itemId
});
return GetMediaStreamsForItem(list);
}
private IEnumerable<MediaStream> GetMediaStreamsForItem(IEnumerable<MediaStream> streams)
{
var list = streams.ToList();
var subtitleStreams = list
.Where(i => i.Type == MediaStreamType.Subtitle)
.ToList();
if (subtitleStreams.Count > 0)
{
var videoStream = list.FirstOrDefault(i => i.Type == MediaStreamType.Video);
// This is abitrary but at some point it becomes too slow to extract subtitles on the fly
// We need to learn more about when this is the case vs. when it isn't
const int maxAllowedBitrateForExternalSubtitleStream = 10000000;
var videoBitrate = videoStream == null ? maxAllowedBitrateForExternalSubtitleStream : videoStream.BitRate ?? maxAllowedBitrateForExternalSubtitleStream;
foreach (var subStream in subtitleStreams)
{
var supportsExternalStream = StreamSupportsExternalStream(subStream);
if (supportsExternalStream && videoBitrate >= maxAllowedBitrateForExternalSubtitleStream)
{
supportsExternalStream = false;
}
subStream.SupportsExternalStream = supportsExternalStream;
}
}
return list;
}
} }
} }

@ -278,6 +278,7 @@
<Compile Include="Sorting\CommunityRatingComparer.cs" /> <Compile Include="Sorting\CommunityRatingComparer.cs" />
<Compile Include="Sorting\CriticRatingComparer.cs" /> <Compile Include="Sorting\CriticRatingComparer.cs" />
<Compile Include="Sorting\DateCreatedComparer.cs" /> <Compile Include="Sorting\DateCreatedComparer.cs" />
<Compile Include="Sorting\DateLastMediaAddedComparer.cs" />
<Compile Include="Sorting\DatePlayedComparer.cs" /> <Compile Include="Sorting\DatePlayedComparer.cs" />
<Compile Include="Sorting\GameSystemComparer.cs" /> <Compile Include="Sorting\GameSystemComparer.cs" />
<Compile Include="Sorting\IsFavoriteOrLikeComparer.cs" /> <Compile Include="Sorting\IsFavoriteOrLikeComparer.cs" />

@ -108,7 +108,12 @@ namespace MediaBrowser.Server.Implementations.Photos
protected Task<Stream> GetThumbCollage(List<BaseItem> items) protected Task<Stream> GetThumbCollage(List<BaseItem> items)
{ {
return DynamicImageHelpers.GetThumbCollage(items.Select(i => i.GetImagePath(ImageType.Primary) ?? i.GetImagePath(ImageType.Thumb)).ToList(), var files = items
.Select(i => i.GetImagePath(ImageType.Primary) ?? i.GetImagePath(ImageType.Thumb))
.Where(i => !string.IsNullOrWhiteSpace(i))
.ToList();
return DynamicImageHelpers.GetThumbCollage(files,
FileSystem, FileSystem,
1600, 1600,
900, 900,
@ -117,7 +122,12 @@ namespace MediaBrowser.Server.Implementations.Photos
protected Task<Stream> GetSquareCollage(List<BaseItem> items) protected Task<Stream> GetSquareCollage(List<BaseItem> items)
{ {
return DynamicImageHelpers.GetSquareCollage(items.Select(i => i.GetImagePath(ImageType.Primary) ?? i.GetImagePath(ImageType.Thumb)).ToList(), var files = items
.Select(i => i.GetImagePath(ImageType.Primary) ?? i.GetImagePath(ImageType.Thumb))
.Where(i => !string.IsNullOrWhiteSpace(i))
.ToList();
return DynamicImageHelpers.GetSquareCollage(files,
FileSystem, FileSystem,
800, ApplicationPaths); 800, ApplicationPaths);
} }

@ -4,6 +4,7 @@ using MediaBrowser.Common.IO;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace MediaBrowser.Server.Implementations.Photos namespace MediaBrowser.Server.Implementations.Photos
@ -15,6 +16,11 @@ namespace MediaBrowser.Server.Implementations.Photos
int width, int width,
int height, IApplicationPaths appPaths) int height, IApplicationPaths appPaths)
{ {
if (files.Any(string.IsNullOrWhiteSpace))
{
throw new ArgumentException("Empty file found in files list");
}
if (files.Count < 3) if (files.Count < 3)
{ {
return await GetSingleImage(files, fileSystem).ConfigureAwait(false); return await GetSingleImage(files, fileSystem).ConfigureAwait(false);
@ -27,7 +33,7 @@ namespace MediaBrowser.Server.Implementations.Photos
int cellHeight = height; int cellHeight = height;
var index = 0; var index = 0;
using (var wand = new MagickWand(width, height, "transparent")) using (var wand = new MagickWand(width, height, new PixelWand(ColorName.None, 1)))
{ {
for (var row = 0; row < rows; row++) for (var row = 0; row < rows; row++)
{ {
@ -57,6 +63,11 @@ namespace MediaBrowser.Server.Implementations.Photos
IFileSystem fileSystem, IFileSystem fileSystem,
int size, IApplicationPaths appPaths) int size, IApplicationPaths appPaths)
{ {
if (files.Any(string.IsNullOrWhiteSpace))
{
throw new ArgumentException("Empty file found in files list");
}
if (files.Count < 4) if (files.Count < 4)
{ {
return await GetSingleImage(files, fileSystem).ConfigureAwait(false); return await GetSingleImage(files, fileSystem).ConfigureAwait(false);
@ -68,7 +79,7 @@ namespace MediaBrowser.Server.Implementations.Photos
int singleSize = size / 2; int singleSize = size / 2;
var index = 0; var index = 0;
using (var wand = new MagickWand(size, size, "transparent")) using (var wand = new MagickWand(size, size, new PixelWand(ColorName.None, 1)))
{ {
for (var row = 0; row < rows; row++) for (var row = 0; row < rows; row++)
{ {

@ -1579,11 +1579,7 @@ namespace MediaBrowser.Server.Implementations.Session
if (!string.IsNullOrWhiteSpace(mediaSourceId)) if (!string.IsNullOrWhiteSpace(mediaSourceId))
{ {
info.MediaStreams = _mediaSourceManager.GetMediaStreams(new MediaStreamQuery info.MediaStreams = _mediaSourceManager.GetMediaStreams(mediaSourceId).ToList();
{
ItemId = new Guid(mediaSourceId)
}).ToList();
} }
return info; return info;

@ -0,0 +1,70 @@
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Sorting;
using MediaBrowser.Model.Querying;
using System;
using System.Linq;
namespace MediaBrowser.Server.Implementations.Sorting
{
public class DateLastMediaAddedComparer : IUserBaseItemComparer
{
/// <summary>
/// Gets or sets the user.
/// </summary>
/// <value>The user.</value>
public User User { get; set; }
/// <summary>
/// Gets or sets the user manager.
/// </summary>
/// <value>The user manager.</value>
public IUserManager UserManager { get; set; }
/// <summary>
/// Gets or sets the user data repository.
/// </summary>
/// <value>The user data repository.</value>
public IUserDataManager UserDataRepository { get; set; }
/// <summary>
/// Compares the specified x.
/// </summary>
/// <param name="x">The x.</param>
/// <param name="y">The y.</param>
/// <returns>System.Int32.</returns>
public int Compare(BaseItem x, BaseItem y)
{
return GetDate(x).CompareTo(GetDate(y));
}
/// <summary>
/// Gets the date.
/// </summary>
/// <param name="x">The x.</param>
/// <returns>DateTime.</returns>
private DateTime GetDate(BaseItem x)
{
var folder = x as Folder;
if (folder != null)
{
return folder.GetRecursiveChildren(User, i => !i.IsFolder)
.Select(i => i.DateCreated)
.OrderByDescending(i => i)
.FirstOrDefault();
}
return x.DateCreated;
}
/// <summary>
/// Gets the name.
/// </summary>
/// <value>The name.</value>
public string Name
{
get { return ItemSortBy.DateLastContentAdded; }
}
}
}

@ -1,6 +1,5 @@
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Persistence;
using MediaBrowser.Controller.Sorting; using MediaBrowser.Controller.Sorting;
using MediaBrowser.Model.Querying; using MediaBrowser.Model.Querying;
using System; using System;

Loading…
Cancel
Save