aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Api/Library
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2016-02-14 16:35:09 -0500
committerLuke Pulverenti <luke.pulverenti@gmail.com>2016-02-14 16:35:09 -0500
commitdaa0b6cd0ecefd60611752802d062c15e6da85de (patch)
treef58a16e47afed9b61471e3871280faa9fc8bd951 /MediaBrowser.Api/Library
parent7d26b8995f313917829573a7cd96c37decc9158a (diff)
parentfd5f12e76227d96c52cdc31b67ef9543b485169b (diff)
Merge branch 'beta'
Diffstat (limited to 'MediaBrowser.Api/Library')
-rw-r--r--MediaBrowser.Api/Library/FileOrganizationService.cs48
-rw-r--r--MediaBrowser.Api/Library/LibraryService.cs70
2 files changed, 103 insertions, 15 deletions
diff --git a/MediaBrowser.Api/Library/FileOrganizationService.cs b/MediaBrowser.Api/Library/FileOrganizationService.cs
index 29a982629..1224fa957 100644
--- a/MediaBrowser.Api/Library/FileOrganizationService.cs
+++ b/MediaBrowser.Api/Library/FileOrganizationService.cs
@@ -1,9 +1,11 @@
-using MediaBrowser.Controller.FileOrganization;
+using System.Collections.Generic;
+using MediaBrowser.Controller.FileOrganization;
using MediaBrowser.Controller.Net;
using MediaBrowser.Model.FileOrganization;
using MediaBrowser.Model.Querying;
using ServiceStack;
using System.Threading.Tasks;
+using MediaBrowser.Model.Dto;
namespace MediaBrowser.Api.Library
{
@@ -74,6 +76,31 @@ namespace MediaBrowser.Api.Library
public bool RememberCorrection { get; set; }
}
+ [Route("/Library/FileOrganizations/SmartMatches", "GET", Summary = "Gets smart match entries")]
+ public class GetSmartMatchInfos : IReturn<QueryResult<SmartMatchInfo>>
+ {
+ /// <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; }
+ }
+
+ [Route("/Library/FileOrganizations/SmartMatches/Delete", "POST", Summary = "Deletes a smart match entry")]
+ public class DeleteSmartMatchEntry
+ {
+ [ApiMember(Name = "Entries", Description = "SmartMatch Entry", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")]
+ public List<NameValuePair> Entries { get; set; }
+ }
+
[Authenticated(Roles = "Admin")]
public class FileOrganizationService : BaseApiService
{
@@ -130,5 +157,24 @@ namespace MediaBrowser.Api.Library
Task.WaitAll(task);
}
+
+ public object Get(GetSmartMatchInfos request)
+ {
+ var result = _iFileOrganizationService.GetSmartMatchInfos(new FileOrganizationResultQuery
+ {
+ Limit = request.Limit,
+ StartIndex = request.StartIndex
+ });
+
+ return ToOptimizedSerializedResultUsingCache(result);
+ }
+
+ public void Post(DeleteSmartMatchEntry request)
+ {
+ request.Entries.ForEach(entry =>
+ {
+ _iFileOrganizationService.DeleteSmartMatchEntry(entry.Name, entry.Value);
+ });
+ }
}
}
diff --git a/MediaBrowser.Api/Library/LibraryService.cs b/MediaBrowser.Api/Library/LibraryService.cs
index b7066a36d..896f8c990 100644
--- a/MediaBrowser.Api/Library/LibraryService.cs
+++ b/MediaBrowser.Api/Library/LibraryService.cs
@@ -424,7 +424,7 @@ namespace MediaBrowser.Api.Library
public object Get(GetMediaFolders request)
{
- var items = _libraryManager.GetUserRootFolder().Children.OrderBy(i => i.SortName).ToList();
+ var items = _libraryManager.GetUserRootFolder().Children.Concat(_libraryManager.RootFolder.VirtualChildren).OrderBy(i => i.SortName).ToList();
if (request.IsHidden.HasValue)
{
@@ -569,7 +569,7 @@ namespace MediaBrowser.Api.Library
{
throw new ArgumentException("This command cannot be used for remote or virtual items.");
}
- if (_fileSystem.DirectoryExists(item.Path))
+ if (_fileSystem.DirectoryExists(item.Path))
{
throw new ArgumentException("This command cannot be used for directories.");
}
@@ -618,7 +618,7 @@ namespace MediaBrowser.Api.Library
var dtoOptions = GetDtoOptions(request);
- BaseItem parent = item.Parent;
+ BaseItem parent = item.GetParent();
while (parent != null)
{
@@ -629,7 +629,7 @@ namespace MediaBrowser.Api.Library
baseItemDtos.Add(_dtoService.GetBaseItemDto(parent, dtoOptions, user));
- parent = parent.Parent;
+ parent = parent.GetParent();
}
return baseItemDtos.ToList();
@@ -637,7 +637,7 @@ namespace MediaBrowser.Api.Library
private BaseItem TranslateParentItem(BaseItem item, User user)
{
- if (item.Parent is AggregateFolder)
+ if (item.GetParent() is AggregateFolder)
{
return user.RootFolder.GetChildren(user, true).FirstOrDefault(i => i.PhysicalLocations.Contains(item.Path));
}
@@ -685,6 +685,50 @@ namespace MediaBrowser.Api.Library
return ToOptimizedSerializedResultUsingCache(counts);
}
+ private IList<BaseItem> GetAllLibraryItems(string userId, IUserManager userManager, ILibraryManager libraryManager, string parentId, Func<BaseItem, bool> filter)
+ {
+ if (!string.IsNullOrEmpty(parentId))
+ {
+ var folder = (Folder)libraryManager.GetItemById(new Guid(parentId));
+
+ if (!string.IsNullOrWhiteSpace(userId))
+ {
+ var user = userManager.GetUserById(userId);
+
+ if (user == null)
+ {
+ throw new ArgumentException("User not found");
+ }
+
+ return folder
+ .GetRecursiveChildren(user, filter)
+ .ToList();
+ }
+
+ return folder
+ .GetRecursiveChildren(filter);
+ }
+ if (!string.IsNullOrWhiteSpace(userId))
+ {
+ var user = userManager.GetUserById(userId);
+
+ if (user == null)
+ {
+ throw new ArgumentException("User not found");
+ }
+
+ return userManager
+ .GetUserById(userId)
+ .RootFolder
+ .GetRecursiveChildren(user, filter)
+ .ToList();
+ }
+
+ return libraryManager
+ .RootFolder
+ .GetRecursiveChildren(filter);
+ }
+
private bool FilterItem(BaseItem item, GetItemCounts request, string userId)
{
if (!string.IsNullOrWhiteSpace(userId))
@@ -745,12 +789,10 @@ namespace MediaBrowser.Api.Library
return Task.FromResult(true);
}
- if (item is ILiveTvRecording)
+ return item.Delete(new DeleteOptions
{
- return _liveTv.DeleteRecording(i);
- }
-
- return _libraryManager.DeleteItem(item);
+ DeleteFileLocation = true
+ });
}).ToArray();
Task.WaitAll(tasks);
@@ -847,9 +889,9 @@ namespace MediaBrowser.Api.Library
: (Folder)_libraryManager.RootFolder)
: _libraryManager.GetItemById(request.Id);
- while (GetThemeSongIds(item).Count == 0 && request.InheritFromParent && item.Parent != null)
+ while (GetThemeSongIds(item).Count == 0 && request.InheritFromParent && item.GetParent() != null)
{
- item = item.Parent;
+ item = item.GetParent();
}
var dtoOptions = GetDtoOptions(request);
@@ -890,9 +932,9 @@ namespace MediaBrowser.Api.Library
: (Folder)_libraryManager.RootFolder)
: _libraryManager.GetItemById(request.Id);
- while (GetThemeVideoIds(item).Count == 0 && request.InheritFromParent && item.Parent != null)
+ while (GetThemeVideoIds(item).Count == 0 && request.InheritFromParent && item.GetParent() != null)
{
- item = item.Parent;
+ item = item.GetParent();
}
var dtoOptions = GetDtoOptions(request);