The Free Software Media System - Server Backend & API
add specialized get seasons method
Luke Pulverenti4892fb4e95f9
diff --git a/MediaBrowser.Api/Playback/Progressive/BaseProgressiveStreamingService.cs b/MediaBrowser.Api/Playback/Progressive/BaseProgressiveStreamingService.csindex 0b7b48f47e..1f0853e08b 100644--- a/MediaBrowser.Api/Playback/Progressive/BaseProgressiveStreamingService.cs+++ b/MediaBrowser.Api/Playback/Progressive/BaseProgressiveStreamingService.cs@@ -127,44 +127,44 @@ namespace MediaBrowser.Api.Playback.Progressiveconst string dlnaflags = ";DLNA.ORG_FLAGS=01500000000000000000000000000000";- if (string.Equals(extension, ".mp3", StringComparison.OrdinalIgnoreCase))- {- contentFeatures = "DLNA.ORG_PN=MP3";- }- else if (string.Equals(extension, ".aac", StringComparison.OrdinalIgnoreCase))- {- contentFeatures = "DLNA.ORG_PN=AAC_ISO";- }- else if (string.Equals(extension, ".wma", StringComparison.OrdinalIgnoreCase))- {- contentFeatures = "DLNA.ORG_PN=WMABASE";- }- else if (string.Equals(extension, ".avi", StringComparison.OrdinalIgnoreCase))- {- contentFeatures = "DLNA.ORG_PN=AVI";- }- else if (string.Equals(extension, ".mp4", StringComparison.OrdinalIgnoreCase))- {- contentFeatures = "DLNA.ORG_PN=MPEG4_P2_SP_AAC";- }- else if (string.Equals(extension, ".mpeg", StringComparison.OrdinalIgnoreCase))- {- contentFeatures = "DLNA.ORG_PN=MPEG_PS_PAL";- }- else if (string.Equals(extension, ".wmv", StringComparison.OrdinalIgnoreCase))- {- contentFeatures = "DLNA.ORG_PN=WMVHIGH_BASE";- }- else if (string.Equals(extension, ".asf", StringComparison.OrdinalIgnoreCase))- {- // ??- contentFeatures = "DLNA.ORG_PN=WMVHIGH_BASE";- }- else if (string.Equals(extension, ".mkv", StringComparison.OrdinalIgnoreCase))- {- // ??- contentFeatures = "";- }+ //if (string.Equals(extension, ".mp3", StringComparison.OrdinalIgnoreCase))+ //{+ // contentFeatures = "DLNA.ORG_PN=MP3";+ //}+ //else if (string.Equals(extension, ".aac", StringComparison.OrdinalIgnoreCase))+ //{+ // contentFeatures = "DLNA.ORG_PN=AAC_ISO";+ //}+ //else if (string.Equals(extension, ".wma", StringComparison.OrdinalIgnoreCase))+ //{+ // contentFeatures = "DLNA.ORG_PN=WMABASE";+ //}+ //else if (string.Equals(extension, ".avi", StringComparison.OrdinalIgnoreCase))+ //{+ // contentFeatures = "DLNA.ORG_PN=AVI";+ //}+ //else if (string.Equals(extension, ".mp4", StringComparison.OrdinalIgnoreCase))+ //{+ // contentFeatures = "DLNA.ORG_PN=MPEG4_P2_SP_AAC";+ //}+ //else if (string.Equals(extension, ".mpeg", StringComparison.OrdinalIgnoreCase))+ //{+ // contentFeatures = "DLNA.ORG_PN=MPEG_PS_PAL";+ //}+ //else if (string.Equals(extension, ".wmv", StringComparison.OrdinalIgnoreCase))+ //{+ // contentFeatures = "DLNA.ORG_PN=WMVHIGH_BASE";+ //}+ //else if (string.Equals(extension, ".asf", StringComparison.OrdinalIgnoreCase))+ //{+ // // ??+ // contentFeatures = "DLNA.ORG_PN=WMVHIGH_BASE";+ //}+ //else if (string.Equals(extension, ".mkv", StringComparison.OrdinalIgnoreCase))+ //{+ // // ??+ // contentFeatures = "";+ //}if (!string.IsNullOrEmpty(contentFeatures)){@@ -206,10 +206,10 @@ namespace MediaBrowser.Api.Playback.Progressivevar outputPath = GetOutputFilePath(state);var outputPathExists = File.Exists(outputPath);- //var isStatic = request.Static ||- // (outputPathExists && !ApiEntryPoint.Instance.HasActiveTranscodingJob(outputPath, TranscodingJobType.Progressive));+ var isStatic = request.Static ||+ (outputPathExists && !ApiEntryPoint.Instance.HasActiveTranscodingJob(outputPath, TranscodingJobType.Progressive));- //AddDlnaHeaders(state, responseHeaders, isStatic);+ AddDlnaHeaders(state, responseHeaders, isStatic);if (request.Static){diff --git a/MediaBrowser.Api/TvShowsService.cs b/MediaBrowser.Api/TvShowsService.csindex b36005c1aa..95bde2d283 100644--- a/MediaBrowser.Api/TvShowsService.cs+++ b/MediaBrowser.Api/TvShowsService.cs@@ -58,7 +58,7 @@ namespace MediaBrowser.Api}[Route("/Shows/{Id}/Episodes", "GET")]- [Api(Description = "Finds tv shows similar to a given one.")]+ [Api(Description = "Gets episodes for a tv season")]public class GetEpisodes : IReturn<ItemsResult>, IHasItemFields{/// <summary>@@ -85,6 +85,34 @@ namespace MediaBrowser.Apipublic string ExcludeLocationTypes { get; set; }}+ [Route("/Shows/{Id}/Seasons", "GET")]+ [Api(Description = "Gets seasons for a tv series")]+ public class GetSeasons : IReturn<ItemsResult>, IHasItemFields+ {+ /// <summary>+ /// Gets or sets the user id.+ /// </summary>+ /// <value>The user id.</value>+ [ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]+ public Guid UserId { get; set; }++ /// <summary>+ /// Fields to return within the items, in addition to basic information+ /// </summary>+ /// <value>The fields.</value>+ [ApiMember(Name = "Fields", Description = "Optional. Specify additional fields of information to return in the output. This allows multiple, comma delimeted. Options: Budget, Chapters, CriticRatingSummary, DateCreated, Genres, HomePageUrl, IndexOptions, MediaStreams, Overview, OverviewHtml, ParentId, Path, People, ProviderIds, PrimaryImageAspectRatio, Revenue, SortName, Studios, Taglines, TrailerUrls", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]+ public string Fields { get; set; }++ [ApiMember(Name = "Id", Description = "The series id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]+ public Guid Id { get; set; }++ [ApiMember(Name = "ExcludeLocationTypes", Description = "Optional. If specified, results will be filtered based on LocationType. This allows multiple, comma delimeted.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]+ public string ExcludeLocationTypes { get; set; }++ [ApiMember(Name = "IsSpecialSeason", Description = "Optional. Filter by special season.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")]+ public bool? IsSpecialSeason { get; set; }+ }+/// <summary>/// Class TvShowsService/// </summary>@@ -314,6 +342,64 @@ namespace MediaBrowser.Apireturn items;}+ public object Get(GetSeasons request)+ {+ var user = _userManager.GetUserById(request.UserId);++ var series = _libraryManager.GetItemById(request.Id) as Series;++ var fields = request.GetItemFields().ToList();++ var seasons = series.GetChildren(user, true)+ .OfType<Season>();++ var sortOrder = ItemSortBy.SortName;++ if (request.IsSpecialSeason.HasValue)+ {+ var val = request.IsSpecialSeason.Value;++ seasons = seasons.Where(i => i.IsSpecialSeason == val);+ }++ var config = user.Configuration;++ if (!config.DisplayMissingEpisodes && !config.DisplayUnairedEpisodes)+ {+ seasons = seasons.Where(i => !i.IsMissingOrVirtualUnaired);+ }+ else+ {+ if (!config.DisplayMissingEpisodes)+ {+ seasons = seasons.Where(i => !i.IsMissingSeason);+ }+ if (!config.DisplayUnairedEpisodes)+ {+ seasons = seasons.Where(i => !i.IsVirtualUnaired);+ }+ }++ // ExcludeLocationTypes+ if (!string.IsNullOrEmpty(request.ExcludeLocationTypes))+ {+ var vals = request.ExcludeLocationTypes.Split(',');+ seasons = seasons.Where(f => !vals.Contains(f.LocationType.ToString(), StringComparer.OrdinalIgnoreCase));+ }++ seasons = _libraryManager.Sort(seasons, user, new[] { sortOrder }, SortOrder.Ascending)+ .Cast<Season>();++ var returnItems = seasons.Select(i => _dtoService.GetBaseItemDto(i, fields, user))+ .ToArray();++ return new ItemsResult+ {+ TotalRecordCount = returnItems.Length,+ Items = returnItems+ };+ }+public object Get(GetEpisodes request){var user = _userManager.GetUserById(request.UserId);@@ -351,7 +437,7 @@ namespace MediaBrowser.Apivar vals = request.ExcludeLocationTypes.Split(',');episodes = episodes.Where(f => !vals.Contains(f.LocationType.ToString(), StringComparer.OrdinalIgnoreCase));}-+episodes = _libraryManager.Sort(episodes, user, new[] { sortOrder }, SortOrder.Ascending).Cast<Episode>();diff --git a/MediaBrowser.Controller/Entities/TV/Season.cs b/MediaBrowser.Controller/Entities/TV/Season.csindex 97a09b7b55..218c9fa5b6 100644--- a/MediaBrowser.Controller/Entities/TV/Season.cs+++ b/MediaBrowser.Controller/Entities/TV/Season.cs@@ -1,9 +1,9 @@-using System.Linq;-using MediaBrowser.Controller.Library;+using MediaBrowser.Controller.Library;using MediaBrowser.Controller.Localization;using System;using System.Collections.Generic;using System.IO;+using System.Linq;using System.Runtime.Serialization;namespace MediaBrowser.Controller.Entities.TV@@ -172,5 +172,11 @@ namespace MediaBrowser.Controller.Entities.TV{get { return LocationType == Model.Entities.LocationType.Virtual && Children.OfType<Episode>().All(i => i.IsVirtualUnaired || i.IsMissingEpisode); }}++ [IgnoreDataMember]+ public bool IsSpecialSeason+ {+ get { return (IndexNumber ?? -1) == 0; }+ }}}diff --git a/MediaBrowser.Model/ApiClient/IApiClient.cs b/MediaBrowser.Model/ApiClient/IApiClient.csindex ad82966048..16b3543ebd 100644--- a/MediaBrowser.Model/ApiClient/IApiClient.cs+++ b/MediaBrowser.Model/ApiClient/IApiClient.cs@@ -231,6 +231,13 @@ namespace MediaBrowser.Model.ApiClient/// <param name="query">The query.</param>/// <returns>Task{ItemsResult}.</returns>Task<ItemsResult> GetEpisodesAsync(EpisodeQuery query);++ /// <summary>+ /// Gets the seasons asynchronous.+ /// </summary>+ /// <param name="query">The query.</param>+ /// <returns>Task{ItemsResult}.</returns>+ Task<ItemsResult> GetSeasonsAsync(SeasonQuery query);/// <summary>/// Queries for itemsdiff --git a/MediaBrowser.Model/Querying/EpisodeQuery.cs b/MediaBrowser.Model/Querying/EpisodeQuery.csindex ab9b246c8c..406ac9844f 100644--- a/MediaBrowser.Model/Querying/EpisodeQuery.cs+++ b/MediaBrowser.Model/Querying/EpisodeQuery.cs@@ -20,4 +20,23 @@ namespace MediaBrowser.Model.QueryingExcludeLocationTypes = new LocationType[] { };}}++ public class SeasonQuery+ {+ public string UserId { get; set; }++ public string SeriesId { get; set; }++ public LocationType[] ExcludeLocationTypes { get; set; }++ public ItemFields[] Fields { get; set; }++ public bool? IsSpecialSeason { get; set; }++ public SeasonQuery()+ {+ Fields = new ItemFields[] { };+ ExcludeLocationTypes = new LocationType[] { };+ }+ }}diff --git a/MediaBrowser.Providers/MediaBrowser.Providers.csproj b/MediaBrowser.Providers/MediaBrowser.Providers.csprojindex 83e0246c53..c7298b4622 100644--- a/MediaBrowser.Providers/MediaBrowser.Providers.csproj+++ b/MediaBrowser.Providers/MediaBrowser.Providers.csproj@@ -135,6 +135,7 @@<Compile Include="TV\TvdbPersonImageProvider.cs" /><Compile Include="TV\TvdbPrescanTask.cs" /><Compile Include="TV\TvdbSeriesImageProvider.cs" />+ <Compile Include="UserRootFolderNameProvider.cs" /></ItemGroup><ItemGroup><ProjectReference Include="..\MediaBrowser.Common\MediaBrowser.Common.csproj">diff --git a/MediaBrowser.Providers/UserRootFolderNameProvider.cs b/MediaBrowser.Providers/UserRootFolderNameProvider.csnew file mode 100644index 0000000000..5130202139--- /dev/null+++ b/MediaBrowser.Providers/UserRootFolderNameProvider.cs@@ -0,0 +1,42 @@+using MediaBrowser.Controller.Configuration;+using MediaBrowser.Controller.Entities;+using MediaBrowser.Controller.Providers;+using MediaBrowser.Model.Logging;+using System;+using System.IO;+using System.Threading;+using System.Threading.Tasks;++namespace MediaBrowser.Providers+{+ public class UserRootFolderNameProvider : BaseMetadataProvider+ {+ public UserRootFolderNameProvider(ILogManager logManager, IServerConfigurationManager configurationManager)+ : base(logManager, configurationManager)+ {+ }++ public override bool Supports(BaseItem item)+ {+ return item is UserRootFolder;+ }++ public override Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)+ {+ var parentName = Path.GetFileNameWithoutExtension(item.Path);++ if (string.Equals(parentName, "default", StringComparison.OrdinalIgnoreCase))+ {+ item.Name = "Media Library";+ }++ SetLastRefreshed(item, DateTime.UtcNow);+ return TrueTaskResult;+ }++ public override MetadataProviderPriority Priority+ {+ get { return MetadataProviderPriority.First; }+ }+ }+}diff --git a/MediaBrowser.WebDashboard/ApiClient.js b/MediaBrowser.WebDashboard/ApiClient.jsindex 69f3f020cf..36476511ec 100644--- a/MediaBrowser.WebDashboard/ApiClient.js+++ b/MediaBrowser.WebDashboard/ApiClient.js@@ -575,6 +575,17 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi});};+ self.getSeasons = function (itemId, options) {++ var url = self.getUrl("Shows/" + itemId + "/Seasons", options);++ return self.ajax({+ type: "GET",+ url: url,+ dataType: "json"+ });+ };+self.getSimilarMovies = function (itemId, options) {var url = self.getUrl("Movies/" + itemId + "/Similar", options);diff --git a/MediaBrowser.WebDashboard/packages.config b/MediaBrowser.WebDashboard/packages.configindex 35511052f4..25938a358a 100644--- a/MediaBrowser.WebDashboard/packages.config+++ b/MediaBrowser.WebDashboard/packages.config@@ -1,6 +1,6 @@<?xml version="1.0" encoding="utf-8"?><packages>- <package id="MediaBrowser.ApiClient.Javascript" version="3.0.200" targetFramework="net45" />+ <package id="MediaBrowser.ApiClient.Javascript" version="3.0.201" targetFramework="net45" /><package id="ServiceStack.Common" version="3.9.62" targetFramework="net45" /><package id="ServiceStack.Text" version="3.9.62" targetFramework="net45" /></packages>\ No newline at end of file