start on manual collection creation

This commit is contained in:
Luke Pulverenti 2014-03-06 00:17:13 -05:00
parent 9396f16aed
commit 2349c8099d
17 changed files with 239 additions and 24 deletions

View File

@ -66,7 +66,7 @@
<Compile Include="..\SharedVersion.cs"> <Compile Include="..\SharedVersion.cs">
<Link>Properties\SharedVersion.cs</Link> <Link>Properties\SharedVersion.cs</Link>
</Compile> </Compile>
<Compile Include="AlbumsService.cs" /> <Compile Include="Music\AlbumsService.cs" />
<Compile Include="AppThemeService.cs" /> <Compile Include="AppThemeService.cs" />
<Compile Include="BaseApiService.cs" /> <Compile Include="BaseApiService.cs" />
<Compile Include="ConfigurationService.cs" /> <Compile Include="ConfigurationService.cs" />
@ -81,7 +81,7 @@
<Compile Include="Images\ImageRequest.cs" /> <Compile Include="Images\ImageRequest.cs" />
<Compile Include="Images\ImageService.cs" /> <Compile Include="Images\ImageService.cs" />
<Compile Include="Images\ImageWriter.cs" /> <Compile Include="Images\ImageWriter.cs" />
<Compile Include="InstantMixService.cs" /> <Compile Include="Music\InstantMixService.cs" />
<Compile Include="ItemLookupService.cs" /> <Compile Include="ItemLookupService.cs" />
<Compile Include="ItemRefreshService.cs" /> <Compile Include="ItemRefreshService.cs" />
<Compile Include="ItemUpdateService.cs" /> <Compile Include="ItemUpdateService.cs" />

View File

