Use Series.OID (Tests still need to be updated)

CalendarModule working
pull/23/head
Mark McDowall 12 years ago
parent f4170e90ad
commit 7d0d5ab943

@ -39,7 +39,7 @@ namespace NzbDrone.Api
//Series
Mapper.CreateMap<Core.Tv.Series, SeriesResource>()
.ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.SeriesId))
.ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.OID))
.ForMember(dest => dest.CustomStartDate, opt => opt.ResolveUsing<NullableDatetimeToString>().FromMember(src => src.CustomStartDate))
.ForMember(dest => dest.BacklogSetting, opt => opt.MapFrom(src => (Int32)src.BacklogSetting))
.ForMember(dest => dest.NextAiring, opt => opt.ResolveUsing<NextAiringResolver>());

@ -5,26 +5,35 @@ using System.Linq;
using AutoMapper;
using Nancy;
using NzbDrone.Api.Extentions;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Tv;
namespace NzbDrone.Api.Calendar
{
public class CalendarModule : NzbDroneApiModule
{
private readonly UpcomingEpisodesProvider _upcomingEpisodesProvider;
private readonly EpisodeService _episodeService;
public CalendarModule(UpcomingEpisodesProvider upcomingEpisodesProvider)
: base("/Calendar")
public CalendarModule(EpisodeService episodeService)
: base("/calendar")
{
_upcomingEpisodesProvider = upcomingEpisodesProvider;
_episodeService = episodeService;
Get["/"] = x => Calendar();
}
private Response Calendar()
{
var upcoming = _upcomingEpisodesProvider.UpcomingEpisodes();
return Mapper.Map<List<Episode>, List<CalendarResource>>(upcoming).AsResponse();
var year = DateTime.Now.Year;
var month = DateTime.Now.Month;
var yearQuery = Request.Query.Year;
var monthQuery = Request.Query.Month;
if (yearQuery.HasValue) year = Convert.ToInt32(yearQuery.Value);
if(monthQuery.HasValue) month = Convert.ToInt32(monthQuery.Value);
var episodes = _episodeService.GetEpisodesAiredInMonth(year, month);
return Mapper.Map<List<Episode>, List<CalendarResource>>(episodes).AsResponse();
}
}
}

