Added specialized episodes endpoint, updated nuget.

This commit is contained in:
Luke Pulverenti 2013-11-22 10:33:14 -05:00
parent ae63a3c2f7
commit 16203c52b4
24 changed files with 271 additions and 139 deletions

View File

@ -0,0 +1,52 @@
using MediaBrowser.Model.Querying;
using System;
using System.Collections.Generic;
using System.Linq;
namespace MediaBrowser.Api
{
/// <summary>
/// Interface IHasItemFields
/// </summary>
public interface IHasItemFields
{
/// <summary>
/// Gets or sets the fields.
/// </summary>
/// <value>The fields.</value>
string Fields { get; set; }
}
/// <summary>
/// Class ItemFieldsExtensions.
/// </summary>
public static class ItemFieldsExtensions
{
/// <summary>
/// Gets the item fields.
/// </summary>
/// <param name="request">The request.</param>
/// <returns>IEnumerable{ItemFields}.</returns>
public static IEnumerable<ItemFields> GetItemFields(this IHasItemFields request)
{
var val = request.Fields;
if (string.IsNullOrEmpty(val))
{
return new ItemFields[] { };
}
return val.Split(',').Select(v =>
{
ItemFields value;
if (Enum.TryParse(v, true, out value))
{
return (ItemFields?)value;
}
return null;
}).Where(i => i.HasValue).Select(i => i.Value);
}
}
}

View File

@ -70,6 +70,7 @@
<Compile Include="EnvironmentService.cs" />
<Compile Include="AuthorizationRequestFilterAttribute.cs" />
<Compile Include="GamesService.cs" />
<Compile Include="IHasItemFields.cs" />
<Compile Include="Images\ImageByNameService.cs" />
<Compile Include="Images\ImageRequest.cs" />
<Compile Include="Images\ImageService.cs" />

View File

@ -25,7 +25,7 @@ namespace MediaBrowser.Api
public string Id { get; set; }
}
public class BaseGetSimilarItems : IReturn<ItemsResult>
public class BaseGetSimilarItems : IReturn<ItemsResult>, IHasItemFields
{
/// <summary>
/// Gets or sets the user id.
@ -47,32 +47,6 @@ namespace MediaBrowser.Api
/// <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; }
/// <summary>
/// Gets the item fields.
/// </summary>
/// <returns>IEnumerable{ItemFields}.</returns>
public IEnumerable<ItemFields> GetItemFields()
{
var val = Fields;
if (string.IsNullOrEmpty(val))
{
return new ItemFields[] { };
}
return val.Split(',').Select(v =>
{
ItemFields value;
if (Enum.TryParse(v, true, out value))
{
return (ItemFields?)value;
}
return null;
}).Where(i => i.HasValue).Select(i => i.Value);
}
}
/// <summary>

View File

