Merge pull request #3039 from MediaBrowser/dev

Dev
This commit is contained in:
Luke 2017-11-25 23:51:37 -05:00 committed by GitHub
commit acc17634a4
12 changed files with 98 additions and 24 deletions

View File

@ -260,7 +260,7 @@ namespace Emby.Server.Implementations.EntryPoints
LibraryUpdateTimer.Change(LibraryUpdateDuration, Timeout.Infinite);
}
var parent = e.Item.GetParent() as Folder;
var parent = e.Parent as Folder;
if (parent != null)
{
_foldersRemovedFrom.Add(parent);
@ -363,10 +363,16 @@ namespace Emby.Server.Implementations.EntryPoints
/// <param name="foldersRemovedFrom">The folders removed from.</param>
/// <param name="userId">The user id.</param>
/// <returns>LibraryUpdateInfo.</returns>
private LibraryUpdateInfo GetLibraryUpdateInfo(IEnumerable<BaseItem> itemsAdded, IEnumerable<BaseItem> itemsUpdated, IEnumerable<BaseItem> itemsRemoved, IEnumerable<Folder> foldersAddedTo, IEnumerable<Folder> foldersRemovedFrom, Guid userId)
private LibraryUpdateInfo GetLibraryUpdateInfo(List<BaseItem> itemsAdded, List<BaseItem> itemsUpdated, List<BaseItem> itemsRemoved, List<Folder> foldersAddedTo, List<Folder> foldersRemovedFrom, Guid userId)
{
var user = _userManager.GetUserById(userId);
var newAndRemoved = new List<BaseItem>();
newAndRemoved.AddRange(foldersAddedTo);
newAndRemoved.AddRange(foldersRemovedFrom);
var allUserRootChildren = _libraryManager.GetUserRootFolder().GetChildren(user, true).OfType<Folder>().ToList();
return new LibraryUpdateInfo
{
ItemsAdded = itemsAdded.SelectMany(i => TranslatePhysicalItemToUserLibrary(i, user)).Select(i => i.Id.ToString("N")).Distinct().ToArray(),
@ -377,7 +383,9 @@ namespace Emby.Server.Implementations.EntryPoints
FoldersAddedTo = foldersAddedTo.SelectMany(i => TranslatePhysicalItemToUserLibrary(i, user)).Select(i => i.Id.ToString("N")).Distinct().ToArray(),
FoldersRemovedFrom = foldersRemovedFrom.SelectMany(i => TranslatePhysicalItemToUserLibrary(i, user)).Select(i => i.Id.ToString("N")).Distinct().ToArray()
FoldersRemovedFrom = foldersRemovedFrom.SelectMany(i => TranslatePhysicalItemToUserLibrary(i, user)).Select(i => i.Id.ToString("N")).Distinct().ToArray(),
CollectionFolders = GetTopParentIds(newAndRemoved, user, allUserRootChildren).ToArray()
};
}
@ -396,6 +404,28 @@ namespace Emby.Server.Implementations.EntryPoints
return item.SourceType == SourceType.Library;
}
private IEnumerable<string> GetTopParentIds(List<BaseItem> items, User user, List<Folder> allUserRootChildren)
{
var list = new List<string>();
foreach (var item in items)
{
// If the physical root changed, return the user root
if (item is AggregateFolder)
{
continue;
}
var collectionFolders = _libraryManager.GetCollectionFolders(item, allUserRootChildren);
foreach (var folder in allUserRootChildren)
{
list.Add(folder.Id.ToString("N"));
}
}
return list.Distinct(StringComparer.Ordinal);
}
/// <summary>
/// Translates the physical item to user library.
/// </summary>

View File

