Now importing downloaded episodes

pull/4/head
Mark McDowall 12 years ago
parent b8102b0d1f
commit fb96abed49

@ -26,7 +26,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests
nzbPath = pneumaticFolder + title + ".nzb";
Mocker.GetMock<IConfigService>().SetupGet(c => c.PneumaticDirectory).Returns(pneumaticFolder);
Mocker.GetMock<IConfigService>().SetupGet(c => c.DownloadClientTvDirectory).Returns(sabDrop);
Mocker.GetMock<IConfigService>().SetupGet(c => c.DownloadedEpisodesFolder).Returns(sabDrop);
}
private void WithExistingFile()

@ -99,11 +99,11 @@ namespace NzbDrone.Core.Configuration
set { SetValue("SabRecentTvPriority", value); }
}
public String DownloadClientTvDirectory
public String DownloadedEpisodesFolder
{
get { return GetValue("DownloadClientTvDirectory"); }
get { return GetValue("DownloadedEpisodesFolder"); }
set { SetValue("DownloadClientTvDirectory", value); }
set { SetValue("DownloadedEpisodesFolder", value); }
}
public bool UseSeasonFolder

@ -19,7 +19,7 @@ namespace NzbDrone.Core.Configuration
String SabTvCategory { get; set; }
SabPriorityType SabBacklogTvPriority { get; set; }
SabPriorityType SabRecentTvPriority { get; set; }
String DownloadClientTvDirectory { get; set; }
String DownloadedEpisodesFolder { get; set; }
bool UseSeasonFolder { get; set; }
string SortingSeasonFolderFormat { get; set; }
int DefaultQualityProfile { get; set; }

@ -60,7 +60,7 @@ namespace NzbDrone.Core.Download.Clients
logger.Trace("NZB Download succeeded, saved to: {0}", filename);
var contents = String.Format("plugin://plugin.program.pneumatic/?mode=strm&type=add_file&nzb={0}&nzbname={1}", filename, title);
_diskProvider.WriteAllText(Path.Combine(_configService.DownloadClientTvDirectory, title + ".strm"), contents);
_diskProvider.WriteAllText(Path.Combine(_configService.DownloadedEpisodesFolder, title + ".strm"), contents);
return true;
}

@ -67,6 +67,4 @@ namespace NzbDrone.Core.Jobs
Timer.Stop();
}
}
}

@ -38,12 +38,12 @@ namespace NzbDrone.Core.Jobs
{
new ScheduledTask{ Interval = 25, TypeName = typeof(RssSyncCommand).FullName},
new ScheduledTask{ Interval = 12*60, TypeName = typeof(UpdateXemMappings).FullName},
new ScheduledTask{ Interval = 6*60, TypeName = typeof(DiskScanCommand).FullName}
new ScheduledTask{ Interval = 6*60, TypeName = typeof(DiskScanCommand).FullName},
new ScheduledTask{ Interval = 1, TypeName = typeof(DownloadedEpisodesScanCommand).FullName}
};
var currentTasks = _scheduledTaskRepository.All();
_logger.Debug("Initializing jobs. Available: {0} Existing:{1}", defaultTasks.Count(), currentTasks.Count());

@ -13,5 +13,9 @@ namespace NzbDrone.Core.MediaFiles.Commands
SeriesId = seriesId;
}
}
public DiskScanCommand()
{
}
}
}

@ -0,0 +1,11 @@
using NzbDrone.Common.Messaging;
namespace NzbDrone.Core.MediaFiles.Commands
{
public class DownloadedEpisodesScanCommand : ICommand
{
public DownloadedEpisodesScanCommand()
{
}
}
}

