1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-12 11:15:43 +02:00

Post Download Import Job created and in effect. Scans every minute to import files from the users configured "SabDropDirectory".

This commit is contained in:
Mark McDowall 2011-06-07 14:19:11 -07:00
parent c4163d1e0d
commit 5041ff550c
5 changed files with 44 additions and 27 deletions

View File

@ -121,6 +121,7 @@ private static void BindJobs()
_kernel.Bind<IJob>().To<DeleteSeriesJob>().InTransientScope(); _kernel.Bind<IJob>().To<DeleteSeriesJob>().InTransientScope();
_kernel.Bind<IJob>().To<EpisodeSearchJob>().InTransientScope(); _kernel.Bind<IJob>().To<EpisodeSearchJob>().InTransientScope();
_kernel.Bind<IJob>().To<RenameEpisodeJob>().InTransientScope(); _kernel.Bind<IJob>().To<RenameEpisodeJob>().InTransientScope();
_kernel.Bind<IJob>().To<PostDownloadScanJob>().InTransientScope();
_kernel.Get<JobProvider>().Initialize(); _kernel.Get<JobProvider>().Initialize();
_kernel.Get<WebTimer>().StartTimer(30); _kernel.Get<WebTimer>().StartTimer(30);

View File

@ -184,6 +184,7 @@
<Compile Include="Providers\Indexer\SyndicationFeedXmlReader.cs" /> <Compile Include="Providers\Indexer\SyndicationFeedXmlReader.cs" />
<Compile Include="Providers\AutoConfigureProvider.cs" /> <Compile Include="Providers\AutoConfigureProvider.cs" />
<Compile Include="Providers\Indexer\NzbMatrix.cs" /> <Compile Include="Providers\Indexer\NzbMatrix.cs" />
<Compile Include="Providers\Jobs\PostDownloadScanJob.cs" />
<Compile Include="Providers\Jobs\RenameEpisodeJob.cs" /> <Compile Include="Providers\Jobs\RenameEpisodeJob.cs" />
<Compile Include="Providers\Jobs\EpisodeSearchJob.cs" /> <Compile Include="Providers\Jobs\EpisodeSearchJob.cs" />
<Compile Include="Providers\Jobs\DeleteSeriesJob.cs" /> <Compile Include="Providers\Jobs\DeleteSeriesJob.cs" />
@ -195,7 +196,6 @@
<Compile Include="Providers\Jobs\IJob.cs" /> <Compile Include="Providers\Jobs\IJob.cs" />
<Compile Include="Providers\Jobs\RssSyncJob.cs" /> <Compile Include="Providers\Jobs\RssSyncJob.cs" />
<Compile Include="Providers\Jobs\UpdateInfoJob.cs" /> <Compile Include="Providers\Jobs\UpdateInfoJob.cs" />
<Compile Include="Providers\PostProcessingProvider.cs" />
<Compile Include="Providers\StatsProvider.cs" /> <Compile Include="Providers\StatsProvider.cs" />
<Compile Include="Repository\ExternalNotificationSetting.cs" /> <Compile Include="Repository\ExternalNotificationSetting.cs" />
<Compile Include="Repository\JobSetting.cs" /> <Compile Include="Repository\JobSetting.cs" />

View File

@ -51,5 +51,10 @@ public virtual string GetExtension(string path)
{ {
return Path.GetExtension(path); return Path.GetExtension(path);
} }
public virtual void DeleteFolder(string path, bool recursive)
{
Directory.Delete(path, recursive);
}
} }
} }

View File