@ -17,7 +17,7 @@ namespace MediaBrowser.Api
/// </summary>
[Route("/Shows/NextUp", "GET")]
[Api(("Gets a list of currently installed plugins"))]
public class GetNextUpEpisodes : IReturn<ItemsResult>
public class GetNextUpEpisodes : IReturn<ItemsResult>, IHasItemFields
{
/// <summary>
/// Gets or sets the user id.
@ -49,32 +49,6 @@ namespace MediaBrowser.Api
[ApiMember(Name = "SeriesId", Description = "Optional. Filter by series id", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
public string SeriesId { get; set; }
/// <summary>
/// Gets the item fields.
/// </summary>
/// <returns>IEnumerable{ItemFields}.</returns>
public IEnumerable<ItemFields> GetItemFields()
{
var val = Fields;
if (string.IsNullOrEmpty(val))
{
return new ItemFields[] { };
}
return val.Split(',').Select(v =>
{
ItemFields value;
if (Enum.TryParse(v, true, out value))
{
return (ItemFields?)value;
}
return null;
}).Where(i => i.HasValue).Select(i => i.Value);
}
}
[Route("/Shows/{Id}/Similar", "GET")]
@ -83,6 +57,34 @@ namespace MediaBrowser.Api
{
}
[Route("/Shows/{Id}/Episodes", "GET")]
[Api(Description = "Finds tv shows similar to a given one.")]
public class GetEpisodes : 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 = "Season", Description = "Optional filter by season number.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
public int? Season { 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; }
}
/// <summary>
/// Class TvShowsService
/// </summary>
@ -311,5 +313,88 @@ namespace MediaBrowser.Api
return items;
}
public object Get(GetEpisodes request)
{
var user = _userManager.GetUserById(request.UserId);
var series = _libraryManager.GetItemById(request.Id) as Series;
var fields = request.GetItemFields().ToList();
var episodes = series.GetRecursiveChildren(user)
.OfType<Episode>();
var sortOrder = ItemSortBy.SortName;
if (request.Season.HasValue)
{
episodes = FilterEpisodesBySeason(episodes, request.Season.Value, true);
sortOrder = ItemSortBy.AiredEpisodeOrder;
}
var config = user.Configuration;
if (!config.DisplayMissingEpisodes)
{
episodes = episodes.Where(i => !i.IsMissingEpisode);
}
if (!config.DisplayUnairedEpisodes)
{
episodes = episodes.Where(i => !i.IsVirtualUnaired);
}
// ExcludeLocationTypes
if (!string.IsNullOrEmpty(request.ExcludeLocationTypes))
{
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>();
var returnItems = episodes.Select(i => _dtoService.GetBaseItemDto(i, fields, user))
.ToArray();
return new ItemsResult
{
TotalRecordCount = returnItems.Length,
Items = returnItems
};
}
internal static IEnumerable<Episode> FilterEpisodesBySeason(IEnumerable<Episode> episodes, int seasonNumber, bool includeSpecials)
{
if (!includeSpecials || seasonNumber < 1)
{
return episodes.Where(i => (i.PhysicalSeasonNumber ?? -1) == seasonNumber);
}
var episodeList = episodes.ToList();
// We can only enforce the air date requirement if the episodes have air dates
var enforceAirDate = episodeList.Any(i => i.PremiereDate.HasValue);
return episodeList.Where(i =>
{
var episode = i;
if (episode != null)
{
if (enforceAirDate && !episode.PremiereDate.HasValue)
{
return false;
}
var currentSeasonNumber = episode.AiredSeasonNumber;
return currentSeasonNumber.HasValue && currentSeasonNumber.Value == seasonNumber;
}
return false;
});
}
}
}

View File

