Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Tim Hobbs 2014-03-20 13:45:33 -07:00
commit afa9f14cdb
9 changed files with 226 additions and 106 deletions

View File

@ -158,8 +158,7 @@ namespace MediaBrowser.Api
Path = GetMappedPath(i), Path = GetMappedPath(i),
RunTimeTicks = i.RunTimeTicks, RunTimeTicks = i.RunTimeTicks,
Video3DFormat = i.Video3DFormat, Video3DFormat = i.Video3DFormat,
VideoType = i.VideoType, VideoType = i.VideoType
IsHD = i.IsHD
}; };
} }
@ -234,7 +233,12 @@ namespace MediaBrowser.Api
{ {
if (stream.Width.HasValue) if (stream.Width.HasValue)
{ {
if (stream.Width.Value >= 1900) if (stream.Width.Value >= 3800)
{
name = name + " " + "4K";
name = name.Trim();
}
else if (stream.Width.Value >= 1900)
{ {
name = name + " " + "1080P"; name = name + " " + "1080P";
name = name.Trim(); name = name.Trim();

View File

@ -130,7 +130,6 @@ namespace MediaBrowser.Controller.Entities
} }
private List<LinkedChild> _linkedChildren; private List<LinkedChild> _linkedChildren;
/// <summary> /// <summary>
/// Our children are actually just references to the ones in the physical root... /// Our children are actually just references to the ones in the physical root...
/// </summary> /// </summary>
@ -145,21 +144,9 @@ namespace MediaBrowser.Controller.Entities
} }
private List<LinkedChild> GetLinkedChildrenInternal() private List<LinkedChild> GetLinkedChildrenInternal()
{ {
Dictionary<string, string> locationsDicionary;
try
{
locationsDicionary = PhysicalLocations.Distinct(StringComparer.OrdinalIgnoreCase).ToDictionary(i => i, StringComparer.OrdinalIgnoreCase);
}
catch (IOException ex)
{
Logger.ErrorException("Error getting ResolveArgs for {0}", ex, Path);
return new List<LinkedChild>();
}
return LibraryManager.RootFolder.Children return LibraryManager.RootFolder.Children
.OfType<Folder>() .OfType<Folder>()
.Where(i => i.Path != null && locationsDicionary.ContainsKey(i.Path)) .Where(i => i.Path != null && PhysicalLocations.Contains(i.Path, StringComparer.OrdinalIgnoreCase))
.SelectMany(c => c.LinkedChildren) .SelectMany(c => c.LinkedChildren)
.ToList(); .ToList();
} }
@ -177,22 +164,10 @@ namespace MediaBrowser.Controller.Entities
private IEnumerable<BaseItem> GetActualChildren() private IEnumerable<BaseItem> GetActualChildren()
{ {
Dictionary<string, string> locationsDicionary;
try
{
locationsDicionary = PhysicalLocations.Distinct(StringComparer.OrdinalIgnoreCase).ToDictionary(i => i, StringComparer.OrdinalIgnoreCase);
}
catch (IOException ex)
{
Logger.ErrorException("Error getting ResolveArgs for {0}", ex, Path);
return new BaseItem[] { };
}
return return
LibraryManager.RootFolder.Children LibraryManager.RootFolder.Children
.OfType<Folder>() .OfType<Folder>()
.Where(i => i.Path != null && locationsDicionary.ContainsKey(i.Path)) .Where(i => i.Path != null && PhysicalLocations.Contains(i.Path, StringComparer.OrdinalIgnoreCase))
.SelectMany(c => c.Children) .SelectMany(c => c.Children)
.ToList(); .ToList();
} }

View File

@ -446,24 +446,31 @@ namespace MediaBrowser.Controller.Entities
{ {
BaseItem currentChild; BaseItem currentChild;
if (currentChildren.TryGetValue(child.Id, out currentChild) && IsValidFromResolver(currentChild, child)) if (currentChildren.TryGetValue(child.Id, out currentChild))
{ {
var currentChildLocationType = currentChild.LocationType; if (IsValidFromResolver(currentChild, child))
if (currentChildLocationType != LocationType.Remote &&
currentChildLocationType != LocationType.Virtual)
{ {
currentChild.DateModified = child.DateModified; var currentChildLocationType = currentChild.LocationType;
} if (currentChildLocationType != LocationType.Remote &&
currentChildLocationType != LocationType.Virtual)
{
currentChild.DateModified = child.DateModified;
}
currentChild.IsOffline = false; currentChild.IsOffline = false;
validChildren.Add(currentChild);
}
else
{
validChildren.Add(child);
}
} }
else else
{ {
//brand new item - needs to be added // Brand new item - needs to be added
newItems.Add(child); newItems.Add(child);
validChildren.Add(child);
} }
validChildren.Add(currentChild);
} }
// If any items were added or removed.... // If any items were added or removed....
@ -736,7 +743,7 @@ namespace MediaBrowser.Controller.Entities
/// <returns>BaseItem.</returns> /// <returns>BaseItem.</returns>
private BaseItem RetrieveChild(Guid child) private BaseItem RetrieveChild(Guid child)
{ {
var item = LibraryManager.RetrieveItem(child); var item = LibraryManager.GetItemById(child);
if (item != null) if (item != null)
{ {

View File

@ -88,6 +88,12 @@ namespace MediaBrowser.Model.Dto
/// <value>The external urls.</value> /// <value>The external urls.</value>
public ExternalUrl[] ExternalUrls { get; set; } public ExternalUrl[] ExternalUrls { get; set; }
/// <summary>
/// Gets or sets the media versions.
/// </summary>
/// <value>The media versions.</value>
public List<MediaVersionInfo> MediaVersions { get; set; }
/// <summary> /// <summary>
/// Gets or sets the critic rating. /// Gets or sets the critic rating.
/// </summary> /// </summary>

View File

@ -24,7 +24,5 @@ namespace MediaBrowser.Model.Dto
public List<MediaStream> MediaStreams { get; set; } public List<MediaStream> MediaStreams { get; set; }
public List<ChapterInfoDto> Chapters { get; set; } public List<ChapterInfoDto> Chapters { get; set; }
public bool? IsHD { get; set; }
} }
} }

View File

@ -76,6 +76,11 @@ namespace MediaBrowser.Model.Querying
/// </summary> /// </summary>
Keywords, Keywords,
/// <summary>
/// The media versions
/// </summary>
MediaVersions,
/// <summary> /// <summary>
/// The metadata settings /// The metadata settings
/// </summary> /// </summary>

View File

@ -1088,6 +1088,11 @@ namespace MediaBrowser.Server.Implementations.Dto
{ {
dto.Chapters = _itemRepo.GetChapters(video.Id).Select(c => GetChapterInfoDto(c, item)).ToList(); dto.Chapters = _itemRepo.GetChapters(video.Id).Select(c => GetChapterInfoDto(c, item)).ToList();
} }
if (fields.Contains(ItemFields.MediaVersions))
{
//dto.MediaVersions = GetMediaVersions(video);
}
} }
if (fields.Contains(ItemFields.MediaStreams)) if (fields.Contains(ItemFields.MediaStreams))
@ -1223,6 +1228,163 @@ namespace MediaBrowser.Server.Implementations.Dto
} }
} }
private List<MediaVersionInfo> GetMediaVersions(Video video)
{
var result = video.GetAlternateVersions().Select(GetVersionInfo).ToList();
result.Add(GetVersionInfo(video));
return result.OrderBy(i =>
{
if (video.VideoType == VideoType.VideoFile)
{
return 0;
}
return 1;
}).ThenBy(i => i.Video3DFormat.HasValue ? 1 : 0)
.ThenByDescending(i =>
{
var stream = i.MediaStreams.FirstOrDefault(m => m.Type == MediaStreamType.Video);
return stream == null || stream.Width == null ? 0 : stream.Width.Value;
})
.ToList();
}
private MediaVersionInfo GetVersionInfo(Video i)
{
return new MediaVersionInfo
{
Chapters = _itemRepo.GetChapters(i.Id).Select(c => GetChapterInfoDto(c, i)).ToList(),
Id = i.Id.ToString("N"),
IsoType = i.IsoType,
LocationType = i.LocationType,
MediaStreams = _itemRepo.GetMediaStreams(new MediaStreamQuery { ItemId = i.Id }).ToList(),
Name = GetAlternateVersionName(i),
Path = GetMappedPath(i),
RunTimeTicks = i.RunTimeTicks,
Video3DFormat = i.Video3DFormat,
VideoType = i.VideoType
};
}
private string GetMappedPath(Video video)
{
var path = video.Path;
var locationType = video.LocationType;
if (locationType != LocationType.FileSystem && locationType != LocationType.Offline)
{
return path;
}
foreach (var map in _config.Configuration.PathSubstitutions)
{
path = _fileSystem.SubstitutePath(path, map.From, map.To);
}
return path;
}
private string GetAlternateVersionName(Video video)
{
var name = "";
var stream = video.GetDefaultVideoStream();
if (video.Video3DFormat.HasValue)
{
name = "3D " + name;
name = name.Trim();
}
if (video.VideoType == VideoType.BluRay)
{
name = name + " " + "Bluray";
name = name.Trim();
}
else if (video.VideoType == VideoType.Dvd)
{
name = name + " " + "DVD";
name = name.Trim();
}
else if (video.VideoType == VideoType.HdDvd)
{
name = name + " " + "HD-DVD";
name = name.Trim();
}
else if (video.VideoType == VideoType.Iso)
{
if (video.IsoType.HasValue)
{
if (video.IsoType.Value == IsoType.BluRay)
{
name = name + " " + "Bluray";
}
else if (video.IsoType.Value == IsoType.Dvd)
{
name = name + " " + "DVD";
}
}
else
{
name = name + " " + "ISO";
}
name = name.Trim();
}
else if (video.VideoType == VideoType.VideoFile)
{
if (stream != null)
{
if (stream.Width.HasValue)
{
if (stream.Width.Value >= 3800)
{
name = name + " " + "4K";
name = name.Trim();
}
else if (stream.Width.Value >= 1900)
{
name = name + " " + "1080P";
name = name.Trim();
}
else if (stream.Width.Value >= 1270)
{
name = name + " " + "720P";
name = name.Trim();
}
else if (stream.Width.Value >= 700)
{
name = name + " " + "480p";
name = name.Trim();
}
else
{
name = name + " " + "SD";
name = name.Trim();
}
}
}
}
if (stream != null && !string.IsNullOrWhiteSpace(stream.Codec))
{
name = name + " " + stream.Codec.ToUpper();
name = name.Trim();
}
if (string.IsNullOrWhiteSpace(name))
{
return video.Name;
}
return name;
}
private string GetMappedPath(string path) private string GetMappedPath(string path)
{ {
foreach (var map in _config.Configuration.PathSubstitutions) foreach (var map in _config.Configuration.PathSubstitutions)

View File

@ -283,6 +283,15 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
return new[] { user.RootFolder as T }; return new[] { user.RootFolder as T };
} }
// Need to find what user collection folder this belongs to
if (item.Parent is AggregateFolder)
{
if (item.LocationType == LocationType.FileSystem)
{
return collections.Where(i => i.PhysicalLocations.Contains(item.Path)).Cast<T>();
}
}
// Return it only if it's in the user's library // Return it only if it's in the user's library
if (includeIfNotFound || allRecursiveChildren.ContainsKey(item.Id)) if (includeIfNotFound || allRecursiveChildren.ContainsKey(item.Id))
{ {

View File

@ -133,15 +133,7 @@ namespace MediaBrowser.Server.Implementations.Library
/// <summary> /// <summary>
/// The _library items cache /// The _library items cache
/// </summary> /// </summary>
private ConcurrentDictionary<Guid, BaseItem> _libraryItemsCache; private readonly ConcurrentDictionary<Guid, BaseItem> _libraryItemsCache;
/// <summary>
/// The _library items cache sync lock
/// </summary>
private object _libraryItemsCacheSyncLock = new object();
/// <summary>
/// The _library items cache initialized
/// </summary>
private bool _libraryItemsCacheInitialized;
/// <summary> /// <summary>
/// Gets the library items cache. /// Gets the library items cache.
/// </summary> /// </summary>
@ -150,7 +142,6 @@ namespace MediaBrowser.Server.Implementations.Library
{ {
get get
{ {
LazyInitializer.EnsureInitialized(ref _libraryItemsCache, ref _libraryItemsCacheInitialized, ref _libraryItemsCacheSyncLock, CreateLibraryItemsCache);
return _libraryItemsCache; return _libraryItemsCache;
} }
} }
@ -176,6 +167,7 @@ namespace MediaBrowser.Server.Implementations.Library
_fileSystem = fileSystem; _fileSystem = fileSystem;
_providerManagerFactory = providerManagerFactory; _providerManagerFactory = providerManagerFactory;
ByReferenceItems = new ConcurrentDictionary<Guid, BaseItem>(); ByReferenceItems = new ConcurrentDictionary<Guid, BaseItem>();
_libraryItemsCache = new ConcurrentDictionary<Guid, BaseItem>();
ConfigurationManager.ConfigurationUpdated += ConfigurationUpdated; ConfigurationManager.ConfigurationUpdated += ConfigurationUpdated;
@ -358,48 +350,6 @@ namespace MediaBrowser.Server.Implementations.Library
} }
} }
/// <summary>
/// Creates the library items cache.
/// </summary>
/// <returns>ConcurrentDictionary{GuidBaseItem}.</returns>
private ConcurrentDictionary<Guid, BaseItem> CreateLibraryItemsCache()
{
var items = RootFolder.GetRecursiveChildren();
items.Add(RootFolder);
// Need to use Distinct because there could be multiple instances with the same id
// due to sharing the default library
var userRootFolders = _userManager.Users.Select(i => i.RootFolder)
.Distinct()
.ToList();
foreach (var folder in userRootFolders)
{
items.Add(folder);
}
// Get all user collection folders
// Skip BasePluginFolders because we already got them from RootFolder.RecursiveChildren
var userFolders = userRootFolders.SelectMany(i => i.Children)
.Where(i => !(i is BasePluginFolder))
.ToList();
foreach (var folder in userFolders)
{
items.Add(folder);
}
var dictionary = new ConcurrentDictionary<Guid, BaseItem>();
foreach (var item in items)
{
dictionary[item.Id] = item;
}
return dictionary;
}
/// <summary> /// <summary>
/// Updates the item in library cache. /// Updates the item in library cache.
/// </summary> /// </summary>
@ -411,6 +361,10 @@ namespace MediaBrowser.Server.Implementations.Library
public void RegisterItem(BaseItem item) public void RegisterItem(BaseItem item)
{ {
if (item == null)
{
throw new ArgumentNullException("item");
}
RegisterItem(item.Id, item); RegisterItem(item.Id, item);
} }
@ -529,13 +483,6 @@ namespace MediaBrowser.Server.Implementations.Library
if (item != null) if (item != null)
{ {
ResolverHelper.SetInitialItemValues(item, args, _fileSystem); ResolverHelper.SetInitialItemValues(item, args, _fileSystem);
// Now handle the issue with posibly having the same item referenced from multiple physical
// places within the library. Be sure we always end up with just one instance.
if (item is IByReferenceItem)
{
item = GetOrAddByReferenceItem(item);
}
} }
return item; return item;
@ -720,7 +667,7 @@ namespace MediaBrowser.Server.Implementations.Library
Directory.CreateDirectory(rootFolderPath); Directory.CreateDirectory(rootFolderPath);
var rootFolder = RetrieveItem(rootFolderPath.GetMBId(typeof(AggregateFolder))) as AggregateFolder ?? (AggregateFolder)ResolvePath(new DirectoryInfo(rootFolderPath)); var rootFolder = GetItemById(rootFolderPath.GetMBId(typeof(AggregateFolder))) as AggregateFolder ?? (AggregateFolder)ResolvePath(new DirectoryInfo(rootFolderPath));
// Add in the plug-in folders // Add in the plug-in folders
foreach (var child in PluginFolderCreators) foreach (var child in PluginFolderCreators)
@ -747,7 +694,7 @@ namespace MediaBrowser.Server.Implementations.Library
Directory.CreateDirectory(userRootPath); Directory.CreateDirectory(userRootPath);
_userRootFolder = RetrieveItem(userRootPath.GetMBId(typeof(UserRootFolder))) as UserRootFolder ?? _userRootFolder = GetItemById(userRootPath.GetMBId(typeof(UserRootFolder))) as UserRootFolder ??
(UserRootFolder)ResolvePath(new DirectoryInfo(userRootPath)); (UserRootFolder)ResolvePath(new DirectoryInfo(userRootPath));
} }
@ -919,7 +866,7 @@ namespace MediaBrowser.Server.Implementations.Library
isNew = true; isNew = true;
} }
var item = isNew ? null : RetrieveItem(id) as T; var item = isNew ? null : GetItemById(id) as T;
if (item == null) if (item == null)
{ {
@ -1228,7 +1175,14 @@ namespace MediaBrowser.Server.Implementations.Library
return item; return item;
} }
return RetrieveItem(id); item = RetrieveItem(id);
if (item != null)
{
RegisterItem(item);
}
return item;
} }
/// <summary> /// <summary>