2016-02-13 06:19:28 +00:00
using System.Collections.Generic ;
using MediaBrowser.Controller.FileOrganization ;
2014-07-02 18:34:08 +00:00
using MediaBrowser.Controller.Net ;
2014-01-20 18:46:08 +00:00
using MediaBrowser.Model.FileOrganization ;
using MediaBrowser.Model.Querying ;
using ServiceStack ;
2014-01-21 06:10:58 +00:00
using System.Threading.Tasks ;
2016-02-13 06:19:28 +00:00
using MediaBrowser.Model.Dto ;
2016-02-28 02:34:53 +00:00
using MediaBrowser.Model.Serialization ;
2014-01-20 18:46:08 +00:00
namespace MediaBrowser.Api.Library
{
2014-11-15 02:31:03 +00:00
[Route("/Library/FileOrganization", "GET", Summary = "Gets file organization results")]
2014-01-20 18:46:08 +00:00
public class GetFileOrganizationActivity : IReturn < QueryResult < FileOrganizationResult > >
{
/// <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 ; }
}
2014-11-15 02:31:03 +00:00
[Route("/Library/FileOrganizations", "DELETE", Summary = "Clears the activity log")]
2014-01-22 17:05:32 +00:00
public class ClearOrganizationLog : IReturnVoid
{
}
2014-11-15 02:31:03 +00:00
[Route("/Library/FileOrganizations/{Id}/File", "DELETE", Summary = "Deletes the original file of a organizer result")]
2014-01-22 17:05:32 +00:00
public class DeleteOriginalFile : IReturnVoid
2014-01-21 06:10:58 +00:00
{
/// <summary>
/// Gets or sets the id.
/// </summary>
/// <value>The id.</value>
[ApiMember(Name = "Id", Description = "Result Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "DELETE")]
public string Id { get ; set ; }
}
2014-11-15 02:31:03 +00:00
[Route("/Library/FileOrganizations/{Id}/Organize", "POST", Summary = "Performs an organization")]
2014-01-21 06:10:58 +00:00
public class PerformOrganization : IReturn < QueryResult < FileOrganizationResult > >
{
/// <summary>
/// Gets or sets the id.
/// </summary>
/// <value>The id.</value>
[ApiMember(Name = "Id", Description = "Result Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
public string Id { get ; set ; }
}
2014-01-22 17:05:32 +00:00
2016-02-26 23:52:00 +00:00
[Route("/Library/FileOrganizations/{Id}/Episode/Organize", "POST", Summary = "Performs organization of a tv episode")]
2014-01-22 17:05:32 +00:00
public class OrganizeEpisode
{
[ApiMember(Name = "Id", Description = "Result Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
public string Id { get ; set ; }
[ApiMember(Name = "SeriesId", Description = "Series Id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")]
public string SeriesId { get ; set ; }
[ApiMember(Name = "SeasonNumber", IsRequired = true, DataType = "int", ParameterType = "query", Verb = "POST")]
public int SeasonNumber { get ; set ; }
[ApiMember(Name = "EpisodeNumber", IsRequired = true, DataType = "int", ParameterType = "query", Verb = "POST")]
public int EpisodeNumber { get ; set ; }
[ApiMember(Name = "EndingEpisodeNumber", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "POST")]
public int? EndingEpisodeNumber { get ; set ; }
[ApiMember(Name = "RememberCorrection", Description = "Whether or not to apply the same correction to future episodes of the same series.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "POST")]
public bool RememberCorrection { get ; set ; }
2016-02-26 23:52:00 +00:00
2016-02-28 02:56:16 +00:00
[ApiMember(Name = "NewSeriesProviderIds", Description = "A list of provider IDs identifying a new series.", IsRequired = false, DataType = "Dictionary<string, string>", ParameterType = "query", Verb = "POST")]
public Dictionary < string , string > NewSeriesProviderIds { get ; set ; }
2016-02-26 23:52:00 +00:00
[ApiMember(Name = "NewSeriesName", Description = "Name of a series to add.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "POST")]
public string NewSeriesName { get ; set ; }
[ApiMember(Name = "NewSeriesYear", Description = "Year of a series to add.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "POST")]
public string NewSeriesYear { get ; set ; }
[ApiMember(Name = "TargetFolder", Description = "Target Folder", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "POST")]
public string TargetFolder { get ; set ; }
2014-01-22 17:05:32 +00:00
}
2016-02-09 17:13:38 +00:00
[Route("/Library/FileOrganizations/SmartMatches", "GET", Summary = "Gets smart match entries")]
2015-09-23 04:12:46 +00:00
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 ; }
}
2016-02-13 06:39:23 +00:00
[Route("/Library/FileOrganizations/SmartMatches/Delete", "POST", Summary = "Deletes a smart match entry")]
2015-09-23 04:12:46 +00:00
public class DeleteSmartMatchEntry
{
2016-02-13 06:39:23 +00:00
[ApiMember(Name = "Entries", Description = "SmartMatch Entry", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")]
2016-02-13 06:19:28 +00:00
public List < NameValuePair > Entries { get ; set ; }
2015-09-23 04:12:46 +00:00
}
2014-11-15 02:31:03 +00:00
[Authenticated(Roles = "Admin")]
2014-01-20 18:46:08 +00:00
public class FileOrganizationService : BaseApiService
{
private readonly IFileOrganizationService _iFileOrganizationService ;
2016-02-28 02:34:53 +00:00
private readonly IJsonSerializer _jsonSerializer ;
public FileOrganizationService ( IFileOrganizationService iFileOrganizationService , IJsonSerializer jsonSerializer )
2014-01-20 18:46:08 +00:00
{
_iFileOrganizationService = iFileOrganizationService ;
2016-02-28 02:34:53 +00:00
_jsonSerializer = jsonSerializer ;
2014-01-20 18:46:08 +00:00
}
public object Get ( GetFileOrganizationActivity request )
{
var result = _iFileOrganizationService . GetResults ( new FileOrganizationResultQuery
{
Limit = request . Limit ,
2014-01-21 06:10:58 +00:00
StartIndex = request . StartIndex
2014-01-20 18:46:08 +00:00
} ) ;
2014-02-04 04:04:19 +00:00
return ToOptimizedSerializedResultUsingCache ( result ) ;
2014-01-20 18:46:08 +00:00
}
2014-01-21 06:10:58 +00:00
public void Delete ( DeleteOriginalFile request )
{
var task = _iFileOrganizationService . DeleteOriginalFile ( request . Id ) ;
Task . WaitAll ( task ) ;
}
2014-01-22 17:05:32 +00:00
public void Delete ( ClearOrganizationLog request )
{
var task = _iFileOrganizationService . ClearLog ( ) ;
Task . WaitAll ( task ) ;
}
2014-01-21 06:10:58 +00:00
public void Post ( PerformOrganization request )
{
2016-08-19 01:00:04 +00:00
// Don't await this
2014-01-21 06:10:58 +00:00
var task = _iFileOrganizationService . PerformOrganization ( request . Id ) ;
2016-08-19 01:00:04 +00:00
// Async processing (close dialog early instead of waiting until the file has been copied)
// Wait 2s for exceptions that may occur to have them forwarded to the client for immediate error display
task . Wait ( 2000 ) ;
2014-01-21 06:10:58 +00:00
}
2014-01-22 17:05:32 +00:00
public void Post ( OrganizeEpisode request )
{
2016-02-27 03:18:47 +00:00
var dicNewProviderIds = new Dictionary < string , string > ( ) ;
2016-02-28 02:56:16 +00:00
if ( request . NewSeriesProviderIds ! = null )
2016-02-27 03:18:47 +00:00
{
2016-02-28 02:56:16 +00:00
dicNewProviderIds = request . NewSeriesProviderIds ;
2016-02-27 03:18:47 +00:00
}
2016-08-19 01:00:04 +00:00
// Don't await this
2014-01-22 17:05:32 +00:00
var task = _iFileOrganizationService . PerformEpisodeOrganization ( new EpisodeFileOrganizationRequest
{
EndingEpisodeNumber = request . EndingEpisodeNumber ,
EpisodeNumber = request . EpisodeNumber ,
RememberCorrection = request . RememberCorrection ,
ResultId = request . Id ,
SeasonNumber = request . SeasonNumber ,
2016-02-26 23:52:00 +00:00
SeriesId = request . SeriesId ,
NewSeriesName = request . NewSeriesName ,
NewSeriesYear = request . NewSeriesYear ,
2016-02-27 22:09:14 +00:00
NewSeriesProviderIds = dicNewProviderIds ,
2016-02-26 23:52:00 +00:00
TargetFolder = request . TargetFolder
2014-01-22 17:05:32 +00:00
} ) ;
2016-08-19 01:00:04 +00:00
// Async processing (close dialog early instead of waiting until the file has been copied)
// Wait 2s for exceptions that may occur to have them forwarded to the client for immediate error display
task . Wait ( 2000 ) ;
2014-01-22 17:05:32 +00:00
}
2015-09-23 04:12:46 +00:00
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 )
{
2016-02-13 06:19:28 +00:00
request . Entries . ForEach ( entry = >
{
_iFileOrganizationService . DeleteSmartMatchEntry ( entry . Name , entry . Value ) ;
} ) ;
2015-09-23 04:12:46 +00:00
}
2014-01-20 18:46:08 +00:00
}
}