@ -7,7 +7,7 @@ using System;
namespace MediaBrowser.Api.UserLibrary
{
public abstract class BaseItemsRequest
public abstract class BaseItemsRequest : IHasItemFields
{
/// <summary>
/// Skips over a given number of items within the results. Use for paging.
@ -109,32 +109,6 @@ namespace MediaBrowser.Api.UserLibrary
return val.Split(',').Select(v => (ItemFilter)Enum.Parse(typeof(ItemFilter), v, true));
}
/// <summary>
/// Gets the item fields.
/// </summary>
/// <returns>IEnumerable{ItemFields}.</returns>
public IEnumerable<ItemFields> GetItemFields()
{
var val = Fields;
if (string.IsNullOrEmpty(val))
{
return new ItemFields[] { };
}
return val.Split(',').Select(v =>
{
ItemFields value;
if (Enum.TryParse(v, true, out value))
{
return (ItemFields?)value;
}
return null;
}).Where(i => i.HasValue).Select(i => i.Value);
}
/// <summary>
/// Gets the image types.
/// </summary>

View File

@ -1012,7 +1012,7 @@ namespace MediaBrowser.Api.UserLibrary
if (request.AiredDuringSeason.HasValue)
{
items = FilterByAiredDuringSeason(items, request.AiredDuringSeason.Value);
items = TvShowsService.FilterEpisodesBySeason(items.OfType<Episode>(), request.AiredDuringSeason.Value, true);
}
if (!string.IsNullOrEmpty(request.MinPremiereDate))
@ -1032,43 +1032,6 @@ namespace MediaBrowser.Api.UserLibrary
return items;
}
private IEnumerable<BaseItem> FilterByAiredDuringSeason(IEnumerable<BaseItem> items, int seasonNumber)
{
var episodes = items.OfType<Episode>().ToList();
// We can only enforce the air date requirement if the episodes have air dates
var enforceAirDate = episodes.Any(i => i.PremiereDate.HasValue);
return episodes.Where(i =>
{
var episode = i;
if (episode != null)
{
var currentSeasonNumber = episode.AirsAfterSeasonNumber ?? episode.AirsBeforeSeasonNumber ?? episode.ParentIndexNumber;
// If this produced nothing, try and get it from the parent folder
if (!currentSeasonNumber.HasValue)
{
var season = episode.Parent as Season;
if (season != null)
{
currentSeasonNumber = season.IndexNumber;
}
}
if (enforceAirDate && !episode.PremiereDate.HasValue)
{
return false;
}
return currentSeasonNumber.HasValue && currentSeasonNumber.Value == seasonNumber;
}
return false;
});
}
/// <summary>
/// Determines whether the specified item has image.
/// </summary>

View File

@ -168,7 +168,7 @@ namespace MediaBrowser.Common.Implementations.Updates
{
// Let dev users get results more often for testing purposes
var cacheLength = _config.CommonConfiguration.SystemUpdateLevel == PackageVersionClass.Dev
? TimeSpan.FromMinutes(15)
? TimeSpan.FromMinutes(5)
: TimeSpan.FromHours(12);
if ((DateTime.UtcNow - _lastPackageListResult.Item2) < cacheLength)

View File

@ -50,6 +50,33 @@ namespace MediaBrowser.Controller.Entities.TV
get { return true; }
}
[IgnoreDataMember]
public int? AiredSeasonNumber
{
get
{
return AirsBeforeSeasonNumber ?? AirsAfterSeasonNumber ?? PhysicalSeasonNumber;
}
}
[IgnoreDataMember]
public int? PhysicalSeasonNumber
{
get
{
var value = ParentIndexNumber;
if (value.HasValue)
{
return value;
}
var season = Parent as Season;
return season != null ? season.IndexNumber : null;
}
}
/// <summary>
/// We roll up into series
/// </summary>

View File

@ -1072,7 +1072,7 @@ namespace MediaBrowser.Controller.Providers
/// <returns>IEnumerable{PersonInfo}.</returns>
private IEnumerable<PersonInfo> GetPersonsFromXmlNode(XmlReader reader)
{
var names = new List<string>();
var name = string.Empty;
var type = "Actor"; // If type is not specified assume actor
var role = string.Empty;
int? sortOrder = null;
@ -1086,7 +1086,7 @@ namespace MediaBrowser.Controller.Providers
switch (reader.Name)
{
case "Name":
names.AddRange(SplitNames(reader.ReadElementContentAsString()));
name = reader.ReadElementContentAsString() ?? string.Empty;
break;
case "Type":
@ -1132,7 +1132,15 @@ namespace MediaBrowser.Controller.Providers
}
}
return names.Select(n => new PersonInfo { Name = n.Trim(), Role = role, Type = type, SortOrder = sortOrder });
var personInfo = new PersonInfo
{
Name = name.Trim(),
Role = role,
Type = type,
SortOrder = sortOrder
};
return new[] { personInfo };
}
/// <summary>

View File

@ -311,6 +311,9 @@
<Compile Include="..\MediaBrowser.Model\Querying\ArtistsQuery.cs">
<Link>Querying\ArtistsQuery.cs</Link>
</Compile>
<Compile Include="..\MediaBrowser.Model\Querying\EpisodeQuery.cs">
<Link>Querying\EpisodeQuery.cs</Link>
</Compile>
<Compile Include="..\MediaBrowser.Model\Querying\ItemCountsQuery.cs">
<Link>Querying\ItemCountsQuery.cs</Link>
</Compile>

