1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-04 10:02:40 +01:00

Now importing downloaded episodes

This commit is contained in:
Mark McDowall 2013-05-14 19:57:57 -07:00
parent b8102b0d1f
commit fb96abed49
11 changed files with 78 additions and 57 deletions

View File

@ -26,7 +26,7 @@ public void Setup()
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()

View File

@ -99,11 +99,11 @@ public SabPriorityType SabRecentTvPriority
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

View File

@ -19,7 +19,7 @@ public interface IConfigService
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; }

View File

@ -60,7 +60,7 @@ public virtual bool DownloadNzb(string url, string title, bool recentlyAired)
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;
}

View File

@ -67,6 +67,4 @@ public void Handle(ApplicationShutdownRequested message)
Timer.Stop();
}
}
}

View File

@ -38,12 +38,12 @@ public void Handle(ApplicationStartedEvent message)
{
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());

View File

@ -13,5 +13,9 @@ public DiskScanCommand(int seriesId = 0)
SeriesId = seriesId;
}
}
public DiskScanCommand()
{
}
}
}

View File

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

View File

@ -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 @@ public DropFolderImportService(IDiskProvider diskProvider,
_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 @@ public void ProcessSubFolder(DirectoryInfo subfolderInfo)
}
}
public void ProcessVideoFile(string videoFile, Series series)
{
if (_diskProvider.GetLastFileWrite(videoFile).AddMinutes(2) > DateTime.UtcNow)
@ -117,5 +83,46 @@ public void ProcessVideoFile(string videoFile, Series series)
}
}
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
}
}
}

View File

@ -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">

View File

@ -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>