@ -88,7 +88,7 @@ namespace NzbDrone.Api.Series
_seriesRepository.Update(series);
if (oldPath != series.Path)
_jobProvider.QueueJob(typeof(DiskScanJob), new { SeriesId = series.SeriesId });
_jobProvider.QueueJob(typeof(DiskScanJob), new { SeriesId = series.OID });
_seriesRepository.Update(series);
@ -116,7 +116,7 @@ namespace NzbDrone.Api.Series
{
RuleSet("POST", () =>
{
RuleFor(s => s.SeriesId).GreaterThan(0);
RuleFor(s => s.OID).GreaterThan(0);
RuleFor(s => s.Path).NotEmpty().Must(_diskProvider.FolderExists);
RuleFor(s => s.QualityProfileId).GreaterThan(0);
});

@ -0,0 +1,5 @@
<td>{{seriesTitle}}</td>
<td>{{seasonNumber}}x{{episodeNumber}}</td>
<td>{{episodeTitle}}</td>
<td>{{airTime}}</td>
<td>{{status}}</td>

@ -0,0 +1,16 @@
'use strict';
define([
'app',
'Calendar/CalendarCollection'
], function () {
NzbDrone.Calendar.CalendarItemView = Backbone.Marionette.ItemView.extend({
template: 'Calendar/CalendarItemTemplate',
tagName: 'tr',
onRender: function () {
NzbDrone.ModelBinder.bind(this.model, this.el);
}
})
})

@ -52,7 +52,9 @@
<Content Include="Calendar\CalendarCollection.js" />
<Content Include="Calendar\CalendarCollectionTemplate.html" />
<Content Include="Calendar\CalendarCollectionView.js" />
<Content Include="Calendar\CalendarItemTemplate.html" />
<Content Include="Calendar\CalendarModel.js" />
<Content Include="Calendar\CalendarItemView.js" />
<Content Include="Content\base.css" />
<Content Include="Content\menu.css" />
<Content Include="Content\fullcalendar.css" />

@ -1,139 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FizzWare.NBuilder;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.Tv;
using NzbDrone.Core.Model;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Repository;
using NzbDrone.Core.Repository.Quality;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.ProviderTests.MediaFileProviderTests
{
[TestFixture]
public class CleanUpDatabaseFixture : SqlCeTest
{
[SetUp]
public void Setup()
{
WithRealDb();
}
private void WithAutoIgnore(bool autoIgnore)
{
Mocker.GetMock<ConfigProvider>()
.SetupGet(c => c.AutoIgnorePreviouslyDownloadedEpisodes).Returns(autoIgnore);
}
[Test]
public void CleanUpDatabse_should_detach_none_existing_file_from_episodes_with_auto_ignore()
{
WithAutoIgnore(true);
var episodes = Builder<Episode>.CreateListOfSize(3)
.All().With(c => c.GrabDate = DateTime.Now)
.And(c => c.Ignored = false)
.And(c => c.PostDownloadStatus = PostDownloadStatusType.NoError)
.Build();
Db.InsertMany(episodes);
//Act
Mocker.Resolve<MediaFileProvider>().CleanUpDatabase();
var result = Db.Fetch<Episode>();
//Assert
result.Should().HaveSameCount(episodes);
result.Should().OnlyContain(e => e.EpisodeFileId == 0);
result.Should().OnlyContain(e => e.PostDownloadStatus == PostDownloadStatusType.Unknown);
result.Should().OnlyContain(e => e.Ignored);
result.Should().OnlyContain(e => e.GrabDate == null);
}
[Test]
public void CleanUpDatabse_should_detach_none_existing_file_from_episodes_with_no_auto_ignore()
{
WithAutoIgnore(false);
var episodes = Builder<Episode>.CreateListOfSize(3)
.All().With(c => c.GrabDate = DateTime.Now)
.And(c => c.PostDownloadStatus = PostDownloadStatusType.NoError)
.TheFirst(2).With(c => c.Ignored = true)
.TheLast(1).With(c => c.Ignored = false)
.Build();
Db.InsertMany(episodes);
//Act
Mocker.Resolve<MediaFileProvider>().CleanUpDatabase();
var result = Db.Fetch<Episode>();
//Assert
result.Should().HaveSameCount(episodes);
result.Should().OnlyContain(e => e.EpisodeFileId == 0);
result.Should().OnlyContain(e => e.PostDownloadStatus == PostDownloadStatusType.Unknown);
result.Should().OnlyContain(e => e.GrabDate == null);
result.Should().Contain(c => c.Ignored == true);
result.Should().Contain(c => c.Ignored == false);
}
[Test]
public void CleanUpDatabse_should_not_change_episodes_with_no_file_id()
{
//Setup
var episodes = Builder<Episode>.CreateListOfSize(3)
.All().With(c => c.GrabDate = DateTime.Now)
.And(c => c.Ignored = false)
.And(c => c.PostDownloadStatus = PostDownloadStatusType.NoError)
.Build();
Db.InsertMany(episodes);
//Act
Mocker.Resolve<MediaFileProvider>().CleanUpDatabase();
var result = Db.Fetch<Episode>();
//Assert
result.Should().HaveSameCount(episodes);
result.Should().OnlyContain(e => e.EpisodeFileId == 0);
result.Should().NotContain(e => e.PostDownloadStatus == PostDownloadStatusType.Unknown);
result.Should().NotContain(e => e.Ignored);
result.Should().NotContain(e => e.GrabDate == null);
}
[Test]
public void DeleteOrphanedEpisodeFiles()
{
//Setup
var episodeFiles = Builder<EpisodeFile>
.CreateListOfSize(10)
.All()
.With(e => e.Quality = QualityTypes.DVD)
.Build();
var episodes = Builder<Episode>.CreateListOfSize(5).Build();
Db.InsertMany(episodes);
Db.InsertMany(episodeFiles);
//Act
Mocker.Resolve<MediaFileProvider>().CleanUpDatabase();
var result = Db.Fetch<EpisodeFile>();
//Assert
result.Should().HaveCount(5);
result.Should().OnlyContain(e => e.EpisodeFileId > 0);
}
}
}

@ -1,842 +0,0 @@
// ReSharper disable RedundantUsingDirective
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.Tv;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Repository;
using NzbDrone.Core.Repository.Quality;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common.AutoMoq;
namespace NzbDrone.Core.Test.ProviderTests.MediaFileProviderTests
{
[TestFixture]
// ReSharper disable InconsistentNaming
public class MediaFileProvider_GetNewFilenameTest : CoreTest
{
private Series _series;
[SetUp]
public void Setup()
{
_series = Builder<Series>
.CreateNew()
.With(s => s.Title = "South Park")
.Build();
}
[Test]
public void GetNewFilename_Series_Episode_Quality_S01E05_Dash()
{
//Setup
var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true);
fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true);
fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true);
fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(0);
fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(2);
fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false);
var episode = Builder<Episode>.CreateNew()
.With(e => e.Title = "City Sushi")
.With(e => e.SeasonNumber = 15)
.With(e => e.EpisodeNumber = 6)
.Build();
//Act
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episode }, _series, QualityTypes.HDTV720p, false, new EpisodeFile());
//Assert
Assert.AreEqual("South Park - S15E06 - City Sushi [HDTV-720p]", result);
}
[Test]
public void GetNewFilename_Episode_Quality_1x05_Dash()
{
//Setup
var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(false);
fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true);
fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true);
fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(0);
fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(0);
fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false);
var episode = Builder<Episode>.CreateNew()
.With(e => e.Title = "City Sushi")
.With(e => e.SeasonNumber = 15)
.With(e => e.EpisodeNumber = 6)
.Build();
//Act
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episode }, _series, QualityTypes.HDTV720p, false, new EpisodeFile());
//Assert
Assert.AreEqual("15x06 - City Sushi [HDTV-720p]", result);
}
[Test]
public void GetNewFilename_Series_Quality_01x05_Space()
{
//Setup
var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true);
fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(false);
fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true);
fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(1);
fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(1);
fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false);
var episode = Builder<Episode>.CreateNew()
.With(e => e.Title = "City Sushi")
.With(e => e.SeasonNumber = 5)
.With(e => e.EpisodeNumber = 6)
.Build();
//Act
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episode }, _series, QualityTypes.HDTV720p, false, new EpisodeFile());
//Assert
Assert.AreEqual("South Park 05x06 [HDTV-720p]", result);
}
[Test]
public void GetNewFilename_Series_s01e05_Space()
{
//Setup
var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true);
fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(false);
fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false);
fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(1);
fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(3);
fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false);
var episode = Builder<Episode>.CreateNew()
.With(e => e.Title = "City Sushi")
.With(e => e.SeasonNumber = 5)
.With(e => e.EpisodeNumber = 6)
.Build();
//Act
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episode }, _series, QualityTypes.HDTV720p, false, new EpisodeFile());
//Assert
Assert.AreEqual("South Park s05e06", result);
}
[Test]
public void GetNewFilename_Series_Episode_s01e05_Periods()
{
//Setup
var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true);
fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true);
fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false);
fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(1);
fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(3);
fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(true);
var episode = Builder<Episode>.CreateNew()
.With(e => e.Title = "City Sushi")
.With(e => e.SeasonNumber = 5)
.With(e => e.EpisodeNumber = 6)
.Build();
//Act
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episode }, _series, QualityTypes.HDTV720p, false, new EpisodeFile());
//Assert
Assert.AreEqual("South.Park.s05e06.City.Sushi", result);
}
[Test]
public void GetNewFilename_Series_Episode_s01e05_Dash_Periods_Quality()
{
//Setup
var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true);
fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true);
fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true);
fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(0);
fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(3);
fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(true);
var episode = Builder<Episode>.CreateNew()
.With(e => e.Title = "City Sushi")
.With(e => e.SeasonNumber = 5)
.With(e => e.EpisodeNumber = 6)
.Build();
//Act
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episode }, _series, QualityTypes.HDTV720p, false, new EpisodeFile());
//Assert
Assert.AreEqual("South.Park.-.s05e06.-.City.Sushi.[HDTV-720p]", result);
}
[Test]
public void GetNewFilename_S01E05_Dash()
{
//Setup
var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(false);
fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(false);
fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false);
fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(0);
fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(2);
fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false);
var episode = Builder<Episode>.CreateNew()
.With(e => e.Title = "City Sushi")
.With(e => e.SeasonNumber = 15)
.With(e => e.EpisodeNumber = 6)
.Build();
//Act
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episode }, _series, QualityTypes.HDTV720p, false, new EpisodeFile());
//Assert
Assert.AreEqual("S15E06", result);
}
[Test]
public void GetNewFilename_multi_Series_Episode_Quality_S01E05_Scene_Dash()
{
//Setup
var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true);
fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true);
fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true);
fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(0);
fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(2);
fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false);
fakeConfig.SetupGet(c => c.SortingMultiEpisodeStyle).Returns(3);
var episodeOne = Builder<Episode>.CreateNew()
.With(e => e.Title = "Strawberries and Cream (1)")
.With(e => e.SeasonNumber = 3)
.With(e => e.EpisodeNumber = 23)
.Build();
var episodeTwo = Builder<Episode>.CreateNew()
.With(e => e.Title = "Strawberries and Cream (2)")
.With(e => e.SeasonNumber = 3)
.With(e => e.EpisodeNumber = 24)
.Build();
//Act
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, QualityTypes.HDTV720p, false, new EpisodeFile());
//Assert
Assert.AreEqual("The Mentalist - S03E23-E24 - Strawberries and Cream [HDTV-720p]", result);
}
[Test]
public void GetNewFilename_multi_Episode_Quality_1x05_Repeat_Dash()
{
//Setup
var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(false);
fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true);
fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true);
fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(0);
fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(0);
fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false);
fakeConfig.SetupGet(c => c.SortingMultiEpisodeStyle).Returns(2);
var episodeOne = Builder<Episode>.CreateNew()
.With(e => e.Title = "Strawberries and Cream (1)")
.With(e => e.SeasonNumber = 3)
.With(e => e.EpisodeNumber = 23)
.Build();
var episodeTwo = Builder<Episode>.CreateNew()
.With(e => e.Title = "Strawberries and Cream (2)")
.With(e => e.SeasonNumber = 3)
.With(e => e.EpisodeNumber = 24)
.Build();
//Act
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, QualityTypes.HDTV720p, false, new EpisodeFile());
//Assert
Assert.AreEqual("3x23x24 - Strawberries and Cream [HDTV-720p]", result);
}
[Test]
public void GetNewFilename_multi_Episode_Quality_01x05_Repeat_Space()
{
//Setup
var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(false);
fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true);
fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true);
fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(1);
fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(0);
fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false);
fakeConfig.SetupGet(c => c.SortingMultiEpisodeStyle).Returns(2);
var episodeOne = Builder<Episode>.CreateNew()
.With(e => e.Title = "Strawberries and Cream (1)")
.With(e => e.SeasonNumber = 3)
.With(e => e.EpisodeNumber = 23)
.Build();
var episodeTwo = Builder<Episode>.CreateNew()
.With(e => e.Title = "Strawberries and Cream (2)")
.With(e => e.SeasonNumber = 3)
.With(e => e.EpisodeNumber = 24)
.Build();
//Act
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, QualityTypes.HDTV720p, false, new EpisodeFile());
//Assert
Assert.AreEqual("3x23x24 Strawberries and Cream [HDTV-720p]", result);
}
[Test]
public void GetNewFilename_multi_Series_Episode_s01e05_Duplicate_Period()
{
//Setup
var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true);
fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true);
fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false);
fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(1);
fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(3);
fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(true);
fakeConfig.SetupGet(c => c.SortingMultiEpisodeStyle).Returns(1);
var episodeOne = Builder<Episode>.CreateNew()
.With(e => e.Title = "Strawberries and Cream (1)")
.With(e => e.SeasonNumber = 3)
.With(e => e.EpisodeNumber = 23)
.Build();
var episodeTwo = Builder<Episode>.CreateNew()
.With(e => e.Title = "Strawberries and Cream (2)")
.With(e => e.SeasonNumber = 3)
.With(e => e.EpisodeNumber = 24)
.Build();
//Act
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, QualityTypes.HDTV720p, false, new EpisodeFile());
//Assert
Assert.AreEqual("The.Mentalist.s03e23.s03e24.Strawberries.and.Cream", result);
}
[Test]
public void GetNewFilename_multi_Series_S01E05_Extend_Dash_Period()
{
//Setup
var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true);
fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(false);
fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false);
fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(0);
fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(2);
fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(true);
fakeConfig.SetupGet(c => c.SortingMultiEpisodeStyle).Returns(0);
var episodeOne = Builder<Episode>.CreateNew()
.With(e => e.Title = "Strawberries and Cream (1)")
.With(e => e.SeasonNumber = 3)
.With(e => e.EpisodeNumber = 23)
.Build();
var episodeTwo = Builder<Episode>.CreateNew()
.With(e => e.Title = "Strawberries and Cream (2)")
.With(e => e.SeasonNumber = 3)
.With(e => e.EpisodeNumber = 24)
.Build();
//Act
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, QualityTypes.HDTV720p, false, new EpisodeFile());
//Assert
Assert.AreEqual("The.Mentalist.-.S03E23-24", result);
}
[Test]
public void GetNewFilename_multi_1x05_Repeat_Dash_Period()
{
//Setup
var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(false);
fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(false);
fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false);
fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(0);
fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(0);
fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(true);
fakeConfig.SetupGet(c => c.SortingMultiEpisodeStyle).Returns(2);
var episodeOne = Builder<Episode>.CreateNew()
.With(e => e.Title = "Strawberries and Cream (1)")
.With(e => e.SeasonNumber = 3)
.With(e => e.EpisodeNumber = 23)
.Build();
var episodeTwo = Builder<Episode>.CreateNew()
.With(e => e.Title = "Strawberries and Cream (2)")
.With(e => e.SeasonNumber = 3)
.With(e => e.EpisodeNumber = 24)
.Build();
//Act
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, QualityTypes.HDTV720p, false, new EpisodeFile());
//Assert
Assert.AreEqual("3x23x24", result);
}
[Test]
public void GetNewFilename_should_append_proper_when_proper_and_append_quality_is_true()
{
//Setup
var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true);
fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true);
fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true);
fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(0);
fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(2);
fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false);
var episode = Builder<Episode>.CreateNew()
.With(e => e.Title = "City Sushi")
.With(e => e.SeasonNumber = 15)
.With(e => e.EpisodeNumber = 6)
.Build();
//Act
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episode }, _series, QualityTypes.HDTV720p, true, new EpisodeFile());
//Assert
result.Should().Be("South Park - S15E06 - City Sushi [HDTV-720p] [Proper]");
}
[Test]
public void GetNewFilename_should_not_append_proper_when_not_proper_and_append_quality_is_true()
{
//Setup
var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true);
fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true);
fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true);
fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(0);
fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(2);
fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false);
var episode = Builder<Episode>.CreateNew()
.With(e => e.Title = "City Sushi")
.With(e => e.SeasonNumber = 15)
.With(e => e.EpisodeNumber = 6)
.Build();
//Act
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episode }, _series, QualityTypes.HDTV720p, false, new EpisodeFile());
//Assert
result.Should().Be("South Park - S15E06 - City Sushi [HDTV-720p]");
}
[Test]
public void GetNewFilename_should_not_append_proper_when_proper_and_append_quality_is_false()
{
//Setup
var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true);
fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true);
fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false);
fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(0);
fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(2);
fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false);
var episode = Builder<Episode>.CreateNew()
.With(e => e.Title = "City Sushi")
.With(e => e.SeasonNumber = 15)
.With(e => e.EpisodeNumber = 6)
.Build();
//Act
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episode }, _series, QualityTypes.HDTV720p, true, new EpisodeFile());
//Assert
result.Should().Be("South Park - S15E06 - City Sushi");
}
[Test]
public void GetNewFilename_should_order_multiple_episode_files_in_numerical_order()
{
//Setup
var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true);
fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true);
fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false);
fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(0);
fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(2);
fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false);
fakeConfig.SetupGet(c => c.SortingMultiEpisodeStyle).Returns(3);
var episode = Builder<Episode>.CreateNew()
.With(e => e.Title = "Hey, Baby, What's Wrong? (1)")
.With(e => e.SeasonNumber = 6)
.With(e => e.EpisodeNumber = 6)
.Build();
var episode2 = Builder<Episode>.CreateNew()
.With(e => e.Title = "Hey, Baby, What's Wrong? (2)")
.With(e => e.SeasonNumber = 6)
.With(e => e.EpisodeNumber = 7)
.Build();
//Act
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episode2, episode }, new Series { Title = "30 Rock" }, QualityTypes.HDTV720p, false, new EpisodeFile());
//Assert
result.Should().Be("30 Rock - S06E06-E07 - Hey, Baby, What's Wrong!");
}
[Test]
public void GetNewFilename_Series_Episode_Quality_S01E05_Period()
{
//Setup
var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true);
fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true);
fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true);
fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(2);
fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(2);
fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false);
var episode = Builder<Episode>.CreateNew()
.With(e => e.Title = "City Sushi")
.With(e => e.SeasonNumber = 15)
.With(e => e.EpisodeNumber = 6)
.Build();
//Act
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episode }, _series, QualityTypes.HDTV720p, false, new EpisodeFile());
//Assert
Assert.AreEqual("South Park.S15E06.City Sushi [HDTV-720p]", result);
}
[Test]
public void GetNewFilename_Episode_Quality_1x05_Period()
{
//Setup
var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(false);
fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true);
fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true);
fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(2);
fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(0);
fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false);
var episode = Builder<Episode>.CreateNew()
.With(e => e.Title = "City Sushi")
.With(e => e.SeasonNumber = 15)
.With(e => e.EpisodeNumber = 6)
.Build();
//Act
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episode }, _series, QualityTypes.HDTV720p, false, new EpisodeFile());
//Assert
Assert.AreEqual("15x06.City Sushi [HDTV-720p]", result);
}
[Test]
public void GetNewFilename_UseSceneName_when_sceneName_isNull()
{
//Setup
var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(false);
fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true);
fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true);
fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(2);
fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(0);
fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false);
fakeConfig.SetupGet(c => c.SortingUseSceneName).Returns(true);
var episode = Builder<Episode>.CreateNew()
.With(e => e.Title = "City Sushi")
.With(e => e.SeasonNumber = 15)
.With(e => e.EpisodeNumber = 6)
.Build();
var episodeFile = Builder<EpisodeFile>.CreateNew()
.With(e => e.SceneName = null)
.With(e => e.Path = @"C:\Test\TV\30 Rock - S01E01 - Test")
.Build();
//Act
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episode }, _series, QualityTypes.HDTV720p, false, episodeFile);
//Assert
result.Should().Be(Path.GetFileNameWithoutExtension(episodeFile.Path));
}
[Test]
public void GetNewFilename_UseSceneName_when_sceneName_isNotNull()
{
//Setup
var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(false);
fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true);
fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true);
fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(2);
fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(0);
fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false);
fakeConfig.SetupGet(c => c.SortingUseSceneName).Returns(true);
var episode = Builder<Episode>.CreateNew()
.With(e => e.Title = "City Sushi")
.With(e => e.SeasonNumber = 15)
.With(e => e.EpisodeNumber = 6)
.Build();
var episodeFile = Builder<EpisodeFile>.CreateNew()
.With(e => e.SceneName = "30.Rock.S01E01.xvid-LOL")
.With(e => e.Path = @"C:\Test\TV\30 Rock - S01E01 - Test")
.Build();
//Act
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episode }, _series, QualityTypes.HDTV720p, false, episodeFile);
//Assert
result.Should().Be(episodeFile.SceneName);
}
[Test]
public void should_only_have_one_episodeTitle_when_episode_titles_are_the_same()
{
//Setup
var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true);
fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true);
fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false);
fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(0);
fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(2);
fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false);
fakeConfig.SetupGet(c => c.SortingMultiEpisodeStyle).Returns(3);
var episode = Builder<Episode>.CreateNew()
.With(e => e.Title = "Hey, Baby, What's Wrong? (1)")
.With(e => e.SeasonNumber = 6)
.With(e => e.EpisodeNumber = 6)
.Build();
var episode2 = Builder<Episode>.CreateNew()
.With(e => e.Title = "Hey, Baby, What's Wrong? (2)")
.With(e => e.SeasonNumber = 6)
.With(e => e.EpisodeNumber = 7)
.Build();
//Act
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episode2, episode }, new Series { Title = "30 Rock" }, QualityTypes.HDTV720p, false, new EpisodeFile());
//Assert
result.Should().Be("30 Rock - S06E06-E07 - Hey, Baby, What's Wrong!");
}
[Test]
public void should_have_two_episodeTitles_when_episode_titles_are_not_the_same()
{
//Setup
var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true);
fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true);
fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false);
fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(0);
fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(2);
fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false);
fakeConfig.SetupGet(c => c.SortingMultiEpisodeStyle).Returns(3);
var episode = Builder<Episode>.CreateNew()
.With(e => e.Title = "Hello")
.With(e => e.SeasonNumber = 6)
.With(e => e.EpisodeNumber = 6)
.Build();
var episode2 = Builder<Episode>.CreateNew()
.With(e => e.Title = "World")
.With(e => e.SeasonNumber = 6)
.With(e => e.EpisodeNumber = 7)
.Build();
//Act
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episode2, episode }, new Series { Title = "30 Rock" }, QualityTypes.HDTV720p, false, new EpisodeFile());
//Assert
result.Should().Be("30 Rock - S06E06-E07 - Hello + World");
}
[Test]
public void should_have_two_episodeTitles_when_distinct_count_is_two()
{
//Setup
var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true);
fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true);
fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false);
fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(0);
fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(2);
fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false);
fakeConfig.SetupGet(c => c.SortingMultiEpisodeStyle).Returns(3);
var episode = Builder<Episode>.CreateNew()
.With(e => e.Title = "Hello (3)")
.With(e => e.SeasonNumber = 6)
.With(e => e.EpisodeNumber = 6)
.Build();
var episode2 = Builder<Episode>.CreateNew()
.With(e => e.Title = "Hello (2)")
.With(e => e.SeasonNumber = 6)
.With(e => e.EpisodeNumber = 7)
.Build();
var episode3 = Builder<Episode>.CreateNew()
.With(e => e.Title = "World")
.With(e => e.SeasonNumber = 6)
.With(e => e.EpisodeNumber = 8)
.Build();
//Act
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episode, episode2, episode3 }, new Series { Title = "30 Rock" }, QualityTypes.HDTV720p, false, new EpisodeFile());
//Assert
result.Should().Be("30 Rock - S06E06-E07-E08 - Hello + World");
}
[Test]
public void should_use_airDate_if_series_isDaily()
{
var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true);
fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true);
fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true);
fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(0);
fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(2);
fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false);
var series = Builder<Series>
.CreateNew()
.With(s => s.SeriesType = SeriesType.Daily)
.With(s => s.Title = "The Daily Show with Jon Stewart")
.Build();
var episodes = Builder<Episode>
.CreateListOfSize(1)
.All()
.With(e => e.AirDate = new DateTime(2012, 12, 13))
.With(e => e.Title = "Kristen Stewart")
.Build();
var result = Mocker.Resolve<MediaFileProvider>()
.GetNewFilename(episodes, series, QualityTypes.HDTV720p, false, new EpisodeFile());
result.Should().Be("The Daily Show with Jon Stewart - 2012-12-13 - Kristen Stewart [HDTV-720p]");
}
[Test]
public void should_use_airDate_if_series_isDaily_no_episode_title()
{
var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true);
fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(false);
fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false);
fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(0);
fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(2);
fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false);
var series = Builder<Series>
.CreateNew()
.With(s => s.SeriesType = SeriesType.Daily)
.With(s => s.Title = "The Daily Show with Jon Stewart")
.Build();
var episodes = Builder<Episode>
.CreateListOfSize(1)
.All()
.With(e => e.AirDate = new DateTime(2012, 12, 13))
.With(e => e.Title = "Kristen Stewart")
.Build();
var result = Mocker.Resolve<MediaFileProvider>()
.GetNewFilename(episodes, series, QualityTypes.HDTV720p, false, new EpisodeFile());
result.Should().Be("The Daily Show with Jon Stewart - 2012-12-13");
}
[Test]
public void should_set_airdate_to_unknown_if_not_available()
{
var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true);
fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true);
fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false);
fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(0);
fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(2);
fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false);
var series = Builder<Series>
.CreateNew()
.With(s => s.SeriesType = SeriesType.Daily)
.With(s => s.Title = "The Daily Show with Jon Stewart")
.Build();
var episodes = Builder<Episode>
.CreateListOfSize(1)
.All()
.With(e => e.AirDate = null)
.With(e => e.Title = "Kristen Stewart")
.Build();
var result = Mocker.Resolve<MediaFileProvider>()
.GetNewFilename(episodes, series, QualityTypes.HDTV720p, false, new EpisodeFile());
result.Should().Be("The Daily Show with Jon Stewart - Unknown - Kristen Stewart");
}
}
}