View File

@ -298,6 +298,9 @@
<Compile Include="..\MediaBrowser.Model\Querying\ArtistsQuery.cs">
<Link>Querying\ArtistsQuery.cs</Link>
</Compile>
<Compile Include="..\MediaBrowser.Model\Querying\EpisodeQuery.cs">
<Link>Querying\EpisodeQuery.cs</Link>
</Compile>
<Compile Include="..\MediaBrowser.Model\Querying\ItemCountsQuery.cs">
<Link>Querying\ItemCountsQuery.cs</Link>
</Compile>

View File

@ -225,6 +225,13 @@ namespace MediaBrowser.Model.ApiClient
/// <returns>Task{ItemCounts}.</returns>
Task<ItemCounts> GetItemCountsAsync(ItemCountsQuery query);
/// <summary>
/// Gets the episodes asynchronous.
/// </summary>
/// <param name="query">The query.</param>
/// <returns>Task{ItemsResult}.</returns>
Task<ItemsResult> GetEpisodesAsync(EpisodeQuery query);
/// <summary>
/// Queries for items
/// </summary>

View File

@ -90,6 +90,7 @@
<Compile Include="Notifications\NotificationsSummary.cs" />
<Compile Include="Providers\RemoteImageResult.cs" />
<Compile Include="Querying\ArtistsQuery.cs" />
<Compile Include="Querying\EpisodeQuery.cs" />
<Compile Include="Querying\ItemCountsQuery.cs" />
<Compile Include="Querying\ItemReviewsResult.cs" />
<Compile Include="Querying\ItemsByNameQuery.cs" />

View File

@ -0,0 +1,23 @@
using MediaBrowser.Model.Entities;
namespace MediaBrowser.Model.Querying
{
public class EpisodeQuery
{
public string UserId { get; set; }
public string SeriesId { get; set; }
public LocationType[] ExcludeLocationTypes { get; set; }
public int? SeasonNumber { get; set; }
public ItemFields[] Fields { get; set; }
public EpisodeQuery()
{
Fields = new ItemFields[] { };
ExcludeLocationTypes = new LocationType[] { };
}
}
}

View File

@ -68,8 +68,8 @@ namespace MediaBrowser.Providers.Movies
var timestampFileInfo = new FileInfo(timestampFile);
// Don't check for tvdb updates anymore frequently than 24 hours
if (timestampFileInfo.Exists && (DateTime.UtcNow - _fileSystem.GetLastWriteTimeUtc(timestampFileInfo)).TotalDays < 1)
// Don't check for updates every single time
if (timestampFileInfo.Exists && (DateTime.UtcNow - _fileSystem.GetLastWriteTimeUtc(timestampFileInfo)).TotalDays < 3)
{
return;
}

View File

@ -100,8 +100,8 @@ namespace MediaBrowser.Providers.Movies
var timestampFileInfo = new FileInfo(timestampFile);
// Don't check for tvdb updates anymore frequently than 24 hours
if (timestampFileInfo.Exists && (DateTime.UtcNow - _fileSystem.GetLastWriteTimeUtc(timestampFileInfo)).TotalDays < 1)
// Don't check for updates every single time
if (timestampFileInfo.Exists && (DateTime.UtcNow - _fileSystem.GetLastWriteTimeUtc(timestampFileInfo)).TotalDays < 3)
{
return;
}

View File

@ -76,8 +76,8 @@ namespace MediaBrowser.Providers.Movies
var timestampFileInfo = new FileInfo(timestampFile);
// Don't check for tvdb updates anymore frequently than 24 hours
if (timestampFileInfo.Exists && (DateTime.UtcNow - _fileSystem.GetLastWriteTimeUtc(timestampFileInfo)).TotalDays < 1)
// Don't check for updates every single time
if (timestampFileInfo.Exists && (DateTime.UtcNow - _fileSystem.GetLastWriteTimeUtc(timestampFileInfo)).TotalDays < 3)
{
return;
}