@ -237,7 +237,7 @@ namespace Emby.Server.Implementations.IO
/// <param name="e">The <see cref="ItemChangeEventArgs"/> instance containing the event data.</param>
void LibraryManager_ItemRemoved(object sender, ItemChangeEventArgs e)
{
if (e.Item.GetParent() is AggregateFolder)
if (e.Parent is AggregateFolder)
{
StopWatchingPath(e.Item.Path);
}
@ -250,7 +250,7 @@ namespace Emby.Server.Implementations.IO
/// <param name="e">The <see cref="ItemChangeEventArgs"/> instance containing the event data.</param>
void LibraryManager_ItemAdded(object sender, ItemChangeEventArgs e)
{
if (e.Item.GetParent() is AggregateFolder)
if (e.Parent is AggregateFolder)
{
StartWatching(e.Item);
}
@ -320,7 +320,8 @@ namespace Emby.Server.Implementations.IO
IncludeSubdirectories = true
};
if (_environmentInfo.OperatingSystem == MediaBrowser.Model.System.OperatingSystem.Windows)
if (_environmentInfo.OperatingSystem == MediaBrowser.Model.System.OperatingSystem.Windows ||
_environmentInfo.OperatingSystem == MediaBrowser.Model.System.OperatingSystem.OSX)
{
newWatcher.InternalBufferSize = 32767;
}

View File

@ -473,6 +473,11 @@ namespace Emby.Server.Implementations.IO
public void SetHidden(string path, bool isHidden)
{
if (_environmentInfo.OperatingSystem != MediaBrowser.Model.System.OperatingSystem.Windows)
{
return;
}
if (_sharpCifsFileSystem.IsEnabledForPath(path))
{
_sharpCifsFileSystem.SetHidden(path, isHidden);
@ -498,6 +503,11 @@ namespace Emby.Server.Implementations.IO
public void SetReadOnly(string path, bool isReadOnly)
{
if (_environmentInfo.OperatingSystem != MediaBrowser.Model.System.OperatingSystem.Windows)
{
return;
}
if (_sharpCifsFileSystem.IsEnabledForPath(path))
{
_sharpCifsFileSystem.SetReadOnly(path, isReadOnly);
@ -523,6 +533,11 @@ namespace Emby.Server.Implementations.IO
public void SetAttributes(string path, bool isHidden, bool isReadOnly)
{
if (_environmentInfo.OperatingSystem != MediaBrowser.Model.System.OperatingSystem.Windows)
{
return;
}
if (_sharpCifsFileSystem.IsEnabledForPath(path))
{
_sharpCifsFileSystem.SetAttributes(path, isHidden, isReadOnly);

View File

@ -443,7 +443,7 @@ namespace Emby.Server.Implementations.Library
BaseItem removed;
_libraryItemsCache.TryRemove(item.Id, out removed);
ReportItemRemoved(item);
ReportItemRemoved(item, parent);
}
private IEnumerable<string> GetMetadataPaths(BaseItem item, IEnumerable<BaseItem> children)
@ -1804,7 +1804,7 @@ namespace Emby.Server.Implementations.Library
/// <returns>Task.</returns>
public void CreateItem(BaseItem item, CancellationToken cancellationToken)
{
CreateItems(new[] { item }, cancellationToken);
CreateItems(new[] { item }, item.GetParent(), cancellationToken);
}
/// <summary>
@ -1813,7 +1813,7 @@ namespace Emby.Server.Implementations.Library
/// <param name="items">The items.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task.</returns>
public void CreateItems(IEnumerable<BaseItem> items, CancellationToken cancellationToken)
public void CreateItems(IEnumerable<BaseItem> items, BaseItem parent, CancellationToken cancellationToken)
{
var list = items.ToList();
@ -1830,7 +1830,11 @@ namespace Emby.Server.Implementations.Library
{
try
{
ItemAdded(this, new ItemChangeEventArgs { Item = item });
ItemAdded(this, new ItemChangeEventArgs
{
Item = item,
Parent = parent ?? item.GetParent()
});
}
catch (Exception ex)
{
@ -1878,6 +1882,7 @@ namespace Emby.Server.Implementations.Library
ItemUpdated(this, new ItemChangeEventArgs
{
Item = item,
Parent = item.GetParent(),
UpdateReason = updateReason
});
}
@ -1892,13 +1897,17 @@ namespace Emby.Server.Implementations.Library
/// Reports the item removed.
/// </summary>
/// <param name="item">The item.</param>
public void ReportItemRemoved(BaseItem item)
public void ReportItemRemoved(BaseItem item, BaseItem parent)
{
if (ItemRemoved != null)
{
try
{
ItemRemoved(this, new ItemChangeEventArgs { Item = item });
ItemRemoved(this, new ItemChangeEventArgs
{
Item = item,
Parent = parent
});
}
catch (Exception ex)
{

View File

@ -1512,6 +1512,8 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
}
}
DeleteFileIfEmpty(recordPath);
TriggerRefresh(recordPath);
_libraryMonitor.ReportFileSystemChangeComplete(recordPath, false);
@ -1542,6 +1544,23 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
}
}
private void DeleteFileIfEmpty(string path)
{
var file = _fileSystem.GetFileInfo(path);
if (file.Exists && file.Length == 0)
{
try
{
_fileSystem.DeleteFile(path);
}
catch (Exception ex)
{
_logger.ErrorException("Error deleting 0-byte failed recording file {0}", ex, path);
}
}
}
private void TriggerRefresh(string path)
{
_logger.Info("Triggering refresh on {0}", path);

View File

@ -1421,7 +1421,7 @@ namespace Emby.Server.Implementations.LiveTv
if (newPrograms.Count > 0)
{
_libraryManager.CreateItems(newPrograms, cancellationToken);
_libraryManager.CreateItems(newPrograms, null, cancellationToken);
}
// TODO: Do this in bulk

View File

@ -2236,7 +2236,7 @@ namespace MediaBrowser.Controller.Entities
}
var filename = System.IO.Path.GetFileNameWithoutExtension(Path);
var extensions = new List<string> { ".nfo", ".xml", ".srt" };
var extensions = new List<string> { ".nfo", ".xml", ".srt", ".vtt", ".sub", ".idx", ".txt", ".edl" };
extensions.AddRange(SupportedImageExtensions);
return FileSystem.GetFiles(FileSystem.GetDirectoryName(Path), extensions.ToArray(extensions.Count), false, false)

View File

@ -466,11 +466,11 @@ namespace MediaBrowser.Controller.Entities
item.SetParent(null);
await LibraryManager.DeleteItem(item, new DeleteOptions { DeleteFileLocation = false }).ConfigureAwait(false);
LibraryManager.ReportItemRemoved(item);
LibraryManager.ReportItemRemoved(item, this);
}
}
LibraryManager.CreateItems(newItems, cancellationToken);
LibraryManager.CreateItems(newItems, this, cancellationToken);
}
}
else

View File

@ -195,16 +195,12 @@ namespace MediaBrowser.Controller.Library
/// <summary>
/// Creates the item.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="cancellationToken">The cancellation token.</param>
void CreateItem(BaseItem item, CancellationToken cancellationToken);
/// <summary>
/// Creates the items.
/// </summary>
/// <param name="items">The items.</param>
/// <param name="cancellationToken">The cancellation token.</param>
void CreateItems(IEnumerable<BaseItem> items, CancellationToken cancellationToken);
void CreateItems(IEnumerable<BaseItem> items, BaseItem parent, CancellationToken cancellationToken);
/// <summary>
/// Updates the item.
@ -237,8 +233,7 @@ namespace MediaBrowser.Controller.Library
/// <summary>
/// Reports the item removed.
/// </summary>
/// <param name="item">The item.</param>
void ReportItemRemoved(BaseItem item);
void ReportItemRemoved(BaseItem item, BaseItem parent);
/// <summary>
/// Finds the type of the collection.

View File

@ -13,6 +13,8 @@ namespace MediaBrowser.Controller.Library
/// <value>The item.</value>
public BaseItem Item { get; set; }
public BaseItem Parent { get; set; }
/// <summary>
/// Gets or sets the item.
/// </summary>

View File

@ -35,6 +35,8 @@ namespace MediaBrowser.Model.Entities
/// <value>The items updated.</value>
public string[] ItemsUpdated { get; set; }
public string[] CollectionFolders { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="LibraryUpdateInfo"/> class.
/// </summary>
@ -45,6 +47,7 @@ namespace MediaBrowser.Model.Entities
ItemsAdded = new string[] { };
ItemsRemoved = new string[] { };
ItemsUpdated = new string[] { };
CollectionFolders = new string[] { };
}
}
}

View File

@ -1,3 +1,3 @@
using System.Reflection;
[assembly: AssemblyVersion("3.2.40.2")]
[assembly: AssemblyVersion("3.2.40.3")]