mirror of
https://github.com/lidarr/Lidarr
synced 2024-12-27 01:57:21 +00: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:
parent
c4163d1e0d
commit
5041ff550c
5 changed files with 44 additions and 27 deletions
|
@ -121,6 +121,7 @@ private static void BindJobs()
|
|||
_kernel.Bind<IJob>().To<DeleteSeriesJob>().InTransientScope();
|
||||
_kernel.Bind<IJob>().To<EpisodeSearchJob>().InTransientScope();
|
||||
_kernel.Bind<IJob>().To<RenameEpisodeJob>().InTransientScope();
|
||||
_kernel.Bind<IJob>().To<PostDownloadScanJob>().InTransientScope();
|
||||
|
||||
_kernel.Get<JobProvider>().Initialize();
|
||||
_kernel.Get<WebTimer>().StartTimer(30);
|
||||
|
|
|
@ -184,6 +184,7 @@
|
|||
<Compile Include="Providers\Indexer\SyndicationFeedXmlReader.cs" />
|
||||
<Compile Include="Providers\AutoConfigureProvider.cs" />
|
||||
<Compile Include="Providers\Indexer\NzbMatrix.cs" />
|
||||
<Compile Include="Providers\Jobs\PostDownloadScanJob.cs" />
|
||||
<Compile Include="Providers\Jobs\RenameEpisodeJob.cs" />
|
||||
<Compile Include="Providers\Jobs\EpisodeSearchJob.cs" />
|
||||
<Compile Include="Providers\Jobs\DeleteSeriesJob.cs" />
|
||||
|
@ -195,7 +196,6 @@
|
|||
<Compile Include="Providers\Jobs\IJob.cs" />
|
||||
<Compile Include="Providers\Jobs\RssSyncJob.cs" />
|
||||
<Compile Include="Providers\Jobs\UpdateInfoJob.cs" />
|
||||
<Compile Include="Providers\PostProcessingProvider.cs" />
|
||||
<Compile Include="Providers\StatsProvider.cs" />
|
||||
<Compile Include="Repository\ExternalNotificationSetting.cs" />
|
||||
<Compile Include="Repository\JobSetting.cs" />
|
||||
|
|
|
@ -51,5 +51,10 @@ public virtual string GetExtension(string path)
|
|||
{
|
||||
return Path.GetExtension(path);
|
||||
}
|
||||
|
||||
public virtual void DeleteFolder(string path, bool recursive)
|
||||
{
|
||||
Directory.Delete(path, recursive);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,39 +4,46 @@
|
|||
using System.Linq;
|
||||
using System.Text;
|
||||
using NLog;
|
||||
using NzbDrone.Core.Model.Notification;
|
||||
using NzbDrone.Core.Providers.Core;
|
||||
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 DiskProvider _diskProvider;
|
||||
private readonly SeriesProvider _seriesProvider;
|
||||
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,
|
||||
SeriesProvider seriesProvider, MediaFileProvider mediaFileProvider,
|
||||
EpisodeProvider episodeProvider)
|
||||
public PostDownloadScanJob(ConfigProvider configProvider, DiskProvider diskProvider,
|
||||
MediaFileProvider mediaFileProvider, SeriesProvider seriesProvider)
|
||||
{
|
||||
_configProvider = configProvider;
|
||||
_diskProvider = diskProvider;
|
||||
_seriesProvider = seriesProvider;
|
||||
_mediaFileProvider = mediaFileProvider;
|
||||
_episodeProvider = episodeProvider;
|
||||
_seriesProvider = seriesProvider;
|
||||
}
|
||||
|
||||
//Scan folder
|
||||
//Delete Existing episode(s)
|
||||
//Move file(s)
|
||||
//Import file(s)
|
||||
|
||||
public virtual void Scan()
|
||||
public PostDownloadScanJob()
|
||||
{
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
if (String.IsNullOrEmpty(dropFolder))
|
||||
|
@ -47,7 +54,7 @@ public virtual void Scan()
|
|||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -81,6 +88,7 @@ public virtual void Scan()
|
|||
|
||||
_mediaFileProvider.ImportNewFiles(subfolder, series);
|
||||
}
|
||||
Logger.Debug("New Download Scan Job completed successfully");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -226,17 +226,12 @@ private List<string> GetMediaFileList(string path)
|
|||
public virtual List<EpisodeFile> ImportNewFiles(string path, Series series)
|
||||
{
|
||||
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)
|
||||
{
|
||||
//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
|
||||
var parseResult = Parser.ParseEpisodeInfo(Path.GetFileName(file));
|
||||
parseResult.Series = series;
|
||||
|
@ -284,6 +279,14 @@ public virtual List<EpisodeFile> ImportNewFiles(string path, Series series)
|
|||
//Import into DB
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue