mirror of
https://github.com/Radarr/Radarr.git
synced 2024-11-04 10:02:40 +01:00
moved media file service
This commit is contained in:
parent
8900bbb3a1
commit
de5d5b76e8
@ -160,8 +160,8 @@ public void should_be_able_to_find_object_by_id()
|
||||
[Test]
|
||||
public void deleting_child_model_directly_should_set_link_to_null()
|
||||
{
|
||||
_parentModel.Child = _childModel;
|
||||
|
||||
_parentModel.Child = _childModel;
|
||||
|
||||
Db.Insert(_childModel);
|
||||
Db.Insert(_parentModel);
|
||||
|
||||
@ -191,7 +191,30 @@ public void deleting_child_model_directly_should_remove_item_from_child_list()
|
||||
|
||||
Db.AsQueryable<ParentModel>().Single().ChildList.Should().HaveCount(4);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void update_field_should_only_update_that_filed()
|
||||
{
|
||||
var childModel = new ChildModel
|
||||
{
|
||||
A = "A_Original",
|
||||
B = 1,
|
||||
C = 1
|
||||
|
||||
};
|
||||
|
||||
Db.Insert(childModel);
|
||||
|
||||
_childModel.A = "A_New";
|
||||
_childModel.B = 2;
|
||||
_childModel.C = 2;
|
||||
|
||||
Db.UpdateField(childModel, "B");
|
||||
|
||||
Db.AsQueryable<ChildModel>().Single().A.Should().Be("A_Original");
|
||||
Db.AsQueryable<ChildModel>().Single().B.Should().Be(2);
|
||||
Db.AsQueryable<ChildModel>().Single().C.Should().Be(1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_be_able_to_read_unknown_type()
|
||||
|
@ -6,6 +6,7 @@
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Model;
|
||||
|
@ -5,6 +5,7 @@
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Providers;
|
||||
|
@ -2,6 +2,7 @@
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Repository;
|
||||
|
@ -4,6 +4,7 @@
|
||||
using FluentAssertions;
|
||||
using NLog;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Instrumentation;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
@ -6,6 +6,7 @@
|
||||
using FizzWare.NBuilder;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Jobs;
|
||||
using NzbDrone.Core.Model.Notification;
|
||||
|
@ -6,6 +6,7 @@
|
||||
using FizzWare.NBuilder;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Jobs;
|
||||
using NzbDrone.Core.Model.Notification;
|
||||
@ -67,8 +68,8 @@ public void import_new_series_succesful()
|
||||
Mocker.GetMock<ISeriesRepository>()
|
||||
.Setup(s => s.Get(series[1].Id)).Returns(series[1]);
|
||||
|
||||
Mocker.GetMock<MediaFileProvider>()
|
||||
.Setup(s => s.GetSeriesFiles(It.IsAny<int>())).Returns(new List<EpisodeFile>());
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(s => s.GetFilesBySeries(It.IsAny<int>())).Returns(new List<EpisodeFile>());
|
||||
|
||||
//Act
|
||||
Mocker.Resolve<ImportNewSeriesJob>().Start(notification, null);
|
||||
@ -121,8 +122,8 @@ public void failed_import_should_not_be_stuck_in_loop()
|
||||
Mocker.GetMock<ISeriesRepository>()
|
||||
.Setup(s => s.Get(series[0].Id)).Returns(series[0]);
|
||||
|
||||
Mocker.GetMock<MediaFileProvider>()
|
||||
.Setup(s => s.GetSeriesFiles(It.IsAny<int>())).Returns(new List<EpisodeFile>());
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(s => s.GetFilesBySeries(It.IsAny<int>())).Returns(new List<EpisodeFile>());
|
||||
|
||||
Mocker.GetMock<XemUpdateJob>()
|
||||
.Setup(j => j.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") == series[0].Id)));
|
||||
@ -148,8 +149,8 @@ public void AutoIgnoreSeason_new_series_should_not_ignore_any()
|
||||
int seriesId = 12;
|
||||
|
||||
WithStrictMocker();
|
||||
Mocker.GetMock<MediaFileProvider>()
|
||||
.Setup(p => p.GetSeriesFiles(seriesId))
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(p => p.GetFilesBySeries(seriesId))
|
||||
.Returns(new List<EpisodeFile>());
|
||||
|
||||
Mocker.GetMock<ISeasonRepository>()
|
||||
@ -176,8 +177,8 @@ public void AutoIgnoreSeason_existing_should_not_ignore_currentseason()
|
||||
|
||||
WithStrictMocker();
|
||||
|
||||
Mocker.GetMock<MediaFileProvider>()
|
||||
.Setup(p => p.GetSeriesFiles(seriesId))
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(p => p.GetFilesBySeries(seriesId))
|
||||
.Returns(episodesFiles);
|
||||
|
||||
Mocker.GetMock<ISeasonRepository>()
|
||||
@ -202,8 +203,8 @@ public void AutoIgnoreSeason_existing_should_ignore_seasons_with_no_file()
|
||||
|
||||
|
||||
|
||||
Mocker.GetMock<MediaFileProvider>()
|
||||
.Setup(p => p.GetSeriesFiles(seriesId))
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(p => p.GetFilesBySeries(seriesId))
|
||||
.Returns(episodesFiles);
|
||||
|
||||
Mocker.GetMock<ISeasonRepository>()
|
||||
|
@ -5,6 +5,7 @@
|
||||
using FizzWare.NBuilder;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Jobs;
|
||||
using NzbDrone.Core.Model.Notification;
|
||||
@ -40,8 +41,8 @@ public void Setup()
|
||||
.Setup(s => s.Get(_series.Id))
|
||||
.Returns(_series);
|
||||
|
||||
Mocker.GetMock<MediaFileProvider>()
|
||||
.Setup(s => s.GetSeasonFiles(_series.Id, 5))
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(s => s.GetFilesBySeason(_series.Id, 5))
|
||||
.Returns(_episodeFiles);
|
||||
}
|
||||
|
||||
|
@ -1,20 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Providers;
|
||||
using NzbDrone.Core.Providers.Core;
|
||||
using NzbDrone.Core.Repository;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.ProviderTests.MediaFileProviderTests
|
||||
namespace NzbDrone.Core.Test.MediaFileTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class CleanUpDatabaseFixture : SqlCeTest
|
||||
@ -50,7 +46,6 @@ public void CleanUpDatabse_should_detach_none_existing_file_from_episodes_with_a
|
||||
Db.InsertMany(episodes);
|
||||
|
||||
//Act
|
||||
Mocker.Resolve<MediaFileProvider>().CleanUpDatabase();
|
||||
var result = Db.Fetch<Episode>();
|
||||
|
||||
//Assert
|
||||
@ -77,7 +72,6 @@ public void CleanUpDatabse_should_detach_none_existing_file_from_episodes_with_n
|
||||
Db.InsertMany(episodes);
|
||||
|
||||
//Act
|
||||
Mocker.Resolve<MediaFileProvider>().CleanUpDatabase();
|
||||
var result = Db.Fetch<Episode>();
|
||||
|
||||
//Assert
|
||||
@ -102,7 +96,6 @@ public void CleanUpDatabse_should_not_change_episodes_with_no_file_id()
|
||||
Db.InsertMany(episodes);
|
||||
|
||||
//Act
|
||||
Mocker.Resolve<MediaFileProvider>().CleanUpDatabase();
|
||||
var result = Db.Fetch<Episode>();
|
||||
|
||||
//Assert
|
||||
@ -129,12 +122,11 @@ public void DeleteOrphanedEpisodeFiles()
|
||||
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);
|
||||
result.Should().OnlyContain(e => e.Id > 0);
|
||||
}
|
||||
}
|
||||
}
|
@ -8,15 +8,12 @@
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Providers;
|
||||
using NzbDrone.Core.Providers.Core;
|
||||
using NzbDrone.Core.Repository;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Test.Common.AutoMoq;
|
||||
|
||||
namespace NzbDrone.Core.Test.ProviderTests.MediaFileProviderTests
|
||||
namespace NzbDrone.Core.Test.MediaFileTests
|
||||
{
|
||||
[TestFixture]
|
||||
// ReSharper disable InconsistentNaming
|
||||
@ -54,7 +51,7 @@ public void GetNewFilename_Series_Episode_Quality_S01E05_Dash()
|
||||
.Build();
|
||||
|
||||
//Act
|
||||
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episode }, _series, Quality.HDTV720p, false, new EpisodeFile());
|
||||
string result = Mocker.Resolve<IMediaFileService>().GetNewFilename(new List<Episode> { episode }, _series, Quality.HDTV720p, false, new EpisodeFile());
|
||||
|
||||
//Assert
|
||||
Assert.AreEqual("South Park - S15E06 - City Sushi [HDTV-720p]", result);
|
||||
@ -81,7 +78,7 @@ public void GetNewFilename_Episode_Quality_1x05_Dash()
|
||||
.Build();
|
||||
|
||||
//Act
|
||||
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episode }, _series, Quality.HDTV720p, false, new EpisodeFile());
|
||||
string result = Mocker.Resolve<IMediaFileService>().GetNewFilename(new List<Episode> { episode }, _series, Quality.HDTV720p, false, new EpisodeFile());
|
||||
|
||||
//Assert
|
||||
Assert.AreEqual("15x06 - City Sushi [HDTV-720p]", result);
|
||||
@ -108,7 +105,7 @@ public void GetNewFilename_Series_Quality_01x05_Space()
|
||||
.Build();
|
||||
|
||||
//Act
|
||||
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episode }, _series, Quality.HDTV720p, false, new EpisodeFile());
|
||||
string result = Mocker.Resolve<IMediaFileService>().GetNewFilename(new List<Episode> { episode }, _series, Quality.HDTV720p, false, new EpisodeFile());
|
||||
|
||||
//Assert
|
||||
Assert.AreEqual("South Park 05x06 [HDTV-720p]", result);
|
||||
@ -136,7 +133,7 @@ public void GetNewFilename_Series_s01e05_Space()
|
||||
.Build();
|
||||
|
||||
//Act
|
||||
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episode }, _series, Quality.HDTV720p, false, new EpisodeFile());
|
||||
string result = Mocker.Resolve<IMediaFileService>().GetNewFilename(new List<Episode> { episode }, _series, Quality.HDTV720p, false, new EpisodeFile());
|
||||
|
||||
//Assert
|
||||
Assert.AreEqual("South Park s05e06", result);
|
||||
@ -163,7 +160,7 @@ public void GetNewFilename_Series_Episode_s01e05_Periods()
|
||||
.Build();
|
||||
|
||||
//Act
|
||||
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episode }, _series, Quality.HDTV720p, false, new EpisodeFile());
|
||||
string result = Mocker.Resolve<IMediaFileService>().GetNewFilename(new List<Episode> { episode }, _series, Quality.HDTV720p, false, new EpisodeFile());
|
||||
|
||||
//Assert
|
||||
Assert.AreEqual("South.Park.s05e06.City.Sushi", result);
|
||||
@ -190,7 +187,7 @@ public void GetNewFilename_Series_Episode_s01e05_Dash_Periods_Quality()
|
||||
.Build();
|
||||
|
||||
//Act
|
||||
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episode }, _series, Quality.HDTV720p, false, new EpisodeFile());
|
||||
string result = Mocker.Resolve<IMediaFileService>().GetNewFilename(new List<Episode> { episode }, _series, Quality.HDTV720p, false, new EpisodeFile());
|
||||
|
||||
//Assert
|
||||
Assert.AreEqual("South.Park.-.s05e06.-.City.Sushi.[HDTV-720p]", result);
|
||||
@ -218,7 +215,7 @@ public void GetNewFilename_S01E05_Dash()
|
||||
.Build();
|
||||
|
||||
//Act
|
||||
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episode }, _series, Quality.HDTV720p, false, new EpisodeFile());
|
||||
string result = Mocker.Resolve<IMediaFileService>().GetNewFilename(new List<Episode> { episode }, _series, Quality.HDTV720p, false, new EpisodeFile());
|
||||
|
||||
//Assert
|
||||
Assert.AreEqual("S15E06", result);
|
||||
@ -252,7 +249,7 @@ public void GetNewFilename_multi_Series_Episode_Quality_S01E05_Scene_Dash()
|
||||
.Build();
|
||||
|
||||
//Act
|
||||
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, Quality.HDTV720p, false, new EpisodeFile());
|
||||
string result = Mocker.Resolve<IMediaFileService>().GetNewFilename(new List<Episode> { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, Quality.HDTV720p, false, new EpisodeFile());
|
||||
|
||||
//Assert
|
||||
Assert.AreEqual("The Mentalist - S03E23-E24 - Strawberries and Cream [HDTV-720p]", result);
|
||||
@ -286,7 +283,7 @@ public void GetNewFilename_multi_Episode_Quality_1x05_Repeat_Dash()
|
||||
.Build();
|
||||
|
||||
//Act
|
||||
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, Quality.HDTV720p, false, new EpisodeFile());
|
||||
string result = Mocker.Resolve<IMediaFileService>().GetNewFilename(new List<Episode> { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, Quality.HDTV720p, false, new EpisodeFile());
|
||||
|
||||
//Assert
|
||||
Assert.AreEqual("3x23x24 - Strawberries and Cream [HDTV-720p]", result);
|
||||
@ -320,7 +317,7 @@ public void GetNewFilename_multi_Episode_Quality_01x05_Repeat_Space()
|
||||
.Build();
|
||||
|
||||
//Act
|
||||
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, Quality.HDTV720p, false, new EpisodeFile());
|
||||
string result = Mocker.Resolve<IMediaFileService>().GetNewFilename(new List<Episode> { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, Quality.HDTV720p, false, new EpisodeFile());
|
||||
|
||||
//Assert
|
||||
Assert.AreEqual("3x23x24 Strawberries and Cream [HDTV-720p]", result);
|
||||
@ -354,7 +351,7 @@ public void GetNewFilename_multi_Series_Episode_s01e05_Duplicate_Period()
|
||||
.Build();
|
||||
|
||||
//Act
|
||||
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, Quality.HDTV720p, false, new EpisodeFile());
|
||||
string result = Mocker.Resolve<IMediaFileService>().GetNewFilename(new List<Episode> { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, Quality.HDTV720p, false, new EpisodeFile());
|
||||
|
||||
//Assert
|
||||
Assert.AreEqual("The.Mentalist.s03e23.s03e24.Strawberries.and.Cream", result);
|
||||
@ -388,7 +385,7 @@ public void GetNewFilename_multi_Series_S01E05_Extend_Dash_Period()
|
||||
.Build();
|
||||
|
||||
//Act
|
||||
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, Quality.HDTV720p, false, new EpisodeFile());
|
||||
string result = Mocker.Resolve<IMediaFileService>().GetNewFilename(new List<Episode> { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, Quality.HDTV720p, false, new EpisodeFile());
|
||||
|
||||
//Assert
|
||||
Assert.AreEqual("The.Mentalist.-.S03E23-24", result);
|
||||
@ -422,7 +419,7 @@ public void GetNewFilename_multi_1x05_Repeat_Dash_Period()
|
||||
.Build();
|
||||
|
||||
//Act
|
||||
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, Quality.HDTV720p, false, new EpisodeFile());
|
||||
string result = Mocker.Resolve<IMediaFileService>().GetNewFilename(new List<Episode> { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, Quality.HDTV720p, false, new EpisodeFile());
|
||||
|
||||
//Assert
|
||||
Assert.AreEqual("3x23x24", result);
|
||||
@ -447,7 +444,7 @@ public void GetNewFilename_should_append_proper_when_proper_and_append_quality_i
|
||||
.Build();
|
||||
|
||||
//Act
|
||||
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episode }, _series, Quality.HDTV720p, true, new EpisodeFile());
|
||||
string result = Mocker.Resolve<IMediaFileService>().GetNewFilename(new List<Episode> { episode }, _series, Quality.HDTV720p, true, new EpisodeFile());
|
||||
|
||||
//Assert
|
||||
result.Should().Be("South Park - S15E06 - City Sushi [HDTV-720p] [Proper]");
|
||||
@ -472,7 +469,7 @@ public void GetNewFilename_should_not_append_proper_when_not_proper_and_append_q
|
||||
.Build();
|
||||
|
||||
//Act
|
||||
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episode }, _series, Quality.HDTV720p, false, new EpisodeFile());
|
||||
string result = Mocker.Resolve<IMediaFileService>().GetNewFilename(new List<Episode> { episode }, _series, Quality.HDTV720p, false, new EpisodeFile());
|
||||
|
||||
//Assert
|
||||
result.Should().Be("South Park - S15E06 - City Sushi [HDTV-720p]");
|
||||
@ -497,7 +494,7 @@ public void GetNewFilename_should_not_append_proper_when_proper_and_append_quali
|
||||
.Build();
|
||||
|
||||
//Act
|
||||
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episode }, _series, Quality.HDTV720p, true, new EpisodeFile());
|
||||
string result = Mocker.Resolve<IMediaFileService>().GetNewFilename(new List<Episode> { episode }, _series, Quality.HDTV720p, true, new EpisodeFile());
|
||||
|
||||
//Assert
|
||||
result.Should().Be("South Park - S15E06 - City Sushi");
|
||||
@ -529,7 +526,7 @@ public void GetNewFilename_should_order_multiple_episode_files_in_numerical_orde
|
||||
.Build();
|
||||
|
||||
//Act
|
||||
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episode2, episode }, new Series { Title = "30 Rock" }, Quality.HDTV720p, false, new EpisodeFile());
|
||||
string result = Mocker.Resolve<IMediaFileService>().GetNewFilename(new List<Episode> { episode2, episode }, new Series { Title = "30 Rock" }, Quality.HDTV720p, false, new EpisodeFile());
|
||||
|
||||
//Assert
|
||||
result.Should().Be("30 Rock - S06E06-E07 - Hey, Baby, What's Wrong!");
|
||||
@ -556,7 +553,7 @@ public void GetNewFilename_Series_Episode_Quality_S01E05_Period()
|
||||
.Build();
|
||||
|
||||
//Act
|
||||
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episode }, _series, Quality.HDTV720p, false, new EpisodeFile());
|
||||
string result = Mocker.Resolve<IMediaFileService>().GetNewFilename(new List<Episode> { episode }, _series, Quality.HDTV720p, false, new EpisodeFile());
|
||||
|
||||
//Assert
|
||||
Assert.AreEqual("South Park.S15E06.City Sushi [HDTV-720p]", result);
|
||||
@ -583,7 +580,7 @@ public void GetNewFilename_Episode_Quality_1x05_Period()
|
||||
.Build();
|
||||
|
||||
//Act
|
||||
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episode }, _series, Quality.HDTV720p, false, new EpisodeFile());
|
||||
string result = Mocker.Resolve<IMediaFileService>().GetNewFilename(new List<Episode> { episode }, _series, Quality.HDTV720p, false, new EpisodeFile());
|
||||
|
||||
//Assert
|
||||
Assert.AreEqual("15x06.City Sushi [HDTV-720p]", result);
|
||||
@ -614,7 +611,7 @@ public void GetNewFilename_UseSceneName_when_sceneName_isNull()
|
||||
.Build();
|
||||
|
||||
//Act
|
||||
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episode }, _series, Quality.HDTV720p, false, episodeFile);
|
||||
string result = Mocker.Resolve<IMediaFileService>().GetNewFilename(new List<Episode> { episode }, _series, Quality.HDTV720p, false, episodeFile);
|
||||
|
||||
//Assert
|
||||
result.Should().Be(Path.GetFileNameWithoutExtension(episodeFile.Path));
|
||||
@ -645,7 +642,7 @@ public void GetNewFilename_UseSceneName_when_sceneName_isNotNull()
|
||||
.Build();
|
||||
|
||||
//Act
|
||||
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episode }, _series, Quality.HDTV720p, false, episodeFile);
|
||||
string result = Mocker.Resolve<IMediaFileService>().GetNewFilename(new List<Episode> { episode }, _series, Quality.HDTV720p, false, episodeFile);
|
||||
|
||||
//Assert
|
||||
result.Should().Be(episodeFile.SceneName);
|
||||
@ -677,7 +674,7 @@ public void should_only_have_one_episodeTitle_when_episode_titles_are_the_same()
|
||||
.Build();
|
||||
|
||||
//Act
|
||||
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episode2, episode }, new Series { Title = "30 Rock" }, Quality.HDTV720p, false, new EpisodeFile());
|
||||
string result = Mocker.Resolve<IMediaFileService>().GetNewFilename(new List<Episode> { episode2, episode }, new Series { Title = "30 Rock" }, Quality.HDTV720p, false, new EpisodeFile());
|
||||
|
||||
//Assert
|
||||
result.Should().Be("30 Rock - S06E06-E07 - Hey, Baby, What's Wrong!");
|
||||
@ -709,7 +706,7 @@ public void should_have_two_episodeTitles_when_episode_titles_are_not_the_same()
|
||||
.Build();
|
||||
|
||||
//Act
|
||||
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episode2, episode }, new Series { Title = "30 Rock" }, Quality.HDTV720p, false, new EpisodeFile());
|
||||
string result = Mocker.Resolve<IMediaFileService>().GetNewFilename(new List<Episode> { episode2, episode }, new Series { Title = "30 Rock" }, Quality.HDTV720p, false, new EpisodeFile());
|
||||
|
||||
//Assert
|
||||
result.Should().Be("30 Rock - S06E06-E07 - Hello + World");
|
||||
@ -747,7 +744,7 @@ public void should_have_two_episodeTitles_when_distinct_count_is_two()
|
||||
.Build();
|
||||
|
||||
//Act
|
||||
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episode, episode2, episode3 }, new Series { Title = "30 Rock" }, Quality.HDTV720p, false, new EpisodeFile());
|
||||
string result = Mocker.Resolve<IMediaFileService>().GetNewFilename(new List<Episode> { episode, episode2, episode3 }, new Series { Title = "30 Rock" }, Quality.HDTV720p, false, new EpisodeFile());
|
||||
|
||||
//Assert
|
||||
result.Should().Be("30 Rock - S06E06-E07-E08 - Hello + World");
|
||||
@ -777,7 +774,7 @@ public void should_use_airDate_if_series_isDaily()
|
||||
.With(e => e.Title = "Kristen Stewart")
|
||||
.Build();
|
||||
|
||||
var result = Mocker.Resolve<MediaFileProvider>()
|
||||
var result = Mocker.Resolve<IMediaFileService>()
|
||||
.GetNewFilename(episodes, series, Quality.HDTV720p, false, new EpisodeFile());
|
||||
result.Should().Be("The Daily Show with Jon Stewart - 2012-12-13 - Kristen Stewart [HDTV-720p]");
|
||||
}
|
||||
@ -806,7 +803,7 @@ public void should_use_airDate_if_series_isDaily_no_episode_title()
|
||||
.With(e => e.Title = "Kristen Stewart")
|
||||
.Build();
|
||||
|
||||
var result = Mocker.Resolve<MediaFileProvider>()
|
||||
var result = Mocker.Resolve<IMediaFileService>()
|
||||
.GetNewFilename(episodes, series, Quality.HDTV720p, false, new EpisodeFile());
|
||||
result.Should().Be("The Daily Show with Jon Stewart - 2012-12-13");
|
||||
}
|
||||
@ -835,7 +832,7 @@ public void should_set_airdate_to_unknown_if_not_available()
|
||||
.With(e => e.Title = "Kristen Stewart")
|
||||
.Build();
|
||||
|
||||
var result = Mocker.Resolve<MediaFileProvider>()
|
||||
var result = Mocker.Resolve<IMediaFileService>()
|
||||
.GetNewFilename(episodes, series, Quality.HDTV720p, false, new EpisodeFile());
|
||||
result.Should().Be("The Daily Show with Jon Stewart - Unknown - Kristen Stewart");
|
||||
}
|
@ -1,28 +1,25 @@
|
||||
// ReSharper disable RedundantUsingDirective
|
||||
|
||||
using System.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Providers;
|
||||
using NzbDrone.Core.Providers.Core;
|
||||
using NzbDrone.Core.Repository;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Test.Common.AutoMoq;
|
||||
|
||||
namespace NzbDrone.Core.Test.ProviderTests
|
||||
namespace NzbDrone.Core.Test.MediaFileTests
|
||||
{
|
||||
[TestFixture]
|
||||
// ReSharper disable InconsistentNaming
|
||||
public class MediaFileProviderTest : SqlCeTest
|
||||
public class MediaFileServiceTest : SqlCeTest
|
||||
{
|
||||
[Test]
|
||||
public void get_series_files()
|
||||
@ -45,7 +42,7 @@ public void get_series_files()
|
||||
Db.InsertMany(firstSeriesFiles);
|
||||
Db.InsertMany(secondSeriesFiles);
|
||||
|
||||
var result = Mocker.Resolve<MediaFileProvider>().GetSeriesFiles(12);
|
||||
var result = Mocker.Resolve<IMediaFileService>().GetFilesBySeries(12);
|
||||
|
||||
|
||||
result.Should().HaveSameCount(firstSeriesFiles);
|
||||
@ -74,7 +71,7 @@ public void get_season_files()
|
||||
Db.InsertMany(firstSeriesFiles);
|
||||
Db.InsertMany(secondSeriesFiles);
|
||||
|
||||
var result = Mocker.Resolve<MediaFileProvider>().GetSeasonFiles(12, 1);
|
||||
var result = Mocker.Resolve<IMediaFileService>().GetFilesBySeason(12, 1);
|
||||
|
||||
result.Should().HaveSameCount(firstSeriesFiles);
|
||||
}
|
||||
@ -88,9 +85,6 @@ public void Scan_series_should_skip_series_with_no_episodes()
|
||||
.Setup(c => c.GetEpisodeBySeries(12))
|
||||
.Returns(new List<Episode>());
|
||||
|
||||
Mocker.GetMock<MediaFileProvider>()
|
||||
.Setup(e => e.CleanUpDatabase());
|
||||
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(c => c.FolderExists(It.IsAny<string>()))
|
||||
@ -112,7 +106,7 @@ public void Scan_series_should_skip_series_with_no_episodes()
|
||||
public void CleanFileName(string name, string expectedName)
|
||||
{
|
||||
//Act
|
||||
var result = MediaFileProvider.CleanFilename(name);
|
||||
var result = MediaFileService.CleanFilename(name);
|
||||
|
||||
//Assert
|
||||
Assert.AreEqual(expectedName, result);
|
||||
@ -137,7 +131,7 @@ public void CalculateFilePath_SeasonFolder_SingleNumber(string filename, int sea
|
||||
Mocker.GetMock<IConfigService>().Setup(e => e.SortingSeasonFolderFormat).Returns(seasonFolderFormat);
|
||||
|
||||
//Act
|
||||
var result = Mocker.Resolve<MediaFileProvider>().CalculateFilePath(fakeSeries, 1, filename, ".mkv");
|
||||
var result = Mocker.Resolve<IMediaFileService>().CalculateFilePath(fakeSeries, 1, filename, ".mkv");
|
||||
|
||||
//Assert
|
||||
Assert.AreEqual(expectedPath, result.FullName);
|
||||
@ -158,12 +152,12 @@ public void DeleteEpisodeFile()
|
||||
Db.InsertMany(episodeFiles);
|
||||
|
||||
//Act
|
||||
Mocker.Resolve<MediaFileProvider>().Delete(1);
|
||||
Mocker.Resolve<IMediaFileService>().Delete(1);
|
||||
var result = Db.Fetch<EpisodeFile>();
|
||||
|
||||
//Assert
|
||||
result.Should().HaveCount(9);
|
||||
result.Should().NotContain(e => e.EpisodeFileId == 1);
|
||||
result.Should().NotContain(e => e.Id == 1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -173,7 +167,7 @@ public void GetFileByPath_should_return_null_if_file_does_not_exist_in_database(
|
||||
WithRealDb();
|
||||
|
||||
//Act
|
||||
var result = Mocker.Resolve<MediaFileProvider>().GetFileByPath(@"C:\Test\EpisodeFile.avi");
|
||||
var result = Mocker.Resolve<IMediaFileService>().GetFileByPath(@"C:\Test\EpisodeFile.avi");
|
||||
|
||||
//Resolve
|
||||
result.Should().BeNull();
|
||||
@ -194,12 +188,12 @@ public void GetFileByPath_should_return_EpisodeFile_if_file_exists_in_database()
|
||||
var episodeFileId = Convert.ToInt32(Db.Insert(episodeFile));
|
||||
|
||||
//Act
|
||||
var result = Mocker.Resolve<MediaFileProvider>().GetFileByPath(path);
|
||||
var result = Mocker.Resolve<IMediaFileService>().GetFileByPath(path);
|
||||
|
||||
//Resolve
|
||||
result.Should().NotBeNull();
|
||||
result.Path.Should().Be(path.NormalizePath());
|
||||
result.EpisodeFileId.Should().Be(episodeFileId);
|
||||
result.Id.Should().Be(episodeFileId);
|
||||
}
|
||||
}
|
||||
}
|
@ -199,7 +199,7 @@
|
||||
<Compile Include="DecisionEngineTests\QualityUpgradeSpecificationFixture.cs" />
|
||||
<Compile Include="DecisionEngineTests\UpgradePossibleSpecificationFixture.cs" />
|
||||
<Compile Include="ProviderTests\DownloadClientTests\BlackholeProviderFixture.cs" />
|
||||
<Compile Include="ProviderTests\MediaFileProviderTests\CleanUpDatabaseFixture.cs" />
|
||||
<Compile Include="MediaFileTests\CleanUpDatabaseFixture.cs" />
|
||||
<Compile Include="ProviderTests\ReferenceDataProviderTest.cs" />
|
||||
<Compile Include="ProviderTests\NotificationProviderTests\NotificationProviderFixture.cs" />
|
||||
<Compile Include="ProviderTests\DownloadClientTests\SabProviderTests\QueueFixture.cs" />
|
||||
@ -232,7 +232,7 @@
|
||||
<Compile Include="ProviderTests\DiskScanProviderTests\ImportFileFixture.cs" />
|
||||
<Compile Include="FluentTest.cs" />
|
||||
<Compile Include="InstrumentationTests\DatabaseTargetFixture.cs" />
|
||||
<Compile Include="ProviderTests\MediaFileProviderTests\GetNewFilenameFixture.cs" />
|
||||
<Compile Include="MediaFileTests\GetNewFilenameFixture.cs" />
|
||||
<Compile Include="Framework\SqlCeTest.cs" />
|
||||
<Compile Include="DecisionEngineTests\MonitoredEpisodeSpecificationFixture.cs" />
|
||||
<Compile Include="ProviderTests\DownloadProviderTests\DownloadProviderFixture.cs" />
|
||||
@ -246,7 +246,7 @@
|
||||
<Compile Include="RootFolderTests\RootFolderServiceFixture.cs" />
|
||||
<Compile Include="Indexers\IndexerServiceTest.cs" />
|
||||
<Compile Include="HistoryTests\HistoryServiceTest.cs" />
|
||||
<Compile Include="ProviderTests\MediaFileProviderTest.cs" />
|
||||
<Compile Include="MediaFileTests\MediaFileServiceTest.cs" />
|
||||
<Compile Include="Configuration\ConfigServiceFixture.cs" />
|
||||
<Compile Include="TvTests\EpisodeProviderTests\EpisodeProviderTest.cs" />
|
||||
<Compile Include="Framework\TestDbHelper.cs" />
|
||||
|
@ -8,6 +8,7 @@
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Model;
|
||||
@ -36,7 +37,7 @@ public void should_do_nothing_if_no_files_are_found()
|
||||
Mocker.Resolve<DiskScanProvider>().CleanUpDropFolder(folder);
|
||||
|
||||
//Assert
|
||||
Mocker.GetMock<MediaFileProvider>().Verify(v => v.GetFileByPath(It.IsAny<string>()), Times.Never());
|
||||
Mocker.GetMock<IMediaFileService>().Verify(v => v.GetFileByPath(It.IsAny<string>()), Times.Never());
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -54,14 +55,14 @@ public void should_do_nothing_if_no_conflicting_files_are_found()
|
||||
Mocker.GetMock<DiskProvider>().Setup(s => s.GetFiles(folder, SearchOption.AllDirectories))
|
||||
.Returns(new string[] { filename });
|
||||
|
||||
Mocker.GetMock<MediaFileProvider>().Setup(s => s.GetFileByPath(filename))
|
||||
Mocker.GetMock<IMediaFileService>().Setup(s => s.GetFileByPath(filename))
|
||||
.Returns(() => null);
|
||||
|
||||
//Act
|
||||
Mocker.Resolve<DiskScanProvider>().CleanUpDropFolder(folder);
|
||||
|
||||
//Assert
|
||||
Mocker.GetMock<MediaFileProvider>().Verify(v => v.GetFileByPath(filename), Times.Once());
|
||||
Mocker.GetMock<IMediaFileService>().Verify(v => v.GetFileByPath(filename), Times.Once());
|
||||
Mocker.GetMock<ISeriesRepository>().Verify(v => v.Get(It.IsAny<int>()), Times.Never());
|
||||
}
|
||||
|
||||
@ -91,25 +92,25 @@ public void should_move_file_if_a_conflict_is_found()
|
||||
.With(e => e.EpisodeFile = episodeFile)
|
||||
.Build();
|
||||
|
||||
Mocker.GetMock<MediaFileProvider>().Setup(v => v.GetFileByPath(filename))
|
||||
Mocker.GetMock<IMediaFileService>().Setup(v => v.GetFileByPath(filename))
|
||||
.Returns(() => null);
|
||||
|
||||
Mocker.GetMock<DiskProvider>().Setup(s => s.GetFiles(folder, SearchOption.AllDirectories))
|
||||
.Returns(new string[] { filename });
|
||||
|
||||
Mocker.GetMock<MediaFileProvider>().Setup(s => s.GetFileByPath(filename))
|
||||
Mocker.GetMock<IMediaFileService>().Setup(s => s.GetFileByPath(filename))
|
||||
.Returns(episodeFile);
|
||||
|
||||
Mocker.GetMock<ISeriesRepository>().Setup(s => s.Get(It.IsAny<int>()))
|
||||
.Returns(series);
|
||||
|
||||
Mocker.GetMock<IEpisodeService>().Setup(s => s.GetEpisodesByFileId(episodeFile.EpisodeFileId))
|
||||
Mocker.GetMock<IEpisodeService>().Setup(s => s.GetEpisodesByFileId(episodeFile.Id))
|
||||
.Returns(episode);
|
||||
|
||||
Mocker.GetMock<MediaFileProvider>().Setup(s => s.GetNewFilename(It.IsAny<IList<Episode>>(), series, Quality.Unknown, false, It.IsAny<EpisodeFile>()))
|
||||
Mocker.GetMock<IMediaFileService>().Setup(s => s.GetNewFilename(It.IsAny<IList<Episode>>(), series, Quality.Unknown, false, It.IsAny<EpisodeFile>()))
|
||||
.Returns(newFilename);
|
||||
|
||||
Mocker.GetMock<MediaFileProvider>().Setup(s => s.CalculateFilePath(It.IsAny<Series>(), It.IsAny<int>(), It.IsAny<string>(), It.IsAny<string>()))
|
||||
Mocker.GetMock<IMediaFileService>().Setup(s => s.CalculateFilePath(It.IsAny<Series>(), It.IsAny<int>(), It.IsAny<string>(), It.IsAny<string>()))
|
||||
.Returns(new FileInfo(newFilePath));
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
@ -122,7 +123,7 @@ public void should_move_file_if_a_conflict_is_found()
|
||||
Mocker.Resolve<DiskScanProvider>().CleanUpDropFolder(folder);
|
||||
|
||||
//Assert
|
||||
Mocker.GetMock<MediaFileProvider>().Verify(v => v.GetFileByPath(filename), Times.Once());
|
||||
Mocker.GetMock<IMediaFileService>().Verify(v => v.GetFileByPath(filename), Times.Once());
|
||||
Mocker.GetMock<DiskProvider>().Verify(v => v.MoveFile(filename.NormalizePath(), newFilePath), Times.Once());
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,7 @@
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Providers;
|
||||
@ -53,7 +54,7 @@ public void should_delete_none_existing_files()
|
||||
.Setup(e => e.GetEpisodesByFileId(It.IsAny<int>()))
|
||||
.Returns(new List<Episode>());
|
||||
|
||||
Mocker.GetMock<MediaFileProvider>()
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(e => e.Delete(It.IsAny<int>()));
|
||||
|
||||
|
||||
@ -66,7 +67,7 @@ public void should_delete_none_existing_files()
|
||||
Mocker.GetMock<IEpisodeService>()
|
||||
.Verify(e => e.GetEpisodesByFileId(It.IsAny<int>()), Times.Exactly(10));
|
||||
|
||||
Mocker.GetMock<MediaFileProvider>()
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Verify(e => e.Delete(It.IsAny<int>()), Times.Exactly(10));
|
||||
|
||||
}
|
||||
@ -82,12 +83,12 @@ public void should_delete_none_existing_files_remove_links_to_episodes()
|
||||
|
||||
Mocker.GetMock<IEpisodeService>()
|
||||
.Setup(e => e.GetEpisodesByFileId(It.IsAny<int>()))
|
||||
.Returns(new List<Episode> { new Episode { EpisodeFile = new EpisodeFile { EpisodeFileId = 10 } }, new Episode { EpisodeFile = new EpisodeFile { EpisodeFileId = 10 } } });
|
||||
.Returns(new List<Episode> { new Episode { EpisodeFile = new EpisodeFile { Id = 10 } }, new Episode { EpisodeFile = new EpisodeFile { Id = 10 } } });
|
||||
|
||||
Mocker.GetMock<IEpisodeService>()
|
||||
.Setup(e => e.UpdateEpisode(It.IsAny<Episode>()));
|
||||
|
||||
Mocker.GetMock<MediaFileProvider>()
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(e => e.Delete(It.IsAny<int>()));
|
||||
|
||||
Mocker.GetMock<IConfigService>()
|
||||
@ -106,10 +107,10 @@ public void should_delete_none_existing_files_remove_links_to_episodes()
|
||||
Mocker.GetMock<IEpisodeService>()
|
||||
.Verify(e => e.UpdateEpisode(It.Is<Episode>(g => g.EpisodeFileId == 0)), Times.Exactly(20));
|
||||
|
||||
Mocker.GetMock<MediaFileProvider>()
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Verify(e => e.Delete(It.IsAny<int>()), Times.Exactly(10));
|
||||
|
||||
Mocker.GetMock<MediaFileProvider>()
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Verify(e => e.Delete(It.IsAny<int>()), Times.Exactly(10));
|
||||
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Model;
|
||||
@ -63,7 +64,7 @@ public void import_new_file_should_succeed()
|
||||
//Mocks
|
||||
With80MBFile();
|
||||
|
||||
Mocker.GetMock<MediaFileProvider>()
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(p => p.Exists(It.IsAny<String>()))
|
||||
.Returns(false);
|
||||
|
||||
@ -120,7 +121,7 @@ public void import_new_file_episode_has_same_or_better_quality_should_skip(strin
|
||||
//Mocks
|
||||
With80MBFile();
|
||||
|
||||
Mocker.GetMock<MediaFileProvider>()
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(p => p.Exists(It.IsAny<String>()))
|
||||
.Returns(false);
|
||||
|
||||
@ -141,7 +142,7 @@ public void import_unparsable_file_should_skip()
|
||||
|
||||
var fakeSeries = Builder<Series>.CreateNew().Build();
|
||||
|
||||
Mocker.GetMock<MediaFileProvider>()
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(p => p.Exists(It.IsAny<String>())).Returns(false);
|
||||
|
||||
With80MBFile();
|
||||
@ -162,7 +163,7 @@ public void import_existing_file_should_skip()
|
||||
var fakeSeries = Builder<Series>.CreateNew().Build();
|
||||
|
||||
WithStrictMocker();
|
||||
Mocker.GetMock<MediaFileProvider>()
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(p => p.Exists(It.IsAny<String>()))
|
||||
.Returns(true);
|
||||
|
||||
@ -190,7 +191,7 @@ public void import_file_with_no_episode_in_db_should_skip()
|
||||
|
||||
With80MBFile();
|
||||
|
||||
Mocker.GetMock<MediaFileProvider>()
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(p => p.Exists(It.IsAny<String>()))
|
||||
.Returns(false);
|
||||
|
||||
@ -221,7 +222,7 @@ public void import_new_file_episode_has_better_quality_than_existing(string file
|
||||
//Mocks
|
||||
With80MBFile();
|
||||
|
||||
Mocker.GetMock<MediaFileProvider>()
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(p => p.Exists(It.IsAny<String>()))
|
||||
.Returns(false);
|
||||
|
||||
@ -253,7 +254,7 @@ public void import_new_multi_part_file_episode_has_equal_or_better_quality_than_
|
||||
|
||||
With80MBFile();
|
||||
|
||||
Mocker.GetMock<MediaFileProvider>()
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(p => p.Exists(It.IsAny<String>()))
|
||||
.Returns(false);
|
||||
|
||||
@ -286,7 +287,7 @@ public void skip_import_new_multi_part_file_episode_existing_has_better_quality(
|
||||
|
||||
With80MBFile();
|
||||
|
||||
Mocker.GetMock<MediaFileProvider>()
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(p => p.Exists(It.IsAny<String>()))
|
||||
.Returns(false);
|
||||
|
||||
@ -324,7 +325,7 @@ public void import_new_multi_part_file_episode_replace_two_files()
|
||||
//Mocks
|
||||
With80MBFile();
|
||||
|
||||
Mocker.GetMock<MediaFileProvider>()
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(p => p.Exists(It.IsAny<String>()))
|
||||
.Returns(false);
|
||||
|
||||
@ -353,7 +354,7 @@ public void should_import_new_episode_no_existing_episode_file()
|
||||
//Mocks
|
||||
With80MBFile();
|
||||
|
||||
Mocker.GetMock<MediaFileProvider>()
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(p => p.Exists(It.IsAny<String>()))
|
||||
.Returns(false);
|
||||
|
||||
@ -419,7 +420,7 @@ public void should_return_null_if_file_size_is_under_70MB_and_runTime_under_3_mi
|
||||
{
|
||||
const string path = @"C:\Test\TV\30.rock.s01e01.pilot.avi";
|
||||
|
||||
Mocker.GetMock<MediaFileProvider>()
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(m => m.Exists(path))
|
||||
.Returns(false);
|
||||
|
||||
@ -442,7 +443,7 @@ public void should_import_if_file_size_is_under_70MB_but_runTime_over_3_minutes(
|
||||
|
||||
const string path = @"C:\Test\TV\30.rock.s01e01.pilot.avi";
|
||||
|
||||
Mocker.GetMock<MediaFileProvider>()
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(m => m.Exists(path))
|
||||
.Returns(false);
|
||||
|
||||
@ -473,7 +474,7 @@ public void should_import_if_file_size_is_over_70MB_but_runTime_under_3_minutes(
|
||||
|
||||
const string path = @"C:\Test\TV\30.rock.s01e01.pilot.avi";
|
||||
|
||||
Mocker.GetMock<MediaFileProvider>()
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(m => m.Exists(path))
|
||||
.Returns(false);
|
||||
|
||||
@ -500,7 +501,7 @@ public void should_import_special_even_if_file_size_is_under_70MB_and_runTime_un
|
||||
|
||||
const string path = @"C:\Test\TV\30.rock.s00e01.pre-pilot.avi";
|
||||
|
||||
Mocker.GetMock<MediaFileProvider>()
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(m => m.Exists(path))
|
||||
.Returns(false);
|
||||
|
||||
@ -528,7 +529,7 @@ public void should_return_null_if_daily_series_with_file_size_is_under_70MB_and_
|
||||
|
||||
const string path = @"C:\Test\TV\30.rock.s01e01.pilot.avi";
|
||||
|
||||
Mocker.GetMock<MediaFileProvider>()
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(m => m.Exists(path))
|
||||
.Returns(false);
|
||||
|
||||
@ -549,18 +550,18 @@ private static void VerifyFileImport(EpisodeFile result, AutoMoqer Mocker, Episo
|
||||
result.SeriesId.Should().Be(fakeEpisode.SeriesId);
|
||||
result.Size.Should().Be(size);
|
||||
result.DateAdded.Should().HaveDay(DateTime.Now.Day);
|
||||
Mocker.GetMock<MediaFileProvider>().Verify(p => p.Add(It.IsAny<EpisodeFile>()), Times.Once());
|
||||
Mocker.GetMock<IMediaFileService>().Verify(p => p.Add(It.IsAny<EpisodeFile>()), Times.Once());
|
||||
|
||||
//Get the count of episodes linked
|
||||
var count = Mocker.GetMock<IEpisodeService>().Object.GetEpisodesByParseResult(null).Count;
|
||||
|
||||
Mocker.GetMock<IEpisodeService>().Verify(p => p.UpdateEpisode(It.Is<Episode>(e => e.EpisodeFileId == result.EpisodeFileId)), Times.Exactly(count));
|
||||
Mocker.GetMock<IEpisodeService>().Verify(p => p.UpdateEpisode(It.Is<Episode>(e => e.EpisodeFileId == result.Id)), Times.Exactly(count));
|
||||
}
|
||||
|
||||
private static void VerifySkipImport(EpisodeFile result, AutoMoqer Mocker)
|
||||
{
|
||||
result.Should().BeNull();
|
||||
Mocker.GetMock<MediaFileProvider>().Verify(p => p.Add(It.IsAny<EpisodeFile>()), Times.Never());
|
||||
Mocker.GetMock<IMediaFileService>().Verify(p => p.Add(It.IsAny<EpisodeFile>()), Times.Never());
|
||||
Mocker.GetMock<IEpisodeService>().Verify(p => p.UpdateEpisode(It.IsAny<Episode>()), Times.Never());
|
||||
Mocker.GetMock<DiskProvider>().Verify(p => p.DeleteFile(It.IsAny<string>()), Times.Never());
|
||||
}
|
||||
|
@ -10,6 +10,7 @@
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Download;
|
||||
using NzbDrone.Core.ExternalNotification;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Model;
|
||||
@ -53,14 +54,14 @@ public void should_not_move_file_if_source_and_destination_are_the_same_path()
|
||||
.Returns(fakeSeries);
|
||||
|
||||
Mocker.GetMock<IEpisodeService>()
|
||||
.Setup(e => e.GetEpisodesByFileId(file.EpisodeFileId))
|
||||
.Setup(e => e.GetEpisodesByFileId(file.Id))
|
||||
.Returns(fakeEpisode);
|
||||
|
||||
Mocker.GetMock<MediaFileProvider>()
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(e => e.GetNewFilename(fakeEpisode, fakeSeries, It.IsAny<Quality>(), It.IsAny<bool>(), It.IsAny<EpisodeFile>()))
|
||||
.Returns(filename);
|
||||
|
||||
Mocker.GetMock<MediaFileProvider>()
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(e => e.CalculateFilePath(It.IsAny<Series>(), fakeEpisode.First().SeasonNumber, filename, ".avi"))
|
||||
.Returns(fi);
|
||||
|
||||
@ -103,14 +104,14 @@ public void should_use_EpisodeFiles_quality()
|
||||
.Returns(fakeSeries);
|
||||
|
||||
Mocker.GetMock<IEpisodeService>()
|
||||
.Setup(e => e.GetEpisodesByFileId(file.EpisodeFileId))
|
||||
.Setup(e => e.GetEpisodesByFileId(file.Id))
|
||||
.Returns(fakeEpisode);
|
||||
|
||||
Mocker.GetMock<MediaFileProvider>()
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(e => e.GetNewFilename(fakeEpisode, fakeSeries, It.IsAny<Quality>(), It.IsAny<bool>(), It.IsAny<EpisodeFile>()))
|
||||
.Returns(filename);
|
||||
|
||||
Mocker.GetMock<MediaFileProvider>()
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(e => e.CalculateFilePath(It.IsAny<Series>(), fakeEpisode.First().SeasonNumber, filename, ".mkv"))
|
||||
.Returns(fi);
|
||||
|
||||
@ -155,14 +156,14 @@ public void should_log_error_and_return_null_when_source_file_does_not_exists()
|
||||
.Returns(fakeSeries);
|
||||
|
||||
Mocker.GetMock<IEpisodeService>()
|
||||
.Setup(e => e.GetEpisodesByFileId(file.EpisodeFileId))
|
||||
.Setup(e => e.GetEpisodesByFileId(file.Id))
|
||||
.Returns(fakeEpisode);
|
||||
|
||||
Mocker.GetMock<MediaFileProvider>()
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(e => e.GetNewFilename(fakeEpisode, fakeSeries, It.IsAny<Quality>(), It.IsAny<bool>(), It.IsAny<EpisodeFile>()))
|
||||
.Returns(filename);
|
||||
|
||||
Mocker.GetMock<MediaFileProvider>()
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(e => e.CalculateFilePath(It.IsAny<Series>(), fakeEpisode.First().SeasonNumber, filename, ".mkv"))
|
||||
.Returns(fi);
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Providers;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
@ -30,8 +31,8 @@ public void series_should_update_the_last_scan_date()
|
||||
.Setup(c => c.FolderExists(It.IsAny<string>()))
|
||||
.Returns(true);
|
||||
|
||||
Mocker.GetMock<MediaFileProvider>()
|
||||
.Setup(c => c.GetSeriesFiles(It.IsAny<int>()))
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(c => c.GetFilesBySeries(It.IsAny<int>()))
|
||||
.Returns(new List<EpisodeFile>());
|
||||
|
||||
Mocker.Resolve<DiskScanProvider>().Scan(new Series());
|
||||
@ -51,10 +52,6 @@ public void series_should_log_warning_if_path_doesnt_exist_on_disk()
|
||||
.Build();
|
||||
|
||||
|
||||
Mocker.GetMock<MediaFileProvider>()
|
||||
.Setup(c => c.CleanUpDatabase());
|
||||
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(c => c.FolderExists(series.Path))
|
||||
.Returns(false);
|
||||
|
@ -9,6 +9,7 @@
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Model.Notification;
|
||||
using NzbDrone.Core.Providers;
|
||||
@ -105,7 +106,7 @@ private void WithSingleEpisodeFile()
|
||||
.Build();
|
||||
|
||||
Mocker.GetMock<IEpisodeService>()
|
||||
.Setup(s => s.GetEpisodesByFileId(episodeFile.EpisodeFileId))
|
||||
.Setup(s => s.GetEpisodesByFileId(episodeFile.Id))
|
||||
.Returns(new List<Episode> { episode });
|
||||
}
|
||||
|
||||
@ -118,7 +119,7 @@ private void WithMultiEpisodeFile()
|
||||
.Build();
|
||||
|
||||
Mocker.GetMock<IEpisodeService>()
|
||||
.Setup(s => s.GetEpisodesByFileId(episodeFile.EpisodeFileId))
|
||||
.Setup(s => s.GetEpisodesByFileId(episodeFile.Id))
|
||||
.Returns(episodes.ToList());
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Providers;
|
||||
@ -26,10 +27,10 @@ public void no_misnamed_files()
|
||||
|
||||
var episodeFiles = Builder<EpisodeFile>.CreateListOfSize(2)
|
||||
.TheFirst(1)
|
||||
.With(f => f.EpisodeFileId = 1)
|
||||
.With(f => f.Id = 1)
|
||||
.With(f => f.Path = @"C:\Test\Title1.avi")
|
||||
.TheNext(1)
|
||||
.With(f => f.EpisodeFileId = 2)
|
||||
.With(f => f.Id = 2)
|
||||
.With(f => f.Path = @"C:\Test\Title2.avi")
|
||||
.Build();
|
||||
|
||||
@ -47,11 +48,11 @@ public void no_misnamed_files()
|
||||
Mocker.GetMock<IEpisodeService>()
|
||||
.Setup(c => c.EpisodesWithFiles()).Returns(episodes);
|
||||
|
||||
Mocker.GetMock<MediaFileProvider>()
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(c => c.GetNewFilename(new List<Episode> { episodes[0] }, It.IsAny<Series>(), It.IsAny<Quality>(), It.IsAny<bool>(), episodeFiles[0]))
|
||||
.Returns("Title1");
|
||||
|
||||
Mocker.GetMock<MediaFileProvider>()
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(c => c.GetNewFilename(new List<Episode> { episodes[1] }, It.IsAny<Series>(), It.IsAny<Quality>(), It.IsAny<bool>(), episodeFiles[1]))
|
||||
.Returns("Title2");
|
||||
|
||||
@ -73,10 +74,10 @@ public void all_misnamed_files()
|
||||
|
||||
var episodeFiles = Builder<EpisodeFile>.CreateListOfSize(2)
|
||||
.TheFirst(1)
|
||||
.With(f => f.EpisodeFileId = 1)
|
||||
.With(f => f.Id = 1)
|
||||
.With(f => f.Path = @"C:\Test\Title1.avi")
|
||||
.TheNext(1)
|
||||
.With(f => f.EpisodeFileId = 2)
|
||||
.With(f => f.Id = 2)
|
||||
.With(f => f.Path = @"C:\Test\Title2.avi")
|
||||
.Build();
|
||||
|
||||
@ -94,11 +95,11 @@ public void all_misnamed_files()
|
||||
Mocker.GetMock<IEpisodeService>()
|
||||
.Setup(c => c.EpisodesWithFiles()).Returns(episodes);
|
||||
|
||||
Mocker.GetMock<MediaFileProvider>()
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(c => c.GetNewFilename(new List<Episode> { episodes[0] }, It.IsAny<Series>(), It.IsAny<Quality>(), It.IsAny<bool>(), episodeFiles[0]))
|
||||
.Returns("New Title 1");
|
||||
|
||||
Mocker.GetMock<MediaFileProvider>()
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(c => c.GetNewFilename(new List<Episode> { episodes[1] }, It.IsAny<Series>(), It.IsAny<Quality>(), It.IsAny<bool>(), episodeFiles[1]))
|
||||
.Returns("New Title 2");
|
||||
|
||||
@ -120,10 +121,10 @@ public void one_misnamed_file()
|
||||
|
||||
var episodeFiles = Builder<EpisodeFile>.CreateListOfSize(2)
|
||||
.TheFirst(1)
|
||||
.With(f => f.EpisodeFileId = 1)
|
||||
.With(f => f.Id = 1)
|
||||
.With(f => f.Path = @"C:\Test\Title1.avi")
|
||||
.TheNext(1)
|
||||
.With(f => f.EpisodeFileId = 2)
|
||||
.With(f => f.Id = 2)
|
||||
.With(f => f.Path = @"C:\Test\Title2.avi")
|
||||
.Build();
|
||||
|
||||
@ -141,11 +142,11 @@ public void one_misnamed_file()
|
||||
Mocker.GetMock<IEpisodeService>()
|
||||
.Setup(c => c.EpisodesWithFiles()).Returns(episodes);
|
||||
|
||||
Mocker.GetMock<MediaFileProvider>()
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(c => c.GetNewFilename(new List<Episode> { episodes[0] }, It.IsAny<Series>(), It.IsAny<Quality>(), It.IsAny<bool>(), episodeFiles[0]))
|
||||
.Returns("New Title 1");
|
||||
|
||||
Mocker.GetMock<MediaFileProvider>()
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(c => c.GetNewFilename(new List<Episode> { episodes[1] }, It.IsAny<Series>(), It.IsAny<Quality>(), It.IsAny<bool>(), episodeFiles[1]))
|
||||
.Returns("Title2");
|
||||
|
||||
@ -169,10 +170,10 @@ public void misnamed_multi_episode_file()
|
||||
|
||||
var episodeFiles = Builder<EpisodeFile>.CreateListOfSize(2)
|
||||
.TheFirst(1)
|
||||
.With(f => f.EpisodeFileId = 1)
|
||||
.With(f => f.Id = 1)
|
||||
.With(f => f.Path = @"C:\Test\Title1.avi")
|
||||
.TheNext(1)
|
||||
.With(f => f.EpisodeFileId = 2)
|
||||
.With(f => f.Id = 2)
|
||||
.With(f => f.Path = @"C:\Test\Title2.avi")
|
||||
.Build();
|
||||
|
||||
@ -190,11 +191,11 @@ public void misnamed_multi_episode_file()
|
||||
Mocker.GetMock<IEpisodeService>()
|
||||
.Setup(c => c.EpisodesWithFiles()).Returns(episodes);
|
||||
|
||||
Mocker.GetMock<MediaFileProvider>()
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(c => c.GetNewFilename(new List<Episode> { episodes[0], episodes[1] }, It.IsAny<Series>(), It.IsAny<Quality>(), It.IsAny<bool>(), episodeFiles[0]))
|
||||
.Returns("New Title 1");
|
||||
|
||||
Mocker.GetMock<MediaFileProvider>()
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(c => c.GetNewFilename(new List<Episode> { episodes[2] }, It.IsAny<Series>(), It.IsAny<Quality>(), It.IsAny<bool>(), episodeFiles[1]))
|
||||
.Returns("Title2");
|
||||
|
||||
@ -218,10 +219,10 @@ public void no_misnamed_multi_episode_file()
|
||||
|
||||
var episodeFiles = Builder<EpisodeFile>.CreateListOfSize(2)
|
||||
.TheFirst(1)
|
||||
.With(f => f.EpisodeFileId = 1)
|
||||
.With(f => f.Id = 1)
|
||||
.With(f => f.Path = @"C:\Test\Title1.avi")
|
||||
.TheNext(1)
|
||||
.With(f => f.EpisodeFileId = 2)
|
||||
.With(f => f.Id = 2)
|
||||
.With(f => f.Path = @"C:\Test\Title2.avi")
|
||||
.Build();
|
||||
|
||||
@ -239,11 +240,11 @@ public void no_misnamed_multi_episode_file()
|
||||
Mocker.GetMock<IEpisodeService>()
|
||||
.Setup(c => c.EpisodesWithFiles()).Returns(episodes);
|
||||
|
||||
Mocker.GetMock<MediaFileProvider>()
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(c => c.GetNewFilename(new List<Episode> { episodes[0], episodes[1] }, It.IsAny<Series>(), It.IsAny<Quality>(), It.IsAny<bool>(), episodeFiles[0]))
|
||||
.Returns("Title1");
|
||||
|
||||
Mocker.GetMock<MediaFileProvider>()
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(c => c.GetNewFilename(new List<Episode> { episodes[2] }, It.IsAny<Series>(), It.IsAny<Quality>(), It.IsAny<bool>(), episodeFiles[1]))
|
||||
.Returns("Title2");
|
||||
|
||||
|
@ -8,6 +8,7 @@
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Providers;
|
||||
|
@ -8,6 +8,7 @@
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Providers;
|
||||
|
@ -8,6 +8,7 @@
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Providers;
|
||||
|
@ -9,6 +9,7 @@
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.Download;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Model;
|
||||
@ -86,9 +87,9 @@ public void GetEpisode_with_EpisodeFile()
|
||||
WithRealDb();
|
||||
|
||||
var fakeSeries = Builder<Series>.CreateNew().Build();
|
||||
var fakeFile = Builder<EpisodeFile>.CreateNew().With(f => f.EpisodeFileId).With(c => c.Quality = Quality.SDTV).Build();
|
||||
var fakeFile = Builder<EpisodeFile>.CreateNew().With(f => f.Id).With(c => c.Quality = Quality.SDTV).Build();
|
||||
var fakeEpisodes = Builder<Episode>.CreateListOfSize(5)
|
||||
.All().With(e => e.SeriesId = 1).TheFirst(1).With(e => e.EpisodeFile = new EpisodeFile { EpisodeFileId = 1 }).With(e => e.EpisodeFile = fakeFile).Build();
|
||||
.All().With(e => e.SeriesId = 1).TheFirst(1).With(e => e.EpisodeFile = new EpisodeFile { Id = 1 }).With(e => e.EpisodeFile = fakeFile).Build();
|
||||
|
||||
Db.Insert(fakeSeries);
|
||||
Db.InsertMany(fakeEpisodes);
|
||||
@ -630,7 +631,7 @@ public void existing_episodes_keep_their_episodeId_file_id()
|
||||
{
|
||||
TvDbEpisodeId = tvDbEpisode.Id,
|
||||
Id = 99,
|
||||
EpisodeFile = new EpisodeFile { EpisodeFileId = 69 },
|
||||
EpisodeFile = new EpisodeFile { Id = 69 },
|
||||
Ignored = true,
|
||||
Series = fakeSeries,
|
||||
EpisodeNumber = tvDbEpisode.EpisodeNumber,
|
||||
@ -679,7 +680,7 @@ public void existing_episodes_remote_their_episodeId_file_id_when_episode_number
|
||||
{
|
||||
TvDbEpisodeId = tvDbEpisode.Id,
|
||||
Id = 99,
|
||||
EpisodeFile = new EpisodeFile { EpisodeFileId = 69 },
|
||||
EpisodeFile = new EpisodeFile { Id = 69 },
|
||||
Ignored = true,
|
||||
Series = fakeSeries,
|
||||
EpisodeNumber = tvDbEpisode.EpisodeNumber + 1,
|
||||
@ -725,7 +726,7 @@ public void existing_episodes_remote_their_episodeId_file_id_when_season_number_
|
||||
{
|
||||
TvDbEpisodeId = tvDbEpisode.Id,
|
||||
Id = 99,
|
||||
EpisodeFile = new EpisodeFile { EpisodeFileId = 69 },
|
||||
EpisodeFile = new EpisodeFile { Id = 69 },
|
||||
Ignored = true,
|
||||
Series = fakeSeries,
|
||||
EpisodeNumber = tvDbEpisode.EpisodeNumber,
|
||||
@ -857,9 +858,9 @@ public void GetEpisode_by_Season_Episode_with_EpisodeFile()
|
||||
WithRealDb();
|
||||
|
||||
var fakeSeries = Builder<Series>.CreateNew().Build();
|
||||
var fakeFile = Builder<EpisodeFile>.CreateNew().With(f => f.EpisodeFileId).With(c => c.Quality = Quality.SDTV).Build();
|
||||
var fakeFile = Builder<EpisodeFile>.CreateNew().With(f => f.Id).With(c => c.Quality = Quality.SDTV).Build();
|
||||
var fakeEpisodes = Builder<Episode>.CreateListOfSize(5)
|
||||
.All().With(e => e.SeriesId = 1).TheFirst(1).With(c => c.EpisodeFile = new EpisodeFile { EpisodeFileId = 1 }).With(e => e.EpisodeFile = fakeFile).Build();
|
||||
.All().With(e => e.SeriesId = 1).TheFirst(1).With(c => c.EpisodeFile = new EpisodeFile { Id = 1 }).With(e => e.EpisodeFile = fakeFile).Build();
|
||||
|
||||
Db.Insert(fakeSeries);
|
||||
Db.InsertMany(fakeEpisodes);
|
||||
@ -901,9 +902,9 @@ public void GetEpisode_by_AirDate_with_EpisodeFile()
|
||||
WithRealDb();
|
||||
|
||||
var fakeSeries = Builder<Series>.CreateNew().Build();
|
||||
var fakeFile = Builder<EpisodeFile>.CreateNew().With(f => f.EpisodeFileId).With(c => c.Quality = Quality.SDTV).Build();
|
||||
var fakeFile = Builder<EpisodeFile>.CreateNew().With(f => f.Id).With(c => c.Quality = Quality.SDTV).Build();
|
||||
var fakeEpisodes = Builder<Episode>.CreateListOfSize(5)
|
||||
.All().With(e => e.SeriesId = 1).TheFirst(1).With(e => e.EpisodeFile = new EpisodeFile { EpisodeFileId = 1 }).With(e => e.EpisodeFile = fakeFile).Build();
|
||||
.All().With(e => e.SeriesId = 1).TheFirst(1).With(e => e.EpisodeFile = new EpisodeFile { Id = 1 }).With(e => e.EpisodeFile = fakeFile).Build();
|
||||
|
||||
Db.Insert(fakeSeries);
|
||||
Db.InsertMany(fakeEpisodes);
|
||||
@ -925,7 +926,7 @@ public void GetEpisode_by_AirDate_without_EpisodeFile()
|
||||
|
||||
var fakeSeries = Builder<Series>.CreateNew().Build();
|
||||
var fakeEpisodes = Builder<Episode>.CreateListOfSize(5)
|
||||
.All().With(e => e.SeriesId = 1).TheFirst(1).With(e => e.EpisodeFile = new EpisodeFile { EpisodeFileId = 1 }).Build();
|
||||
.All().With(e => e.SeriesId = 1).TheFirst(1).With(e => e.EpisodeFile = new EpisodeFile { Id = 1 }).Build();
|
||||
|
||||
Db.InsertMany(fakeEpisodes);
|
||||
Db.Insert(fakeSeries);
|
||||
@ -1212,7 +1213,7 @@ public void EpisodesWithFiles_success()
|
||||
.Build();
|
||||
|
||||
var episodeFile = Builder<EpisodeFile>.CreateNew()
|
||||
.With(c => c.EpisodeFileId = 1)
|
||||
.With(c => c.Id = 1)
|
||||
.With(c => c.Quality = Quality.SDTV)
|
||||
.Build();
|
||||
|
||||
@ -1288,7 +1289,7 @@ public void GetEpisodesByFileId_multi_episodes()
|
||||
.All()
|
||||
.With(c => c.SeriesId = 10)
|
||||
.With(c => c.SeasonNumber = 1)
|
||||
.With(c => c.EpisodeFile = new EpisodeFile { EpisodeFileId = 12345 })
|
||||
.With(c => c.EpisodeFile = new EpisodeFile { Id = 12345 })
|
||||
.Build();
|
||||
|
||||
Db.Insert(series);
|
||||
@ -1314,7 +1315,7 @@ public void GetEpisodesByFileId_single_episode()
|
||||
var fakeEpisode = Builder<Episode>.CreateNew()
|
||||
.With(c => c.SeriesId = 10)
|
||||
.With(c => c.SeasonNumber = 1)
|
||||
.With(c => c.EpisodeFile = new EpisodeFile { EpisodeFileId = 12345 })
|
||||
.With(c => c.EpisodeFile = new EpisodeFile { Id = 12345 })
|
||||
.Build();
|
||||
|
||||
Db.Insert(series);
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Repository;
|
||||
|
||||
|
@ -15,6 +15,7 @@ public interface IObjectDatabase : IDisposable
|
||||
IList<T> UpdateMany<T>(IList<T> objects) where T : ModelBase;
|
||||
void Delete<T>(T obj) where T : ModelBase;
|
||||
void DeleteMany<T>(IEnumerable<T> objects) where T : ModelBase;
|
||||
void UpdateField<T>(T model, string fieldName) where T : ModelBase;
|
||||
}
|
||||
|
||||
public static class SiaqodbLogger
|
||||
@ -22,8 +23,8 @@ public static class SiaqodbLogger
|
||||
public static void ListenTo(Siaqodb db)
|
||||
{
|
||||
db.DeletedObject += OnDeletedObject;
|
||||
db.LoadingObject +=OnLoadingObject;
|
||||
db.LoadedObject +=OnLoadedObject;
|
||||
db.LoadingObject += OnLoadingObject;
|
||||
db.LoadedObject += OnLoadedObject;
|
||||
}
|
||||
|
||||
private static void OnLoadedObject(object sender, LoadedObjectEventArgs e)
|
||||
@ -116,6 +117,11 @@ public void DeleteMany<T>(IEnumerable<T> objects) where T : ModelBase
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateField<T>(T model, string fieldName) where T : ModelBase
|
||||
{
|
||||
_db.UpdateObjectBy(model, fieldName);
|
||||
}
|
||||
|
||||
private IList<T> DoMany<T>(IEnumerable<T> objects, Func<T, T> function) where T : ModelBase
|
||||
{
|
||||
return objects.Select(function).ToList();
|
||||
|
@ -4,6 +4,7 @@
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Model.Notification;
|
||||
using NzbDrone.Core.Providers;
|
||||
@ -18,7 +19,7 @@ public class ImportNewSeriesJob : IJob
|
||||
{
|
||||
private readonly ISeriesService _seriesService;
|
||||
private readonly IEpisodeService _episodeService;
|
||||
private readonly MediaFileProvider _mediaFileProvider;
|
||||
private readonly IMediaFileService _mediaFileService;
|
||||
private readonly UpdateInfoJob _updateInfoJob;
|
||||
private readonly DiskScanJob _diskScanJob;
|
||||
private readonly BannerDownloadJob _bannerDownloadJob;
|
||||
@ -32,13 +33,13 @@ public class ImportNewSeriesJob : IJob
|
||||
private List<int> _attemptedSeries;
|
||||
|
||||
public ImportNewSeriesJob(ISeriesService seriesService, IEpisodeService episodeService,
|
||||
MediaFileProvider mediaFileProvider, UpdateInfoJob updateInfoJob,
|
||||
IMediaFileService mediaFileService, UpdateInfoJob updateInfoJob,
|
||||
DiskScanJob diskScanJob, BannerDownloadJob bannerDownloadJob,
|
||||
ISeasonRepository seasonRepository, XemUpdateJob xemUpdateJob, ISeriesRepository seriesRepository,ISeasonService seasonService)
|
||||
{
|
||||
_seriesService = seriesService;
|
||||
_episodeService = episodeService;
|
||||
_mediaFileProvider = mediaFileProvider;
|
||||
_mediaFileService = mediaFileService;
|
||||
_updateInfoJob = updateInfoJob;
|
||||
_diskScanJob = diskScanJob;
|
||||
_bannerDownloadJob = bannerDownloadJob;
|
||||
@ -108,7 +109,7 @@ public void AutoIgnoreSeasons(int seriesId)
|
||||
{
|
||||
//Todo: Need to convert this over to ObjectDb
|
||||
return;
|
||||
var episodeFiles = _mediaFileProvider.GetSeriesFiles(seriesId);
|
||||
var episodeFiles = _mediaFileService.GetFilesBySeries(seriesId);
|
||||
|
||||
if (episodeFiles.Count() != 0)
|
||||
{
|
||||
|
@ -3,6 +3,7 @@
|
||||
using System;
|
||||
using NLog;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Model.Notification;
|
||||
using NzbDrone.Core.Providers;
|
||||
@ -12,17 +13,17 @@ namespace NzbDrone.Core.Jobs
|
||||
{
|
||||
public class RefreshEpisodeMetadata : IJob
|
||||
{
|
||||
private readonly MediaFileProvider _mediaFileProvider;
|
||||
private readonly IMediaFileService _mediaFileService;
|
||||
private readonly ISeriesService _seriesService;
|
||||
private readonly MetadataProvider _metadataProvider;
|
||||
private readonly ISeriesRepository _seriesRepository;
|
||||
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public RefreshEpisodeMetadata(MediaFileProvider mediaFileProvider, ISeriesService seriesService,
|
||||
public RefreshEpisodeMetadata(IMediaFileService mediaFileService, ISeriesService seriesService,
|
||||
MetadataProvider metadataProvider,ISeriesRepository seriesRepository)
|
||||
{
|
||||
_mediaFileProvider = mediaFileProvider;
|
||||
_mediaFileService = mediaFileService;
|
||||
_seriesService = seriesService;
|
||||
_metadataProvider = metadataProvider;
|
||||
_seriesRepository = seriesRepository;
|
||||
@ -59,7 +60,7 @@ private void RefreshMetadata(ProgressNotification notification, Series series)
|
||||
notification.CurrentMessage = String.Format("Refreshing episode metadata for '{0}'", series.Title);
|
||||
|
||||
Logger.Debug("Getting episodes from database for series: {0}", series.Id);
|
||||
var episodeFiles = _mediaFileProvider.GetSeriesFiles(series.Id);
|
||||
var episodeFiles = _mediaFileService.GetFilesBySeries(series.Id);
|
||||
|
||||
if (episodeFiles == null || episodeFiles.Count == 0)
|
||||
{
|
||||
|
@ -5,6 +5,7 @@
|
||||
using NzbDrone.Common.Eventing;
|
||||
using NzbDrone.Core.Download;
|
||||
using NzbDrone.Core.ExternalNotification;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Model.Notification;
|
||||
using NzbDrone.Core.Providers;
|
||||
@ -13,7 +14,7 @@ namespace NzbDrone.Core.Jobs
|
||||
{
|
||||
public class RenameSeasonJob : IJob
|
||||
{
|
||||
private readonly MediaFileProvider _mediaFileProvider;
|
||||
private readonly IMediaFileService _mediaFileService;
|
||||
private readonly DiskScanProvider _diskScanProvider;
|
||||
private readonly ISeriesService _seriesService;
|
||||
private readonly MetadataProvider _metadataProvider;
|
||||
@ -22,10 +23,10 @@ public class RenameSeasonJob : IJob
|
||||
|
||||
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public RenameSeasonJob(MediaFileProvider mediaFileProvider, DiskScanProvider diskScanProvider, ISeriesService seriesService,
|
||||
public RenameSeasonJob(IMediaFileService mediaFileService, DiskScanProvider diskScanProvider, ISeriesService seriesService,
|
||||
MetadataProvider metadataProvider, ISeriesRepository seriesRepository, IEventAggregator eventAggregator)
|
||||
{
|
||||
_mediaFileProvider = mediaFileProvider;
|
||||
_mediaFileService = mediaFileService;
|
||||
_diskScanProvider = diskScanProvider;
|
||||
_seriesService = seriesService;
|
||||
_metadataProvider = metadataProvider;
|
||||
@ -56,7 +57,7 @@ public void Start(ProgressNotification notification, dynamic options)
|
||||
notification.CurrentMessage = String.Format("Renaming episodes for {0} Season {1}", series.Title, options.SeasonNumber);
|
||||
|
||||
logger.Debug("Getting episodes from database for series: {0} and season: {1}", options.SeriesId, options.SeasonNumber);
|
||||
IList<EpisodeFile> episodeFiles = _mediaFileProvider.GetSeasonFiles((int)options.SeriesId, (int)options.SeasonNumber);
|
||||
IList<EpisodeFile> episodeFiles = _mediaFileService.GetFilesBySeason((int)options.SeriesId, (int)options.SeasonNumber);
|
||||
|
||||
if (episodeFiles == null || !episodeFiles.Any())
|
||||
{
|
||||
|
@ -4,6 +4,7 @@
|
||||
using NLog;
|
||||
using NzbDrone.Common.Eventing;
|
||||
using NzbDrone.Core.Download;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Model.Notification;
|
||||
using NzbDrone.Core.Providers;
|
||||
@ -12,7 +13,7 @@ namespace NzbDrone.Core.Jobs
|
||||
{
|
||||
public class RenameSeriesJob : IJob
|
||||
{
|
||||
private readonly MediaFileProvider _mediaFileProvider;
|
||||
private readonly IMediaFileService _mediaFileService;
|
||||
private readonly DiskScanProvider _diskScanProvider;
|
||||
private readonly MetadataProvider _metadataProvider;
|
||||
private readonly ISeriesRepository _seriesRepository;
|
||||
@ -20,10 +21,10 @@ public class RenameSeriesJob : IJob
|
||||
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public RenameSeriesJob(MediaFileProvider mediaFileProvider, DiskScanProvider diskScanProvider,
|
||||
public RenameSeriesJob(IMediaFileService mediaFileService, DiskScanProvider diskScanProvider,
|
||||
MetadataProvider metadataProvider,ISeriesRepository seriesRepository,IEventAggregator eventAggregator)
|
||||
{
|
||||
_mediaFileProvider = mediaFileProvider;
|
||||
_mediaFileService = mediaFileService;
|
||||
_diskScanProvider = diskScanProvider;
|
||||
_metadataProvider = metadataProvider;
|
||||
_seriesRepository = seriesRepository;
|
||||
@ -59,7 +60,7 @@ public void Start(ProgressNotification notification, dynamic options)
|
||||
notification.CurrentMessage = String.Format("Renaming episodes for '{0}'", series.Title);
|
||||
|
||||
Logger.Debug("Getting episodes from database for series: {0}", series.Id);
|
||||
var episodeFiles = _mediaFileProvider.GetSeriesFiles(series.Id);
|
||||
var episodeFiles = _mediaFileService.GetFilesBySeries(series.Id);
|
||||
|
||||
if (episodeFiles == null || episodeFiles.Count == 0)
|
||||
{
|
||||
|
@ -1,11 +1,12 @@
|
||||
using System.Linq;
|
||||
using System;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using PetaPoco;
|
||||
using NzbDrone.Core.Tv;
|
||||
|
||||
namespace NzbDrone.Core.Tv
|
||||
namespace NzbDrone.Core.MediaFiles
|
||||
{
|
||||
public class EpisodeFile
|
||||
public class EpisodeFile : ModelBase
|
||||
{
|
||||
public EpisodeFile()
|
||||
{
|
||||
@ -14,7 +15,7 @@ public EpisodeFile()
|
||||
|
||||
public EpisodeFile(EpisodeFile source)
|
||||
{
|
||||
EpisodeFileId = source.EpisodeFileId;
|
||||
Id = source.Id;
|
||||
SeriesId = source.SeriesId;
|
||||
SeasonNumber = source.SeasonNumber;
|
||||
Path = source.Path;
|
||||
@ -23,8 +24,6 @@ public EpisodeFile(EpisodeFile source)
|
||||
Size = source.Size;
|
||||
}
|
||||
|
||||
public int EpisodeFileId { get; set; }
|
||||
|
||||
public int SeriesId { get; set; }
|
||||
public int SeasonNumber { get; set; }
|
||||
public string Path { get; set; }
|
39
NzbDrone.Core/MediaFiles/MediaFileRepository.cs
Normal file
39
NzbDrone.Core/MediaFiles/MediaFileRepository.cs
Normal file
@ -0,0 +1,39 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NzbDrone.Core.Datastore;
|
||||
|
||||
namespace NzbDrone.Core.MediaFiles
|
||||
{
|
||||
public interface IMediaFileRepository : IBasicRepository<EpisodeFile>
|
||||
{
|
||||
EpisodeFile GetFileByPath(string path);
|
||||
List<EpisodeFile> GetFilesBySeries(int seriesId);
|
||||
List<EpisodeFile> GetFilesBySeason(int seriesId, int seasonNumber);
|
||||
}
|
||||
|
||||
|
||||
public class MediaFileRepository : BasicRepository<EpisodeFile>, IMediaFileRepository
|
||||
{
|
||||
public MediaFileRepository(IObjectDatabase objectDatabase)
|
||||
: base(objectDatabase)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public EpisodeFile GetFileByPath(string path)
|
||||
{
|
||||
return Queryable.SingleOrDefault(c => c.Path == path);
|
||||
}
|
||||
|
||||
public List<EpisodeFile> GetFilesBySeries(int seriesId)
|
||||
{
|
||||
return Queryable.Where(c => c.SeriesId == seriesId).ToList();
|
||||
}
|
||||
|
||||
public List<EpisodeFile> GetFilesBySeason(int seriesId, int seasonNumber)
|
||||
{
|
||||
return Queryable.Where(c => c.SeriesId == seriesId && c.SeasonNumber == seasonNumber).ToList();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
214
NzbDrone.Core/MediaFiles/MediaFileService.cs
Normal file
214
NzbDrone.Core/MediaFiles/MediaFileService.cs
Normal file
@ -0,0 +1,214 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Helpers;
|
||||
|
||||
namespace NzbDrone.Core.MediaFiles
|
||||
{
|
||||
public interface IMediaFileService
|
||||
{
|
||||
EpisodeFile Add(EpisodeFile episodeFile);
|
||||
void Update(EpisodeFile episodeFile);
|
||||
void Delete(int episodeFileId);
|
||||
bool Exists(string path);
|
||||
EpisodeFile GetFileByPath(string path);
|
||||
IList<EpisodeFile> GetFilesBySeries(int seriesId);
|
||||
IList<EpisodeFile> GetFilesBySeason(int seriesId, int seasonNumber);
|
||||
FileInfo CalculateFilePath(Series series, int seasonNumber, string fileName, string extention);
|
||||
string GetNewFilename(IList<Episode> episodes, Series series, Quality quality, bool proper, EpisodeFile episodeFile);
|
||||
}
|
||||
|
||||
public class MediaFileService : IMediaFileService
|
||||
{
|
||||
private readonly IConfigService _configService;
|
||||
private readonly IEpisodeService _episodeService;
|
||||
private readonly Logger _logger;
|
||||
private readonly IMediaFileRepository _mediaFileRepository;
|
||||
|
||||
|
||||
public MediaFileService(IMediaFileRepository mediaFileRepository, IConfigService configService, IEpisodeService episodeService, Logger logger)
|
||||
{
|
||||
_mediaFileRepository = mediaFileRepository;
|
||||
_configService = configService;
|
||||
_episodeService = episodeService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public EpisodeFile Add(EpisodeFile episodeFile)
|
||||
{
|
||||
return _mediaFileRepository.Insert(episodeFile);
|
||||
}
|
||||
|
||||
public void Update(EpisodeFile episodeFile)
|
||||
{
|
||||
_mediaFileRepository.Update(episodeFile);
|
||||
}
|
||||
|
||||
public void Delete(int episodeFileId)
|
||||
{
|
||||
_mediaFileRepository.Delete(episodeFileId);
|
||||
|
||||
var ep = _episodeService.GetEpisodesByFileId(episodeFileId);
|
||||
|
||||
foreach (var episode in ep)
|
||||
{
|
||||
_episodeService.SetEpisodeIgnore(episode.Id, true);
|
||||
}
|
||||
}
|
||||
|
||||
public bool Exists(string path)
|
||||
{
|
||||
return GetFileByPath(path) != null;
|
||||
}
|
||||
|
||||
public EpisodeFile GetFileByPath(string path)
|
||||
{
|
||||
return _mediaFileRepository.GetFileByPath(path.Normalize());
|
||||
}
|
||||
|
||||
public IList<EpisodeFile> GetFilesBySeries(int seriesId)
|
||||
{
|
||||
return _mediaFileRepository.GetFilesBySeries(seriesId);
|
||||
}
|
||||
|
||||
public IList<EpisodeFile> GetFilesBySeason(int seriesId, int seasonNumber)
|
||||
{
|
||||
return _mediaFileRepository.GetFilesBySeason(seriesId, seasonNumber);
|
||||
}
|
||||
|
||||
|
||||
public FileInfo CalculateFilePath(Series series, int seasonNumber, string fileName, string extention)
|
||||
{
|
||||
string path = series.Path;
|
||||
if (series.SeasonFolder)
|
||||
{
|
||||
var seasonFolder = _configService.SortingSeasonFolderFormat
|
||||
.Replace("%0s", seasonNumber.ToString("00"))
|
||||
.Replace("%s", seasonNumber.ToString());
|
||||
|
||||
path = Path.Combine(path, seasonFolder);
|
||||
}
|
||||
|
||||
path = Path.Combine(path, fileName + extention);
|
||||
|
||||
return new FileInfo(path);
|
||||
}
|
||||
|
||||
|
||||
public string GetNewFilename(IList<Episode> episodes, Series series, Quality quality, bool proper, EpisodeFile episodeFile)
|
||||
{
|
||||
if (_configService.SortingUseSceneName)
|
||||
{
|
||||
_logger.Trace("Attempting to use scene name");
|
||||
if (String.IsNullOrWhiteSpace(episodeFile.SceneName))
|
||||
{
|
||||
var name = Path.GetFileNameWithoutExtension(episodeFile.Path);
|
||||
_logger.Trace("Unable to use scene name, because it is null, sticking with current name: {0}", name);
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
return episodeFile.SceneName;
|
||||
}
|
||||
|
||||
var sortedEpisodes = episodes.OrderBy(e => e.EpisodeNumber);
|
||||
|
||||
var separatorStyle = EpisodeSortingHelper.GetSeparatorStyle(_configService.SortingSeparatorStyle);
|
||||
var numberStyle = EpisodeSortingHelper.GetNumberStyle(_configService.SortingNumberStyle);
|
||||
|
||||
var episodeNames = new List<String>();
|
||||
|
||||
episodeNames.Add(Parser.CleanupEpisodeTitle(sortedEpisodes.First().Title));
|
||||
|
||||
string result = String.Empty;
|
||||
|
||||
if (_configService.SortingIncludeSeriesName)
|
||||
{
|
||||
result += series.Title + separatorStyle.Pattern;
|
||||
}
|
||||
|
||||
if (series.SeriesType == SeriesType.Standard)
|
||||
{
|
||||
result += numberStyle.Pattern.Replace("%0e",
|
||||
String.Format("{0:00}", sortedEpisodes.First().EpisodeNumber));
|
||||
|
||||
if (episodes.Count > 1)
|
||||
{
|
||||
var multiEpisodeStyle =
|
||||
EpisodeSortingHelper.GetMultiEpisodeStyle(_configService.SortingMultiEpisodeStyle);
|
||||
|
||||
foreach (var episode in sortedEpisodes.Skip(1))
|
||||
{
|
||||
if (multiEpisodeStyle.Name == "Duplicate")
|
||||
{
|
||||
result += separatorStyle.Pattern + numberStyle.Pattern;
|
||||
}
|
||||
else
|
||||
{
|
||||
result += multiEpisodeStyle.Pattern;
|
||||
}
|
||||
|
||||
result = result.Replace("%0e", String.Format("{0:00}", episode.EpisodeNumber));
|
||||
episodeNames.Add(Parser.CleanupEpisodeTitle(episode.Title));
|
||||
}
|
||||
}
|
||||
|
||||
result = result
|
||||
.Replace("%s", String.Format("{0}", episodes.First().SeasonNumber))
|
||||
.Replace("%0s", String.Format("{0:00}", episodes.First().SeasonNumber))
|
||||
.Replace("%x", numberStyle.EpisodeSeparator)
|
||||
.Replace("%p", separatorStyle.Pattern);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
if (episodes.First().AirDate.HasValue)
|
||||
result += episodes.First().AirDate.Value.ToString("yyyy-MM-dd");
|
||||
|
||||
else
|
||||
result += "Unknown";
|
||||
}
|
||||
|
||||
if (_configService.SortingIncludeEpisodeTitle)
|
||||
{
|
||||
if (episodeNames.Distinct().Count() == 1)
|
||||
result += separatorStyle.Pattern + episodeNames.First();
|
||||
|
||||
else
|
||||
result += separatorStyle.Pattern + String.Join(" + ", episodeNames.Distinct());
|
||||
}
|
||||
|
||||
if (_configService.SortingAppendQuality)
|
||||
{
|
||||
result += String.Format(" [{0}]", quality);
|
||||
|
||||
if (proper)
|
||||
result += " [Proper]";
|
||||
}
|
||||
|
||||
if (_configService.SortingReplaceSpaces)
|
||||
result = result.Replace(' ', '.');
|
||||
|
||||
_logger.Trace("New File Name is: [{0}]", result.Trim());
|
||||
return CleanFilename(result.Trim());
|
||||
}
|
||||
|
||||
|
||||
public static string CleanFilename(string name)
|
||||
{
|
||||
string result = name;
|
||||
string[] badCharacters = { "\\", "/", "<", ">", "?", "*", ":", "|", "\"" };
|
||||
string[] goodCharacters = { "+", "+", "{", "}", "!", "@", "-", "#", "`" };
|
||||
|
||||
for (int i = 0; i < badCharacters.Length; i++)
|
||||
result = result.Replace(badCharacters[i], goodCharacters[i]);
|
||||
|
||||
return result.Trim();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Providers;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Repository;
|
||||
@ -76,7 +77,7 @@ public override string ToString()
|
||||
|
||||
public string GetDownloadTitle()
|
||||
{
|
||||
var seriesTitle = MediaFileProvider.CleanFilename(Series.Title);
|
||||
var seriesTitle = MediaFileService.CleanFilename(Series.Title);
|
||||
|
||||
//Handle Full Naming
|
||||
if (FullSeason)
|
||||
|
@ -285,6 +285,7 @@
|
||||
<Compile Include="Jobs\RefreshEpsiodeMetadata.cs" />
|
||||
<Compile Include="Jobs\PastWeekBacklogSearchJob.cs" />
|
||||
<Compile Include="Lifecycle\IInitializable.cs" />
|
||||
<Compile Include="MediaFiles\MediaFileRepository.cs" />
|
||||
<Compile Include="Model\DownloadClientType.cs" />
|
||||
<Compile Include="Instrumentation\LogService.cs" />
|
||||
<Compile Include="Instrumentation\DatabaseTarget.cs" />
|
||||
@ -508,7 +509,7 @@
|
||||
<Compile Include="Indexers\SyndicationFeedXmlReader.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Providers\MediaFileProvider.cs">
|
||||
<Compile Include="MediaFiles\MediaFileService.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Providers\MisnamedProvider.cs">
|
||||
@ -582,7 +583,7 @@
|
||||
<Compile Include="Model\EpisodeStatusType.cs" />
|
||||
<Compile Include="Model\Sabnzbd\SabPriorityType.cs" />
|
||||
<Compile Include="Model\SeasonParseResult.cs" />
|
||||
<Compile Include="Tv\EpisodeFile.cs" />
|
||||
<Compile Include="MediaFiles\EpisodeFile.cs" />
|
||||
<Compile Include="Model\Notification\ProgressNotificationStatus.cs" />
|
||||
<Compile Include="Parser.cs" />
|
||||
<Compile Include="Model\Notification\ProgressNotification.cs" />
|
||||
|
@ -8,6 +8,7 @@
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.Download;
|
||||
using NzbDrone.Core.ExternalNotification;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Model;
|
||||
|
||||
@ -19,7 +20,7 @@ public class DiskScanProvider
|
||||
private static readonly string[] mediaExtentions = new[] { ".mkv", ".avi", ".wmv", ".mp4", ".mpg", ".mpeg", ".xvid", ".flv", ".mov", ".rm", ".rmvb", ".divx", ".dvr-ms", ".ts", ".ogm", ".m4v", ".strm" };
|
||||
private readonly DiskProvider _diskProvider;
|
||||
private readonly IEpisodeService _episodeService;
|
||||
private readonly MediaFileProvider _mediaFileProvider;
|
||||
private readonly IMediaFileService _mediaFileService;
|
||||
private readonly SignalRProvider _signalRProvider;
|
||||
private readonly IConfigService _configService;
|
||||
private readonly RecycleBinProvider _recycleBinProvider;
|
||||
@ -27,13 +28,13 @@ public class DiskScanProvider
|
||||
private readonly ISeriesRepository _seriesRepository;
|
||||
private readonly IEventAggregator _eventAggregator;
|
||||
|
||||
public DiskScanProvider(DiskProvider diskProvider, IEpisodeService episodeService, MediaFileProvider mediaFileProvider,
|
||||
public DiskScanProvider(DiskProvider diskProvider, IEpisodeService episodeService, IMediaFileService mediaFileService,
|
||||
SignalRProvider signalRProvider, IConfigService configService,
|
||||
RecycleBinProvider recycleBinProvider, MediaInfoProvider mediaInfoProvider, ISeriesRepository seriesRepository, IEventAggregator eventAggregator)
|
||||
{
|
||||
_diskProvider = diskProvider;
|
||||
_episodeService = episodeService;
|
||||
_mediaFileProvider = mediaFileProvider;
|
||||
_mediaFileService = mediaFileService;
|
||||
_signalRProvider = signalRProvider;
|
||||
_configService = configService;
|
||||
_recycleBinProvider = recycleBinProvider;
|
||||
@ -62,8 +63,6 @@ public virtual List<EpisodeFile> Scan(Series series)
|
||||
/// <param name="path">Path to scan</param>
|
||||
public virtual List<EpisodeFile> Scan(Series series, string path)
|
||||
{
|
||||
_mediaFileProvider.CleanUpDatabase();
|
||||
|
||||
if (!_diskProvider.FolderExists(path))
|
||||
{
|
||||
Logger.Warn("Series folder doesn't exist: {0}", path);
|
||||
@ -76,7 +75,7 @@ public virtual List<EpisodeFile> Scan(Series series, string path)
|
||||
return new List<EpisodeFile>();
|
||||
}
|
||||
|
||||
var seriesFile = _mediaFileProvider.GetSeriesFiles(series.Id);
|
||||
var seriesFile = _mediaFileService.GetFilesBySeries(series.Id);
|
||||
CleanUp(seriesFile);
|
||||
|
||||
var mediaFileList = GetVideoFiles(path);
|
||||
@ -104,7 +103,7 @@ public virtual EpisodeFile ImportFile(Series series, string filePath)
|
||||
{
|
||||
Logger.Trace("Importing file to database [{0}]", filePath);
|
||||
|
||||
if (_mediaFileProvider.Exists(filePath))
|
||||
if (_mediaFileService.Exists(filePath))
|
||||
{
|
||||
Logger.Trace("[{0}] already exists in the database. skipping.", filePath);
|
||||
return null;
|
||||
@ -169,7 +168,7 @@ public virtual EpisodeFile ImportFile(Series series, string filePath)
|
||||
|
||||
//Todo: We shouldn't actually import the file until we confirm its the only one we want.
|
||||
//Todo: Separate episodeFile creation from importing (pass file to import to import)
|
||||
_mediaFileProvider.Add(episodeFile);
|
||||
_mediaFileService.Add(episodeFile);
|
||||
|
||||
//Link file to all episodes
|
||||
foreach (var ep in episodes)
|
||||
@ -189,9 +188,9 @@ public virtual EpisodeFile MoveEpisodeFile(EpisodeFile episodeFile, bool newDown
|
||||
throw new ArgumentNullException("episodeFile");
|
||||
|
||||
var series = _seriesRepository.Get(episodeFile.SeriesId);
|
||||
var episodes = _episodeService.GetEpisodesByFileId(episodeFile.EpisodeFileId);
|
||||
string newFileName = _mediaFileProvider.GetNewFilename(episodes, series, episodeFile.Quality, episodeFile.Proper, episodeFile);
|
||||
var newFile = _mediaFileProvider.CalculateFilePath(series, episodes.First().SeasonNumber, newFileName, Path.GetExtension(episodeFile.Path));
|
||||
var episodes = _episodeService.GetEpisodesByFileId(episodeFile.Id);
|
||||
string newFileName = _mediaFileService.GetNewFilename(episodes, series, episodeFile.Quality, episodeFile.Proper, episodeFile);
|
||||
var newFile = _mediaFileService.CalculateFilePath(series, episodes.First().SeasonNumber, newFileName, Path.GetExtension(episodeFile.Path));
|
||||
|
||||
//Only rename if existing and new filenames don't match
|
||||
if (DiskProvider.PathEquals(episodeFile.Path, newFile.FullName))
|
||||
@ -223,7 +222,7 @@ public virtual EpisodeFile MoveEpisodeFile(EpisodeFile episodeFile, bool newDown
|
||||
}
|
||||
|
||||
episodeFile.Path = newFile.FullName;
|
||||
_mediaFileProvider.Update(episodeFile);
|
||||
_mediaFileService.Update(episodeFile);
|
||||
|
||||
var parseResult = Parser.ParsePath(episodeFile.Path);
|
||||
parseResult.Series = series;
|
||||
@ -257,7 +256,7 @@ public virtual void CleanUp(IList<EpisodeFile> files)
|
||||
Logger.Trace("File [{0}] no longer exists on disk. removing from db", episodeFile.Path);
|
||||
|
||||
//Set the EpisodeFileId for each episode attached to this file to 0
|
||||
foreach (var episode in _episodeService.GetEpisodesByFileId(episodeFile.EpisodeFileId))
|
||||
foreach (var episode in _episodeService.GetEpisodesByFileId(episodeFile.Id))
|
||||
{
|
||||
Logger.Trace("Detaching episode {0} from file.", episode.Id);
|
||||
episode.EpisodeFile = null;
|
||||
@ -269,12 +268,12 @@ public virtual void CleanUp(IList<EpisodeFile> files)
|
||||
|
||||
//Delete it from the DB
|
||||
Logger.Trace("Removing EpisodeFile from DB.");
|
||||
_mediaFileProvider.Delete(episodeFile.EpisodeFileId);
|
||||
_mediaFileService.Delete(episodeFile.Id);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var message = String.Format("Unable to cleanup EpisodeFile in DB: {0}", episodeFile.EpisodeFileId);
|
||||
var message = String.Format("Unable to cleanup EpisodeFile in DB: {0}", episodeFile.Id);
|
||||
Logger.ErrorException(message, ex);
|
||||
}
|
||||
}
|
||||
@ -290,7 +289,7 @@ public virtual void CleanUpDropFolder(string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
var episodeFile = _mediaFileProvider.GetFileByPath(file);
|
||||
var episodeFile = _mediaFileService.GetFileByPath(file);
|
||||
|
||||
if (episodeFile != null)
|
||||
{
|
||||
|
@ -5,6 +5,7 @@
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.History;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Providers.Core;
|
||||
using NzbDrone.Core.DecisionEngine;
|
||||
@ -38,7 +39,7 @@ public virtual bool DownloadNzb(string url, string title, bool recentlyAired)
|
||||
{
|
||||
try
|
||||
{
|
||||
title = MediaFileProvider.CleanFilename(title);
|
||||
title = MediaFileService.CleanFilename(title);
|
||||
|
||||
var filename = Path.Combine(_configService.BlackholeDirectory, title + ".nzb");
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
using NLog;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Providers.Core;
|
||||
using NzbDrone.Core.DecisionEngine;
|
||||
@ -43,7 +44,7 @@ public virtual bool DownloadNzb(string url, string title, bool recentlyAired)
|
||||
return false;
|
||||
}
|
||||
|
||||
title = MediaFileProvider.CleanFilename(title);
|
||||
title = MediaFileService.CleanFilename(title);
|
||||
|
||||
//Save to the Pneumatic directory (The user will need to ensure its accessible by XBMC)
|
||||
var filename = Path.Combine(_configService.PneumaticDirectory, title + ".nzb");
|
||||
|
@ -1,265 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Helpers;
|
||||
using NzbDrone.Core.Providers.Core;
|
||||
using NzbDrone.Core.Repository;
|
||||
using PetaPoco;
|
||||
using NzbDrone.Common;
|
||||
|
||||
namespace NzbDrone.Core.Providers
|
||||
{
|
||||
public class MediaFileProvider
|
||||
{
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
private readonly IConfigService _configService;
|
||||
private readonly IDatabase _database;
|
||||
private readonly IEpisodeService _episodeService;
|
||||
|
||||
public MediaFileProvider(IEpisodeService episodeService, IConfigService configService, IDatabase database)
|
||||
{
|
||||
_episodeService = episodeService;
|
||||
_configService = configService;
|
||||
_database = database;
|
||||
}
|
||||
|
||||
public MediaFileProvider()
|
||||
{
|
||||
}
|
||||
|
||||
public virtual int Add(EpisodeFile episodeFile)
|
||||
{
|
||||
return Convert.ToInt32(_database.Insert(episodeFile));
|
||||
}
|
||||
|
||||
public virtual void Update(EpisodeFile episodeFile)
|
||||
{
|
||||
_database.Update(episodeFile);
|
||||
}
|
||||
|
||||
public virtual void Delete(int episodeFileId)
|
||||
{
|
||||
_database.Delete<EpisodeFile>(episodeFileId);
|
||||
}
|
||||
|
||||
public virtual bool Exists(string path)
|
||||
{
|
||||
return _database.Exists<EpisodeFile>("WHERE Path =@0", path.NormalizePath());
|
||||
}
|
||||
|
||||
public virtual EpisodeFile GetFileByPath(string path)
|
||||
{
|
||||
return _database.SingleOrDefault<EpisodeFile>("WHERE Path =@0", path.NormalizePath());
|
||||
}
|
||||
|
||||
public virtual EpisodeFile GetEpisodeFile(int episodeFileId)
|
||||
{
|
||||
return _database.Single<EpisodeFile>(episodeFileId);
|
||||
}
|
||||
|
||||
public virtual List<EpisodeFile> GetEpisodeFiles()
|
||||
{
|
||||
return _database.Fetch<EpisodeFile>();
|
||||
}
|
||||
|
||||
public virtual IList<EpisodeFile> GetSeriesFiles(int seriesId)
|
||||
{
|
||||
return _database.Fetch<EpisodeFile>("WHERE SeriesId= @0", seriesId);
|
||||
}
|
||||
|
||||
public virtual IList<EpisodeFile> GetSeasonFiles(int seriesId, int seasonNumber)
|
||||
{
|
||||
return _database.Fetch<EpisodeFile>("WHERE SeriesId= @0 AND SeasonNumber = @1", seriesId, seasonNumber);
|
||||
}
|
||||
|
||||
public virtual Tuple<int, int> GetEpisodeFilesCount(int seriesId)
|
||||
{
|
||||
var allEpisodes = _episodeService.GetEpisodeBySeries(seriesId).ToList();
|
||||
|
||||
var episodeTotal = allEpisodes.Where(e => !e.Ignored && e.AirDate != null && e.AirDate <= DateTime.Today).ToList();
|
||||
var avilableEpisodes = episodeTotal.Where(e => e.EpisodeFileId > 0).ToList();
|
||||
|
||||
return new Tuple<int, int>(avilableEpisodes.Count, episodeTotal.Count);
|
||||
}
|
||||
|
||||
public virtual FileInfo CalculateFilePath(Series series, int seasonNumber, string fileName, string extention)
|
||||
{
|
||||
string path = series.Path;
|
||||
if (series.SeasonFolder)
|
||||
{
|
||||
var seasonFolder = _configService.SortingSeasonFolderFormat
|
||||
.Replace("%0s", seasonNumber.ToString("00"))
|
||||
.Replace("%s", seasonNumber.ToString());
|
||||
|
||||
path = Path.Combine(path, seasonFolder);
|
||||
}
|
||||
|
||||
path = Path.Combine(path, fileName + extention);
|
||||
|
||||
return new FileInfo(path);
|
||||
}
|
||||
|
||||
public virtual void CleanUpDatabase()
|
||||
{
|
||||
Logger.Trace("Verifying Episode > Episode file relationships.");
|
||||
|
||||
string updateString = "UPDATE Episodes SET EpisodeFileId = 0, GrabDate = NULL, PostDownloadStatus = 0";
|
||||
|
||||
if (_configService.AutoIgnorePreviouslyDownloadedEpisodes)
|
||||
{
|
||||
updateString += ", Ignored = 1";
|
||||
}
|
||||
|
||||
var updated = _database.Execute(updateString +
|
||||
@"WHERE EpisodeFileId IN
|
||||
(SELECT Episodes.EpisodeFileId FROM Episodes
|
||||
LEFT OUTER JOIN EpisodeFiles
|
||||
ON Episodes.EpisodeFileId = EpisodeFiles.EpisodeFileId
|
||||
WHERE Episodes.EpisodeFileId > 0 AND EpisodeFiles.EpisodeFileId IS NULL)");
|
||||
|
||||
if (updated > 0)
|
||||
{
|
||||
Logger.Debug("Removed {0} invalid links to episode files.", updated);
|
||||
}
|
||||
|
||||
Logger.Trace("Deleting orphan files.");
|
||||
|
||||
updated = _database.Execute(@"DELETE FROM EpisodeFiles
|
||||
WHERE EpisodeFileId IN
|
||||
(SELECT EpisodeFiles.EpisodeFileId FROM EpisodeFiles
|
||||
LEFT OUTER JOIN Episodes
|
||||
ON EpisodeFiles.EpisodeFileId = Episodes.EpisodeFileId
|
||||
WHERE Episodes.EpisodeFileId IS NULL)");
|
||||
|
||||
if (updated > 0)
|
||||
{
|
||||
Logger.Debug("Removed {0} orphan file(s) from database.", updated);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual string GetNewFilename(IList<Episode> episodes, Series series, Quality quality, bool proper, EpisodeFile episodeFile)
|
||||
{
|
||||
if (_configService.SortingUseSceneName)
|
||||
{
|
||||
Logger.Trace("Attempting to use scene name");
|
||||
if (String.IsNullOrWhiteSpace(episodeFile.SceneName))
|
||||
{
|
||||
var name = Path.GetFileNameWithoutExtension(episodeFile.Path);
|
||||
Logger.Trace("Unable to use scene name, because it is null, sticking with current name: {0}", name);
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
return episodeFile.SceneName;
|
||||
}
|
||||
|
||||
var sortedEpisodes = episodes.OrderBy(e => e.EpisodeNumber);
|
||||
|
||||
var separatorStyle = EpisodeSortingHelper.GetSeparatorStyle(_configService.SortingSeparatorStyle);
|
||||
var numberStyle = EpisodeSortingHelper.GetNumberStyle(_configService.SortingNumberStyle);
|
||||
|
||||
var episodeNames = new List<String>();
|
||||
|
||||
episodeNames.Add(Parser.CleanupEpisodeTitle(sortedEpisodes.First().Title));
|
||||
|
||||
string result = String.Empty;
|
||||
|
||||
if (_configService.SortingIncludeSeriesName)
|
||||
{
|
||||
result += series.Title + separatorStyle.Pattern;
|
||||
}
|
||||
|
||||
if (series.SeriesType == SeriesType.Standard)
|
||||
{
|
||||
result += numberStyle.Pattern.Replace("%0e",
|
||||
String.Format("{0:00}", sortedEpisodes.First().EpisodeNumber));
|
||||
|
||||
if(episodes.Count > 1)
|
||||
{
|
||||
var multiEpisodeStyle =
|
||||
EpisodeSortingHelper.GetMultiEpisodeStyle(_configService.SortingMultiEpisodeStyle);
|
||||
|
||||
foreach(var episode in sortedEpisodes.Skip(1))
|
||||
{
|
||||
if(multiEpisodeStyle.Name == "Duplicate")
|
||||
{
|
||||
result += separatorStyle.Pattern + numberStyle.Pattern;
|
||||
}
|
||||
else
|
||||
{
|
||||
result += multiEpisodeStyle.Pattern;
|
||||
}
|
||||
|
||||
result = result.Replace("%0e", String.Format("{0:00}", episode.EpisodeNumber));
|
||||
episodeNames.Add(Parser.CleanupEpisodeTitle(episode.Title));
|
||||
}
|
||||
}
|
||||
|
||||
result = result
|
||||
.Replace("%s", String.Format("{0}", episodes.First().SeasonNumber))
|
||||
.Replace("%0s", String.Format("{0:00}", episodes.First().SeasonNumber))
|
||||
.Replace("%x", numberStyle.EpisodeSeparator)
|
||||
.Replace("%p", separatorStyle.Pattern);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
if(episodes.First().AirDate.HasValue)
|
||||
result += episodes.First().AirDate.Value.ToString("yyyy-MM-dd");
|
||||
|
||||
else
|
||||
result += "Unknown";
|
||||
}
|
||||
|
||||
if (_configService.SortingIncludeEpisodeTitle)
|
||||
{
|
||||
if (episodeNames.Distinct().Count() == 1)
|
||||
result += separatorStyle.Pattern + episodeNames.First();
|
||||
|
||||
else
|
||||
result += separatorStyle.Pattern + String.Join(" + ", episodeNames.Distinct());
|
||||
}
|
||||
|
||||
if (_configService.SortingAppendQuality)
|
||||
{
|
||||
result += String.Format(" [{0}]", quality);
|
||||
|
||||
if (proper)
|
||||
result += " [Proper]";
|
||||
}
|
||||
|
||||
if (_configService.SortingReplaceSpaces)
|
||||
result = result.Replace(' ', '.');
|
||||
|
||||
Logger.Trace("New File Name is: [{0}]", result.Trim());
|
||||
return CleanFilename(result.Trim());
|
||||
}
|
||||
|
||||
public virtual void ChangeQuality(int episodeFileId, Quality quality)
|
||||
{
|
||||
_database.Execute("UPDATE EpisodeFiles SET Quality = @quality WHERE EpisodeFileId = @episodeFileId", new { episodeFileId, quality });
|
||||
}
|
||||
|
||||
public virtual void ChangeQuality(int seriesId, int seasonNumber, Quality quality)
|
||||
{
|
||||
_database.Execute("UPDATE EpisodeFiles SET Quality = @quality WHERE SeriesId = @seriesId AND SeasonNumber = @seasonNumber", new { seriesId, seasonNumber, quality });
|
||||
}
|
||||
|
||||
public static string CleanFilename(string name)
|
||||
{
|
||||
string result = name;
|
||||
string[] badCharacters = { "\\", "/", "<", ">", "?", "*", ":", "|", "\"" };
|
||||
string[] goodCharacters = { "+", "+", "{", "}", "!", "@", "-", "#", "`" };
|
||||
|
||||
for (int i = 0; i < badCharacters.Length; i++)
|
||||
result = result.Replace(badCharacters[i], goodCharacters[i]);
|
||||
|
||||
return result.Trim();
|
||||
}
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
using NLog;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Providers.Core;
|
||||
|
@ -7,6 +7,7 @@
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Providers.Core;
|
||||
@ -115,11 +116,11 @@ public override void CreateForSeries(Series series, TvdbSeries tvDbSeries)
|
||||
public override void CreateForEpisodeFile(EpisodeFile episodeFile, TvdbSeries tvDbSeries)
|
||||
{
|
||||
//Create filename.tbn and filename.nfo
|
||||
var episodes = _episodeService.GetEpisodesByFileId(episodeFile.EpisodeFileId);
|
||||
var episodes = _episodeService.GetEpisodesByFileId(episodeFile.Id);
|
||||
|
||||
if (!episodes.Any())
|
||||
{
|
||||
_logger.Debug("No episodes where found for this episode file: {0}", episodeFile.EpisodeFileId);
|
||||
_logger.Debug("No episodes where found for this episode file: {0}", episodeFile.Id);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -137,7 +138,7 @@ public override void CreateForEpisodeFile(EpisodeFile episodeFile, TvdbSeries tv
|
||||
{
|
||||
if (!_diskProvider.FileExists(episodeFile.Path.Replace(Path.GetExtension(episodeFile.Path), ".tbn")))
|
||||
{
|
||||
_logger.Debug("Downloading episode thumbnail for: {0}", episodeFile.EpisodeFileId);
|
||||
_logger.Debug("Downloading episode thumbnail for: {0}", episodeFile.Id);
|
||||
_bannerProvider.Download(episodeFileThumbnail.BannerPath,
|
||||
episodeFile.Path.Replace(Path.GetExtension(episodeFile.Path), ".tbn"));
|
||||
}
|
||||
@ -145,7 +146,7 @@ public override void CreateForEpisodeFile(EpisodeFile episodeFile, TvdbSeries tv
|
||||
|
||||
|
||||
|
||||
_logger.Debug("Generating filename.nfo for: {0}", episodeFile.EpisodeFileId);
|
||||
_logger.Debug("Generating filename.nfo for: {0}", episodeFile.Id);
|
||||
|
||||
var xmlResult = String.Empty;
|
||||
foreach (var episode in episodes)
|
||||
|
@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Providers.Metadata;
|
||||
using NzbDrone.Core.Repository;
|
||||
@ -135,7 +136,7 @@ public virtual void CreateForEpisodeFiles(List<EpisodeFile> episodeFiles)
|
||||
{
|
||||
foreach (var provider in _metadataProviders.Where(i => GetSettings(i.GetType()).Enable))
|
||||
{
|
||||
Logger.Trace("Creating {0} metadata for {1}", provider.Name, episodeFile.EpisodeFileId);
|
||||
Logger.Trace("Creating {0} metadata for {1}", provider.Name, episodeFile.Id);
|
||||
provider.CreateForEpisodeFile(episodeFile, tvDbSeries);
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
using System.Text;
|
||||
using System.Diagnostics;
|
||||
using NLog;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Repository;
|
||||
@ -13,14 +14,14 @@ namespace NzbDrone.Core.Providers
|
||||
{
|
||||
public class MisnamedProvider
|
||||
{
|
||||
private readonly MediaFileProvider _mediaFileProvider;
|
||||
private readonly IMediaFileService _mediaFileService;
|
||||
private readonly IEpisodeService _episodeService;
|
||||
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public MisnamedProvider(MediaFileProvider mediaFileProvider, IEpisodeService episodeService)
|
||||
public MisnamedProvider(IMediaFileService mediaFileService, IEpisodeService episodeService)
|
||||
{
|
||||
_mediaFileProvider = mediaFileProvider;
|
||||
_mediaFileService = mediaFileService;
|
||||
_episodeService = episodeService;
|
||||
}
|
||||
|
||||
@ -36,7 +37,7 @@ public virtual List<MisnamedEpisodeModel> MisnamedFiles(int pageNumber, int page
|
||||
var misnamedFilesSelect = episodesWithFiles.AsParallel().Where(
|
||||
w =>
|
||||
w.First().EpisodeFile.Path !=
|
||||
_mediaFileProvider.GetNewFilename(w.Select(e => e).ToList(), w.First().Series,
|
||||
_mediaFileService.GetNewFilename(w.Select(e => e).ToList(), w.First().Series,
|
||||
w.First().EpisodeFile.Quality, w.First().EpisodeFile.Proper, w.First().EpisodeFile)).Skip(Math.Max(pageSize * (pageNumber - 1), 0)).Take(pageSize);
|
||||
|
||||
//Process the episodes
|
||||
@ -44,7 +45,7 @@ public virtual List<MisnamedEpisodeModel> MisnamedFiles(int pageNumber, int page
|
||||
{
|
||||
var episodes = f.Select(e => e).ToList();
|
||||
var firstEpisode = episodes[0];
|
||||
var properName = _mediaFileProvider.GetNewFilename(episodes,
|
||||
var properName = _mediaFileService.GetNewFilename(episodes,
|
||||
firstEpisode.Series,
|
||||
firstEpisode.EpisodeFile.Quality, firstEpisode.EpisodeFile.Proper, firstEpisode.EpisodeFile);
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
using System.Linq;
|
||||
using System;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Model;
|
||||
using Sqo.Attributes;
|
||||
|
||||
@ -40,7 +41,7 @@ public int EpisodeFileId
|
||||
get
|
||||
{
|
||||
if (!HasFile) return 0;
|
||||
return EpisodeFile.EpisodeFileId;
|
||||
return EpisodeFile.Id;
|
||||
}
|
||||
}
|
||||
|
||||
|
Binary file not shown.
@ -283,8 +283,7 @@ public virtual IList<int> GetEpisodeNumbersBySeason(int seriesId, int seasonNumb
|
||||
public virtual void SetEpisodeIgnore(int episodeId, bool isIgnored)
|
||||
{
|
||||
var episode = _episodeRepository.Get(episodeId);
|
||||
episode.Ignored = isIgnored;
|
||||
_episodeRepository.Update(episode);
|
||||
_episodeRepository.SetIgnoreFlat(episode, isIgnored);
|
||||
|
||||
logger.Info("Ignore flag for Episode:{0} was set to {1}", episodeId, isIgnored);
|
||||
}
|
||||
|
@ -9,7 +9,6 @@
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Providers;
|
||||
using NzbDrone.Core.Providers.Core;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Tv.Events;
|
||||
|
||||
@ -185,4 +184,4 @@ private static string CleanAirsTime(string rawTime)
|
||||
return dateTime.ToString("hh:mm tt");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user