Enforce extras folder structure according to Emby's wiki

This commit is contained in:
Claus Vium 2019-05-02 08:14:00 +02:00
parent c1daea0ec7
commit b8a09339cd

View File

@ -82,6 +82,21 @@ namespace MediaBrowser.Controller.Entities
public static string ThemeSongsFolderName = "theme-music"; public static string ThemeSongsFolderName = "theme-music";
public static string ThemeSongFilename = "theme"; public static string ThemeSongFilename = "theme";
public static string ThemeVideosFolderName = "backdrops"; public static string ThemeVideosFolderName = "backdrops";
public static string ExtrasFolderName = "extras";
public static string BehindTheScenesFolderName = "behind the scenes";
public static string DeletedScenesFolderName = "deleted scenes";
public static string InterviewFolderName = "interviews";
public static string SceneFolderName = "scenes";
public static string SampleFolderName = "samples";
public static string[] AllExtrasTypesFolderNames = {
ExtrasFolderName,
BehindTheScenesFolderName,
DeletedScenesFolderName,
InterviewFolderName,
SceneFolderName,
SampleFolderName
};
[IgnoreDataMember] [IgnoreDataMember]
public Guid[] ThemeSongIds { get; set; } public Guid[] ThemeSongIds { get; set; }
@ -1276,16 +1291,15 @@ namespace MediaBrowser.Controller.Entities
.Select(item => .Select(item =>
{ {
// Try to retrieve it from the db. If we don't find it, use the resolved version // Try to retrieve it from the db. If we don't find it, use the resolved version
var dbItem = LibraryManager.GetItemById(item.Id) as Video;
if (dbItem != null) if (LibraryManager.GetItemById(item.Id) is Video dbItem)
{ {
item = dbItem; item = dbItem;
} }
else else
{ {
// item is new // item is new
item.ExtraType = MediaBrowser.Model.Entities.ExtraType.ThemeVideo; item.ExtraType = Model.Entities.ExtraType.ThemeVideo;
} }
return item; return item;
@ -1296,33 +1310,37 @@ namespace MediaBrowser.Controller.Entities
protected virtual BaseItem[] LoadExtras(List<FileSystemMetadata> fileSystemChildren, IDirectoryService directoryService) protected virtual BaseItem[] LoadExtras(List<FileSystemMetadata> fileSystemChildren, IDirectoryService directoryService)
{ {
var files = fileSystemChildren.Where(i => i.IsDirectory) var extras = new List<Video>();
.SelectMany(i => FileSystem.GetFiles(i.FullName));
return LibraryManager.ResolvePaths(files, directoryService, null, new LibraryOptions()) foreach (var extraFolderName in AllExtrasTypesFolderNames)
.OfType<Video>() {
.Select(item => var files = fileSystemChildren.Where(i => i.IsDirectory)
{ .Where(i => string.Equals(i.Name, extraFolderName, StringComparison.OrdinalIgnoreCase))
// Try to retrieve it from the db. If we don't find it, use the resolved version .SelectMany(i => FileSystem.GetFiles(i.FullName));
var dbItem = LibraryManager.GetItemById(item.Id) as Video;
if (dbItem != null) extras.AddRange(LibraryManager.ResolvePaths(files, directoryService, null, new LibraryOptions())
.OfType<Video>()
.Select(item =>
{ {
item = dbItem; // Try to retrieve it from the db. If we don't find it, use the resolved version
} if (LibraryManager.GetItemById(item.Id) is Video dbItem)
else {
{ item = dbItem;
// item is new }
item.ExtraType = MediaBrowser.Model.Entities.ExtraType.Clip;
}
return item; // Use some hackery to get the extra type based on foldername
Enum.TryParse(extraFolderName.Replace(" ", ""), true, out ExtraType extraType);
item.ExtraType = extraType;
// Sort them so that the list can be easily compared for changes return item;
}).OrderBy(i => i.Path).ToArray();
// Sort them so that the list can be easily compared for changes
}).OrderBy(i => i.Path));
}
return extras.ToArray();
} }
public Task RefreshMetadata(CancellationToken cancellationToken) public Task RefreshMetadata(CancellationToken cancellationToken)
{ {
return RefreshMetadata(new MetadataRefreshOptions(new DirectoryService(Logger, FileSystem)), cancellationToken); return RefreshMetadata(new MetadataRefreshOptions(new DirectoryService(Logger, FileSystem)), cancellationToken);
@ -1497,8 +1515,7 @@ namespace MediaBrowser.Controller.Entities
var tasks = newExtras.Select(i => var tasks = newExtras.Select(i =>
{ {
var subOptions = new MetadataRefreshOptions(options); var subOptions = new MetadataRefreshOptions(options);
if (!i.ExtraType.HasValue || if (i.OwnerId != ownerId ||
i.OwnerId != ownerId ||
!i.ParentId.Equals(Guid.Empty)) !i.ParentId.Equals(Guid.Empty))
{ {
i.OwnerId = ownerId; i.OwnerId = ownerId;