aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Server.Implementations/Library/LibraryManager.cs
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.Server.Implementations/Library/LibraryManager.cs')
-rw-r--r--MediaBrowser.Server.Implementations/Library/LibraryManager.cs187
1 files changed, 94 insertions, 93 deletions
diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs
index 712ea4ef3..cc3a7e41f 100644
--- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs
+++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs
@@ -364,7 +364,7 @@ namespace MediaBrowser.Server.Implementations.Library
if (item.IsFolder)
{
- if (!(item is ICollectionFolder) && !(item is UserView) && !(item is Channel))
+ if (!(item is ICollectionFolder) && !(item is UserView) && !(item is Channel) && !(item is AggregateFolder))
{
if (item.SourceType != SourceType.Library)
{
@@ -556,7 +556,12 @@ namespace MediaBrowser.Server.Implementations.Library
return ResolvePath(fileInfo, new DirectoryService(_logger, _fileSystem), null, parent);
}
- private BaseItem ResolvePath(FileSystemMetadata fileInfo, IDirectoryService directoryService, IItemResolver[] resolvers, Folder parent = null, string collectionType = null)
+ private BaseItem ResolvePath(FileSystemMetadata fileInfo,
+ IDirectoryService directoryService,
+ IItemResolver[] resolvers,
+ Folder parent = null,
+ string collectionType = null,
+ LibraryOptions libraryOptions = null)
{
if (fileInfo == null)
{
@@ -575,7 +580,8 @@ namespace MediaBrowser.Server.Implementations.Library
Parent = parent,
Path = fullPath,
FileInfo = fileInfo,
- CollectionType = collectionType
+ CollectionType = collectionType,
+ LibraryOptions = libraryOptions
};
// Return null if ignore rules deem that we should do so
@@ -653,12 +659,17 @@ namespace MediaBrowser.Server.Implementations.Library
return !args.ContainsFileSystemEntryByName(".ignore");
}
- public IEnumerable<BaseItem> ResolvePaths(IEnumerable<FileSystemMetadata> files, IDirectoryService directoryService, Folder parent, string collectionType)
+ public IEnumerable<BaseItem> ResolvePaths(IEnumerable<FileSystemMetadata> files, IDirectoryService directoryService, Folder parent, LibraryOptions libraryOptions, string collectionType)
{
- return ResolvePaths(files, directoryService, parent, collectionType, EntityResolvers);
+ return ResolvePaths(files, directoryService, parent, libraryOptions, collectionType, EntityResolvers);
}
- public IEnumerable<BaseItem> ResolvePaths(IEnumerable<FileSystemMetadata> files, IDirectoryService directoryService, Folder parent, string collectionType, IItemResolver[] resolvers)
+ public IEnumerable<BaseItem> ResolvePaths(IEnumerable<FileSystemMetadata> files,
+ IDirectoryService directoryService,
+ Folder parent,
+ LibraryOptions libraryOptions,
+ string collectionType,
+ IItemResolver[] resolvers)
{
var fileList = files.Where(i => !IgnoreFile(i, parent)).ToList();
@@ -679,22 +690,27 @@ namespace MediaBrowser.Server.Implementations.Library
{
ResolverHelper.SetInitialItemValues(item, parent, _fileSystem, this, directoryService);
}
- items.AddRange(ResolveFileList(result.ExtraFiles, directoryService, parent, collectionType, resolvers));
+ items.AddRange(ResolveFileList(result.ExtraFiles, directoryService, parent, collectionType, resolvers, libraryOptions));
return items;
}
}
}
- return ResolveFileList(fileList, directoryService, parent, collectionType, resolvers);
+ return ResolveFileList(fileList, directoryService, parent, collectionType, resolvers, libraryOptions);
}
- private IEnumerable<BaseItem> ResolveFileList(IEnumerable<FileSystemMetadata> fileList, IDirectoryService directoryService, Folder parent, string collectionType, IItemResolver[] resolvers)
+ private IEnumerable<BaseItem> ResolveFileList(IEnumerable<FileSystemMetadata> fileList,
+ IDirectoryService directoryService,
+ Folder parent,
+ string collectionType,
+ IItemResolver[] resolvers,
+ LibraryOptions libraryOptions)
{
return fileList.Select(f =>
{
try
{
- return ResolvePath(f, directoryService, resolvers, parent, collectionType);
+ return ResolvePath(f, directoryService, resolvers, parent, collectionType, libraryOptions);
}
catch (Exception ex)
{
@@ -813,7 +829,7 @@ namespace MediaBrowser.Server.Implementations.Library
/// <returns>Task{Person}.</returns>
public Person GetPerson(string name)
{
- return GetItemByName<Person>(ConfigurationManager.ApplicationPaths.PeoplePath, name);
+ return CreateItemByName<Person>(Person.GetPath(name), name);
}
/// <summary>
@@ -823,7 +839,7 @@ namespace MediaBrowser.Server.Implementations.Library
/// <returns>Task{Studio}.</returns>
public Studio GetStudio(string name)
{
- return GetItemByName<Studio>(ConfigurationManager.ApplicationPaths.StudioPath, name);
+ return CreateItemByName<Studio>(Studio.GetPath(name), name);
}
/// <summary>
@@ -833,7 +849,7 @@ namespace MediaBrowser.Server.Implementations.Library
/// <returns>Task{Genre}.</returns>
public Genre GetGenre(string name)
{
- return GetItemByName<Genre>(ConfigurationManager.ApplicationPaths.GenrePath, name);
+ return CreateItemByName<Genre>(Genre.GetPath(name), name);
}
/// <summary>
@@ -843,7 +859,7 @@ namespace MediaBrowser.Server.Implementations.Library
/// <returns>Task{MusicGenre}.</returns>
public MusicGenre GetMusicGenre(string name)
{
- return GetItemByName<MusicGenre>(ConfigurationManager.ApplicationPaths.MusicGenrePath, name);
+ return CreateItemByName<MusicGenre>(MusicGenre.GetPath(name), name);
}
/// <summary>
@@ -853,15 +869,10 @@ namespace MediaBrowser.Server.Implementations.Library
/// <returns>Task{GameGenre}.</returns>
public GameGenre GetGameGenre(string name)
{
- return GetItemByName<GameGenre>(ConfigurationManager.ApplicationPaths.GameGenrePath, name);
+ return CreateItemByName<GameGenre>(GameGenre.GetPath(name), name);
}
/// <summary>
- /// The us culture
- /// </summary>
- private static readonly CultureInfo UsCulture = new CultureInfo("en-US");
-
- /// <summary>
/// Gets a Year
/// </summary>
/// <param name="value">The value.</param>
@@ -874,19 +885,9 @@ namespace MediaBrowser.Server.Implementations.Library
throw new ArgumentOutOfRangeException("Years less than or equal to 0 are invalid.");
}
- return GetItemByName<Year>(ConfigurationManager.ApplicationPaths.YearPath, value.ToString(UsCulture));
- }
+ var name = value.ToString(CultureInfo.InvariantCulture);
- /// <summary>
- /// Gets the artists path.
- /// </summary>
- /// <value>The artists path.</value>
- public string ArtistsPath
- {
- get
- {
- return Path.Combine(ConfigurationManager.ApplicationPaths.ItemsByNamePath, "artists");
- }
+ return CreateItemByName<Year>(Year.GetPath(name), name);
}
/// <summary>
@@ -896,48 +897,7 @@ namespace MediaBrowser.Server.Implementations.Library
/// <returns>Task{Genre}.</returns>
public MusicArtist GetArtist(string name)
{
- return GetItemByName<MusicArtist>(ArtistsPath, name);
- }
-
- private T GetItemByName<T>(string path, string name)
- where T : BaseItem, new()
- {
- if (string.IsNullOrWhiteSpace(path))
- {
- throw new ArgumentNullException("path");
- }
-
- if (string.IsNullOrWhiteSpace(name))
- {
- throw new ArgumentNullException("name");
- }
-
- // Trim the period at the end because windows will have a hard time with that
- var validFilename = _fileSystem.GetValidFilename(name)
- .Trim()
- .TrimEnd('.');
-
- string subFolderPrefix = null;
-
- var type = typeof(T);
-
- if (type == typeof(Person))
- {
- var subFolderIndex = 0;
-
- while (!char.IsLetterOrDigit(validFilename[subFolderIndex]))
- {
- subFolderIndex++;
- }
-
- subFolderPrefix = validFilename.Substring(subFolderIndex, 1);
- }
-
- var fullPath = string.IsNullOrEmpty(subFolderPrefix) ?
- Path.Combine(path, validFilename) :
- Path.Combine(path, subFolderPrefix, validFilename);
-
- return CreateItemByName<T>(fullPath, name);
+ return CreateItemByName<MusicArtist>(MusicArtist.GetPath(name), name);
}
private T CreateItemByName<T>(string path, string name)
@@ -1207,7 +1167,7 @@ namespace MediaBrowser.Server.Implementations.Library
.Select(dir => GetVirtualFolderInfo(dir, topLibraryFolders));
}
- private VirtualFolderInfo GetVirtualFolderInfo(string dir, List<BaseItem> collectionFolders)
+ private VirtualFolderInfo GetVirtualFolderInfo(string dir, List<BaseItem> allCollectionFolders)
{
var info = new VirtualFolderInfo
{
@@ -1221,7 +1181,7 @@ namespace MediaBrowser.Server.Implementations.Library
CollectionType = GetCollectionType(dir)
};
- var libraryFolder = collectionFolders.FirstOrDefault(i => string.Equals(i.Path, dir, StringComparison.OrdinalIgnoreCase));
+ var libraryFolder = allCollectionFolders.FirstOrDefault(i => string.Equals(i.Path, dir, StringComparison.OrdinalIgnoreCase));
if (libraryFolder != null && libraryFolder.HasImage(ImageType.Primary))
{
@@ -1233,6 +1193,12 @@ namespace MediaBrowser.Server.Implementations.Library
info.ItemId = libraryFolder.Id.ToString("N");
}
+ var collectionFolder = libraryFolder as CollectionFolder;
+ if (collectionFolder != null)
+ {
+ info.LibraryOptions = collectionFolder.GetLibraryOptions();
+ }
+
return info;
}
@@ -1385,6 +1351,17 @@ namespace MediaBrowser.Server.Implementations.Library
return ItemRepository.GetMusicGenres(query);
}
+ public QueryResult<Tuple<BaseItem, ItemCounts>> GetAllArtists(InternalItemsQuery query)
+ {
+ if (query.User != null)
+ {
+ AddUserToQuery(query, query.User);
+ }
+
+ SetTopParentOrAncestorIds(query);
+ return ItemRepository.GetAllArtists(query);
+ }
+
public QueryResult<Tuple<BaseItem, ItemCounts>> GetArtists(InternalItemsQuery query)
{
if (query.User != null)
@@ -1488,7 +1465,12 @@ namespace MediaBrowser.Server.Implementations.Library
private void AddUserToQuery(InternalItemsQuery query, User user)
{
- if (query.AncestorIds.Length == 0 && !query.ParentId.HasValue && query.ChannelIds.Length == 0 && query.TopParentIds.Length == 0 && string.IsNullOrWhiteSpace(query.AncestorWithPresentationUniqueKey))
+ if (query.AncestorIds.Length == 0 &&
+ !query.ParentId.HasValue &&
+ query.ChannelIds.Length == 0 &&
+ query.TopParentIds.Length == 0 &&
+ string.IsNullOrWhiteSpace(query.AncestorWithPresentationUniqueKey)
+ && query.ItemIds.Length == 0)
{
var userViews = _userviewManager().GetUserViews(new UserViewQuery
{
@@ -1880,6 +1862,15 @@ namespace MediaBrowser.Server.Implementations.Library
.Where(i => string.Equals(i.Path, item.Path, StringComparison.OrdinalIgnoreCase) || i.PhysicalLocations.Contains(item.Path, StringComparer.OrdinalIgnoreCase));
}
+ public LibraryOptions GetLibraryOptions(BaseItem item)
+ {
+ var collectionFolder = GetCollectionFolders(item)
+ .OfType<CollectionFolder>()
+ .FirstOrDefault();
+
+ return collectionFolder == null ? new LibraryOptions() : collectionFolder.GetLibraryOptions();
+ }
+
public string GetContentType(BaseItem item)
{
string configuredContentType = GetConfiguredContentType(item, false);
@@ -2231,18 +2222,28 @@ namespace MediaBrowser.Server.Implementations.Library
return item;
}
- public bool IsVideoFile(string path)
+ public bool IsVideoFile(string path, LibraryOptions libraryOptions)
{
- var resolver = new VideoResolver(GetNamingOptions(), new PatternsLogger());
+ var resolver = new VideoResolver(GetNamingOptions(libraryOptions), new PatternsLogger());
return resolver.IsVideoFile(path);
}
- public bool IsAudioFile(string path)
+ public bool IsVideoFile(string path)
{
- var parser = new AudioFileParser(GetNamingOptions());
+ return IsVideoFile(path, new LibraryOptions());
+ }
+
+ public bool IsAudioFile(string path, LibraryOptions libraryOptions)
+ {
+ var parser = new AudioFileParser(GetNamingOptions(libraryOptions));
return parser.IsAudioFile(path);
}
+ public bool IsAudioFile(string path)
+ {
+ return IsAudioFile(path, new LibraryOptions());
+ }
+
public int? GetSeasonNumberFromPath(string path)
{
return new SeasonPathParser(GetNamingOptions(), new RegexProvider()).Parse(path, true, true).SeasonNumber;
@@ -2369,19 +2370,24 @@ namespace MediaBrowser.Server.Implementations.Library
public NamingOptions GetNamingOptions()
{
+ return GetNamingOptions(new LibraryOptions());
+ }
+
+ public NamingOptions GetNamingOptions(LibraryOptions libraryOptions)
+ {
var options = new ExtendedNamingOptions();
// These cause apps to have problems
options.AudioFileExtensions.Remove(".m3u");
options.AudioFileExtensions.Remove(".wpl");
- if (!ConfigurationManager.Configuration.EnableAudioArchiveFiles)
+ if (!libraryOptions.EnableArchiveMediaFiles)
{
options.AudioFileExtensions.Remove(".rar");
options.AudioFileExtensions.Remove(".zip");
}
- if (!ConfigurationManager.Configuration.EnableVideoArchiveFiles)
+ if (!libraryOptions.EnableArchiveMediaFiles)
{
options.VideoFileExtensions.Remove(".rar");
options.VideoFileExtensions.Remove(".zip");
@@ -2432,7 +2438,7 @@ namespace MediaBrowser.Server.Implementations.Library
new GenericVideoResolver<Trailer>(this)
};
- return ResolvePaths(files, directoryService, null, null, resolvers)
+ return ResolvePaths(files, directoryService, null, new LibraryOptions(), null, resolvers)
.OfType<Trailer>()
.Select(video =>
{
@@ -2476,7 +2482,7 @@ namespace MediaBrowser.Server.Implementations.Library
files.AddRange(currentVideo.Extras.Where(i => !string.Equals(i.ExtraType, "trailer", StringComparison.OrdinalIgnoreCase)).Select(i => _fileSystem.GetFileInfo(i.Path)));
}
- return ResolvePaths(files, directoryService, null, null)
+ return ResolvePaths(files, directoryService, null, new LibraryOptions(), null)
.OfType<Video>()
.Select(video =>
{
@@ -2605,13 +2611,6 @@ namespace MediaBrowser.Server.Implementations.Library
return ItemRepository.GetPeopleNames(query);
}
- public List<PersonInfo> GetAllPeople()
- {
- return GetPeople(new InternalPeopleQuery())
- .DistinctBy(i => i.Name, StringComparer.OrdinalIgnoreCase)
- .ToList();
- }
-
public Task UpdatePeople(BaseItem item, List<PersonInfo> people)
{
if (!item.SupportsPeople)
@@ -2661,7 +2660,7 @@ namespace MediaBrowser.Server.Implementations.Library
throw new InvalidOperationException();
}
- public void AddVirtualFolder(string name, string collectionType, string[] mediaPaths, bool refreshLibrary)
+ public void AddVirtualFolder(string name, string collectionType, string[] mediaPaths, LibraryOptions options, bool refreshLibrary)
{
if (string.IsNullOrWhiteSpace(name))
{
@@ -2704,6 +2703,8 @@ namespace MediaBrowser.Server.Implementations.Library
}
}
+ CollectionFolder.SaveLibraryOptions(virtualFolderPath, options);
+
if (mediaPaths != null)
{
foreach (var path in mediaPaths)