Merge branch 'markus' into kay.one

pull/4/head
kay.one 13 years ago
commit c23447e994

@ -0,0 +1,5 @@
csinewyork,73696,CSI
csiny,73696,CSI
csi,72546,CSI
csilasvegas,72546,CSI
archer,110381,Archer
1 csinewyork 73696 CSI
2 csiny 73696 CSI
3 csi 72546 CSI
4 csilasvegas 72546 CSI
5 archer 110381 Archer

@ -159,7 +159,7 @@
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="QualityProfileTest.cs" /> <Compile Include="QualityProfileTest.cs" />
<Compile Include="ProviderTests\SabProviderTest.cs" /> <Compile Include="ProviderTests\SabProviderTest.cs" />
<Compile Include="SceneMappingTest.cs" /> <Compile Include="ProviderTests\SceneMappingProviderTest.cs" />
<Compile Include="ProviderTests\SeriesProviderTest.cs" /> <Compile Include="ProviderTests\SeriesProviderTest.cs" />
<Compile Include="ProviderTests\TvDbProviderTest.cs" /> <Compile Include="ProviderTests\TvDbProviderTest.cs" />
</ItemGroup> </ItemGroup>
@ -235,6 +235,9 @@
<SubType>Designer</SubType> <SubType>Designer</SubType>
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content> </Content>
<None Include="Files\SceneMappings.csv">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Files\TestArchive.zip"> <None Include="Files\TestArchive.zip">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None> </None>

@ -582,6 +582,57 @@ namespace NzbDrone.Core.Test.ProviderTests
updatedEpisodes.Should().OnlyContain(c => c.Ignored == true); updatedEpisodes.Should().OnlyContain(c => c.Ignored == true);
} }
[Test]
public void RefreshEpisodeInfo_should_ignore_new_episode_for_ignored_season()
{
//Arrange
const int seriesId = 71663;
const int episodeCount = 2;
var fakeEpisode = Builder<Episode>.CreateNew()
.With(e => e.SeasonNumber = 5)
.With(e => e.EpisodeNumber = 1)
.With(e => e.TvDbEpisodeId = 11)
.With(e => e.SeriesId = seriesId)
.With(e => e.Ignored = true)
.Build();
var tvdbSeries = Builder<TvdbSeries>.CreateNew().With(
c => c.Episodes =
new List<TvdbEpisode>(Builder<TvdbEpisode>.CreateListOfSize(episodeCount).
All()
.With(l => l.Language = new TvdbLanguage(0, "eng", "a"))
.With(e => e.SeasonNumber = 5)
.TheFirst(1)
.With(e => e.EpisodeNumber = 1)
.With(e => e.Id = 11)
.TheNext(1)
.With(e => e.EpisodeNumber = 2)
.With(e => e.Id = 22)
.Build())
).With(c => c.Id = seriesId).Build();
var fakeSeries = Builder<Series>.CreateNew().With(c => c.SeriesId = seriesId).Build();
WithRealDb();
Db.Insert(fakeSeries);
Db.Insert(fakeEpisode);
Mocker.GetMock<TvDbProvider>()
.Setup(c => c.GetSeries(seriesId, true))
.Returns(tvdbSeries);
//Act
Mocker.Resolve<EpisodeProvider>().RefreshEpisodeInfo(fakeSeries);
//Assert
var result = Mocker.Resolve<EpisodeProvider>().GetEpisodeBySeries(seriesId).ToList();
Mocker.GetMock<TvDbProvider>().VerifyAll();
result.Should().HaveCount(episodeCount);
result.Where(e => e.Ignored).Should().HaveCount(episodeCount);
}
[Test] [Test]
public void IsSeasonIgnored_should_return_true_if_all_episodes_ignored() public void IsSeasonIgnored_should_return_true_if_all_episodes_ignored()
{ {

@ -127,7 +127,6 @@ namespace NzbDrone.Core.Test.ProviderTests
ep.Should().HaveCount(2); ep.Should().HaveCount(2);
Db.Fetch<Episode>().Should().HaveCount(2); Db.Fetch<Episode>().Should().HaveCount(2);
ep.First().ShouldHave().AllPropertiesBut(e => e.Series); ep.First().ShouldHave().AllPropertiesBut(e => e.Series);
parseResult.EpisodeTitle.Should().Be(fakeEpisode.Title);
} }
[Test] [Test]
@ -313,5 +312,77 @@ namespace NzbDrone.Core.Test.ProviderTests
episodes.Should().BeEmpty(); episodes.Should().BeEmpty();
Db.Fetch<Episode>().Should().BeEmpty(); Db.Fetch<Episode>().Should().BeEmpty();
} }
[Test]
public void GetEpisodeParseResult_should_return_multiple_titles_for_multiple_episodes()
{
WithRealDb();
var fakeEpisode = Builder<Episode>.CreateNew()
.With(e => e.SeriesId = 1)
.With(e => e.SeasonNumber = 2)
.With(e => e.EpisodeNumber = 10)
.With(e => e.Title = "Title1")
.Build();
var fakeEpisode2 = Builder<Episode>.CreateNew()
.With(e => e.SeriesId = 1)
.With(e => e.SeasonNumber = 2)
.With(e => e.EpisodeNumber = 11)
.With(e => e.Title = "Title2")
.Build();
var fakeSeries = Builder<Series>.CreateNew().Build();
Db.Insert(fakeEpisode);
Db.Insert(fakeEpisode2);
Db.Insert(fakeSeries);
var parseResult = new EpisodeParseResult
{
Series = fakeSeries,
SeasonNumber = 2,
EpisodeNumbers = new List<int> { fakeEpisode.EpisodeNumber, fakeEpisode2.EpisodeNumber }
};
var ep = Mocker.Resolve<EpisodeProvider>().GetEpisodesByParseResult(parseResult);
ep.Should().HaveCount(2);
Db.Fetch<Episode>().Should().HaveCount(2);
ep.First().ShouldHave().AllPropertiesBut(e => e.Series);
parseResult.EpisodeTitle.Should().Be(fakeEpisode.Title + " + " + fakeEpisode2.Title);
}
[Test]
public void GetEpisodeParseResult_should_return_single_title_for_single_episode()
{
WithRealDb();
var fakeEpisode = Builder<Episode>.CreateNew()
.With(e => e.SeriesId = 1)
.With(e => e.SeasonNumber = 2)
.With(e => e.EpisodeNumber = 10)
.With(e => e.Title = "Title1")
.Build();
var fakeSeries = Builder<Series>.CreateNew().Build();
Db.Insert(fakeEpisode);
Db.Insert(fakeSeries);
var parseResult = new EpisodeParseResult
{
Series = fakeSeries,
SeasonNumber = 2,
EpisodeNumbers = new List<int> { fakeEpisode.EpisodeNumber }
};
var ep = Mocker.Resolve<EpisodeProvider>().GetEpisodesByParseResult(parseResult);
ep.Should().HaveCount(1);
Db.Fetch<Episode>().Should().HaveCount(1);
ep.First().ShouldHave().AllPropertiesBut(e => e.Series);
parseResult.EpisodeTitle.Should().Be(fakeEpisode.Title);
}
} }
} }