@ -56,7 +56,7 @@ namespace NzbDrone.Core.DecisionEngine
//Check if there was only one episode parsed
//and it is the first or last episode of the season
if (subject.EpisodeNumbers != null && subject.EpisodeNumbers.Count == 1 &&
_episodeService.IsFirstOrLastEpisodeOfSeason(series.SeriesId,
_episodeService.IsFirstOrLastEpisodeOfSeason(series.OID,
subject.SeasonNumber, subject.EpisodeNumbers[0]))
{
maxSize = maxSize * 2;

@ -75,20 +75,20 @@ namespace NzbDrone.Core.Jobs
{
try
{
_attemptedSeries.Add(currentSeries.SeriesId);
_attemptedSeries.Add(currentSeries.OID);
notification.CurrentMessage = String.Format("Searching for '{0}'", new DirectoryInfo(currentSeries.Path).Name);
_updateInfoJob.Start(notification, new { SeriesId = currentSeries.SeriesId });
_diskScanJob.Start(notification, new { SeriesId = currentSeries.SeriesId });
_updateInfoJob.Start(notification, new { SeriesId = currentSeries.OID });
_diskScanJob.Start(notification, new { SeriesId = currentSeries.OID });
var updatedSeries = _seriesRepository.Get(currentSeries.SeriesId);
AutoIgnoreSeasons(updatedSeries.SeriesId);
var updatedSeries = _seriesRepository.Get(currentSeries.OID);
AutoIgnoreSeasons(updatedSeries.OID);
//Download the banner for the new series
_bannerDownloadJob.Start(notification, new { SeriesId = updatedSeries.SeriesId });
_bannerDownloadJob.Start(notification, new { SeriesId = updatedSeries.OID });
//Get Scene Numbering if applicable
_xemUpdateJob.Start(notification, new { SeriesId = updatedSeries.SeriesId });
_xemUpdateJob.Start(notification, new { SeriesId = updatedSeries.OID });
notification.CurrentMessage = String.Format("{0} was successfully imported", updatedSeries.Title);
}

@ -57,12 +57,12 @@ namespace NzbDrone.Core.Jobs
{
notification.CurrentMessage = String.Format("Refreshing episode metadata for '{0}'", series.Title);
Logger.Debug("Getting episodes from database for series: {0}", series.SeriesId);
var episodeFiles = _mediaFileProvider.GetSeriesFiles(series.SeriesId);
Logger.Debug("Getting episodes from database for series: {0}", series.OID);
var episodeFiles = _mediaFileProvider.GetSeriesFiles(series.OID);
if (episodeFiles == null || episodeFiles.Count == 0)
{
Logger.Warn("No episodes in database found for series: {0}", series.SeriesId);
Logger.Warn("No episodes in database found for series: {0}", series.OID);
return;
}

@ -60,12 +60,12 @@ namespace NzbDrone.Core.Jobs
{
notification.CurrentMessage = String.Format("Renaming episodes for '{0}'", series.Title);
Logger.Debug("Getting episodes from database for series: {0}", series.SeriesId);
var episodeFiles = _mediaFileProvider.GetSeriesFiles(series.SeriesId);
Logger.Debug("Getting episodes from database for series: {0}", series.OID);
var episodeFiles = _mediaFileProvider.GetSeriesFiles(series.OID);
if (episodeFiles == null || episodeFiles.Count == 0)
{
Logger.Warn("No episodes in database found for series: {0}", series.SeriesId);
Logger.Warn("No episodes in database found for series: {0}", series.OID);
return;
}

@ -72,7 +72,7 @@ namespace NzbDrone.Core.Jobs
try
{
notification.CurrentMessage = "Updating " + series.Title;
_seriesService.UpdateSeriesInfo(series.SeriesId);
_seriesService.UpdateSeriesInfo(series.OID);
_episodeService.RefreshEpisodeInfo(series);
notification.CurrentMessage = "Update completed for " + series.Title;
}

@ -40,7 +40,7 @@ namespace NzbDrone.Core.Providers
logger.Trace("Ensuring Banner Folder exists: ", bannerPath);
_diskProvider.CreateDirectory(bannerPath);
var bannerFilename = Path.Combine(bannerPath, series.SeriesId.ToString()) + ".jpg";
var bannerFilename = Path.Combine(bannerPath, series.OID.ToString()) + ".jpg";
logger.Trace("Downloading banner for '{0}'", series.Title);

@ -74,13 +74,13 @@ namespace NzbDrone.Core.Providers
return new List<EpisodeFile>();
}
if (_episodeService.GetEpisodeBySeries(series.SeriesId).Count == 0)
if (_episodeService.GetEpisodeBySeries(series.OID).Count == 0)
{
Logger.Debug("Series {0} has no episodes. skipping", series.Title);
return new List<EpisodeFile>();
}
var seriesFile = _mediaFileProvider.GetSeriesFiles(series.SeriesId);
var seriesFile = _mediaFileProvider.GetSeriesFiles(series.OID);
CleanUp(seriesFile);
var mediaFileList = GetVideoFiles(path);
@ -162,7 +162,7 @@ namespace NzbDrone.Core.Providers
var episodeFile = new EpisodeFile();
episodeFile.DateAdded = DateTime.Now;
episodeFile.SeriesId = series.SeriesId;
episodeFile.SeriesId = series.OID;
episodeFile.Path = filePath.NormalizePath();
episodeFile.Size = size;
episodeFile.Quality = parseResult.Quality.Quality;

@ -30,7 +30,7 @@ namespace NzbDrone.Core.Providers.Metadata
public override void CreateForSeries(Series series, TvdbSeries tvDbSeries)
{
//Create tvshow.nfo, fanart.jpg, folder.jpg and season##.tbn
var episodeGuideUrl = GetEpisodeGuideUrl(series.SeriesId);
var episodeGuideUrl = GetEpisodeGuideUrl(series.OID);
_logger.Debug("Generating tvshow.nfo for: {0}", series.Title);
var sb = new StringBuilder();

@ -93,7 +93,7 @@ namespace NzbDrone.Core.Providers
public virtual void CreateForSeries(Series series)
{
var tvDbSeries = _tvDbProvider.GetSeries(series.SeriesId, false, true);
var tvDbSeries = _tvDbProvider.GetSeries(series.OID, false, true);
CreateForSeries(series, tvDbSeries);
}

@ -58,7 +58,7 @@ namespace NzbDrone.Core.Providers.Search
var searchResult = new SearchHistory
{
SearchTime = DateTime.Now,
SeriesId = series.SeriesId,
SeriesId = series.OID,
EpisodeId = options.GetType().GetProperty("Episode") != null ? options.Episode.EpisodeId : null,
SeasonNumber = options.GetType().GetProperty("SeasonNumber") != null ? options.SeasonNumber : null
};
@ -108,7 +108,7 @@ namespace NzbDrone.Core.Providers.Search
logger.Trace("Analysing report " + episodeParseResult);
episodeParseResult.Series = _seriesRepository.GetByTitle(episodeParseResult.CleanTitle);
if(episodeParseResult.Series == null || episodeParseResult.Series.SeriesId != series.SeriesId)
if(episodeParseResult.Series == null || episodeParseResult.Series.OID != series.OID)
{
item.SearchError = ReportRejectionType.WrongSeries;
continue;
@ -170,12 +170,12 @@ namespace NzbDrone.Core.Providers.Search
public virtual string GetSearchTitle(Series series, int seasonNumber = -1)
{
var seasonTitle = _sceneMappingProvider.GetSceneName(series.SeriesId, seasonNumber);
var seasonTitle = _sceneMappingProvider.GetSceneName(series.OID, seasonNumber);
if(!String.IsNullOrWhiteSpace(seasonTitle))
return seasonTitle;
var title = _sceneMappingProvider.GetSceneName(series.SeriesId);
var title = _sceneMappingProvider.GetSceneName(series.OID);
if (String.IsNullOrWhiteSpace(title))
{

@ -31,7 +31,7 @@ namespace NzbDrone.Core.Providers
public Series FindMatchingTvRageSeries(Series series)
{
var firstEpisode = _episodeService.GetEpisode(series.SeriesId, 1, 1);
var firstEpisode = _episodeService.GetEpisode(series.OID, 1, 1);
var cleanName = _sceneMappingProvider.GetCleanName(series.SeriesId);
var results = _tvRageProvider.SearchSeries(series.Title);

@ -89,7 +89,7 @@ namespace NzbDrone.Core.Providers
return;
}
var episodes = _episodeService.GetEpisodeBySeries(series.SeriesId);
var episodes = _episodeService.GetEpisodeBySeries(series.OID);
foreach (var mapping in mappings)
{

@ -30,6 +30,7 @@ namespace NzbDrone.Core.Tv
void SetPostDownloadStatus(List<int> episodeIds, PostDownloadStatusType postDownloadStatus);
void UpdateEpisodes(List<Episode> episodes);
Episode GetEpisodeBySceneNumbering(int seriesId, int seasonNumber, int episodeNumber);
List<Episode> GetEpisodesAiredInMonth(int year, int month);
}
public class EpisodeService : IEpisodeService
@ -100,7 +101,7 @@ namespace NzbDrone.Core.Tv
return new List<Episode>();
}
var episodeInfo = GetEpisode(parseResult.Series.SeriesId, parseResult.AirDate.Value);
var episodeInfo = GetEpisode(parseResult.Series.OID, parseResult.AirDate.Value);
if (episodeInfo != null)
{
@ -122,14 +123,14 @@ namespace NzbDrone.Core.Tv
Episode episodeInfo = null;
if (parseResult.SceneSource && parseResult.Series.UseSceneNumbering)
episodeInfo = GetEpisodeBySceneNumbering(parseResult.Series.SeriesId, parseResult.SeasonNumber, episodeNumber);
episodeInfo = GetEpisodeBySceneNumbering(parseResult.Series.OID, parseResult.SeasonNumber, episodeNumber);
if (episodeInfo == null)
{
episodeInfo = GetEpisode(parseResult.Series.SeriesId, parseResult.SeasonNumber, episodeNumber);
episodeInfo = GetEpisode(parseResult.Series.OID, parseResult.SeasonNumber, episodeNumber);
if (episodeInfo == null && parseResult.AirDate != null)
{
episodeInfo = GetEpisode(parseResult.Series.SeriesId, parseResult.AirDate.Value);
episodeInfo = GetEpisode(parseResult.Series.OID, parseResult.AirDate.Value);
}
}
@ -182,7 +183,7 @@ namespace NzbDrone.Core.Tv
public virtual void RefreshEpisodeInfo(Series series)
{
logger.Trace("Starting episode info refresh for series: {0}", series.Title.WithDefault(series.SeriesId));
logger.Trace("Starting episode info refresh for series: {0}", series.Title.WithDefault(series.OID));
var successCount = 0;
var failCount = 0;
@ -192,7 +193,7 @@ namespace NzbDrone.Core.Tv
(episode.FirstAired < DateTime.Now.AddDays(2) && episode.FirstAired.Year > 1900))
.ToList();
var seriesEpisodes = GetEpisodeBySeries(series.SeriesId);
var seriesEpisodes = GetEpisodeBySeries(series.OID);
var updateList = new List<Episode>();
var newList = new List<Episode>();
@ -223,7 +224,7 @@ namespace NzbDrone.Core.Tv
}
else
{
episodeToUpdate.Ignored = _seasonRepository.IsIgnored(series.SeriesId, episode.SeasonNumber);
episodeToUpdate.Ignored = _seasonRepository.IsIgnored(series.OID, episode.SeasonNumber);
}
}
else
@ -239,7 +240,7 @@ namespace NzbDrone.Core.Tv
episodeToUpdate.EpisodeFile = null;
}
episodeToUpdate.SeriesId = series.SeriesId;
episodeToUpdate.SeriesId = series.OID;
episodeToUpdate.TvDbEpisodeId = episode.Id;
episodeToUpdate.EpisodeNumber = episode.EpisodeNumber;
episodeToUpdate.SeasonNumber = episode.SeasonNumber;
@ -283,7 +284,6 @@ namespace NzbDrone.Core.Tv
_episodeRepository.Update(episode);
}
public virtual IList<int> GetEpisodeNumbersBySeason(int seriesId, int seasonNumber)
{
return GetEpisodesBySeason(seriesId, seasonNumber).Select(c => c.OID).ToList();
@ -315,11 +315,11 @@ namespace NzbDrone.Core.Tv
public virtual void DeleteEpisodesNotInTvdb(Series series, IList<TvdbEpisode> tvdbEpisodes)
{
logger.Trace("Starting deletion of episodes that no longer exist in TVDB: {0}", series.Title.WithDefault(series.SeriesId));
logger.Trace("Starting deletion of episodes that no longer exist in TVDB: {0}", series.Title.WithDefault(series.OID));
if (!tvdbEpisodes.Any()) return;
var seriesEpisodeIds = _episodeRepository.GetEpisodes(series.SeriesId).Select(c => c.OID);
var seriesEpisodeIds = _episodeRepository.GetEpisodes(series.OID).Select(c => c.OID);
var toBeDeleted = seriesEpisodeIds.Except(tvdbEpisodes.Select(e => e.Id));
@ -328,7 +328,7 @@ namespace NzbDrone.Core.Tv
_episodeRepository.Delete(id);
}
logger.Trace("Deleted episodes that no longer exist in TVDB for {0}", series.SeriesId);
logger.Trace("Deleted episodes that no longer exist in TVDB for {0}", series.OID);
}
public virtual void SetPostDownloadStatus(List<int> episodeIds, PostDownloadStatusType postDownloadStatus)
@ -356,5 +356,13 @@ namespace NzbDrone.Core.Tv
{
return _episodeRepository.GetEpisodeBySceneNumbering(seriesId, seasonNumber, episodeNumber);
}
public List<Episode> GetEpisodesAiredInMonth(int year, int month)
{
var firstDay = new DateTime(year, month, 1);
var lastDay = firstDay.AddMonths(1).AddDays(-1);
return _episodeRepository.EpisodesBetweenDates(firstDay, lastDay);
}
}
}

@ -56,10 +56,9 @@ namespace NzbDrone.Core.Tv
public Series UpdateSeriesInfo(int seriesId)
{
var tvDbSeries = _tvDbProvider.GetSeries(seriesId, false, true);
var series = _seriesRepository.Get(seriesId);
series.SeriesId = tvDbSeries.Id;
var tvDbSeries = _tvDbProvider.GetSeries(series.SeriesId, false, true);
series.Title = tvDbSeries.SeriesName;
series.AirTime = CleanAirsTime(tvDbSeries.AirsTime);
series.AirsDayOfWeek = tvDbSeries.AirsDayOfWeek;
@ -113,7 +112,8 @@ namespace NzbDrone.Core.Tv
logger.Info("Adding Series [{0}] Path: [{1}]", tvDbSeriesId, path);
Ensure.That(() => tvDbSeriesId).IsGreaterThan(0);
Ensure.That(() => title).IsNotNullOrWhiteSpace();
//Todo: We can't validate the title if we're passing in an empty string
//Ensure.That(() => title).IsNotNullOrWhiteSpace();
Ensure.That(() => path).IsNotNullOrWhiteSpace();
var repoSeries = new Series();
@ -144,7 +144,7 @@ namespace NzbDrone.Core.Tv
foreach (var series in allSeries)
{
//Only update parameters that can be changed in MassEdit
var edited = editedSeries.Single(s => s.SeriesId == series.SeriesId);
var edited = editedSeries.Single(s => s.OID == series.OID);
series.QualityProfileId = edited.QualityProfileId;
series.Monitored = edited.Monitored;
series.SeasonFolder = edited.SeasonFolder;

Binary file not shown.
Loading…
Cancel
Save