View File

@ -67,8 +67,8 @@ namespace MediaBrowser.Providers.Music
var timestampFileInfo = new FileInfo(timestampFile);
// Don't check for tvdb updates anymore frequently than 24 hours
if (timestampFileInfo.Exists && (DateTime.UtcNow - _fileSystem.GetLastWriteTimeUtc(timestampFileInfo)).TotalDays < 1)
// Don't check for updates every single time
if (timestampFileInfo.Exists && (DateTime.UtcNow - _fileSystem.GetLastWriteTimeUtc(timestampFileInfo)).TotalDays < 3)
{
return;
}

View File

@ -68,8 +68,8 @@ namespace MediaBrowser.Providers.TV
var timestampFileInfo = new FileInfo(timestampFile);
// Don't check for tvdb updates anymore frequently than 24 hours
if (timestampFileInfo.Exists && (DateTime.UtcNow - _fileSystem.GetLastWriteTimeUtc(timestampFileInfo)).TotalDays < 1)
// Don't check for updates every single time
if (timestampFileInfo.Exists && (DateTime.UtcNow - _fileSystem.GetLastWriteTimeUtc(timestampFileInfo)).TotalDays < 3)
{
return;
}

View File

@ -469,6 +469,17 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi
});
};
self.getEpisodes = function (itemId, options) {
var url = self.getUrl("Shows/" + itemId + "/Episodes", options);
return self.ajax({
type: "GET",
url: url,
dataType: "json"
});
};
self.getSimilarMovies = function (itemId, options) {
var url = self.getUrl("Movies/" + itemId + "/Similar", options);

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="MediaBrowser.ApiClient.Javascript" version="3.0.193" targetFramework="net45" />
<package id="MediaBrowser.ApiClient.Javascript" version="3.0.194" targetFramework="net45" />
<package id="ServiceStack.Common" version="3.9.62" targetFramework="net45" />
<package id="ServiceStack.Text" version="3.9.62" targetFramework="net45" />
</packages>

View File

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>MediaBrowser.Common.Internal</id>
<version>3.0.244</version>
<version>3.0.245</version>
<title>MediaBrowser.Common.Internal</title>
<authors>Luke</authors>
<owners>ebr,Luke,scottisafool</owners>
@ -12,7 +12,7 @@
<description>Contains common components shared by Media Browser Theater and Media Browser Server. Not intended for plugin developer consumption.</description>
<copyright>Copyright © Media Browser 2013</copyright>
<dependencies>
<dependency id="MediaBrowser.Common" version="3.0.244" />
<dependency id="MediaBrowser.Common" version="3.0.245" />
<dependency id="NLog" version="2.1.0" />
<dependency id="ServiceStack.Text" version="3.9.58" />
<dependency id="SimpleInjector" version="2.3.6" />

View File

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>MediaBrowser.Common</id>
<version>3.0.244</version>
<version>3.0.245</version>
<title>MediaBrowser.Common</title>
<authors>Media Browser Team</authors>
<owners>ebr,Luke,scottisafool</owners>

View File

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>MediaBrowser.Server.Core</id>
<version>3.0.244</version>
<version>3.0.245</version>
<title>Media Browser.Server.Core</title>
<authors>Media Browser Team</authors>
<owners>ebr,Luke,scottisafool</owners>
@ -12,7 +12,7 @@
<description>Contains core components required to build plugins for Media Browser Server.</description>
<copyright>Copyright © Media Browser 2013</copyright>
<dependencies>
<dependency id="MediaBrowser.Common" version="3.0.244" />
<dependency id="MediaBrowser.Common" version="3.0.245" />
</dependencies>
</metadata>
<files>