@ -364,5 +364,28 @@ namespace NzbDrone.Core.Test.ProviderTests
//Assert //Assert
result.Should().BeTrue(); result.Should().BeTrue();
} }
[Test]
public void IsAcceptableSize_should_treat_daily_series_as_single_episode()
{
parseResultSingle.Series = series60minutes;
parseResultSingle.Size = 300.Megabytes();
parseResultSingle.AirDate = DateTime.Today;
parseResultSingle.EpisodeNumbers = null;
qualityType.MaxSize = (int)600.Megabytes();
Mocker.GetMock<QualityTypeProvider>().Setup(s => s.Get(1)).Returns(qualityType);
Mocker.GetMock<EpisodeProvider>().Setup(
s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>()))
.Returns(true);
//Act
bool result = Mocker.Resolve<InventoryProvider>().IsAcceptableSize(parseResultSingle);
//Assert
result.Should().BeTrue();
}
} }
} }

@ -321,6 +321,32 @@ namespace NzbDrone.Core.Test.ProviderTests
Assert.AreEqual(expected, actual); Assert.AreEqual(expected, actual);
} }
[TestCase(true, "My Series Name - 2011-12-01 - My Episode Title [Bluray720p] [Proper]")]
[TestCase(false, "My Series Name - 2011-12-01 - My Episode Title [Bluray720p]")]
public void sab_daily_series_title(bool proper, string expected)
{
var mocker = new AutoMoqer();
var series = Builder<Series>.CreateNew()
.With(c => c.Path = @"d:\tv shows\My Series Name")
.With(c => c.IsDaily = true)
.Build();
var parsResult = new EpisodeParseResult
{
AirDate = new DateTime(2011, 12,1),
Quality = new Quality(QualityTypes.Bluray720p, proper),
Series = series,
EpisodeTitle = "My Episode Title",
};
//Act
var actual = mocker.Resolve<SabProvider>().GetSabTitle(parsResult);
//Assert
Assert.AreEqual(expected, actual);
}
[Test] [Test]
[Explicit] [Explicit]
public void AddNewzbingByUrlSuccess() public void AddNewzbingByUrlSuccess()