@ -2,31 +2,30 @@
using System.IO;
using NLog;
using NzbDrone.Common;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Common.Messaging;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.MediaFiles.Commands;
using NzbDrone.Core.Parser;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.Providers
namespace NzbDrone.Core.MediaFiles
{
public interface IDropFolderImportService
{
void ProcessDropFolder(string dropFolder);
}
public class DropFolderImportService : IDropFolderImportService
public class DownloadedEpisodesImportService : IExecute<DownloadedEpisodesScanCommand>
{
private readonly IDiskProvider _diskProvider;
private readonly IDiskScanService _diskScanService;
private readonly ISeriesService _seriesService;
private readonly IMoveEpisodeFiles _episodeFileMover;
private readonly IParsingService _parsingService;
private readonly IConfigService _configService;
private readonly Logger _logger;
public DropFolderImportService(IDiskProvider diskProvider,
public DownloadedEpisodesImportService(IDiskProvider diskProvider,
IDiskScanService diskScanService,
ISeriesService seriesService,
IMoveEpisodeFiles episodeFileMover,
IParsingService parsingService,
IConfigService configService,
Logger logger)
{
_diskProvider = diskProvider;
@ -34,42 +33,10 @@ namespace NzbDrone.Core.Providers
_seriesService = seriesService;
_episodeFileMover = episodeFileMover;
_parsingService = parsingService;
_configService = configService;
_logger = logger;
}
public virtual void ProcessDropFolder(string dropFolder)
{
foreach (var subfolder in _diskProvider.GetDirectories(dropFolder))
{
try
{
if (!_seriesService.SeriesPathExists(subfolder))
{
ProcessSubFolder(new DirectoryInfo(subfolder));
}
}
catch (Exception e)
{
_logger.ErrorException("An error has occurred while importing folder: " + subfolder, e);
}
}
foreach (var videoFile in _diskScanService.GetVideoFiles(dropFolder, false))
{
try
{
var series = _parsingService.GetSeries(videoFile);
ProcessVideoFile(videoFile, series);
}
catch (Exception ex)
{
_logger.ErrorException("An error has occurred while importing video file" + videoFile, ex);
}
}
//TODO: cleanup empty folders
}
public void ProcessSubFolder(DirectoryInfo subfolderInfo)
{
if (_diskProvider.GetLastFolderWrite(subfolderInfo.FullName).AddMinutes(2) > DateTime.UtcNow)
@ -94,7 +61,6 @@ namespace NzbDrone.Core.Providers
}
}
public void ProcessVideoFile(string videoFile, Series series)
{
if (_diskProvider.GetLastFileWrite(videoFile).AddMinutes(2) > DateTime.UtcNow)
@ -117,5 +83,46 @@ namespace NzbDrone.Core.Providers
}
}
public void Execute(DownloadedEpisodesScanCommand message)
{
//TODO: We should also process the download client's category folder
var downloadedEpisodesFolder = _configService.DownloadedEpisodesFolder;
if (String.IsNullOrEmpty(downloadedEpisodesFolder))
{
_logger.Warn("Downloaded Episodes Folder is not configured");
return;
}
foreach (var subfolder in _diskProvider.GetDirectories(downloadedEpisodesFolder))
{
try
{
if (!_seriesService.SeriesPathExists(subfolder))
{
ProcessSubFolder(new DirectoryInfo(subfolder));
}
}
catch (Exception e)
{
_logger.ErrorException("An error has occurred while importing folder: " + subfolder, e);
}
}
foreach (var videoFile in _diskScanService.GetVideoFiles(downloadedEpisodesFolder, false))
{
try
{
var series = _parsingService.GetSeries(videoFile);
ProcessVideoFile(videoFile, series);
}
catch (Exception ex)
{
_logger.ErrorException("An error has occurred while importing video file" + videoFile, ex);
}
}
//TODO: cleanup empty folders
}
}
}

@ -249,6 +249,7 @@
<Compile Include="Lifecycle\ApplicationShutdownRequested.cs" />
<Compile Include="MediaFiles\Commands\CleanMediaFileDb.cs" />
<Compile Include="MediaFiles\Commands\CleanUpRecycleBinCommand.cs" />
<Compile Include="MediaFiles\Commands\DownloadedEpisodesScanCommand.cs" />
<Compile Include="MediaFiles\Commands\DiskScanCommand.cs" />
<Compile Include="MediaFiles\Events\EpisodeDownloadedEvent.cs" />
<Compile Include="Download\EpisodeGrabbedEvent.cs" />
@ -459,7 +460,7 @@
<SubType>Code</SubType>
</Compile>
<Compile Include="ExternalNotification\PlexProvider.cs" />
<Compile Include="Providers\DropfolderImportService.cs">
<Compile Include="MediaFiles\DownloadedEpisodesImportService.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Providers\ProwlProvider.cs">

@ -17,12 +17,12 @@
</div>
</div>
<div class="control-group">
<label class="control-label">Unsorted TV Directory</label>
<label class="control-label">Downloaded Episodes Folder</label>
<div class="controls">
<input type="text" placeholder="C:\Unsorted TV" name="downloadClientTvDirectory" class="x-path"/>
<input type="text" placeholder="C:\Unsorted TV" name="downloadedEpisodesFolder" class="x-path"/>
<span class="help-inline">
<i class="icon-question-sign" title="The directory where your download client downloads TV shows to."></i>
<i class="icon-question-sign" title="The folder where your download client downloads TV shows to."></i>
</span>
</div>
</div>

Loading…
Cancel
Save