From 6a6f9deefc411c7dfcbb9250204b897d98327e6a Mon Sep 17 00:00:00 2001 From: David Date: Wed, 12 Aug 2020 18:24:04 +0200 Subject: [PATCH 1/2] Move to Asp.Net Web Api --- .../Api/FileOrganizationController.cs | 242 ++++++++++++++++ .../Api/FileOrganizationService.cs | 272 ------------------ Emby.AutoOrganize/Emby.AutoOrganize.csproj | 1 + 3 files changed, 243 insertions(+), 272 deletions(-) create mode 100644 Emby.AutoOrganize/Api/FileOrganizationController.cs delete mode 100644 Emby.AutoOrganize/Api/FileOrganizationService.cs diff --git a/Emby.AutoOrganize/Api/FileOrganizationController.cs b/Emby.AutoOrganize/Api/FileOrganizationController.cs new file mode 100644 index 0000000..c8140fd --- /dev/null +++ b/Emby.AutoOrganize/Api/FileOrganizationController.cs @@ -0,0 +1,242 @@ +using System.Collections.Generic; +using System.Net.Mime; +using System.Threading.Tasks; +using Emby.AutoOrganize.Core; +using Emby.AutoOrganize.Model; +using MediaBrowser.Model.Dto; +using MediaBrowser.Model.Querying; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; + +namespace Emby.AutoOrganize.Api +{ + /// + /// The file organization controller. + /// + [ApiController] + [Authorize(Policy = "RequiresElevation")] + [Route("Library/FileOrganizations")] + [Produces(MediaTypeNames.Application.Json)] + public class FileOrganizationController : ControllerBase + { + private static IFileOrganizationService InternalFileOrganizationService + => PluginEntryPoint.Current.FileOrganizationService; + + /// + /// Gets file organization results. + /// + /// Optional. The record index to start at. All items with a lower index will be dropped from the results. + /// Optional. The maximum number of records to return. + /// Organization result returned. + /// A . + [HttpGet] + [ProducesResponseType(StatusCodes.Status200OK)] + public ActionResult> Get(int? startIndex, int? limit) + { + var result = InternalFileOrganizationService.GetResults(new FileOrganizationResultQuery + { + Limit = limit, + StartIndex = startIndex + }); + + return result; + } + + /// + /// Deletes the original file of a organizer result. + /// + /// The result id. + /// Original file deleted. + /// A indicating success. + [HttpDelete("{id}/File")] + [ProducesResponseType(StatusCodes.Status204NoContent)] + public ActionResult Delete([FromRoute] string id) + { + var task = InternalFileOrganizationService.DeleteOriginalFile(id); + + Task.WaitAll(task); + + return NoContent(); + } + + /// + /// Clears the activity log. + /// + /// Activity log cleared. + /// A indicating success. + [HttpDelete] + [ProducesResponseType(StatusCodes.Status204NoContent)] + public ActionResult ClearActivityLog() + { + var task = InternalFileOrganizationService.ClearLog(); + + Task.WaitAll(task); + + return NoContent(); + } + + /// + /// Clears the activity log. + /// + /// A indicating success. + [HttpDelete("Completed")] + [ProducesResponseType(StatusCodes.Status204NoContent)] + public ActionResult ClearCompletedActivityLog() + { + var task = InternalFileOrganizationService.ClearCompleted(); + + Task.WaitAll(task); + + return NoContent(); + } + + /// + /// Performs an organization. + /// + /// Result id. + /// Performing organization. + /// A indicating success. + [HttpPost("{id}/Organize")] + [ProducesResponseType(StatusCodes.Status204NoContent)] + public ActionResult PerformOrganization([FromRoute] string id) + { + // Don't await this + var task = InternalFileOrganizationService.PerformOrganization(id); + + // 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); + + return NoContent(); + } + + /// + /// Performs organization of a tv episode. + /// + /// Result id. + /// Series id. + /// Season number. + /// Episode number. + /// Ending episode number. + /// Name of a series to add. + /// Year of a series to add. + /// A list of provider IDs identifying a new series. + /// Whether or not to apply the same correction to future episodes of the same series. + /// Target folder. + /// Organization performed successfully. + /// An indicating success. + [HttpPost("{id}/Episode/Organize")] + [ProducesResponseType(StatusCodes.Status204NoContent)] + public ActionResult OrganizeEpisode( + [FromRoute] string id, + [FromQuery] string seriesId, + [FromQuery] int seasonNumber, + [FromQuery] int episodeNumber, + [FromQuery] int? endingEpisodeNumber, + [FromQuery] string newSeriesName, + [FromQuery] int? newSeriesYear, + [FromQuery] Dictionary newSeriesProviderIds, + [FromQuery] bool rememberCorrection, + [FromQuery] string targetFolder) + { + // Don't await this + var task = InternalFileOrganizationService.PerformOrganization(new EpisodeFileOrganizationRequest + { + EndingEpisodeNumber = endingEpisodeNumber, + EpisodeNumber = episodeNumber, + RememberCorrection = rememberCorrection, + ResultId = id, + SeasonNumber = seasonNumber, + SeriesId = seriesId, + NewSeriesName = newSeriesName, + NewSeriesYear = newSeriesYear, + NewSeriesProviderIds = newSeriesProviderIds ?? new Dictionary(), + TargetFolder = targetFolder + }); + + // 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); + + return NoContent(); + } + + /// + /// Performs organization of a movie. + /// + /// Result id. + /// Movie id + /// Name of a movie to add. + /// Year of a movie to add. + /// A list of provider IDs identifying a new movie. + /// Target Folder. + /// Organization performed successfully. + /// A indicating success. + [HttpPost("{id}/Movie/Organize")] + [ProducesResponseType(StatusCodes.Status204NoContent)] + public ActionResult OrganizeMovie( + [FromRoute] string id, + [FromQuery] string movieId, + [FromQuery] string newMovieName, + [FromQuery] int? newMovieYear, + [FromQuery] Dictionary newMovieProviderIds, + [FromQuery] string targetFolder) + { + // Don't await this + var task = InternalFileOrganizationService.PerformOrganization(new MovieFileOrganizationRequest + { + ResultId = id, + MovieId = movieId, + NewMovieName = newMovieName, + NewMovieYear = newMovieYear, + NewMovieProviderIds = newMovieProviderIds ?? new Dictionary(), + TargetFolder = targetFolder + }); + + // 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); + + return NoContent(); + } + + /// + /// Gets smart match entries. + /// + /// Optional. The record index to start at. All items with a lower index will be dropped from the results. + /// Optional. The maximum number of records to return. + /// Smart watch entries returned. + /// A . + [HttpGet("SmartMatches")] + [ProducesResponseType(StatusCodes.Status200OK)] + public ActionResult> GetSmartMatchInfos(int? startIndex, int? limit) + { + var result = InternalFileOrganizationService.GetSmartMatchInfos(new FileOrganizationResultQuery + { + Limit = limit, + StartIndex = startIndex + }); + + return result; + } + + /// + /// Deletes a smart match entry. + /// + /// SmartMatch Entry. + /// Smart watch entry deleted. + /// A indicating success. + [HttpPost("SmartMatches/Delete")] + [ProducesResponseType(StatusCodes.Status204NoContent)] + public ActionResult DeleteSmartWatchEntry([FromQuery] IReadOnlyList entries) + { + foreach (var entry in entries) + { + InternalFileOrganizationService.DeleteSmartMatchEntry(entry.Name, entry.Value); + } + + return NoContent(); + } + } +} diff --git a/Emby.AutoOrganize/Api/FileOrganizationService.cs b/Emby.AutoOrganize/Api/FileOrganizationService.cs deleted file mode 100644 index 553d9a8..0000000 --- a/Emby.AutoOrganize/Api/FileOrganizationService.cs +++ /dev/null @@ -1,272 +0,0 @@ -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member -#pragma warning disable SA1402 // File may only contain a single type -#pragma warning disable SA1649 // File name should match first type name - -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Threading.Tasks; -using Emby.AutoOrganize.Core; -using Emby.AutoOrganize.Model; -using MediaBrowser.Controller.Net; -using MediaBrowser.Model.Dto; -using MediaBrowser.Model.Querying; -using MediaBrowser.Model.Services; - -namespace Emby.AutoOrganize.Api -{ - [Route("/Library/FileOrganization", "GET", Summary = "Gets file organization results")] - public class GetFileOrganizationActivity : IReturn> - { - /// - /// Gets or sets a value indicating the number of items to skip over in the query. Use to specify a page - /// number. - /// - [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; } - - /// - /// Gets or sets the maximum number of items to return. Use to specify a page size. - /// - [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", "DELETE", Summary = "Clears the activity log")] - public class ClearOrganizationLog : IReturnVoid - { - } - - [Route("/Library/FileOrganizations/Completed", "DELETE", Summary = "Clears the activity log")] - public class ClearOrganizationCompletedLog : IReturnVoid - { - } - - [Route("/Library/FileOrganizations/{Id}/File", "DELETE", Summary = "Deletes the original file of a organizer result")] - public class DeleteOriginalFile : IReturnVoid - { - /// - /// Gets or sets the id. - /// - /// The id. - [ApiMember(Name = "Id", Description = "Result Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "DELETE")] - public string Id { get; set; } - } - - [Route("/Library/FileOrganizations/{Id}/Organize", "POST", Summary = "Performs an organization")] - public class PerformOrganization : IReturn> - { - /// - /// Gets or sets the id. - /// - /// The id. - [ApiMember(Name = "Id", Description = "Result Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")] - public string Id { get; set; } - } - - [Route("/Library/FileOrganizations/{Id}/Episode/Organize", "POST", Summary = "Performs organization of a tv episode")] - 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; } - - [ApiMember(Name = "NewSeriesProviderIds", Description = "A list of provider IDs identifying a new series.", IsRequired = false, DataType = "Dictionary", ParameterType = "query", Verb = "POST")] - [SuppressMessage("Usage", "CA2227:Collection properties should be read only", Justification = "ServiceStack cannot deserialize readonly dictionaries.")] - public Dictionary NewSeriesProviderIds { get; set; } - - [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 int? NewSeriesYear { get; set; } - - [ApiMember(Name = "TargetFolder", Description = "Target Folder", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "POST")] - public string TargetFolder { get; set; } - } - - [Route("/Library/FileOrganizations/{Id}/Movie/Organize", "POST", Summary = "Performs organization of a movie")] - public class OrganizeMovie - { - [ApiMember(Name = "Id", Description = "Result Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")] - public string Id { get; set; } - - [ApiMember(Name = "MovieId", Description = "Movie Id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")] - public string MovieId { get; set; } - - [ApiMember(Name = "NewMovieProviderIds", Description = "A list of provider IDs identifying a new movie.", IsRequired = false, DataType = "Dictionary", ParameterType = "query", Verb = "POST")] - [SuppressMessage("Usage", "CA2227:Collection properties should be read only", Justification = "ServiceStack cannot deserialize readonly dictionaries.")] - public Dictionary NewMovieProviderIds { get; set; } - - [ApiMember(Name = "NewMovieName", Description = "Name of a movie to add.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "POST")] - public string NewMovieName { get; set; } - - [ApiMember(Name = "NewMovieYear", Description = "Year of a movie to add.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "POST")] - public int? NewMovieYear { get; set; } - - [ApiMember(Name = "TargetFolder", Description = "Target Folder", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "POST")] - public string TargetFolder { get; set; } - } - - [Route("/Library/FileOrganizations/SmartMatches", "GET", Summary = "Gets smart match entries")] - public class GetSmartMatchInfos : IReturn> - { - /// - /// Gets or sets a value indicating the number of items to skips over in the query. Use to specify a page - /// number. - /// - [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; } - - /// - /// Gets or sets the maximum number of items to return. Use to specify a page size. - /// - [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 IReadOnlyList Entries { get; set; } - } - - [Authenticated(Roles = "Admin")] - public class FileOrganizationService : IService, IRequiresRequest - { - private readonly IHttpResultFactory _resultFactory; - - /// - /// Initializes a new instance of the class. - /// - /// HTTP result factory to use for making requests. - public FileOrganizationService(IHttpResultFactory resultFactory) - { - _resultFactory = resultFactory; - } - - public IRequest Request { get; set; } - - private IFileOrganizationService InternalFileOrganizationService - { - get { return PluginEntryPoint.Current.FileOrganizationService; } - } - - public object Get(GetFileOrganizationActivity request) - { - var result = InternalFileOrganizationService.GetResults(new FileOrganizationResultQuery - { - Limit = request.Limit, - StartIndex = request.StartIndex - }); - - return _resultFactory.GetResult(Request, result); - } - - public void Delete(DeleteOriginalFile request) - { - var task = InternalFileOrganizationService.DeleteOriginalFile(request.Id); - - Task.WaitAll(task); - } - - [SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", Justification = "Parameter is used to define an API route.")] - public void Delete(ClearOrganizationLog request) - { - var task = InternalFileOrganizationService.ClearLog(); - - Task.WaitAll(task); - } - - [SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", Justification = "Parameter is used to define an API route.")] - public void Delete(ClearOrganizationCompletedLog request) - { - var task = InternalFileOrganizationService.ClearCompleted(); - - Task.WaitAll(task); - } - - public void Post(PerformOrganization request) - { - // Don't await this - var task = InternalFileOrganizationService.PerformOrganization(request.Id); - - // 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); - } - - public void Post(OrganizeEpisode request) - { - // Don't await this - var task = InternalFileOrganizationService.PerformOrganization(new EpisodeFileOrganizationRequest - { - EndingEpisodeNumber = request.EndingEpisodeNumber, - EpisodeNumber = request.EpisodeNumber, - RememberCorrection = request.RememberCorrection, - ResultId = request.Id, - SeasonNumber = request.SeasonNumber, - SeriesId = request.SeriesId, - NewSeriesName = request.NewSeriesName, - NewSeriesYear = request.NewSeriesYear, - NewSeriesProviderIds = request.NewSeriesProviderIds ?? new Dictionary(), - TargetFolder = request.TargetFolder - }); - - // 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); - } - - public void Post(OrganizeMovie request) - { - // Don't await this - var task = InternalFileOrganizationService.PerformOrganization(new MovieFileOrganizationRequest - { - ResultId = request.Id, - MovieId = request.MovieId, - NewMovieName = request.NewMovieName, - NewMovieYear = request.NewMovieYear, - NewMovieProviderIds = request.NewMovieProviderIds ?? new Dictionary(), - TargetFolder = request.TargetFolder - }); - - // 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); - } - - public object Get(GetSmartMatchInfos request) - { - var result = InternalFileOrganizationService.GetSmartMatchInfos(new FileOrganizationResultQuery - { - Limit = request.Limit, - StartIndex = request.StartIndex - }); - - return _resultFactory.GetResult(Request, result); - } - - public void Post(DeleteSmartMatchEntry request) - { - foreach (var entry in request.Entries) - { - InternalFileOrganizationService.DeleteSmartMatchEntry(entry.Name, entry.Value); - } - } - } -} diff --git a/Emby.AutoOrganize/Emby.AutoOrganize.csproj b/Emby.AutoOrganize/Emby.AutoOrganize.csproj index 8d38aed..4c8e9ec 100644 --- a/Emby.AutoOrganize/Emby.AutoOrganize.csproj +++ b/Emby.AutoOrganize/Emby.AutoOrganize.csproj @@ -41,6 +41,7 @@ + From 4dd93b329d6e2a53bf3cf5ef9ef1da79a2555f90 Mon Sep 17 00:00:00 2001 From: crobibero Date: Wed, 2 Dec 2020 16:29:41 -0700 Subject: [PATCH 2/2] Target 10.7 --- .../Api/FileOrganizationController.cs | 2 +- .../Core/EpisodeFileOrganizer.cs | 4 +- .../Core/FileOrganizationService.cs | 31 -------------- .../Core/IFileOrganizationService.cs | 22 ---------- Emby.AutoOrganize/Core/MovieFileOrganizer.cs | 14 +++---- Emby.AutoOrganize/Emby.AutoOrganize.csproj | 6 +-- Emby.AutoOrganize/PluginEntryPoint.cs | 41 +++---------------- build.yaml | 5 ++- 8 files changed, 19 insertions(+), 106 deletions(-) diff --git a/Emby.AutoOrganize/Api/FileOrganizationController.cs b/Emby.AutoOrganize/Api/FileOrganizationController.cs index c8140fd..b553ceb 100644 --- a/Emby.AutoOrganize/Api/FileOrganizationController.cs +++ b/Emby.AutoOrganize/Api/FileOrganizationController.cs @@ -166,7 +166,7 @@ public ActionResult OrganizeEpisode( /// Performs organization of a movie. /// /// Result id. - /// Movie id + /// Movie id. /// Name of a movie to add. /// Year of a movie to add. /// A list of provider IDs identifying a new movie. diff --git a/Emby.AutoOrganize/Core/EpisodeFileOrganizer.cs b/Emby.AutoOrganize/Core/EpisodeFileOrganizer.cs index b40cc78..aadcd16 100644 --- a/Emby.AutoOrganize/Core/EpisodeFileOrganizer.cs +++ b/Emby.AutoOrganize/Core/EpisodeFileOrganizer.cs @@ -104,7 +104,7 @@ public async Task OrganizeEpisodeFile( var resolver = new EpisodeResolver(namingOptions); var episodeInfo = resolver.Resolve(path, false) ?? - new Naming.TV.EpisodeInfo(); + new Naming.TV.EpisodeInfo(string.Empty); var seriesName = episodeInfo.SeriesName; int? seriesYear = null; @@ -153,7 +153,7 @@ public async Task OrganizeEpisodeFile( // if an earlier result exist with an different type, we update it result.Type = CurrentFileOrganizerType; - var endingEpisodeNumber = episodeInfo.EndingEpsiodeNumber; + var endingEpisodeNumber = episodeInfo.EndingEpisodeNumber; result.ExtractedEndingEpisodeNumber = endingEpisodeNumber; diff --git a/Emby.AutoOrganize/Core/FileOrganizationService.cs b/Emby.AutoOrganize/Core/FileOrganizationService.cs index 442b29c..fb86e41 100644 --- a/Emby.AutoOrganize/Core/FileOrganizationService.cs +++ b/Emby.AutoOrganize/Core/FileOrganizationService.cs @@ -2,7 +2,6 @@ using System.Collections.Concurrent; using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; using System.Threading; using System.Threading.Tasks; using Emby.AutoOrganize.Data; @@ -11,7 +10,6 @@ using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Providers; -using MediaBrowser.Model.Events; using MediaBrowser.Model.IO; using MediaBrowser.Model.Querying; using MediaBrowser.Model.Tasks; @@ -58,18 +56,6 @@ public FileOrganizationService( _providerManager = providerManager; } - /// - public event EventHandler> ItemAdded; - - /// - public event EventHandler> ItemUpdated; - - /// - public event EventHandler> ItemRemoved; - - /// - public event EventHandler LogReset; - /// public void BeginProcessNewFiles() { @@ -165,8 +151,6 @@ public async Task DeleteOriginalFile(string resultId) } await _repo.Delete(resultId).ConfigureAwait(false); - - ItemRemoved?.Invoke(this, new GenericEventArgs(result)); } /// @@ -219,14 +203,12 @@ public async Task PerformOrganization(string resultId) public async Task ClearLog() { await _repo.DeleteAll().ConfigureAwait(false); - LogReset?.Invoke(this, EventArgs.Empty); } /// public async Task ClearCompleted() { await _repo.DeleteCompleted().ConfigureAwait(false); - LogReset?.Invoke(this, EventArgs.Empty); } /// @@ -311,16 +293,6 @@ public bool AddToInProgressList(FileOrganizationResult result, bool isNewItem) } result.IsInProgress = true; - - if (isNewItem) - { - ItemAdded?.Invoke(this, new GenericEventArgs(result)); - } - else - { - ItemUpdated?.Invoke(this, new GenericEventArgs(result)); - } - return true; } @@ -331,9 +303,6 @@ public bool RemoveFromInprogressList(FileOrganizationResult result) var retval = _inProgressItemIds.TryRemove(result.Id, out itemValue); result.IsInProgress = false; - - ItemUpdated.Invoke(this, new GenericEventArgs(result)); - return retval; } } diff --git a/Emby.AutoOrganize/Core/IFileOrganizationService.cs b/Emby.AutoOrganize/Core/IFileOrganizationService.cs index 258991f..6ffd8bb 100644 --- a/Emby.AutoOrganize/Core/IFileOrganizationService.cs +++ b/Emby.AutoOrganize/Core/IFileOrganizationService.cs @@ -1,8 +1,6 @@ -using System; using System.Threading; using System.Threading.Tasks; using Emby.AutoOrganize.Model; -using MediaBrowser.Model.Events; using MediaBrowser.Model.Querying; namespace Emby.AutoOrganize.Core @@ -12,26 +10,6 @@ namespace Emby.AutoOrganize.Core /// public interface IFileOrganizationService { - /// - /// Occurs when a new record has been created. - /// - event EventHandler> ItemAdded; - - /// - /// Occurs when a record has been updated. - /// - event EventHandler> ItemUpdated; - - /// - /// Occurs when a record has been deleted. - /// - event EventHandler> ItemRemoved; - - /// - /// Occurs when multiple records are deleted. - /// - event EventHandler LogReset; - /// /// Processes the new files. /// diff --git a/Emby.AutoOrganize/Core/MovieFileOrganizer.cs b/Emby.AutoOrganize/Core/MovieFileOrganizer.cs index 199fa11..4fc24a2 100644 --- a/Emby.AutoOrganize/Core/MovieFileOrganizer.cs +++ b/Emby.AutoOrganize/Core/MovieFileOrganizer.cs @@ -90,23 +90,19 @@ public async Task OrganizeMovieFile( return result; } - _namingOptions = _namingOptions ?? new NamingOptions(); + _namingOptions ??= new NamingOptions(); var resolver = new VideoResolver(_namingOptions); - var movieInfo = resolver.Resolve(path, false) ?? - new VideoFileInfo(); - - var movieName = movieInfo.Name; - - if (!string.IsNullOrEmpty(movieName)) + var movieInfo = resolver.Resolve(path, false); + if (!string.IsNullOrEmpty(movieInfo?.Name)) { var movieYear = movieInfo.Year; - _logger.LogDebug("Extracted information from {0}. Movie {1}, Year {2}", path, movieName, movieYear); + _logger.LogDebug("Extracted information from {0}. Movie {1}, Year {2}", path, movieInfo.Name, movieYear); await OrganizeMovie( path, - movieName, + movieInfo.Name, movieYear, options, overwriteExisting, diff --git a/Emby.AutoOrganize/Emby.AutoOrganize.csproj b/Emby.AutoOrganize/Emby.AutoOrganize.csproj index 4c8e9ec..4894092 100644 --- a/Emby.AutoOrganize/Emby.AutoOrganize.csproj +++ b/Emby.AutoOrganize/Emby.AutoOrganize.csproj @@ -1,9 +1,9 @@ - netstandard2.1 - 8.0.0.0 - 8.0.0.0 + net5.0 + 9.0.0.0 + 9.0.0.0 true diff --git a/Emby.AutoOrganize/PluginEntryPoint.cs b/Emby.AutoOrganize/PluginEntryPoint.cs index e18222b..5bf6127 100644 --- a/Emby.AutoOrganize/PluginEntryPoint.cs +++ b/Emby.AutoOrganize/PluginEntryPoint.cs @@ -4,14 +4,15 @@ using Emby.AutoOrganize.Core; using Emby.AutoOrganize.Data; using Emby.AutoOrganize.Model; +using Jellyfin.Data.Events; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Plugins; using MediaBrowser.Controller.Providers; using MediaBrowser.Controller.Session; -using MediaBrowser.Model.Events; using MediaBrowser.Model.IO; using MediaBrowser.Model.Serialization; +using MediaBrowser.Model.Session; using MediaBrowser.Model.Tasks; using Microsoft.Extensions.Logging; @@ -86,11 +87,6 @@ public Task RunAsync() Current = this; FileOrganizationService = new FileOrganizationService(_taskManager, _repository, _loggerFactory, _libraryMonitor, _libraryManager, _config, _fileSystem, _providerManager); - FileOrganizationService.ItemAdded += OnOrganizationServiceItemAdded; - FileOrganizationService.ItemRemoved += OnOrganizationServiceItemRemoved; - FileOrganizationService.ItemUpdated += OnOrganizationServiceItemUpdated; - FileOrganizationService.LogReset += OnOrganizationServiceLogReset; - // Convert Config _config.ConvertSmartMatchInfo(FileOrganizationService); @@ -109,38 +105,11 @@ private IFileOrganizationRepository GetRepository() return repo; } - private void OnOrganizationServiceLogReset(object sender, EventArgs e) - { - _sessionManager.SendMessageToAdminSessions("AutoOrganize_LogReset", (FileOrganizationResult)null, CancellationToken.None); - } - - private void OnOrganizationServiceItemUpdated(object sender, GenericEventArgs e) - { - _sessionManager.SendMessageToAdminSessions("AutoOrganize_ItemUpdated", e.Argument, CancellationToken.None); - } - - private void OnOrganizationServiceItemRemoved(object sender, GenericEventArgs e) - { - _sessionManager.SendMessageToAdminSessions("AutoOrganize_ItemRemoved", e.Argument, CancellationToken.None); - } - - private void OnOrganizationServiceItemAdded(object sender, GenericEventArgs e) - { - _sessionManager.SendMessageToAdminSessions("AutoOrganize_ItemAdded", e.Argument, CancellationToken.None); - } - - /// public void Dispose() { - FileOrganizationService.ItemAdded -= OnOrganizationServiceItemAdded; - FileOrganizationService.ItemRemoved -= OnOrganizationServiceItemRemoved; - FileOrganizationService.ItemUpdated -= OnOrganizationServiceItemUpdated; - FileOrganizationService.LogReset -= OnOrganizationServiceLogReset; - - if (_repository is IDisposable repo) - { - repo.Dispose(); - } + _taskManager?.Dispose(); + _loggerFactory?.Dispose(); + _libraryMonitor?.Dispose(); } } } diff --git a/build.yaml b/build.yaml index 0bb2dd1..ec1fdcc 100644 --- a/build.yaml +++ b/build.yaml @@ -1,8 +1,9 @@ --- name: "Auto Organize" guid: "70b7b43b-471b-4159-b4be-56750c795499" -version: "8.0.0.0" -targetAbi: "10.6.0.0" +version: "9.0.0.0" +targetAbi: "10.7.0.0" +framework: "net5.0" owner: "jellyfin" overview: "Automatically organize your media" description: "Automatically organize your media"