@ -1,7 +1,13 @@
 
using System;
using System.IO;
using System.Net;
using FizzWare.NBuilder; using FizzWare.NBuilder;
using FluentAssertions;
using Moq;
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Core.Providers; using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Repository; using NzbDrone.Core.Repository;
using NzbDrone.Core.Test.Framework; using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common.AutoMoq; using NzbDrone.Test.Common.AutoMoq;
@ -10,8 +16,24 @@ namespace NzbDrone.Core.Test
{ {
[TestFixture] [TestFixture]
// ReSharper disable InconsistentNaming // ReSharper disable InconsistentNaming
public class SceneMappingTest : CoreTest public class SceneMappingProviderTest : CoreTest
{ {
private const string SceneMappingUrl = "http://www.nzbdrone.com/SceneMappings.csv";
private void WithValidCsv()
{
Mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadString(SceneMappingUrl))
.Returns(File.ReadAllText(@".\Files\SceneMappings.csv"));
}
private void WithErrorDownloadingCsv()
{
Mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadString(SceneMappingUrl))
.Throws(new WebException());
}
[Test] [Test]
public void GetSceneName_exists() public void GetSceneName_exists()
{ {
@ -136,5 +158,103 @@ namespace NzbDrone.Core.Test
//Assert //Assert
Assert.AreEqual(fakeMap.SceneName, sceneName); Assert.AreEqual(fakeMap.SceneName, sceneName);
} }
[Test]
public void UpdateMappings_should_add_all_mappings_to_database()
{
//Setup
WithRealDb();
WithValidCsv();
//Act
Mocker.Resolve<SceneMappingProvider>().UpdateMappings();
//Assert
Mocker.Verify<HttpProvider>(v => v.DownloadString(It.IsAny<string>()), Times.Once());
var result = Db.Fetch<SceneMapping>();
result.Should().HaveCount(5);
}
[Test]
public void UpdateMappings_should_overwrite_existing_mappings()
{
//Setup
var fakeMap = Builder<SceneMapping>.CreateNew()
.With(f => f.SeriesId = 12345)
.With(f => f.SceneName = "Law and Order")
.With(f => f.SceneName = "laworder")
.Build();
WithRealDb();
WithValidCsv();
Db.Insert(fakeMap);
//Act
Mocker.Resolve<SceneMappingProvider>().UpdateMappings();
//Assert
Mocker.Verify<HttpProvider>(v => v.DownloadString(It.IsAny<string>()), Times.Once());
var result = Db.Fetch<SceneMapping>();
result.Should().HaveCount(5);
}
[Test]
public void UpdateMappings_should_not_delete_if_csv_download_fails()
{
//Setup
var fakeMap = Builder<SceneMapping>.CreateNew()
.With(f => f.SeriesId = 12345)
.With(f => f.SceneName = "Law and Order")
.With(f => f.SceneName = "laworder")
.Build();
WithRealDb();
WithErrorDownloadingCsv();
Db.Insert(fakeMap);
//Act
Mocker.Resolve<SceneMappingProvider>().UpdateMappings();
//Assert
Mocker.Verify<HttpProvider>(v => v.DownloadString(It.IsAny<string>()), Times.Once());
var result = Db.Fetch<SceneMapping>();
result.Should().HaveCount(1);
}
[Test]
public void UpdateIfEmpty_should_not_update_if_count_is_not_zero()
{
//Setup
var fakeMap = Builder<SceneMapping>.CreateNew()
.With(f => f.SeriesId = 12345)
.With(f => f.SceneName = "Law and Order")
.With(f => f.SceneName = "laworder")
.Build();
WithRealDb();
Db.Insert(fakeMap);
//Act
Mocker.Resolve<SceneMappingProvider>().UpdateIfEmpty();
//Assert
Mocker.Verify<HttpProvider>(v => v.DownloadString(It.IsAny<string>()), Times.Never());
}
[Test]
public void UpdateIfEmpty_should_update_if_count_is_zero()
{
//Setup
WithRealDb();
WithValidCsv();
//Act
Mocker.Resolve<SceneMappingProvider>().UpdateIfEmpty();
//Assert
Mocker.Verify<HttpProvider>(v => v.DownloadString(SceneMappingUrl), Times.Once());
var result = Db.Fetch<SceneMapping>();
result.Should().HaveCount(5);
}
} }
} }

