added auto-organize setting

This commit is contained in:
Luke Pulverenti 2015-08-22 15:46:55 -04:00
parent de8bf2b396
commit 795a8ab33b
4 changed files with 59 additions and 19 deletions

View File

@ -7,6 +7,7 @@ namespace MediaBrowser.Model.LiveTv
public int? GuideDays { get; set; }
public bool EnableMovieProviders { get; set; }
public string RecordingPath { get; set; }
public bool EnableAutoOrganize { get; set; }
public List<TunerHostInfo> TunerHosts { get; set; }
public List<ListingsProviderInfo> ListingProviders { get; set; }

View File

@ -43,6 +43,13 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
_providerManager = providerManager;
}
public Task<FileOrganizationResult> OrganizeEpisodeFile(string path, CancellationToken cancellationToken)
{
var options = _config.GetAutoOrganizeOptions().TvOptions;
return OrganizeEpisodeFile(path, options, false, cancellationToken);
}
public async Task<FileOrganizationResult> OrganizeEpisodeFile(string path, TvFileOrganizationOptions options, bool overwriteExisting, CancellationToken cancellationToken)
{
_logger.Info("Sorting file {0}", path);
@ -56,7 +63,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
FileSize = new FileInfo(path).Length
};
var namingOptions = ((LibraryManager) _libraryManager).GetNamingOptions();
var namingOptions = ((LibraryManager)_libraryManager).GetNamingOptions();
var resolver = new Naming.TV.EpisodeResolver(namingOptions, new PatternsLogger());
var episodeInfo = resolver.Resolve(path, false) ??
@ -254,7 +261,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
.ToList();
var targetFilenameWithoutExtension = Path.GetFileNameWithoutExtension(targetPath);
foreach (var file in files)
{
directory = Path.GetDirectoryName(file);

View File

@ -48,8 +48,6 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
progress.Report(10);
var scanLibrary = false;
if (eligibleFiles.Count > 0)
{
var numComplete = 0;
@ -61,12 +59,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
try
{
var result = await organizer.OrganizeEpisodeFile(file.FullName, options, options.OverwriteExistingEpisodes, cancellationToken).ConfigureAwait(false);
if (result.Status == FileSortingStatus.Success)
{
scanLibrary = true;
}
await organizer.OrganizeEpisodeFile(file.FullName, options, options.OverwriteExistingEpisodes, cancellationToken).ConfigureAwait(false);
}
catch (Exception ex)
{
@ -106,12 +99,6 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
}
}
if (scanLibrary)
{
await _libraryManager.ValidateMediaLibrary(new Progress<double>(), CancellationToken.None)
.ConfigureAwait(false);
}
progress.Report(100);
}

View File

@ -3,14 +3,20 @@ using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.IO;
using MediaBrowser.Common.Net;
using MediaBrowser.Common.Security;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Drawing;
using MediaBrowser.Controller.FileOrganization;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.LiveTv;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Events;
using MediaBrowser.Model.FileOrganization;
using MediaBrowser.Model.LiveTv;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Serialization;
using MediaBrowser.Server.Implementations.FileOrganization;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
@ -21,12 +27,12 @@ using System.Threading.Tasks;
namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
{
public class EmbyTV : ILiveTvService/*, IHasRegistrationInfo*/, IDisposable
public class EmbyTV : ILiveTvService, IHasRegistrationInfo, IDisposable
{
private readonly IApplicationHost _appHpst;
private readonly ILogger _logger;
private readonly IHttpClient _httpClient;
private readonly IConfigurationManager _config;
private readonly IServerConfigurationManager _config;
private readonly IJsonSerializer _jsonSerializer;
private readonly ItemDataProvider<RecordingInfo> _recordingProvider;
@ -37,9 +43,14 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
private readonly IFileSystem _fileSystem;
private readonly ISecurityManager _security;
private readonly ILibraryMonitor _libraryMonitor;
private readonly ILibraryManager _libraryManager;
private readonly IProviderManager _providerManager;
private readonly IFileOrganizationService _organizationService;
public static EmbyTV Current;
public EmbyTV(IApplicationHost appHost, ILogger logger, IJsonSerializer jsonSerializer, IHttpClient httpClient, IConfigurationManager config, ILiveTvManager liveTvManager, IFileSystem fileSystem, ISecurityManager security)
public EmbyTV(IApplicationHost appHost, ILogger logger, IJsonSerializer jsonSerializer, IHttpClient httpClient, IServerConfigurationManager config, ILiveTvManager liveTvManager, IFileSystem fileSystem, ISecurityManager security, ILibraryManager libraryManager, ILibraryMonitor libraryMonitor, IProviderManager providerManager, IFileOrganizationService organizationService)
{
Current = this;
@ -49,6 +60,10 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
_config = config;
_fileSystem = fileSystem;
_security = security;
_libraryManager = libraryManager;
_libraryMonitor = libraryMonitor;
_providerManager = providerManager;
_organizationService = organizationService;
_liveTvManager = (LiveTvManager)liveTvManager;
_jsonSerializer = jsonSerializer;
@ -610,6 +625,36 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
_recordingProvider.Update(recording);
_timerProvider.Delete(timer);
_logger.Info("Recording was a success");
if (recording.Status == RecordingStatus.Completed)
{
OnSuccessfulRecording(recording);
}
}
private async void OnSuccessfulRecording(RecordingInfo recording)
{
if (GetConfiguration().EnableAutoOrganize)
{
if (recording.IsSeries)
{
try
{
var organize = new EpisodeFileOrganizer(_organizationService, _config, _fileSystem, _logger, _libraryManager, _libraryMonitor, _providerManager);
var result = await organize.OrganizeEpisodeFile(recording.Path, CancellationToken.None).ConfigureAwait(false);
if (result.Status == FileSortingStatus.Success)
{
_recordingProvider.Delete(recording);
}
}
catch (Exception ex)
{
_logger.ErrorException("Error processing new recording", ex);
}
}
}
}
private ProgramInfo GetProgramInfoFromCache(string channelId, string programId)