add specialized get seasons method

This commit is contained in:
Luke Pulverenti 2013-11-28 13:27:29 -05:00
parent 06dab86d6a
commit 4892fb4e95
9 changed files with 218 additions and 46 deletions

View file

@ -127,44 +127,44 @@ namespace MediaBrowser.Api.Playback.Progressive
const string dlnaflags = ";DLNA.ORG_FLAGS=01500000000000000000000000000000"; const string dlnaflags = ";DLNA.ORG_FLAGS=01500000000000000000000000000000";
if (string.Equals(extension, ".mp3", StringComparison.OrdinalIgnoreCase)) //if (string.Equals(extension, ".mp3", StringComparison.OrdinalIgnoreCase))
{ //{
contentFeatures = "DLNA.ORG_PN=MP3"; // contentFeatures = "DLNA.ORG_PN=MP3";
} //}
else if (string.Equals(extension, ".aac", StringComparison.OrdinalIgnoreCase)) //else if (string.Equals(extension, ".aac", StringComparison.OrdinalIgnoreCase))
{ //{
contentFeatures = "DLNA.ORG_PN=AAC_ISO"; // contentFeatures = "DLNA.ORG_PN=AAC_ISO";
} //}
else if (string.Equals(extension, ".wma", StringComparison.OrdinalIgnoreCase)) //else if (string.Equals(extension, ".wma", StringComparison.OrdinalIgnoreCase))
{ //{
contentFeatures = "DLNA.ORG_PN=WMABASE"; // contentFeatures = "DLNA.ORG_PN=WMABASE";
} //}
else if (string.Equals(extension, ".avi", StringComparison.OrdinalIgnoreCase)) //else if (string.Equals(extension, ".avi", StringComparison.OrdinalIgnoreCase))
{ //{
contentFeatures = "DLNA.ORG_PN=AVI"; // contentFeatures = "DLNA.ORG_PN=AVI";
} //}
else if (string.Equals(extension, ".mp4", StringComparison.OrdinalIgnoreCase)) //else if (string.Equals(extension, ".mp4", StringComparison.OrdinalIgnoreCase))
{ //{
contentFeatures = "DLNA.ORG_PN=MPEG4_P2_SP_AAC"; // contentFeatures = "DLNA.ORG_PN=MPEG4_P2_SP_AAC";
} //}
else if (string.Equals(extension, ".mpeg", StringComparison.OrdinalIgnoreCase)) //else if (string.Equals(extension, ".mpeg", StringComparison.OrdinalIgnoreCase))
{ //{
contentFeatures = "DLNA.ORG_PN=MPEG_PS_PAL"; // contentFeatures = "DLNA.ORG_PN=MPEG_PS_PAL";
} //}
else if (string.Equals(extension, ".wmv", StringComparison.OrdinalIgnoreCase)) //else if (string.Equals(extension, ".wmv", StringComparison.OrdinalIgnoreCase))
{ //{
contentFeatures = "DLNA.ORG_PN=WMVHIGH_BASE"; // contentFeatures = "DLNA.ORG_PN=WMVHIGH_BASE";
} //}
else if (string.Equals(extension, ".asf", StringComparison.OrdinalIgnoreCase)) //else if (string.Equals(extension, ".asf", StringComparison.OrdinalIgnoreCase))
{ //{
// ?? // // ??
contentFeatures = "DLNA.ORG_PN=WMVHIGH_BASE"; // contentFeatures = "DLNA.ORG_PN=WMVHIGH_BASE";
} //}
else if (string.Equals(extension, ".mkv", StringComparison.OrdinalIgnoreCase)) //else if (string.Equals(extension, ".mkv", StringComparison.OrdinalIgnoreCase))
{ //{
// ?? // // ??
contentFeatures = ""; // contentFeatures = "";
} //}
if (!string.IsNullOrEmpty(contentFeatures)) if (!string.IsNullOrEmpty(contentFeatures))
{ {
@ -206,10 +206,10 @@ namespace MediaBrowser.Api.Playback.Progressive
var outputPath = GetOutputFilePath(state); var outputPath = GetOutputFilePath(state);
var outputPathExists = File.Exists(outputPath); var outputPathExists = File.Exists(outputPath);
//var isStatic = request.Static || var isStatic = request.Static ||
// (outputPathExists && !ApiEntryPoint.Instance.HasActiveTranscodingJob(outputPath, TranscodingJobType.Progressive)); (outputPathExists && !ApiEntryPoint.Instance.HasActiveTranscodingJob(outputPath, TranscodingJobType.Progressive));
//AddDlnaHeaders(state, responseHeaders, isStatic); AddDlnaHeaders(state, responseHeaders, isStatic);
if (request.Static) if (request.Static)
{ {

View file

@ -58,7 +58,7 @@ namespace MediaBrowser.Api
} }
[Route("/Shows/{Id}/Episodes", "GET")] [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 public class GetEpisodes : IReturn<ItemsResult>, IHasItemFields
{ {
/// <summary> /// <summary>
@ -85,6 +85,34 @@ namespace MediaBrowser.Api
public string ExcludeLocationTypes { get; set; } 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> /// <summary>
/// Class TvShowsService /// Class TvShowsService
/// </summary> /// </summary>
@ -314,6 +342,64 @@ namespace MediaBrowser.Api
return items; 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) public object Get(GetEpisodes request)
{ {
var user = _userManager.GetUserById(request.UserId); var user = _userManager.GetUserById(request.UserId);
@ -351,7 +437,7 @@ namespace MediaBrowser.Api
var vals = request.ExcludeLocationTypes.Split(','); var vals = request.ExcludeLocationTypes.Split(',');
episodes = episodes.Where(f => !vals.Contains(f.LocationType.ToString(), StringComparer.OrdinalIgnoreCase)); episodes = episodes.Where(f => !vals.Contains(f.LocationType.ToString(), StringComparer.OrdinalIgnoreCase));
} }
episodes = _libraryManager.Sort(episodes, user, new[] { sortOrder }, SortOrder.Ascending) episodes = _libraryManager.Sort(episodes, user, new[] { sortOrder }, SortOrder.Ascending)
.Cast<Episode>(); .Cast<Episode>();

View file

@ -1,9 +1,9 @@
using System.Linq; using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Localization; using MediaBrowser.Controller.Localization;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using System.Runtime.Serialization; using System.Runtime.Serialization;
namespace MediaBrowser.Controller.Entities.TV 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); } 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; }
}
} }
} }

