diff --git a/MediaBrowser.Api/BaseApiService.cs b/MediaBrowser.Api/BaseApiService.cs
index 30750b3741..44d459a01e 100644
--- a/MediaBrowser.Api/BaseApiService.cs
+++ b/MediaBrowser.Api/BaseApiService.cs
@@ -79,7 +79,7 @@ namespace MediaBrowser.Api
}
}
}
-
+
///
/// To the optimized serialized result using cache.
///
@@ -118,9 +118,6 @@ namespace MediaBrowser.Api
return ResultFactory.GetStaticFileResult(Request, path);
}
- private readonly char[] _dashReplaceChars = { '?', '/', '&' };
- private const char SlugChar = '-';
-
protected DtoOptions GetDtoOptions(object request)
{
var options = new DtoOptions();
@@ -154,152 +151,122 @@ namespace MediaBrowser.Api
protected MusicArtist GetArtist(string name, ILibraryManager libraryManager)
{
- return libraryManager.GetArtist(DeSlugArtistName(name, libraryManager));
+ if (name.IndexOf(BaseItem.SlugChar) != -1)
+ {
+ var result = libraryManager.GetItemList(new InternalItemsQuery
+ {
+ SlugName = name,
+ IncludeItemTypes = new[] { typeof(MusicArtist).Name }
+
+ }).OfType().FirstOrDefault();
+
+ if (result != null)
+ {
+ return result;
+ }
+ }
+
+ return libraryManager.GetArtist(name);
}
protected Studio GetStudio(string name, ILibraryManager libraryManager)
{
- return libraryManager.GetStudio(DeSlugStudioName(name, libraryManager));
+ if (name.IndexOf(BaseItem.SlugChar) != -1)
+ {
+ var result = libraryManager.GetItemList(new InternalItemsQuery
+ {
+ SlugName = name,
+ IncludeItemTypes = new[] { typeof(Studio).Name }
+
+ }).OfType().FirstOrDefault();
+
+ if (result != null)
+ {
+ return result;
+ }
+ }
+
+ return libraryManager.GetStudio(name);
}
protected Genre GetGenre(string name, ILibraryManager libraryManager)
{
- return libraryManager.GetGenre(DeSlugGenreName(name, libraryManager));
+ if (name.IndexOf(BaseItem.SlugChar) != -1)
+ {
+ var result = libraryManager.GetItemList(new InternalItemsQuery
+ {
+ SlugName = name,
+ IncludeItemTypes = new[] { typeof(Genre).Name }
+
+ }).OfType().FirstOrDefault();
+
+ if (result != null)
+ {
+ return result;
+ }
+ }
+
+ return libraryManager.GetGenre(name);
}
protected MusicGenre GetMusicGenre(string name, ILibraryManager libraryManager)
{
- return libraryManager.GetMusicGenre(DeSlugGenreName(name, libraryManager));
+ if (name.IndexOf(BaseItem.SlugChar) != -1)
+ {
+ var result = libraryManager.GetItemList(new InternalItemsQuery
+ {
+ SlugName = name,
+ IncludeItemTypes = new[] { typeof(MusicGenre).Name }
+
+ }).OfType().FirstOrDefault();
+
+ if (result != null)
+ {
+ return result;
+ }
+ }
+
+ return libraryManager.GetMusicGenre(name);
}
protected GameGenre GetGameGenre(string name, ILibraryManager libraryManager)
{
- return libraryManager.GetGameGenre(DeSlugGameGenreName(name, libraryManager));
+ if (name.IndexOf(BaseItem.SlugChar) != -1)
+ {
+ var result = libraryManager.GetItemList(new InternalItemsQuery
+ {
+ SlugName = name,
+ IncludeItemTypes = new[] { typeof(GameGenre).Name }
+
+ }).OfType().FirstOrDefault();
+
+ if (result != null)
+ {
+ return result;
+ }
+ }
+
+ return libraryManager.GetGameGenre(name);
}
protected Person GetPerson(string name, ILibraryManager libraryManager)
{
- return libraryManager.GetPerson(DeSlugPersonName(name, libraryManager));
- }
-
- ///
- /// Deslugs an artist name by finding the correct entry in the library
- ///
- ///
- ///
- ///
- protected string DeSlugArtistName(string name, ILibraryManager libraryManager)
- {
- if (name.IndexOf(SlugChar) == -1)
+ if (name.IndexOf(BaseItem.SlugChar) != -1)
{
- return name;
+ var result = libraryManager.GetItemList(new InternalItemsQuery
+ {
+ SlugName = name,
+ IncludeItemTypes = new[] { typeof(Person).Name }
+
+ }).OfType().FirstOrDefault();
+
+ if (result != null)
+ {
+ return result;
+ }
}
- var items = libraryManager.GetItemList(new InternalItemsQuery
- {
- IncludeItemTypes = new[] { typeof(Audio).Name, typeof(MusicVideo).Name, typeof(MusicAlbum).Name }
- });
-
- return items
- .OfType()
- .SelectMany(i => i.AllArtists)
- .DistinctNames()
- .FirstOrDefault(i =>
- {
- i = _dashReplaceChars.Aggregate(i, (current, c) => current.Replace(c, SlugChar));
-
- return string.Equals(i, name, StringComparison.OrdinalIgnoreCase);
-
- }) ?? name;
- }
-
- ///
- /// Deslugs a genre name by finding the correct entry in the library
- ///
- protected string DeSlugGenreName(string name, ILibraryManager libraryManager)
- {
- if (name.IndexOf(SlugChar) == -1)
- {
- return name;
- }
-
- return libraryManager.RootFolder.GetRecursiveChildren()
- .SelectMany(i => i.Genres)
- .DistinctNames()
- .FirstOrDefault(i =>
- {
- i = _dashReplaceChars.Aggregate(i, (current, c) => current.Replace(c, SlugChar));
-
- return string.Equals(i, name, StringComparison.OrdinalIgnoreCase);
-
- }) ?? name;
- }
-
- protected string DeSlugGameGenreName(string name, ILibraryManager libraryManager)
- {
- if (name.IndexOf(SlugChar) == -1)
- {
- return name;
- }
-
- var items = libraryManager.GetItemList(new InternalItemsQuery
- {
- IncludeItemTypes = new[] { typeof(Game).Name }
- });
-
- return items
- .SelectMany(i => i.Genres)
- .DistinctNames()
- .FirstOrDefault(i =>
- {
- i = _dashReplaceChars.Aggregate(i, (current, c) => current.Replace(c, SlugChar));
-
- return string.Equals(i, name, StringComparison.OrdinalIgnoreCase);
-
- }) ?? name;
- }
-
- ///
- /// Deslugs a studio name by finding the correct entry in the library
- ///
- protected string DeSlugStudioName(string name, ILibraryManager libraryManager)
- {
- if (name.IndexOf(SlugChar) == -1)
- {
- return name;
- }
-
- return libraryManager.RootFolder
- .GetRecursiveChildren()
- .SelectMany(i => i.Studios)
- .DistinctNames()
- .FirstOrDefault(i =>
- {
- i = _dashReplaceChars.Aggregate(i, (current, c) => current.Replace(c, SlugChar));
-
- return string.Equals(i, name, StringComparison.OrdinalIgnoreCase);
-
- }) ?? name;
- }
-
- ///
- /// Deslugs a person name by finding the correct entry in the library
- ///
- protected string DeSlugPersonName(string name, ILibraryManager libraryManager)
- {
- if (name.IndexOf(SlugChar) == -1)
- {
- return name;
- }
-
- return libraryManager.GetPeopleNames(new InternalPeopleQuery())
- .FirstOrDefault(i =>
- {
- i = _dashReplaceChars.Aggregate(i, (current, c) => current.Replace(c, SlugChar));
-
- return string.Equals(i, name, StringComparison.OrdinalIgnoreCase);
-
- }) ?? name;
+ return libraryManager.GetPerson(name);
}
protected string GetPathValue(int index)
diff --git a/MediaBrowser.Api/Library/LibraryHelpers.cs b/MediaBrowser.Api/Library/LibraryHelpers.cs
deleted file mode 100644
index 22a88e2bf1..0000000000
--- a/MediaBrowser.Api/Library/LibraryHelpers.cs
+++ /dev/null
@@ -1,54 +0,0 @@
-using MediaBrowser.Controller;
-using System;
-using System.IO;
-using System.Linq;
-using CommonIO;
-
-namespace MediaBrowser.Api.Library
-{
- ///
- /// Class LibraryHelpers
- ///
- public static class LibraryHelpers
- {
- ///
- /// The shortcut file extension
- ///
- private const string ShortcutFileExtension = ".mblink";
- ///
- /// The shortcut file search
- ///
- private const string ShortcutFileSearch = "*" + ShortcutFileExtension;
-
- ///
- /// Deletes a shortcut from within a virtual folder, within either the default view or a user view
- ///
- /// The file system.
- /// Name of the virtual folder.
- /// The media path.
- /// The app paths.
- /// The media folder does not exist
- public static void RemoveMediaPath(IFileSystem fileSystem, string virtualFolderName, string mediaPath, IServerApplicationPaths appPaths)
- {
- if (string.IsNullOrWhiteSpace(mediaPath))
- {
- throw new ArgumentNullException("mediaPath");
- }
-
- var rootFolderPath = appPaths.DefaultUserViewsPath;
- var path = Path.Combine(rootFolderPath, virtualFolderName);
-
- if (!fileSystem.DirectoryExists(path))
- {
- throw new DirectoryNotFoundException(string.Format("The media collection {0} does not exist", virtualFolderName));
- }
-
- var shortcut = Directory.EnumerateFiles(path, ShortcutFileSearch, SearchOption.AllDirectories).FirstOrDefault(f => fileSystem.ResolveShortcut(f).Equals(mediaPath, StringComparison.OrdinalIgnoreCase));
-
- if (!string.IsNullOrEmpty(shortcut))
- {
- fileSystem.DeleteFile(shortcut);
- }
- }
- }
-}
diff --git a/MediaBrowser.Api/Library/LibraryStructureService.cs b/MediaBrowser.Api/Library/LibraryStructureService.cs
index 817fd9ce00..3cf0d5d937 100644
--- a/MediaBrowser.Api/Library/LibraryStructureService.cs
+++ b/MediaBrowser.Api/Library/LibraryStructureService.cs
@@ -268,46 +268,7 @@ namespace MediaBrowser.Api.Library
/// The request.
public void Delete(RemoveVirtualFolder request)
{
- if (string.IsNullOrWhiteSpace(request.Name))
- {
- throw new ArgumentNullException("request");
- }
-
- var rootFolderPath = _appPaths.DefaultUserViewsPath;
-
- var path = Path.Combine(rootFolderPath, request.Name);
-
- if (!_fileSystem.DirectoryExists(path))
- {
- throw new DirectoryNotFoundException("The media folder does not exist");
- }
-
- _libraryMonitor.Stop();
-
- try
- {
- _fileSystem.DeleteDirectory(path, true);
- }
- finally
- {
- Task.Run(() =>
- {
- // No need to start if scanning the library because it will handle it
- if (request.RefreshLibrary)
- {
- _libraryManager.ValidateMediaLibrary(new Progress(), CancellationToken.None);
- }
- else
- {
- // Need to add a delay here or directory watchers may still pick up the changes
- var task = Task.Delay(1000);
- // Have to block here to allow exceptions to bubble
- Task.WaitAll(task);
-
- _libraryMonitor.Start();
- }
- });
- }
+ _libraryManager.RemoveVirtualFolder(request.Name, request.RefreshLibrary);
}
///
@@ -364,7 +325,7 @@ namespace MediaBrowser.Api.Library
try
{
- LibraryHelpers.RemoveMediaPath(_fileSystem, request.Name, request.Path, _appPaths);
+ _libraryManager.RemoveMediaPath(request.Name, request.Path);
}
finally
{
diff --git a/MediaBrowser.Api/MediaBrowser.Api.csproj b/MediaBrowser.Api/MediaBrowser.Api.csproj
index db8961a66c..77949d1793 100644
--- a/MediaBrowser.Api/MediaBrowser.Api.csproj
+++ b/MediaBrowser.Api/MediaBrowser.Api.csproj
@@ -129,7 +129,6 @@
-
diff --git a/MediaBrowser.Api/VideosService.cs b/MediaBrowser.Api/VideosService.cs
index 6cefda3a35..c8dbb7bb26 100644
--- a/MediaBrowser.Api/VideosService.cs
+++ b/MediaBrowser.Api/VideosService.cs
@@ -175,7 +175,7 @@ namespace MediaBrowser.Api
foreach (var item in items.Where(i => i.Id != primaryVersion.Id))
{
- item.PrimaryVersionId = primaryVersion.Id;
+ item.PrimaryVersionId = primaryVersion.Id.ToString("N");
await item.UpdateToRepository(ItemUpdateType.MetadataEdit, CancellationToken.None).ConfigureAwait(false);
diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs
index 6bf55e108c..2e968c8803 100644
--- a/MediaBrowser.Controller/Entities/BaseItem.cs
+++ b/MediaBrowser.Controller/Entities/BaseItem.cs
@@ -44,6 +44,9 @@ namespace MediaBrowser.Controller.Entities
ImageInfos = new List();
}
+ public static readonly char[] SlugReplaceChars = { '?', '/', '&' };
+ public static char SlugChar = '-';
+
///
/// The supported image extensions
///
@@ -125,6 +128,21 @@ namespace MediaBrowser.Controller.Entities
}
}
+ [IgnoreDataMember]
+ public string SlugName
+ {
+ get
+ {
+ var name = Name;
+ if (string.IsNullOrWhiteSpace(name))
+ {
+ return string.Empty;
+ }
+
+ return SlugReplaceChars.Aggregate(name, (current, c) => current.Replace(c, SlugChar));
+ }
+ }
+
public string OriginalTitle { get; set; }
///
@@ -728,12 +746,14 @@ namespace MediaBrowser.Controller.Entities
/// Gets or sets the critic rating.
///
/// The critic rating.
+ [IgnoreDataMember]
public float? CriticRating { get; set; }
///
/// Gets or sets the critic rating summary.
///
/// The critic rating summary.
+ [IgnoreDataMember]
public string CriticRatingSummary { get; set; }
///
diff --git a/MediaBrowser.Controller/Entities/Folder.cs b/MediaBrowser.Controller/Entities/Folder.cs
index f57e2fa17a..d9c0b7bfe3 100644
--- a/MediaBrowser.Controller/Entities/Folder.cs
+++ b/MediaBrowser.Controller/Entities/Folder.cs
@@ -707,8 +707,8 @@ namespace MediaBrowser.Controller.Entities
{
return ItemRepository.GetItemIdsList(new InternalItemsQuery
{
- ParentId = Id
-
+ ParentId = Id,
+ GroupByPresentationUniqueKey = false
});
}
diff --git a/MediaBrowser.Controller/Entities/InternalItemsQuery.cs b/MediaBrowser.Controller/Entities/InternalItemsQuery.cs
index 6838fde714..2615f351ad 100644
--- a/MediaBrowser.Controller/Entities/InternalItemsQuery.cs
+++ b/MediaBrowser.Controller/Entities/InternalItemsQuery.cs
@@ -49,6 +49,7 @@ namespace MediaBrowser.Controller.Entities
public string PresentationUniqueKey { get; set; }
public string Path { get; set; }
public string Name { get; set; }
+ public string SlugName { get; set; }
public string Person { get; set; }
public string[] PersonIds { get; set; }
@@ -133,9 +134,13 @@ namespace MediaBrowser.Controller.Entities
public string[] AlbumNames { get; set; }
public string[] ArtistNames { get; set; }
-
+
+ public bool GroupByPresentationUniqueKey { get; set; }
+
public InternalItemsQuery()
{
+ GroupByPresentationUniqueKey = true;
+
AlbumNames = new string[] { };
ArtistNames = new string[] { };
diff --git a/MediaBrowser.Controller/Entities/Movies/BoxSet.cs b/MediaBrowser.Controller/Entities/Movies/BoxSet.cs
index cd3e07ea38..09a9d97bcf 100644
--- a/MediaBrowser.Controller/Entities/Movies/BoxSet.cs
+++ b/MediaBrowser.Controller/Entities/Movies/BoxSet.cs
@@ -8,6 +8,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
+using MediaBrowser.Controller.Entities.Audio;
namespace MediaBrowser.Controller.Entities.Movies
{
@@ -118,7 +119,7 @@ namespace MediaBrowser.Controller.Entities.Movies
// Gather all possible ratings
var ratings = GetRecursiveChildren()
.Concat(GetLinkedChildren())
- .Where(i => i is Movie || i is Series)
+ .Where(i => i is Movie || i is Series || i is MusicAlbum || i is Game)
.Select(i => i.OfficialRating)
.Where(i => !string.IsNullOrEmpty(i))
.Distinct(StringComparer.OrdinalIgnoreCase)
diff --git a/MediaBrowser.Controller/Entities/Video.cs b/MediaBrowser.Controller/Entities/Video.cs
index 67b710534c..6a9d7cb511 100644
--- a/MediaBrowser.Controller/Entities/Video.cs
+++ b/MediaBrowser.Controller/Entities/Video.cs
@@ -28,7 +28,8 @@ namespace MediaBrowser.Controller.Entities
IThemeMedia,
IArchivable
{
- public Guid? PrimaryVersionId { get; set; }
+ [IgnoreDataMember]
+ public string PrimaryVersionId { get; set; }
public List AdditionalParts { get; set; }
public List LocalAlternateVersions { get; set; }
@@ -49,9 +50,9 @@ namespace MediaBrowser.Controller.Entities
{
get
{
- if (PrimaryVersionId.HasValue)
+ if (!string.IsNullOrWhiteSpace(PrimaryVersionId))
{
- return PrimaryVersionId.Value.ToString("N");
+ return PrimaryVersionId;
}
return base.PresentationUniqueKey;
@@ -70,6 +71,72 @@ namespace MediaBrowser.Controller.Entities
/// The timestamp.
public TransportStreamTimestamp? Timestamp { get; set; }
+ ///
+ /// Gets or sets the subtitle paths.
+ ///
+ /// The subtitle paths.
+ public List SubtitleFiles { get; set; }
+
+ ///
+ /// Gets or sets a value indicating whether this instance has subtitles.
+ ///
+ /// true if this instance has subtitles; otherwise, false.
+ public bool HasSubtitles { get; set; }
+
+ public bool IsPlaceHolder { get; set; }
+ public bool IsShortcut { get; set; }
+ public string ShortcutPath { get; set; }
+
+ ///
+ /// Gets or sets the video bit rate.
+ ///
+ /// The video bit rate.
+ public int? VideoBitRate { get; set; }
+
+ ///
+ /// Gets or sets the default index of the video stream.
+ ///
+ /// The default index of the video stream.
+ public int? DefaultVideoStreamIndex { get; set; }
+
+ ///
+ /// Gets or sets the type of the video.
+ ///
+ /// The type of the video.
+ public VideoType VideoType { get; set; }
+
+ ///
+ /// Gets or sets the type of the iso.
+ ///
+ /// The type of the iso.
+ public IsoType? IsoType { get; set; }
+
+ ///
+ /// Gets or sets the video3 D format.
+ ///
+ /// The video3 D format.
+ public Video3DFormat? Video3DFormat { get; set; }
+
+ ///
+ /// If the video is a folder-rip, this will hold the file list for the largest playlist
+ ///
+ public List PlayableStreamFileNames { get; set; }
+
+ ///
+ /// Gets the playable stream files.
+ ///
+ /// List{System.String}.
+ public List GetPlayableStreamFiles()
+ {
+ return GetPlayableStreamFiles(Path);
+ }
+
+ ///
+ /// Gets or sets the aspect ratio.
+ ///
+ /// The aspect ratio.
+ public string AspectRatio { get; set; }
+
public Video()
{
PlayableStreamFileNames = new List();
@@ -104,9 +171,9 @@ namespace MediaBrowser.Controller.Entities
{
get
{
- if (PrimaryVersionId.HasValue)
+ if (!string.IsNullOrWhiteSpace(PrimaryVersionId))
{
- var item = LibraryManager.GetItemById(PrimaryVersionId.Value) as Video;
+ var item = LibraryManager.GetItemById(PrimaryVersionId) as Video;
if (item != null)
{
return item.MediaSourceCount;
@@ -238,72 +305,6 @@ namespace MediaBrowser.Controller.Entities
.OrderBy(i => i.SortName);
}
- ///
- /// Gets or sets the subtitle paths.
- ///
- /// The subtitle paths.
- public List SubtitleFiles { get; set; }
-
- ///
- /// Gets or sets a value indicating whether this instance has subtitles.
- ///
- /// true if this instance has subtitles; otherwise, false.
- public bool HasSubtitles { get; set; }
-
- public bool IsPlaceHolder { get; set; }
- public bool IsShortcut { get; set; }
- public string ShortcutPath { get; set; }
-
- ///
- /// Gets or sets the video bit rate.
- ///
- /// The video bit rate.
- public int? VideoBitRate { get; set; }
-
- ///
- /// Gets or sets the default index of the video stream.
- ///
- /// The default index of the video stream.
- public int? DefaultVideoStreamIndex { get; set; }
-
- ///
- /// Gets or sets the type of the video.
- ///
- /// The type of the video.
- public VideoType VideoType { get; set; }
-
- ///
- /// Gets or sets the type of the iso.
- ///
- /// The type of the iso.
- public IsoType? IsoType { get; set; }
-
- ///
- /// Gets or sets the video3 D format.
- ///
- /// The video3 D format.
- public Video3DFormat? Video3DFormat { get; set; }
-
- ///
- /// If the video is a folder-rip, this will hold the file list for the largest playlist
- ///
- public List PlayableStreamFileNames { get; set; }
-
- ///
- /// Gets the playable stream files.
- ///
- /// List{System.String}.
- public List GetPlayableStreamFiles()
- {
- return GetPlayableStreamFiles(Path);
- }
-
- ///
- /// Gets or sets the aspect ratio.
- ///
- /// The aspect ratio.
- public string AspectRatio { get; set; }
-
[IgnoreDataMember]
public override string ContainingFolderPath
{
@@ -520,9 +521,9 @@ namespace MediaBrowser.Controller.Entities
list.Add(new Tuple