Episode file import fixes

Fixed: Import event when file doesn't have a valid scene name
Fixed: Filename when file doesn't have a valid scene name
pull/118/head
Mark McDowall 10 years ago
parent 7c01f46cc0
commit 4cbb59d4e8

@ -1,4 +1,11 @@
using NUnit.Framework;
using System.IO;
using System.Linq;
using FizzWare.NBuilder;
using Moq;
using NUnit.Framework;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.MediaFiles.Events;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Profiles;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.History;
@ -6,6 +13,7 @@ using NzbDrone.Core.Qualities;
using System.Collections.Generic;
using NzbDrone.Core.Test.Qualities;
using FluentAssertions;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.Test.HistoryTests
{
@ -56,5 +64,27 @@ namespace NzbDrone.Core.Test.HistoryTests
quality.Should().Be(new QualityModel(Quality.DVD));
}
[Test]
public void should_use_file_name_for_source_title_if_scene_name_is_null()
{
var series = Builder<Series>.CreateNew().Build();
var episodes = Builder<Episode>.CreateListOfSize(1).Build().ToList();
var episodeFile = Builder<EpisodeFile>.CreateNew()
.With(f => f.SceneName = null)
.Build();
var localEpisode = new LocalEpisode
{
Series = series,
Episodes = episodes,
Path = @"C:\Test\Unsorted\Series.s01e01.mkv"
};
Subject.Handle(new EpisodeImportedEvent(localEpisode, episodeFile, true));
Mocker.GetMock<IHistoryRepository>()
.Verify(v => v.Insert(It.Is<History.History>(h => h.SourceTitle == Path.GetFileNameWithoutExtension(localEpisode.Path))));
}
}
}

@ -314,7 +314,6 @@
<Link>sqlite3.dll</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="License.txt" />
<None Include="..\NzbDrone.Test.Common\App.config">
<Link>App.config</Link>
</None>

@ -233,6 +233,17 @@ namespace NzbDrone.Core.Test.OrganizerTests
.Should().Be(Path.GetFileNameWithoutExtension(_episodeFile.RelativePath));
}
[Test]
public void use_path_when_sceneName_and_relative_path_are_null()
{
_namingConfig.RenameEpisodes = false;
_episodeFile.RelativePath = null;
_episodeFile.Path = @"C:\Test\Unsorted\Series - S01E01 - Test";
Subject.BuildFileName(new List<Episode> { _episode1 }, _series, _episodeFile)
.Should().Be(Path.GetFileNameWithoutExtension(_episodeFile.Path));
}
[Test]
public void use_file_name_when_sceneName_is_not_null()
{

@ -167,7 +167,7 @@ namespace NzbDrone.Core.History
EventType = HistoryEventType.DownloadFolderImported,
Date = DateTime.UtcNow,
Quality = message.EpisodeInfo.Quality,
SourceTitle = message.ImportedEpisode.SceneName,
SourceTitle = message.ImportedEpisode.SceneName ?? Path.GetFileNameWithoutExtension(message.EpisodeInfo.Path),
SeriesId = message.ImportedEpisode.SeriesId,
EpisodeId = episode.Id
};

@ -80,6 +80,11 @@ namespace NzbDrone.Core.Organizer
{
if (episodeFile.SceneName.IsNullOrWhiteSpace())
{
if (episodeFile.RelativePath.IsNullOrWhiteSpace())
{
return Path.GetFileNameWithoutExtension(episodeFile.Path);
}
return Path.GetFileNameWithoutExtension(episodeFile.RelativePath);
}

@ -90,7 +90,7 @@
{{/if_eq}}
{{#if_eq reason compare="Upgrade"}}
File was deleted to imported an upgrade
File was deleted to import an upgrade
{{/if_eq}}
</dd>
{{/with}}

Loading…
Cancel
Save