View file

@ -231,6 +231,13 @@ namespace MediaBrowser.Model.ApiClient
/// <param name="query">The query.</param> /// <param name="query">The query.</param>
/// <returns>Task{ItemsResult}.</returns> /// <returns>Task{ItemsResult}.</returns>
Task<ItemsResult> GetEpisodesAsync(EpisodeQuery query); 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> /// <summary>
/// Queries for items /// Queries for items

View file

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

View file

@ -135,6 +135,7 @@
<Compile Include="TV\TvdbPersonImageProvider.cs" /> <Compile Include="TV\TvdbPersonImageProvider.cs" />
<Compile Include="TV\TvdbPrescanTask.cs" /> <Compile Include="TV\TvdbPrescanTask.cs" />
<Compile Include="TV\TvdbSeriesImageProvider.cs" /> <Compile Include="TV\TvdbSeriesImageProvider.cs" />
<Compile Include="UserRootFolderNameProvider.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\MediaBrowser.Common\MediaBrowser.Common.csproj"> <ProjectReference Include="..\MediaBrowser.Common\MediaBrowser.Common.csproj">

View file

@ -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; }
}
}
}

View file

@ -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) { self.getSimilarMovies = function (itemId, options) {
var url = self.getUrl("Movies/" + itemId + "/Similar", options); var url = self.getUrl("Movies/" + itemId + "/Similar", options);

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <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.Common" version="3.9.62" targetFramework="net45" />
<package id="ServiceStack.Text" version="3.9.62" targetFramework="net45" /> <package id="ServiceStack.Text" version="3.9.62" targetFramework="net45" />
</packages> </packages>