mirror of https://github.com/lidarr/Lidarr
Merge pull request #650 from Kayomani/develop
Allow downloads to be tracked by the source name in addition to the download name
This commit is contained in:
commit
84ae81efe3
|
@ -34,11 +34,7 @@ namespace NzbDrone.Core.Test.Download
|
||||||
.With(h => h.Title = "Drone.S01E01.HDTV")
|
.With(h => h.Title = "Drone.S01E01.HDTV")
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
var remoteEpisode = new RemoteEpisode
|
var remoteEpisode = BuildRemoteEpisode();
|
||||||
{
|
|
||||||
Series = new Series(),
|
|
||||||
Episodes = new List<Episode> { new Episode { Id = 1 } }
|
|
||||||
};
|
|
||||||
|
|
||||||
_trackedDownload = Builder<TrackedDownload>.CreateNew()
|
_trackedDownload = Builder<TrackedDownload>.CreateNew()
|
||||||
.With(c => c.State = TrackedDownloadStage.Downloading)
|
.With(c => c.State = TrackedDownloadStage.Downloading)
|
||||||
|
@ -65,6 +61,16 @@ namespace NzbDrone.Core.Test.Download
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private RemoteEpisode BuildRemoteEpisode()
|
||||||
|
{
|
||||||
|
return new RemoteEpisode
|
||||||
|
{
|
||||||
|
Series = new Series(),
|
||||||
|
Episodes = new List<Episode> { new Episode { Id = 1 } }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void GivenNoGrabbedHistory()
|
private void GivenNoGrabbedHistory()
|
||||||
{
|
{
|
||||||
Mocker.GetMock<IHistoryService>()
|
Mocker.GetMock<IHistoryService>()
|
||||||
|
@ -82,6 +88,24 @@ namespace NzbDrone.Core.Test.Download
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void GivenABadlyNamedDownload()
|
||||||
|
{
|
||||||
|
_trackedDownload.DownloadItem.DownloadId = "1234";
|
||||||
|
_trackedDownload.DownloadItem.Title = "Droned Pilot"; // Set a badly named download
|
||||||
|
Mocker.GetMock<IHistoryService>()
|
||||||
|
.Setup(s => s.MostRecentForDownloadId(It.Is<string>(i => i == "1234")))
|
||||||
|
.Returns(new History.History() { SourceTitle = "Droned S01E01" });
|
||||||
|
|
||||||
|
Mocker.GetMock<IParsingService>()
|
||||||
|
.Setup(s => s.GetSeries(It.IsAny<string>()))
|
||||||
|
.Returns((Series)null);
|
||||||
|
|
||||||
|
Mocker.GetMock<IParsingService>()
|
||||||
|
.Setup(s => s.GetSeries("Droned S01E01"))
|
||||||
|
.Returns(BuildRemoteEpisode().Series);
|
||||||
|
}
|
||||||
|
|
||||||
private void GivenSeriesMatch()
|
private void GivenSeriesMatch()
|
||||||
{
|
{
|
||||||
Mocker.GetMock<IParsingService>()
|
Mocker.GetMock<IParsingService>()
|
||||||
|
@ -284,6 +308,47 @@ namespace NzbDrone.Core.Test.Download
|
||||||
AssertNoCompletedDownload();
|
AssertNoCompletedDownload();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_mark_as_imported_if_the_download_can_be_tracked_using_the_source_seriesid()
|
||||||
|
{
|
||||||
|
GivenABadlyNamedDownload();
|
||||||
|
|
||||||
|
Mocker.GetMock<IDownloadedEpisodesImportService>()
|
||||||
|
.Setup(v => v.ProcessPath(It.IsAny<string>(), It.IsAny<Series>(), It.IsAny<DownloadClientItem>()))
|
||||||
|
.Returns(new List<ImportResult>
|
||||||
|
{
|
||||||
|
new ImportResult(new ImportDecision(new LocalEpisode {Path = @"C:\TestPath\Droned.S01E01.mkv"}))
|
||||||
|
});
|
||||||
|
|
||||||
|
Mocker.GetMock<ISeriesService>()
|
||||||
|
.Setup(v => v.GetSeries(It.IsAny<int>()))
|
||||||
|
.Returns(BuildRemoteEpisode().Series);
|
||||||
|
|
||||||
|
Subject.Process(_trackedDownload);
|
||||||
|
|
||||||
|
AssertCompletedDownload();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_not_mark_as_imported_if_the_download_cannot_be_tracked_using_the_source_title_as_it_was_initiated_externally()
|
||||||
|
{
|
||||||
|
GivenABadlyNamedDownload();
|
||||||
|
|
||||||
|
Mocker.GetMock<IDownloadedEpisodesImportService>()
|
||||||
|
.Setup(v => v.ProcessPath(It.IsAny<string>(), It.IsAny<Series>(), It.IsAny<DownloadClientItem>()))
|
||||||
|
.Returns(new List<ImportResult>
|
||||||
|
{
|
||||||
|
new ImportResult(new ImportDecision(new LocalEpisode {Path = @"C:\TestPath\Droned.S01E01.mkv"}))
|
||||||
|
});
|
||||||
|
|
||||||
|
Mocker.GetMock<IHistoryService>()
|
||||||
|
.Setup(s => s.MostRecentForDownloadId(It.Is<string>(i => i == "1234")));
|
||||||
|
|
||||||
|
Subject.Process(_trackedDownload);
|
||||||
|
|
||||||
|
AssertNoCompletedDownload();
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void should_not_import_when_there_is_a_title_mismatch()
|
public void should_not_import_when_there_is_a_title_mismatch()
|
||||||
{
|
{
|
||||||
|
|
|
@ -0,0 +1,82 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using FizzWare.NBuilder;
|
||||||
|
using FluentAssertions;
|
||||||
|
using Moq;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using NzbDrone.Common.Disk;
|
||||||
|
using NzbDrone.Core.Configuration;
|
||||||
|
using NzbDrone.Core.DecisionEngine;
|
||||||
|
using NzbDrone.Core.Download;
|
||||||
|
using NzbDrone.Core.Download.TrackedDownloads;
|
||||||
|
using NzbDrone.Core.History;
|
||||||
|
using NzbDrone.Core.MediaFiles;
|
||||||
|
using NzbDrone.Core.MediaFiles.EpisodeImport;
|
||||||
|
using NzbDrone.Core.Messaging.Events;
|
||||||
|
using NzbDrone.Core.Parser;
|
||||||
|
using NzbDrone.Core.Parser.Model;
|
||||||
|
using NzbDrone.Core.Test.Framework;
|
||||||
|
using NzbDrone.Core.Tv;
|
||||||
|
using NzbDrone.Test.Common;
|
||||||
|
using NzbDrone.Core.Indexers;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Test.Download
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class TrackedDownloadServiceFixture : CoreTest<TrackedDownloadService>
|
||||||
|
{
|
||||||
|
private void GivenAHistoryWithADownload()
|
||||||
|
{
|
||||||
|
Mocker.GetMock<IHistoryService>()
|
||||||
|
.Setup(s => s.FindByDownloadId(It.Is<string>(sr => sr == "35238")))
|
||||||
|
.Returns(new List<History.History>(){
|
||||||
|
new History.History(){
|
||||||
|
DownloadId = "35238",
|
||||||
|
SourceTitle = "Tv Series S01",
|
||||||
|
SeriesId = 5,
|
||||||
|
EpisodeId = 4
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_track_downloads_using_the_source_title_if_it_cannot_be_found_using_the_download_title()
|
||||||
|
{
|
||||||
|
GivenAHistoryWithADownload();
|
||||||
|
|
||||||
|
var remoteEpisode = new RemoteEpisode
|
||||||
|
{
|
||||||
|
Series = new Series() { Id = 5 },
|
||||||
|
Episodes = new List<Episode> { new Episode { Id = 4 } },
|
||||||
|
ParsedEpisodeInfo = new ParsedEpisodeInfo()
|
||||||
|
{
|
||||||
|
SeriesTitle = "tvseries",
|
||||||
|
SeasonNumber = 1
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Mocker.GetMock<IParsingService>()
|
||||||
|
.Setup(s => s.Map(It.Is<ParsedEpisodeInfo>(i => i.SeasonNumber == 1 && i.SeriesTitle == "tvseries"), It.IsAny<int>(), It.IsAny<IEnumerable<int>>()))
|
||||||
|
.Returns(remoteEpisode);
|
||||||
|
|
||||||
|
var client = new DownloadClientDefinition()
|
||||||
|
{
|
||||||
|
Id = 1,
|
||||||
|
Protocol = DownloadProtocol.Torrent
|
||||||
|
};
|
||||||
|
|
||||||
|
var item = new DownloadClientItem()
|
||||||
|
{
|
||||||
|
Title = "The torrent release folder",
|
||||||
|
DownloadId = "35238",
|
||||||
|
};
|
||||||
|
|
||||||
|
var trackedDownload = Subject.TrackDownload(client, item);
|
||||||
|
|
||||||
|
trackedDownload.RemoteEpisode.Series.Id.Should().Be(5);
|
||||||
|
trackedDownload.RemoteEpisode.Episodes.First().Id.Should().Be(4);
|
||||||
|
trackedDownload.RemoteEpisode.ParsedEpisodeInfo.SeasonNumber.Should().Be(1);
|
||||||
|
trackedDownload.RemoteEpisode.ParsedEpisodeInfo.SeriesTitle.Should().Be("tvseries");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -178,6 +178,7 @@
|
||||||
<None Include="Files\Indexers\Rarbg\RecentFeed_v2.json">
|
<None Include="Files\Indexers\Rarbg\RecentFeed_v2.json">
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
|
<Compile Include="Download\TrackedDownloads\TrackedDownloadServiceFixture.cs" />
|
||||||
<Compile Include="FluentTest.cs" />
|
<Compile Include="FluentTest.cs" />
|
||||||
<Compile Include="Framework\CoreTest.cs" />
|
<Compile Include="Framework\CoreTest.cs" />
|
||||||
<Compile Include="Framework\DbTest.cs" />
|
<Compile Include="Framework\DbTest.cs" />
|
||||||
|
|
|
@ -11,6 +11,7 @@ using NzbDrone.Core.MediaFiles;
|
||||||
using NzbDrone.Core.MediaFiles.EpisodeImport;
|
using NzbDrone.Core.MediaFiles.EpisodeImport;
|
||||||
using NzbDrone.Core.Messaging.Events;
|
using NzbDrone.Core.Messaging.Events;
|
||||||
using NzbDrone.Core.Parser;
|
using NzbDrone.Core.Parser;
|
||||||
|
using NzbDrone.Core.Tv;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Download
|
namespace NzbDrone.Core.Download
|
||||||
{
|
{
|
||||||
|
@ -27,12 +28,14 @@ namespace NzbDrone.Core.Download
|
||||||
private readonly IDownloadedEpisodesImportService _downloadedEpisodesImportService;
|
private readonly IDownloadedEpisodesImportService _downloadedEpisodesImportService;
|
||||||
private readonly IParsingService _parsingService;
|
private readonly IParsingService _parsingService;
|
||||||
private readonly Logger _logger;
|
private readonly Logger _logger;
|
||||||
|
private readonly ISeriesService _seriesService;
|
||||||
|
|
||||||
public CompletedDownloadService(IConfigService configService,
|
public CompletedDownloadService(IConfigService configService,
|
||||||
IEventAggregator eventAggregator,
|
IEventAggregator eventAggregator,
|
||||||
IHistoryService historyService,
|
IHistoryService historyService,
|
||||||
IDownloadedEpisodesImportService downloadedEpisodesImportService,
|
IDownloadedEpisodesImportService downloadedEpisodesImportService,
|
||||||
IParsingService parsingService,
|
IParsingService parsingService,
|
||||||
|
ISeriesService seriesService,
|
||||||
Logger logger)
|
Logger logger)
|
||||||
{
|
{
|
||||||
_configService = configService;
|
_configService = configService;
|
||||||
|
@ -41,6 +44,7 @@ namespace NzbDrone.Core.Download
|
||||||
_downloadedEpisodesImportService = downloadedEpisodesImportService;
|
_downloadedEpisodesImportService = downloadedEpisodesImportService;
|
||||||
_parsingService = parsingService;
|
_parsingService = parsingService;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
_seriesService = seriesService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Process(TrackedDownload trackedDownload, bool ignoreWarnings = false)
|
public void Process(TrackedDownload trackedDownload, bool ignoreWarnings = false)
|
||||||
|
@ -78,12 +82,20 @@ namespace NzbDrone.Core.Download
|
||||||
|
|
||||||
var series = _parsingService.GetSeries(trackedDownload.DownloadItem.Title);
|
var series = _parsingService.GetSeries(trackedDownload.DownloadItem.Title);
|
||||||
|
|
||||||
|
if (series == null)
|
||||||
|
{
|
||||||
|
if (historyItem != null)
|
||||||
|
{
|
||||||
|
series = _seriesService.GetSeries(historyItem.SeriesId);
|
||||||
|
}
|
||||||
|
|
||||||
if (series == null)
|
if (series == null)
|
||||||
{
|
{
|
||||||
trackedDownload.Warn("Series title mismatch, automatic import is not possible.");
|
trackedDownload.Warn("Series title mismatch, automatic import is not possible.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Import(trackedDownload);
|
Import(trackedDownload);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ using NzbDrone.Common.Cache;
|
||||||
using NzbDrone.Common.Extensions;
|
using NzbDrone.Common.Extensions;
|
||||||
using NzbDrone.Core.History;
|
using NzbDrone.Core.History;
|
||||||
using NzbDrone.Core.Parser;
|
using NzbDrone.Core.Parser;
|
||||||
|
using NzbDrone.Core.Parser.Model;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Download.TrackedDownloads
|
namespace NzbDrone.Core.Download.TrackedDownloads
|
||||||
{
|
{
|
||||||
|
@ -57,23 +58,35 @@ namespace NzbDrone.Core.Download.TrackedDownloads
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var parsedEpisodeInfo = Parser.Parser.ParseTitle(trackedDownload.DownloadItem.Title);
|
var parsedEpisodeInfo = Parser.Parser.ParseTitle(trackedDownload.DownloadItem.Title);
|
||||||
if (parsedEpisodeInfo == null) return null;
|
|
||||||
|
|
||||||
var remoteEpisode = _parsingService.Map(parsedEpisodeInfo);
|
|
||||||
|
|
||||||
if (remoteEpisode.Series == null || !remoteEpisode.Episodes.Any())
|
|
||||||
{
|
|
||||||
var historyItems = _historyService.FindByDownloadId(downloadItem.DownloadId);
|
var historyItems = _historyService.FindByDownloadId(downloadItem.DownloadId);
|
||||||
|
|
||||||
if (historyItems.Empty())
|
if (parsedEpisodeInfo != null)
|
||||||
|
{
|
||||||
|
trackedDownload.RemoteEpisode = _parsingService.Map(parsedEpisodeInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (historyItems.Any())
|
||||||
|
{
|
||||||
|
var firstHistoryItem = historyItems.OrderByDescending(h => h.Date).First();
|
||||||
|
trackedDownload.State = GetStateFromHistory(firstHistoryItem.EventType);
|
||||||
|
|
||||||
|
if (parsedEpisodeInfo == null ||
|
||||||
|
trackedDownload.RemoteEpisode == null ||
|
||||||
|
trackedDownload.RemoteEpisode.Series == null ||
|
||||||
|
trackedDownload.RemoteEpisode.Episodes.Empty())
|
||||||
|
{
|
||||||
|
parsedEpisodeInfo = Parser.Parser.ParseTitle(firstHistoryItem.SourceTitle);
|
||||||
|
if (parsedEpisodeInfo != null)
|
||||||
|
{
|
||||||
|
trackedDownload.RemoteEpisode = _parsingService.Map(parsedEpisodeInfo, firstHistoryItem.SeriesId, historyItems.Select(h => h.EpisodeId));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (trackedDownload.RemoteEpisode == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
remoteEpisode = _parsingService.Map(parsedEpisodeInfo, historyItems.First().SeriesId, historyItems.Select(h => h.EpisodeId));
|
|
||||||
}
|
|
||||||
|
|
||||||
trackedDownload.RemoteEpisode = remoteEpisode;
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
@ -81,15 +94,7 @@ namespace NzbDrone.Core.Download.TrackedDownloads
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var historyItem = _historyService.MostRecentForDownloadId(downloadItem.DownloadId);
|
|
||||||
|
|
||||||
if (historyItem != null)
|
|
||||||
{
|
|
||||||
trackedDownload.State = GetStateFromHistory(historyItem.EventType);
|
|
||||||
}
|
|
||||||
|
|
||||||
_cache.Set(trackedDownload.DownloadItem.DownloadId, trackedDownload);
|
_cache.Set(trackedDownload.DownloadItem.DownloadId, trackedDownload);
|
||||||
|
|
||||||
return trackedDownload;
|
return trackedDownload;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue