mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-06-04 06:48:35 +01:00
update owned items
This commit is contained in:
@@ -137,7 +137,7 @@ namespace MediaBrowser.Controller.Entities
|
||||
{
|
||||
FileInfo = FileSystem.GetDirectoryInfo(path),
|
||||
Path = path,
|
||||
Parent = Parent
|
||||
Parent = GetParent() as Folder
|
||||
};
|
||||
|
||||
// Gather child folder and files
|
||||
|
||||
@@ -97,7 +97,7 @@ namespace MediaBrowser.Controller.Entities
|
||||
public string Tagline { get; set; }
|
||||
|
||||
[IgnoreDataMember]
|
||||
public ItemImageInfo[] ImageInfos { get; set; }
|
||||
public virtual ItemImageInfo[] ImageInfos { get; set; }
|
||||
|
||||
[IgnoreDataMember]
|
||||
public bool IsVirtualItem { get; set; }
|
||||
@@ -216,6 +216,9 @@ namespace MediaBrowser.Controller.Entities
|
||||
[IgnoreDataMember]
|
||||
public Guid Id { get; set; }
|
||||
|
||||
[IgnoreDataMember]
|
||||
public Guid OwnerId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether this instance is hd.
|
||||
/// </summary>
|
||||
@@ -321,12 +324,31 @@ namespace MediaBrowser.Controller.Entities
|
||||
{
|
||||
get
|
||||
{
|
||||
if (OwnerId != Guid.Empty)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// legacy
|
||||
|
||||
// Local trailer, special feature, theme video, etc.
|
||||
// An item that belongs to another item but is not part of the Parent-Child tree
|
||||
return !IsFolder && ParentId == Guid.Empty && LocationType == LocationType.FileSystem;
|
||||
// This is a hack for now relying on ExtraType. Eventually we may need to persist this
|
||||
if (ParentId == Guid.Empty && !IsFolder && LocationType == LocationType.FileSystem)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public BaseItem GetOwner()
|
||||
{
|
||||
var ownerId = OwnerId;
|
||||
return ownerId == Guid.Empty ? null : LibraryManager.GetItemById(ownerId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the type of the location.
|
||||
/// </summary>
|
||||
@@ -727,17 +749,12 @@ namespace MediaBrowser.Controller.Entities
|
||||
ParentId = parent == null ? Guid.Empty : parent.Id;
|
||||
}
|
||||
|
||||
[IgnoreDataMember]
|
||||
public IEnumerable<Folder> Parents
|
||||
{
|
||||
get { return GetParents().OfType<Folder>(); }
|
||||
}
|
||||
|
||||
public BaseItem GetParent()
|
||||
{
|
||||
if (ParentId != Guid.Empty)
|
||||
var parentId = ParentId;
|
||||
if (parentId != Guid.Empty)
|
||||
{
|
||||
return LibraryManager.GetItemById(ParentId);
|
||||
return LibraryManager.GetItemById(parentId);
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -779,11 +796,13 @@ namespace MediaBrowser.Controller.Entities
|
||||
{
|
||||
get
|
||||
{
|
||||
if (ParentId == Guid.Empty)
|
||||
var parentId = ParentId;
|
||||
|
||||
if (parentId == Guid.Empty)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return ParentId;
|
||||
return parentId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1002,8 +1021,11 @@ namespace MediaBrowser.Controller.Entities
|
||||
{
|
||||
audio = dbItem;
|
||||
}
|
||||
|
||||
audio.ExtraType = MediaBrowser.Model.Entities.ExtraType.ThemeSong;
|
||||
else
|
||||
{
|
||||
// item is new
|
||||
audio.ExtraType = MediaBrowser.Model.Entities.ExtraType.ThemeSong;
|
||||
}
|
||||
|
||||
return audio;
|
||||
|
||||
@@ -1032,8 +1054,11 @@ namespace MediaBrowser.Controller.Entities
|
||||
{
|
||||
item = dbItem;
|
||||
}
|
||||
|
||||
item.ExtraType = MediaBrowser.Model.Entities.ExtraType.ThemeVideo;
|
||||
else
|
||||
{
|
||||
// item is new
|
||||
item.ExtraType = MediaBrowser.Model.Entities.ExtraType.ThemeVideo;
|
||||
}
|
||||
|
||||
return item;
|
||||
|
||||
@@ -1178,8 +1203,25 @@ namespace MediaBrowser.Controller.Entities
|
||||
var newItemIds = newItems.Select(i => i.Id).ToArray();
|
||||
|
||||
var itemsChanged = !item.LocalTrailerIds.SequenceEqual(newItemIds);
|
||||
var ownerId = item.Id;
|
||||
|
||||
var tasks = newItems.Select(i => RefreshMetadataForOwnedItem(i, true, options, cancellationToken));
|
||||
var tasks = newItems.Select(i =>
|
||||
{
|
||||
var subOptions = new MetadataRefreshOptions(options);
|
||||
|
||||
if (!i.ExtraType.HasValue ||
|
||||
i.ExtraType.Value != Model.Entities.ExtraType.Trailer ||
|
||||
i.OwnerId != ownerId ||
|
||||
i.ParentId != Guid.Empty)
|
||||
{
|
||||
i.ExtraType = Model.Entities.ExtraType.Trailer;
|
||||
i.OwnerId = ownerId;
|
||||
i.ParentId = Guid.Empty;
|
||||
subOptions.ForceSave = true;
|
||||
}
|
||||
|
||||
return RefreshMetadataForOwnedItem(i, true, subOptions, cancellationToken);
|
||||
});
|
||||
|
||||
await Task.WhenAll(tasks).ConfigureAwait(false);
|
||||
|
||||
@@ -1196,13 +1238,20 @@ namespace MediaBrowser.Controller.Entities
|
||||
|
||||
var themeVideosChanged = !item.ThemeVideoIds.SequenceEqual(newThemeVideoIds);
|
||||
|
||||
var ownerId = item.Id;
|
||||
|
||||
var tasks = newThemeVideos.Select(i =>
|
||||
{
|
||||
var subOptions = new MetadataRefreshOptions(options);
|
||||
|
||||
if (!i.IsThemeMedia)
|
||||
if (!i.ExtraType.HasValue ||
|
||||
i.ExtraType.Value != Model.Entities.ExtraType.ThemeVideo ||
|
||||
i.OwnerId != ownerId ||
|
||||
i.ParentId != Guid.Empty)
|
||||
{
|
||||
i.ExtraType = MediaBrowser.Model.Entities.ExtraType.ThemeVideo;
|
||||
i.ExtraType = Model.Entities.ExtraType.ThemeVideo;
|
||||
i.OwnerId = ownerId;
|
||||
i.ParentId = Guid.Empty;
|
||||
subOptions.ForceSave = true;
|
||||
}
|
||||
|
||||
@@ -1226,13 +1275,20 @@ namespace MediaBrowser.Controller.Entities
|
||||
|
||||
var themeSongsChanged = !item.ThemeSongIds.SequenceEqual(newThemeSongIds);
|
||||
|
||||
var ownerId = item.Id;
|
||||
|
||||
var tasks = newThemeSongs.Select(i =>
|
||||
{
|
||||
var subOptions = new MetadataRefreshOptions(options);
|
||||
|
||||
if (!i.IsThemeMedia)
|
||||
if (!i.ExtraType.HasValue ||
|
||||
i.ExtraType.Value != Model.Entities.ExtraType.ThemeSong ||
|
||||
i.OwnerId != ownerId ||
|
||||
i.ParentId != Guid.Empty)
|
||||
{
|
||||
i.ExtraType = MediaBrowser.Model.Entities.ExtraType.ThemeSong;
|
||||
i.ExtraType = Model.Entities.ExtraType.ThemeSong;
|
||||
i.OwnerId = ownerId;
|
||||
i.ParentId = Guid.Empty;
|
||||
subOptions.ForceSave = true;
|
||||
}
|
||||
|
||||
@@ -1868,7 +1924,6 @@ namespace MediaBrowser.Controller.Entities
|
||||
{
|
||||
existingImage.Path = image.Path;
|
||||
existingImage.DateModified = image.DateModified;
|
||||
existingImage.IsPlaceholder = image.IsPlaceholder;
|
||||
}
|
||||
|
||||
else
|
||||
@@ -1902,7 +1957,6 @@ namespace MediaBrowser.Controller.Entities
|
||||
|
||||
image.Path = file.FullName;
|
||||
image.DateModified = imageInfo.DateModified;
|
||||
image.IsPlaceholder = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2359,6 +2413,14 @@ namespace MediaBrowser.Controller.Entities
|
||||
newOptions.ForceSave = true;
|
||||
}
|
||||
|
||||
//var parentId = Id;
|
||||
//if (!video.IsOwnedItem || video.ParentId != parentId)
|
||||
//{
|
||||
// video.IsOwnedItem = true;
|
||||
// video.ParentId = parentId;
|
||||
// newOptions.ForceSave = true;
|
||||
//}
|
||||
|
||||
if (video == null)
|
||||
{
|
||||
return Task.FromResult(true);
|
||||
|
||||
@@ -280,7 +280,7 @@ namespace MediaBrowser.Controller.Entities
|
||||
{
|
||||
FileInfo = FileSystem.GetDirectoryInfo(path),
|
||||
Path = path,
|
||||
Parent = Parent,
|
||||
Parent = GetParent() as Folder,
|
||||
CollectionType = CollectionType
|
||||
};
|
||||
|
||||
|
||||
@@ -378,6 +378,7 @@ namespace MediaBrowser.Controller.Entities
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var validChildren = new List<BaseItem>();
|
||||
var validChildrenNeedGeneration = false;
|
||||
|
||||
var allLibraryPaths = LibraryManager
|
||||
.GetVirtualFolders()
|
||||
@@ -474,11 +475,7 @@ namespace MediaBrowser.Controller.Entities
|
||||
}
|
||||
else
|
||||
{
|
||||
if (recursive || refreshChildMetadata)
|
||||
{
|
||||
// used below
|
||||
validChildren = Children.ToList();
|
||||
}
|
||||
validChildrenNeedGeneration = true;
|
||||
}
|
||||
|
||||
progress.Report(10);
|
||||
@@ -502,6 +499,12 @@ namespace MediaBrowser.Controller.Entities
|
||||
ProviderManager.OnRefreshProgress(folder, newPct);
|
||||
});
|
||||
|
||||
if (validChildrenNeedGeneration)
|
||||
{
|
||||
validChildren = Children.ToList();
|
||||
validChildrenNeedGeneration = false;
|
||||
}
|
||||
|
||||
await ValidateSubFolders(validChildren.OfType<Folder>().ToList(), directoryService, innerProgress, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
@@ -536,6 +539,12 @@ namespace MediaBrowser.Controller.Entities
|
||||
}
|
||||
else
|
||||
{
|
||||
if (validChildrenNeedGeneration)
|
||||
{
|
||||
validChildren = Children.ToList();
|
||||
validChildrenNeedGeneration = false;
|
||||
}
|
||||
|
||||
await RefreshMetadataRecursive(validChildren, refreshOptions, recursive, innerProgress, cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -565,7 +574,7 @@ namespace MediaBrowser.Controller.Entities
|
||||
});
|
||||
|
||||
await RefreshChildMetadata(child, refreshOptions, recursive && child.IsFolder, innerProgress, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
|
||||
numComplete++;
|
||||
@@ -588,7 +597,10 @@ namespace MediaBrowser.Controller.Entities
|
||||
}
|
||||
else
|
||||
{
|
||||
await child.RefreshMetadata(refreshOptions, cancellationToken).ConfigureAwait(false);
|
||||
if (refreshOptions.RefreshItem(child))
|
||||
{
|
||||
await child.RefreshMetadata(refreshOptions, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (recursive)
|
||||
{
|
||||
@@ -1196,11 +1208,21 @@ namespace MediaBrowser.Controller.Entities
|
||||
/// Gets the linked children.
|
||||
/// </summary>
|
||||
/// <returns>IEnumerable{BaseItem}.</returns>
|
||||
public IEnumerable<BaseItem> GetLinkedChildren()
|
||||
public List<BaseItem> GetLinkedChildren()
|
||||
{
|
||||
return LinkedChildren
|
||||
.Select(GetLinkedChild)
|
||||
.Where(i => i != null);
|
||||
var linkedChildren = LinkedChildren;
|
||||
var list = new List<BaseItem>(linkedChildren.Length);
|
||||
|
||||
foreach (var i in linkedChildren)
|
||||
{
|
||||
var child = GetLinkedChild(i);
|
||||
|
||||
if (child != null)
|
||||
{
|
||||
list.Add(child);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
protected virtual bool FilterLinkedChildrenPerUser
|
||||
@@ -1211,16 +1233,19 @@ namespace MediaBrowser.Controller.Entities
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<BaseItem> GetLinkedChildren(User user)
|
||||
public List<BaseItem> GetLinkedChildren(User user)
|
||||
{
|
||||
if (!FilterLinkedChildrenPerUser || user == null)
|
||||
{
|
||||
return GetLinkedChildren();
|
||||
}
|
||||
|
||||
if (LinkedChildren.Length == 0)
|
||||
var linkedChildren = LinkedChildren;
|
||||
var list = new List<BaseItem>(linkedChildren.Length);
|
||||
|
||||
if (linkedChildren.Length == 0)
|
||||
{
|
||||
return new List<BaseItem>();
|
||||
return list;
|
||||
}
|
||||
|
||||
var allUserRootChildren = user.RootFolder.Children.OfType<Folder>().ToList();
|
||||
@@ -1231,37 +1256,43 @@ namespace MediaBrowser.Controller.Entities
|
||||
.Select(i => i.Id)
|
||||
.ToList();
|
||||
|
||||
return LinkedChildren
|
||||
.Select(i =>
|
||||
foreach (var i in linkedChildren)
|
||||
{
|
||||
var child = GetLinkedChild(i);
|
||||
|
||||
if (child == null)
|
||||
{
|
||||
var child = GetLinkedChild(i);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (child != null)
|
||||
var childOwner = child.IsOwnedItem ? (child.GetOwner() ?? child) : child;
|
||||
|
||||
if (childOwner != null)
|
||||
{
|
||||
var childLocationType = childOwner.LocationType;
|
||||
if (childLocationType == LocationType.Remote || childLocationType == LocationType.Virtual)
|
||||
{
|
||||
var childLocationType = child.LocationType;
|
||||
if (childLocationType == LocationType.Remote || childLocationType == LocationType.Virtual)
|
||||
if (!childOwner.IsVisibleStandalone(user))
|
||||
{
|
||||
if (!child.IsVisibleStandalone(user))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (childLocationType == LocationType.FileSystem)
|
||||
{
|
||||
var itemCollectionFolderIds =
|
||||
LibraryManager.GetCollectionFolders(child, allUserRootChildren)
|
||||
.Select(f => f.Id).ToList();
|
||||
|
||||
if (!itemCollectionFolderIds.Any(collectionFolderIds.Contains))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else if (childLocationType == LocationType.FileSystem)
|
||||
{
|
||||
var itemCollectionFolderIds =
|
||||
LibraryManager.GetCollectionFolders(childOwner, allUserRootChildren).Select(f => f.Id);
|
||||
|
||||
return child;
|
||||
})
|
||||
.Where(i => i != null);
|
||||
if (!itemCollectionFolderIds.Any(collectionFolderIds.Contains))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
list.Add(child);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -5,7 +5,7 @@ using System.Linq;
|
||||
|
||||
namespace MediaBrowser.Controller.Entities
|
||||
{
|
||||
public interface IHasTrailers : IHasProviderIds
|
||||
public interface IHasTrailers : IHasMetadata
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the remote trailers.
|
||||
|
||||
@@ -24,12 +24,6 @@ namespace MediaBrowser.Controller.Entities
|
||||
/// <value>The date modified.</value>
|
||||
public DateTime DateModified { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether this instance is placeholder.
|
||||
/// </summary>
|
||||
/// <value><c>true</c> if this instance is placeholder; otherwise, <c>false</c>.</value>
|
||||
public bool IsPlaceholder { get; set; }
|
||||
|
||||
[IgnoreDataMember]
|
||||
public bool IsLocalFile
|
||||
{
|
||||
|
||||
@@ -81,7 +81,20 @@ namespace MediaBrowser.Controller.Entities.Movies
|
||||
|
||||
var itemsChanged = !SpecialFeatureIds.SequenceEqual(newItemIds);
|
||||
|
||||
var tasks = newItems.Select(i => RefreshMetadataForOwnedItem(i, false, options, cancellationToken));
|
||||
var ownerId = Id;
|
||||
|
||||
var tasks = newItems.Select(i =>
|
||||
{
|
||||
var subOptions = new MetadataRefreshOptions(options);
|
||||
|
||||
if (i.OwnerId != ownerId)
|
||||
{
|
||||
i.OwnerId = ownerId;
|
||||
subOptions.ForceSave = true;
|
||||
}
|
||||
|
||||
return RefreshMetadataForOwnedItem(i, false, subOptions, cancellationToken);
|
||||
});
|
||||
|
||||
await Task.WhenAll(tasks).ConfigureAwait(false);
|
||||
|
||||
|
||||
@@ -347,7 +347,10 @@ namespace MediaBrowser.Controller.Entities.TV
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
await item.RefreshMetadata(refreshOptions, cancellationToken).ConfigureAwait(false);
|
||||
if (refreshOptions.RefreshItem(item))
|
||||
{
|
||||
await item.RefreshMetadata(refreshOptions, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
numComplete++;
|
||||
double percent = numComplete;
|
||||
@@ -382,7 +385,10 @@ namespace MediaBrowser.Controller.Entities.TV
|
||||
|
||||
if (!skipItem)
|
||||
{
|
||||
await item.RefreshMetadata(refreshOptions, cancellationToken).ConfigureAwait(false);
|
||||
if (refreshOptions.RefreshItem(item))
|
||||
{
|
||||
await item.RefreshMetadata(refreshOptions, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
numComplete++;
|
||||
|
||||
@@ -37,6 +37,9 @@ namespace MediaBrowser.Controller.Entities
|
||||
public UserLinkType? ConnectLinkType { get; set; }
|
||||
public string ConnectAccessKey { get; set; }
|
||||
|
||||
// Strictly to remove IgnoreDataMember
|
||||
public override ItemImageInfo[] ImageInfos { get => base.ImageInfos; set => base.ImageInfos = value; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the path.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using System.Linq;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.IO;
|
||||
using MediaBrowser.Model.IO;
|
||||
using MediaBrowser.Model.Logging;
|
||||
@@ -20,6 +22,8 @@ namespace MediaBrowser.Controller.Providers
|
||||
public MetadataRefreshMode MetadataRefreshMode { get; set; }
|
||||
public RemoteSearchResult SearchResult { get; set; }
|
||||
|
||||
public List<string> RefreshPaths { get; set; }
|
||||
|
||||
public bool ForceSave { get; set; }
|
||||
|
||||
public MetadataRefreshOptions(IFileSystem fileSystem)
|
||||
@@ -44,6 +48,26 @@ namespace MediaBrowser.Controller.Providers
|
||||
ReplaceAllImages = copy.ReplaceAllImages;
|
||||
ReplaceImages = copy.ReplaceImages.ToList();
|
||||
SearchResult = copy.SearchResult;
|
||||
|
||||
if (copy.RefreshPaths != null && copy.RefreshPaths.Count > 0)
|
||||
{
|
||||
if (RefreshPaths == null)
|
||||
{
|
||||
RefreshPaths = new List<string>();
|
||||
}
|
||||
|
||||
RefreshPaths.AddRange(copy.RefreshPaths);
|
||||
}
|
||||
}
|
||||
|
||||
public bool RefreshItem(BaseItem item)
|
||||
{
|
||||
if (RefreshPaths != null && RefreshPaths.Count > 0)
|
||||
{
|
||||
return RefreshPaths.Contains(item.Path ?? string.Empty, StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user