Reformated PostDownloadProvider.cs

This commit is contained in:
kay.one 2011-10-22 19:34:31 -07:00
parent ec08436587
commit 7563527eac
1 changed files with 14 additions and 23 deletions

View File

@ -1,33 +1,27 @@
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using NLog; using NLog;
using Ninject; using Ninject;
using NzbDrone.Core.Model; using NzbDrone.Core.Model;
using NzbDrone.Core.Model.Notification;
using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Providers.Core;
namespace NzbDrone.Core.Providers namespace NzbDrone.Core.Providers
{ {
public class PostDownloadProvider public class PostDownloadProvider
{ {
private readonly DiskProvider _diskProvider;
private readonly EpisodeProvider _episodeProvider;
private readonly DiskScanProvider _diskScanProvider;
private readonly SeriesProvider _seriesProvider;
private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private static readonly Regex StatusRegex = new Regex(@"^_[\w_]*_", RegexOptions.Compiled); private static readonly Regex StatusRegex = new Regex(@"^_[\w_]*_", RegexOptions.Compiled);
private readonly DiskProvider _diskProvider;
private readonly DiskScanProvider _diskScanProvider;
private readonly SeriesProvider _seriesProvider;
[Inject] [Inject]
public PostDownloadProvider(DiskProvider diskProvider, EpisodeProvider episodeProvider, public PostDownloadProvider(DiskProvider diskProvider, DiskScanProvider diskScanProvider,
DiskScanProvider diskScanProvider, SeriesProvider seriesProvider) SeriesProvider seriesProvider)
{ {
_diskProvider = diskProvider; _diskProvider = diskProvider;
_episodeProvider = episodeProvider;
_diskScanProvider = diskScanProvider; _diskScanProvider = diskScanProvider;
_seriesProvider = seriesProvider; _seriesProvider = seriesProvider;
} }
@ -53,21 +47,19 @@ namespace NzbDrone.Core.Providers
public virtual void ProcessDownload(DirectoryInfo subfolderInfo) public virtual void ProcessDownload(DirectoryInfo subfolderInfo)
{ {
if (subfolderInfo.Name.StartsWith("_") && subfolderInfo.LastWriteTimeUtc.AddMinutes(1) > DateTime.UtcNow) if (subfolderInfo.Name.StartsWith("_") && subfolderInfo.LastWriteTimeUtc.AddMinutes(1) > DateTime.UtcNow)
{ {
Logger.Trace("[{0}] is too fresh. skipping", subfolderInfo.Name); Logger.Trace("[{0}] is too fresh. skipping", subfolderInfo.Name);
return; return;
} }
var seriesName = Parser.ParseSeriesName(RemoveStatusFromFolderName(subfolderInfo.Name)); string seriesName = Parser.ParseSeriesName(RemoveStatusFromFolderName(subfolderInfo.Name));
var series = _seriesProvider.FindSeries(seriesName); var series = _seriesProvider.FindSeries(seriesName);
if (series == null) if (series == null)
{ {
Logger.Warn("Unable to Import new download [{0}], Can't find matching series in database.", subfolderInfo.Name); Logger.Warn("Unable to Import new download [{0}], Can't find matching series in database.",
subfolderInfo.Name);
//Rename the Directory so it's not processed again.
TagFolder(subfolderInfo, PostDownloadStatusType.UnknownSeries); TagFolder(subfolderInfo, PostDownloadStatusType.UnknownSeries);
return; return;
} }
@ -82,15 +74,15 @@ namespace NzbDrone.Core.Providers
} }
else else
{ {
//Otherwise rename the folder to say it was already processed once by NzbDrone
if (importedFiles.Count == 0) if (importedFiles.Count == 0)
{ {
Logger.Warn("Unable to Import new download [{0}], no importable files were found..", subfolderInfo.Name); Logger.Warn("Unable to Import new download [{0}], no importable files were found..",
subfolderInfo.Name);
TagFolder(subfolderInfo, PostDownloadStatusType.ParseError); TagFolder(subfolderInfo, PostDownloadStatusType.ParseError);
} }
//Unknown Error Importing (Possibly a lesser quality than episode currently on disk)
else else
{ {
//Unknown Error Importing (Possibly a lesser quality than episode currently on disk)
Logger.Warn("Unable to Import new download [{0}].", subfolderInfo.Name); Logger.Warn("Unable to Import new download [{0}].", subfolderInfo.Name);
TagFolder(subfolderInfo, PostDownloadStatusType.Unknown); TagFolder(subfolderInfo, PostDownloadStatusType.Unknown);
} }
@ -107,9 +99,8 @@ namespace NzbDrone.Core.Providers
if (status == PostDownloadStatusType.NoError) if (status == PostDownloadStatusType.NoError)
throw new InvalidOperationException("Can't tag a folder with a None-error status. " + status); throw new InvalidOperationException("Can't tag a folder with a None-error status. " + status);
var cleanName = RemoveStatusFromFolderName(directoryInfo.Name); string cleanName = RemoveStatusFromFolderName(directoryInfo.Name);
string newName = string.Format("_{0}_{1}", status, cleanName);
var newName = string.Format("_{0}_{1}", status, cleanName);
return Path.Combine(directoryInfo.Parent.FullName, newName); return Path.Combine(directoryInfo.Parent.FullName, newName);
} }