@ -161,6 +161,7 @@ namespace NzbDrone.Core.Providers
if (episodeInfo != null) if (episodeInfo != null)
{ {
result.Add(episodeInfo); result.Add(episodeInfo);
parseResult.EpisodeTitle = episodeInfo.Title;
} }
return result; return result;
@ -199,7 +200,8 @@ namespace NzbDrone.Core.Providers
if (episodeInfo != null) if (episodeInfo != null)
{ {
result.Add(episodeInfo); result.Add(episodeInfo);
parseResult.EpisodeTitle = episodeInfo.Title; parseResult.EpisodeTitle += String.Format(" + {0}", episodeInfo.Title);
parseResult.EpisodeTitle = parseResult.EpisodeTitle.Trim('+', ' ');
} }
else else
{ {

@ -156,12 +156,13 @@ namespace NzbDrone.Core.Providers
//Multiply maxSize by Series.Runtime //Multiply maxSize by Series.Runtime
maxSize = maxSize * series.Runtime; maxSize = maxSize * series.Runtime;
//Multiply maxSize by the number of episodes parsed //Multiply maxSize by the number of episodes parsed (if EpisodeNumbers is null it will be treated as a single episode)
if (parseResult.EpisodeNumbers != null)
maxSize = maxSize * parseResult.EpisodeNumbers.Count; maxSize = maxSize * parseResult.EpisodeNumbers.Count;
//Check if there was only one episode parsed //Check if there was only one episode parsed
//and it is the first or last episode of the season //and it is the first or last episode of the season
if (parseResult.EpisodeNumbers.Count == 1 && if (parseResult.EpisodeNumbers != null && parseResult.EpisodeNumbers.Count == 1 &&
_episodeProvider.IsFirstOrLastEpisodeOfSeason(series.SeriesId, _episodeProvider.IsFirstOrLastEpisodeOfSeason(series.SeriesId,
parseResult.SeasonNumber, parseResult.EpisodeNumbers[0])) parseResult.SeasonNumber, parseResult.EpisodeNumbers[0]))
{ {

@ -117,6 +117,17 @@ namespace NzbDrone.Core.Providers
return seasonResult; return seasonResult;
} }
if (parseResult.Series.IsDaily)
{
var dailyResult = String.Format("{0} - {1:yyyy-MM-dd} - {2} [{3}]", new DirectoryInfo(parseResult.Series.Path).Name,
parseResult.AirDate, parseResult.EpisodeTitle, parseResult.Quality.QualityType);
if (parseResult.Quality.Proper)
dailyResult += " [Proper]";
return dailyResult;
}
//Show Name - 1x01-1x02 - Episode Name //Show Name - 1x01-1x02 - Episode Name
//Show Name - 1x01 - Episode Name //Show Name - 1x01 - Episode Name
var episodeString = new List<String>(); var episodeString = new List<String>();

@ -29,7 +29,7 @@ namespace NzbDrone.Core.Providers
{ {
try try
{ {
var mapping = _httpProvider.DownloadString("http://vps.nzbdrone.com/SceneMappings.csv"); var mapping = _httpProvider.DownloadString("http://www.nzbdrone.com/SceneMappings.csv");
var newMaps = new List<SceneMapping>(); var newMaps = new List<SceneMapping>();
using (var reader = new StringReader(mapping)) using (var reader = new StringReader(mapping))
@ -59,7 +59,7 @@ namespace NzbDrone.Core.Providers
catch (Exception ex) catch (Exception ex)
{ {
Logger.InfoException("Failed to Update Scene Mappings", ex); Logger.InfoException("Failed to Update Scene Mappings:", ex);
return false; return false;
} }
return true; return true;
@ -67,6 +67,8 @@ namespace NzbDrone.Core.Providers
public virtual string GetSceneName(int seriesId) public virtual string GetSceneName(int seriesId)
{ {
UpdateIfEmpty();
var item = _database.FirstOrDefault<SceneMapping>("WHERE SeriesId = @0", seriesId); var item = _database.FirstOrDefault<SceneMapping>("WHERE SeriesId = @0", seriesId);
if (item == null) if (item == null)
@ -77,6 +79,8 @@ namespace NzbDrone.Core.Providers
public virtual Nullable<Int32> GetSeriesId(string cleanName) public virtual Nullable<Int32> GetSeriesId(string cleanName)
{ {
UpdateIfEmpty();
var item = _database.SingleOrDefault<SceneMapping>("WHERE CleanTitle = @0", cleanName); var item = _database.SingleOrDefault<SceneMapping>("WHERE CleanTitle = @0", cleanName);
if (item == null) if (item == null)
@ -84,5 +88,13 @@ namespace NzbDrone.Core.Providers
return item.SeriesId; return item.SeriesId;
} }
public void UpdateIfEmpty()
{
var count = _database.ExecuteScalar<int>("SELECT COUNT(*) FROM SceneMappings");
if (count == 0)
UpdateMappings();
}
} }
} }

@ -131,23 +131,21 @@ namespace NzbDrone.Core.Providers
notification.CurrentMessage = "Searching for " + episode; notification.CurrentMessage = "Searching for " + episode;
var series = _seriesProvider.GetSeries(episode.SeriesId);
if (episode.Series.IsDaily && !episode.AirDate.HasValue) if (episode.Series.IsDaily && !episode.AirDate.HasValue)
{ {
Logger.Warn("AirDate is not Valid for: {0}", episode); Logger.Warn("AirDate is not Valid for: {0}", episode);
return false; return false;
} }
var reports = PerformSearch(notification, series, episode.SeasonNumber, new List<Episode> { episode }); var reports = PerformSearch(notification, episode.Series, episode.SeasonNumber, new List<Episode> { episode });
Logger.Debug("Finished searching all indexers. Total {0}", reports.Count); Logger.Debug("Finished searching all indexers. Total {0}", reports.Count);
notification.CurrentMessage = "Processing search results"; notification.CurrentMessage = "Processing search results";
if (!series.IsDaily && ProcessSearchResults(notification, reports, series, episode.SeasonNumber, episode.EpisodeNumber).Count == 1) if (!episode.Series.IsDaily && ProcessSearchResults(notification, reports, episode.Series, episode.SeasonNumber, episode.EpisodeNumber).Count == 1)
return true; return true;
if (series.IsDaily && ProcessSearchResults(notification, reports, series, episode.AirDate.Value)) if (episode.Series.IsDaily && ProcessSearchResults(notification, reports, episode.Series, episode.AirDate.Value))
return true; return true;
Logger.Warn("Unable to find {0} in any of indexers.", episode); Logger.Warn("Unable to find {0} in any of indexers.", episode);

@ -93,7 +93,7 @@ namespace NzbDrone.Web.Controllers
{ {
using (MiniProfiler.StepStatic("Controller")) using (MiniProfiler.StepStatic("Controller"))
{ {
var episodes = GetEpisodeModels(_episodeProvider.GetEpisodesBySeason(seriesId, seasonNumber)); var episodes = GetEpisodeModels(_episodeProvider.GetEpisodesBySeason(seriesId, seasonNumber)).OrderByDescending(e => e.EpisodeNumber);
return View(new GridModel(episodes)); return View(new GridModel(episodes));
} }
} }

@ -126,18 +126,12 @@
.Width(80); .Width(80);
}) })
.DetailView(detailView => detailView.ClientTemplate("<div><#= Overview #> </br><#= Path #> </div>")) .DetailView(detailView => detailView.ClientTemplate("<div><#= Overview #> </br><#= Path #> </div>"))
.Sortable(rows => rows.OrderBy(epSort => epSort.Add(c => c.EpisodeNumber).Descending()).Enabled(false)) //.Sortable(rows => rows.OrderBy(epSort => epSort.Add(c => c.EpisodeNumber).Descending()).Enabled(false))
.Footer(true) .Footer(true)
.DataBinding( .DataBinding(
d => d =>
d.Ajax().Select("_AjaxSeasonGrid", "Series", d.Ajax().Select("_AjaxSeasonGrid", "Series",
new RouteValueDictionary { { "seriesId", Model.SeriesId }, { "seasonNumber", season } })) new RouteValueDictionary { { "seriesId", Model.SeriesId }, { "seasonNumber", season } }))
@*.ToolBar(toolbar => toolbar.Template(@<text>
<ul class="sub-menu">
<li><a href="../Episode/SearchSeason?seriesId=@seriesId&seasonNumber=@season" onclick="searchSeason('@seriesId', @season); return false;">Search for Season</a></li>
<li><a href="../Episode/RenameSeason?seriesId=@seriesId&seasonNumber=@season" onclick="renameSeason('@seriesId', @season); return false;">Rename Season</a></li>
</ul>
</text>))*@
.ClientEvents(clientEvents => .ClientEvents(clientEvents =>
{ {
clientEvents.OnRowDataBound("grid_rowBound"); clientEvents.OnRowDataBound("grid_rowBound");

Loading…
Cancel
Save