Przeglądaj źródła

add specialized get seasons method

Luke Pulverenti 11 lat temu
rodzic
commit
4892fb4e95

+ 41 - 41
MediaBrowser.Api/Playback/Progressive/BaseProgressiveStreamingService.cs

@@ -127,44 +127,44 @@ namespace MediaBrowser.Api.Playback.Progressive
 
             const 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.Progressive
             var 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)
             {

+ 88 - 2
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.Api
         public 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.Api
             return 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.Api
                 var 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>();
 

+ 8 - 2
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; }
+        }
     }
 }

+ 7 - 0
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 items

+ 19 - 0
MediaBrowser.Model/Querying/EpisodeQuery.cs

@@ -20,4 +20,23 @@ namespace MediaBrowser.Model.Querying
             ExcludeLocationTypes = 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[] { };
+        }
+    }
 }

+ 1 - 0
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">

+ 42 - 0
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; }
+        }
+    }
+}

+ 11 - 0
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);

+ 1 - 1
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>