diff --git a/MediaBrowser.Api/BaseApiService.cs b/MediaBrowser.Api/BaseApiService.cs index 23d9b0126f..e8af6ab136 100644 --- a/MediaBrowser.Api/BaseApiService.cs +++ b/MediaBrowser.Api/BaseApiService.cs @@ -1,5 +1,8 @@ -using MediaBrowser.Common.Net; +using System.Linq; +using System.Threading.Tasks; +using MediaBrowser.Common.Net; using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Session; using MediaBrowser.Model.Logging; @@ -33,7 +36,7 @@ namespace MediaBrowser.Api /// /// The request context. public IRequestContext RequestContext { get; set; } - + /// /// To the optimized result. /// @@ -88,6 +91,123 @@ namespace MediaBrowser.Api { return ResultFactory.GetStaticFileResult(RequestContext, path); } + + private readonly char[] _dashReplaceChars = new[] { '?', '/' }; + private const char SlugChar = '-'; + + protected Task GetArtist(string name, ILibraryManager libraryManager) + { + return libraryManager.GetArtist(DeSlugArtistName(name, libraryManager)); + } + + protected Task GetStudio(string name, ILibraryManager libraryManager) + { + return libraryManager.GetStudio(DeSlugStudioName(name, libraryManager)); + } + + protected Task GetGenre(string name, ILibraryManager libraryManager) + { + return libraryManager.GetGenre(DeSlugGenreName(name, libraryManager)); + } + + protected Task 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) + { + return name; + } + + return libraryManager.RootFolder.RecursiveChildren + .OfType