@ -4,39 +4,46 @@
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using NLog; using NLog;
using NzbDrone.Core.Model.Notification;
using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Repository; using NzbDrone.Core.Repository;
namespace NzbDrone.Core.Providers namespace NzbDrone.Core.Providers.Jobs
{ {
public class PostProcessingProvider public class PostDownloadScanJob : IJob
{ {
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private readonly ConfigProvider _configProvider; private readonly ConfigProvider _configProvider;
private readonly DiskProvider _diskProvider; private readonly DiskProvider _diskProvider;
private readonly SeriesProvider _seriesProvider;
private readonly MediaFileProvider _mediaFileProvider; private readonly MediaFileProvider _mediaFileProvider;
private readonly EpisodeProvider _episodeProvider; private readonly SeriesProvider _seriesProvider;
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
public PostProcessingProvider(ConfigProvider configProvider, DiskProvider diskProvider, public PostDownloadScanJob(ConfigProvider configProvider, DiskProvider diskProvider,
SeriesProvider seriesProvider, MediaFileProvider mediaFileProvider, MediaFileProvider mediaFileProvider, SeriesProvider seriesProvider)
EpisodeProvider episodeProvider)
{ {
_configProvider = configProvider; _configProvider = configProvider;
_diskProvider = diskProvider; _diskProvider = diskProvider;
_seriesProvider = seriesProvider;
_mediaFileProvider = mediaFileProvider; _mediaFileProvider = mediaFileProvider;
_episodeProvider = episodeProvider; _seriesProvider = seriesProvider;
} }
//Scan folder public PostDownloadScanJob()
//Delete Existing episode(s)
//Move file(s)
//Import file(s)
public virtual void Scan()
{ {
}
public string Name
{
get { return "Post Download Media File Scan"; }
}
public int DefaultInterval
{
get { return 1; }
}
public virtual void Start(ProgressNotification notification, int targetId)
{
Logger.Debug("Starting New Download Scan Job");
var dropFolder = _configProvider.SabDropDirectory; var dropFolder = _configProvider.SabDropDirectory;
if (String.IsNullOrEmpty(dropFolder)) if (String.IsNullOrEmpty(dropFolder))
@ -47,7 +54,7 @@ public virtual void Scan()
if (!_diskProvider.FolderExists(dropFolder)) if (!_diskProvider.FolderExists(dropFolder))
{ {
Logger.Warn("Unable to Scan for New Downloads - Folder Doesn't Exist"); Logger.Warn("Unable to Scan for New Downloads - folder Doesn't exist: {0}", dropFolder);
return; return;
} }
@ -81,6 +88,7 @@ public virtual void Scan()
_mediaFileProvider.ImportNewFiles(subfolder, series); _mediaFileProvider.ImportNewFiles(subfolder, series);
} }
Logger.Debug("New Download Scan Job completed successfully");
} }
} }
} }

View File

@ -226,17 +226,12 @@ private List<string> GetMediaFileList(string path)
public virtual List<EpisodeFile> ImportNewFiles(string path, Series series) public virtual List<EpisodeFile> ImportNewFiles(string path, Series series)
{ {
var result = new List<EpisodeFile>(); var result = new List<EpisodeFile>();
var files = GetMediaFileList(path);
//Get all the files except those that are considered samples
var files = GetMediaFileList(path).Where(f => _diskProvider.GetSize(f) > 40000000 && !f.ToLower().Contains("sample")).ToList();
foreach (var file in files) foreach (var file in files)
{ {
//If Size is less than 40MB and contains sample. Check for Size to ensure its not an episode with sample in the title
if (_diskProvider.GetSize(file) < 40000000 && file.ToLower().Contains("sample"))
{
Logger.Trace("[{0}] appears to be a sample. Skipping.", file);
continue;
}
//Parse the filename //Parse the filename
var parseResult = Parser.ParseEpisodeInfo(Path.GetFileName(file)); var parseResult = Parser.ParseEpisodeInfo(Path.GetFileName(file));
parseResult.Series = series; parseResult.Series = series;
@ -284,6 +279,14 @@ public virtual List<EpisodeFile> ImportNewFiles(string path, Series series)
//Import into DB //Import into DB
result.Add(ImportFile(series, folder + filename)); result.Add(ImportFile(series, folder + filename));
} }
//If we have imported all the non-sample files, delete the folder, requires a minimum of 1 file to be imported.
if (files.Count() > 0 && files.Count() == result.Count)
{
Logger.Debug("All non-sample files have been processed, deleting folder: {0}", path);
_diskProvider.DeleteFolder(path, true);
}
return result; return result;
} }