@ -8,7 +8,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
namespace MediaBrowser.Api namespace MediaBrowser.Api.Music
{ {
[Route("/Albums/{Id}/Similar", "GET")] [Route("/Albums/{Id}/Similar", "GET")]
[Api(Description = "Finds albums similar to a given album.")] [Api(Description = "Finds albums similar to a given album.")]

View File

@ -7,7 +7,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
namespace MediaBrowser.Api namespace MediaBrowser.Api.Music
{ {
[Route("/Songs/{Id}/InstantMix", "GET")] [Route("/Songs/{Id}/InstantMix", "GET")]
[Api(Description = "Creates an instant playlist based on a given song")] [Api(Description = "Creates an instant playlist based on a given song")]

View File

@ -18,7 +18,7 @@ namespace MediaBrowser.Api
/// Class GetNextUpEpisodes /// Class GetNextUpEpisodes
/// </summary> /// </summary>
[Route("/Shows/NextUp", "GET")] [Route("/Shows/NextUp", "GET")]
[Api(("Gets a list of currently installed plugins"))] [Api(("Gets a list of next up episodes"))]
public class GetNextUpEpisodes : IReturn<ItemsResult>, IHasItemFields public class GetNextUpEpisodes : IReturn<ItemsResult>, IHasItemFields
{ {
/// <summary> /// <summary>
@ -53,6 +53,39 @@ namespace MediaBrowser.Api
public string SeriesId { get; set; } public string SeriesId { get; set; }
} }
[Route("/Shows/Upcoming", "GET")]
[Api(("Gets a list of upcoming episodes"))]
public class GetUpcomingEpisodes : 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>
/// Skips over a given number of items within the results. Use for paging.
/// </summary>
/// <value>The start index.</value>
[ApiMember(Name = "StartIndex", Description = "Optional. The record index to start at. All items with a lower index will be dropped from the results.", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
public int? StartIndex { get; set; }
/// <summary>
/// The maximum number of items to return
/// </summary>
/// <value>The limit.</value>
[ApiMember(Name = "Limit", Description = "Optional. The maximum number of records to return", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
public int? Limit { 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; }
}
[Route("/Shows/{Id}/Similar", "GET")] [Route("/Shows/{Id}/Similar", "GET")]
[Api(Description = "Finds tv shows similar to a given one.")] [Api(Description = "Finds tv shows similar to a given one.")]
public class GetSimilarShows : BaseGetSimilarItemsFromItem public class GetSimilarShows : BaseGetSimilarItemsFromItem
@ -85,7 +118,7 @@ namespace MediaBrowser.Api
[ApiMember(Name = "SeasonId", Description = "Optional. Filter by season id", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] [ApiMember(Name = "SeasonId", Description = "Optional. Filter by season id", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
public string SeasonId { get; set; } public string SeasonId { get; set; }
[ApiMember(Name = "IsMissing", Description = "Optional filter by items that are missing episodes or not.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")] [ApiMember(Name = "IsMissing", Description = "Optional filter by items that are missing episodes or not.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")]
public bool? IsMissing { get; set; } public bool? IsMissing { get; set; }
@ -186,6 +219,39 @@ namespace MediaBrowser.Api
return ToOptimizedSerializedResultUsingCache(result); return ToOptimizedSerializedResultUsingCache(result);
} }
public object Get(GetUpcomingEpisodes request)
{
var user = _userManager.GetUserById(request.UserId);
var items = GetAllLibraryItems(request.UserId, _userManager, _libraryManager)
.OfType<Episode>();
var itemsList = _libraryManager.Sort(items, user, new[] { "PremiereDate", "AirTime", "SortName" }, SortOrder.Ascending)
.Cast<Episode>()
.ToList();
var unairedEpisodes = itemsList.Where(i => i.IsUnaired).ToList();
var minPremiereDate = DateTime.Now.Date.AddDays(-1).ToUniversalTime();
var previousEpisodes = itemsList.Where(i => !i.IsUnaired && (i.PremiereDate ?? DateTime.MinValue) >= minPremiereDate).ToList();
previousEpisodes.AddRange(unairedEpisodes);
var pagedItems = ApplyPaging(previousEpisodes, request.StartIndex, request.Limit);
var fields = request.GetItemFields().ToList();
var returnItems = pagedItems.Select(i => _dtoService.GetBaseItemDto(i, fields, user)).ToArray();
var result = new ItemsResult
{
TotalRecordCount = itemsList.Count,
Items = returnItems
};
return ToOptimizedSerializedResultUsingCache(result);
}
/// <summary> /// <summary>
/// Gets the specified request. /// Gets the specified request.
/// </summary> /// </summary>
@ -198,7 +264,7 @@ namespace MediaBrowser.Api
var itemsList = GetNextUpEpisodes(request) var itemsList = GetNextUpEpisodes(request)
.ToList(); .ToList();
var pagedItems = ApplyPaging(request, itemsList); var pagedItems = ApplyPaging(itemsList, request.StartIndex, request.Limit);
var fields = request.GetItemFields().ToList(); var fields = request.GetItemFields().ToList();
@ -321,21 +387,22 @@ namespace MediaBrowser.Api
/// <summary> /// <summary>
/// Applies the paging. /// Applies the paging.
/// </summary> /// </summary>
/// <param name="request">The request.</param>
/// <param name="items">The items.</param> /// <param name="items">The items.</param>
/// <param name="startIndex">The start index.</param>
/// <param name="limit">The limit.</param>
/// <returns>IEnumerable{BaseItem}.</returns> /// <returns>IEnumerable{BaseItem}.</returns>
private IEnumerable<BaseItem> ApplyPaging(GetNextUpEpisodes request, IEnumerable<BaseItem> items) private IEnumerable<BaseItem> ApplyPaging(IEnumerable<BaseItem> items, int? startIndex, int? limit)
{ {
// Start at // Start at
if (request.StartIndex.HasValue) if (startIndex.HasValue)
{ {
items = items.Skip(request.StartIndex.Value); items = items.Skip(startIndex.Value);
} }
// Return limit // Return limit
if (request.Limit.HasValue) if (limit.HasValue)
{ {
items = items.Take(request.Limit.Value); items = items.Take(limit.Value);
} }
return items; return items;
@ -409,7 +476,7 @@ namespace MediaBrowser.Api
return items; return items;
} }
public object Get(GetEpisodes request) public object Get(GetEpisodes request)
{ {
var user = _userManager.GetUserById(request.UserId); var user = _userManager.GetUserById(request.UserId);
@ -435,7 +502,7 @@ namespace MediaBrowser.Api
{ {
throw new ResourceNotFoundException("No season exists with Id " + request.SeasonId); throw new ResourceNotFoundException("No season exists with Id " + request.SeasonId);
} }
episodes = season.GetEpisodes(user); episodes = season.GetEpisodes(user);
} }

View File

@ -0,0 +1,13 @@
using System;
namespace MediaBrowser.Controller.Collections
{
public class CollectionCreationOptions
{
public string Name { get; set; }
public Guid ParentId { get; set; }
public bool IsLocked { get; set; }
}
}

View File

@ -0,0 +1,31 @@
using System;
using System.Threading.Tasks;
namespace MediaBrowser.Controller.Collections
{
public interface ICollectionManager
{
/// <summary>
/// Creates the collection.
/// </summary>
/// <param name="options">The options.</param>
/// <returns>Task.</returns>
Task CreateCollection(CollectionCreationOptions options);
/// <summary>
/// Adds to collection.
/// </summary>
/// <param name="collectionId">The collection identifier.</param>
/// <param name="itemId">The item identifier.</param>
/// <returns>Task.</returns>
Task AddToCollection(Guid collectionId, Guid itemId);
/// <summary>
/// Removes from collection.
/// </summary>
/// <param name="collectionId">The collection identifier.</param>
/// <param name="itemId">The item identifier.</param>
/// <returns>Task.</returns>
Task RemoveFromCollection(Guid collectionId, Guid itemId);
}
}

View File

@ -1,4 +1,5 @@
using MediaBrowser.Controller.Providers; using MediaBrowser.Controller.Providers;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -23,7 +24,7 @@ namespace MediaBrowser.Controller.Entities
{ {
var hasChanges = base.BeforeMetadataRefresh(); var hasChanges = base.BeforeMetadataRefresh();
if (string.Equals("default", Name, System.StringComparison.OrdinalIgnoreCase)) if (string.Equals("default", Name, StringComparison.OrdinalIgnoreCase))
{ {
Name = "Media Folders"; Name = "Media Folders";
hasChanges = true; hasChanges = true;

View File

@ -68,6 +68,8 @@
<Compile Include="..\SharedVersion.cs"> <Compile Include="..\SharedVersion.cs">
<Link>Properties\SharedVersion.cs</Link> <Link>Properties\SharedVersion.cs</Link>
</Compile> </Compile>
<Compile Include="Collections\CollectionCreationOptions.cs" />
<Compile Include="Collections\ICollectionManager.cs" />
<Compile Include="Drawing\IImageProcessor.cs" /> <Compile Include="Drawing\IImageProcessor.cs" />
<Compile Include="Drawing\ImageFormat.cs" /> <Compile Include="Drawing\ImageFormat.cs" />
<Compile Include="Drawing\ImageProcessingOptions.cs" /> <Compile Include="Drawing\ImageProcessingOptions.cs" />

View File

@ -23,7 +23,7 @@ namespace MediaBrowser.Providers.Music
public bool Supports(IHasProviderIds item) public bool Supports(IHasProviderIds item)
{ {
return item is Audio || item is MusicAlbum || item is MusicArtist; return item is Audio || item is MusicAlbum;
} }
} }

View File

@ -0,0 +1,79 @@
using MediaBrowser.Common.IO;
using MediaBrowser.Controller.Collections;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers;
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
namespace MediaBrowser.Server.Implementations.Collections
{
public class CollectionManager : ICollectionManager
{
private readonly ILibraryManager _libraryManager;
private readonly IFileSystem _fileSystem;
private readonly ILibraryMonitor _iLibraryMonitor;
public CollectionManager(ILibraryManager libraryManager, IFileSystem fileSystem, ILibraryMonitor iLibraryMonitor)
{
_libraryManager = libraryManager;
_fileSystem = fileSystem;
_iLibraryMonitor = iLibraryMonitor;
}
public async Task CreateCollection(CollectionCreationOptions options)
{
var name = options.Name;
var folderName = _fileSystem.GetValidFilename(name);
var parentFolder = _libraryManager.GetItemById(options.ParentId) as Folder;
if (parentFolder == null)
{
throw new ArgumentException();
}
var path = Path.Combine(parentFolder.Path, folderName);
_iLibraryMonitor.ReportFileSystemChangeBeginning(path);
try
{
Directory.CreateDirectory(path);
var collection = new BoxSet
{
Name = name,
Parent = parentFolder,
DisplayMediaType = "Collection",
Path = path,
DontFetchMeta = options.IsLocked
};
await parentFolder.AddChild(collection, CancellationToken.None).ConfigureAwait(false);
await collection.RefreshMetadata(new MetadataRefreshOptions(), CancellationToken.None)
.ConfigureAwait(false);
}
finally
{
// Refresh handled internally
_iLibraryMonitor.ReportFileSystemChangeComplete(path, false);
}
}
public Task AddToCollection(Guid collectionId, Guid itemId)
{
throw new NotImplementedException();
}
public Task RemoveFromCollection(Guid collectionId, Guid itemId)
{
throw new NotImplementedException();
}
}
}

View File

@ -3,6 +3,8 @@ using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Plugins; using MediaBrowser.Controller.Plugins;
using MediaBrowser.Model.Logging; using MediaBrowser.Model.Logging;
using Mono.Nat; using Mono.Nat;
using Mono.Nat.Enums;
using Mono.Nat.EventArgs;
using System; using System;
using System.IO; using System.IO;
using System.Text; using System.Text;

View File

@ -48,7 +48,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio
var collectionType = args.GetCollectionType(); var collectionType = args.GetCollectionType();
// If there's a collection type and it's not music, it can't be a series // If there's a collection type and it's not music, don't allow it.
if (!string.IsNullOrEmpty(collectionType) && if (!string.IsNullOrEmpty(collectionType) &&
!string.Equals(collectionType, CollectionType.Music, StringComparison.OrdinalIgnoreCase)) !string.Equals(collectionType, CollectionType.Music, StringComparison.OrdinalIgnoreCase))
{ {

View File

@ -105,7 +105,13 @@ namespace MediaBrowser.Server.Implementations.LiveTv
public bool HasChanged(IHasMetadata item, IDirectoryService directoryService, DateTime date) public bool HasChanged(IHasMetadata item, IDirectoryService directoryService, DateTime date)
{ {
return !item.HasImage(ImageType.Primary) && (DateTime.UtcNow - date).TotalDays >= 1; var liveTvItem = item as LiveTvChannel;
if (liveTvItem != null)
{
return !liveTvItem.HasImage(ImageType.Primary) && (liveTvItem.HasProviderImage ?? true) && (DateTime.UtcNow - date).TotalHours >= 6;
}
return false;
} }
} }
} }

View File

@ -105,7 +105,13 @@ namespace MediaBrowser.Server.Implementations.LiveTv
public bool HasChanged(IHasMetadata item, IDirectoryService directoryService, DateTime date) public bool HasChanged(IHasMetadata item, IDirectoryService directoryService, DateTime date)
{ {
return !item.HasImage(ImageType.Primary) && (DateTime.UtcNow - date).TotalHours >= 6; var liveTvItem = item as LiveTvProgram;
if (liveTvItem != null)
{
return !liveTvItem.HasImage(ImageType.Primary) && (liveTvItem.HasProviderImage ?? true) && (DateTime.UtcNow - date).TotalHours >= 6;
}
return false;
} }
} }
} }

View File

@ -105,7 +105,13 @@ namespace MediaBrowser.Server.Implementations.LiveTv
public bool HasChanged(IHasMetadata item, IDirectoryService directoryService, DateTime date) public bool HasChanged(IHasMetadata item, IDirectoryService directoryService, DateTime date)
{ {
return !item.HasImage(ImageType.Primary) && (DateTime.UtcNow - date).TotalHours >= 3; var liveTvItem = item as ILiveTvRecording;
if (liveTvItem != null)
{
return !liveTvItem.HasImage(ImageType.Primary) && (liveTvItem.RecordingInfo.HasImage ?? true) && (DateTime.UtcNow - date).TotalHours >= 6;
}
return false;
} }
} }
} }

View File

@ -56,8 +56,9 @@
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\MediaBrowser.BdInfo.1.0.0.10\lib\net35\DvdLib.dll</HintPath> <HintPath>..\packages\MediaBrowser.BdInfo.1.0.0.10\lib\net35\DvdLib.dll</HintPath>
</Reference> </Reference>
<Reference Include="Mono.Nat"> <Reference Include="Mono.Nat, Version=1.2.3.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Nat.1.1.13\lib\Net40\Mono.Nat.dll</HintPath> <SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Mono.Nat.1.2.3\lib\Net40\Mono.Nat.dll</HintPath>
</Reference> </Reference>
<Reference Include="ServiceStack.Api.Swagger"> <Reference Include="ServiceStack.Api.Swagger">
<HintPath>..\ThirdParty\ServiceStack\ServiceStack.Api.Swagger.dll</HintPath> <HintPath>..\ThirdParty\ServiceStack\ServiceStack.Api.Swagger.dll</HintPath>
@ -108,6 +109,7 @@
<Link>Properties\SharedVersion.cs</Link> <Link>Properties\SharedVersion.cs</Link>
</Compile> </Compile>
<Compile Include="BdInfo\BdInfoExaminer.cs" /> <Compile Include="BdInfo\BdInfoExaminer.cs" />
<Compile Include="Collections\CollectionManager.cs" />
<Compile Include="Configuration\ServerConfigurationManager.cs" /> <Compile Include="Configuration\ServerConfigurationManager.cs" />
<Compile Include="Drawing\ImageHeader.cs" /> <Compile Include="Drawing\ImageHeader.cs" />
<Compile Include="Drawing\PercentPlayedDrawer.cs" /> <Compile Include="Drawing\PercentPlayedDrawer.cs" />

View File

@ -2,7 +2,7 @@
<packages> <packages>
<package id="Alchemy" version="2.2.1" targetFramework="net45" /> <package id="Alchemy" version="2.2.1" targetFramework="net45" />
<package id="MediaBrowser.BdInfo" version="1.0.0.10" targetFramework="net45" /> <package id="MediaBrowser.BdInfo" version="1.0.0.10" targetFramework="net45" />
<package id="Mono.Nat" version="1.1.13" targetFramework="net45" /> <package id="Mono.Nat" version="1.2.3" targetFramework="net45" />
<package id="morelinq" version="1.0.16006" targetFramework="net45" /> <package id="morelinq" version="1.0.16006" targetFramework="net45" />
<package id="System.Data.SQLite.x86" version="1.0.90.0" targetFramework="net45" /> <package id="System.Data.SQLite.x86" version="1.0.90.0" targetFramework="net45" />
</packages> </packages>