Your ROOT_URL in app.ini is https://git.cloudchain.link/ but you are visiting https://dash.bss.nz/open-source-mirrors/Sonarr/commit/07386f12e62be0088d7facd4393d80de500d8768
You should set ROOT_URL correctly, otherwise the web may not work correctly.
21 changed files with
178 additions and
33 deletions
@ -1,5 +1,6 @@
using System.Linq ;
using FizzWare.NBuilder ;
using FluentAssertions ;
using Marr.Data ;
using Moq ;
using NUnit.Framework ;
@ -149,5 +150,21 @@ namespace NzbDrone.Core.Test.MediaFiles
Mocker . GetMock < IRecycleBinProvider > ( ) . Verify ( v = > v . DeleteFile ( It . IsAny < string > ( ) ) , Times . Never ( ) ) ;
}
[Test]
public void should_return_old_episode_file_in_oldFiles ( )
{
GivenSingleEpisodeWithSingleEpisodeFile ( ) ;
Subject . UpgradeEpisodeFile ( _episodeFile , _localEpisode ) . OldFiles . Count . Should ( ) . Be ( 1 ) ;
}
[Test]
public void should_return_old_episode_files_in_oldFiles ( )
{
GivenMultipleEpisodesWithMultipleEpisodeFiles ( ) ;
Subject . UpgradeEpisodeFile ( _episodeFile , _localEpisode ) . OldFiles . Count . Should ( ) . Be ( 2 ) ;
}
}
}
@ -0,0 +1,73 @@
using System ;
using System.Collections.Generic ;
using System.Linq ;
using System.Text ;
using FizzWare.NBuilder ;
using Moq ;
using NUnit.Framework ;
using NzbDrone.Core.MediaFiles ;
using NzbDrone.Core.Notifications ;
using NzbDrone.Core.Notifications.Xbmc ;
using NzbDrone.Core.Test.Framework ;
using NzbDrone.Core.Tv ;
namespace NzbDrone.Core.Test.NotificationTests.Xbmc
{
[TestFixture]
public class OnDownloadFixture : CoreTest < Notifications . Xbmc . Xbmc >
{
private DownloadMessage _downloadMessage ;
[SetUp]
public void Setup ( )
{
var series = Builder < Series > . CreateNew ( )
. Build ( ) ;
var episodeFile = Builder < EpisodeFile > . CreateNew ( )
. Build ( ) ;
_downloadMessage = Builder < DownloadMessage > . CreateNew ( )
. With ( d = > d . Series = series )
. With ( d = > d . EpisodeFile = episodeFile )
. With ( d = > d . OldFiles = new List < EpisodeFile > ( ) )
. Build ( ) ;
Subject . Definition = new NotificationDefinition ( ) ;
Subject . Definition . Settings = new XbmcSettings
{
UpdateLibrary = true
} ;
}
private void GivenOldFiles ( )
{
_downloadMessage . OldFiles = Builder < EpisodeFile > . CreateListOfSize ( 1 )
. Build ( )
. ToList ( ) ;
Subject . Definition . Settings = new XbmcSettings
{
UpdateLibrary = true ,
CleanLibrary = true
} ;
}
[Test]
public void should_not_clean_if_no_episode_was_replaced ( )
{
Subject . OnDownload ( _downloadMessage ) ;
Mocker . GetMock < IXbmcService > ( ) . Verify ( v = > v . Clean ( It . IsAny < XbmcSettings > ( ) ) , Times . Never ( ) ) ;
}
[Test]
public void should_clean_if_episode_was_replaced ( )
{
GivenOldFiles ( ) ;
Subject . OnDownload ( _downloadMessage ) ;
Mocker . GetMock < IXbmcService > ( ) . Verify ( v = > v . Clean ( It . IsAny < XbmcSettings > ( ) ) , Times . Once ( ) ) ;
}
}
}
@ -169,6 +169,7 @@
<Compile Include= "NotificationTests\Xbmc\Json\CheckForErrorFixture.cs" />
<Compile Include= "NotificationTests\Xbmc\Json\GetSeriesPathFixture.cs" />
<Compile Include= "NotificationTests\Xbmc\Json\UpdateFixture.cs" />
<Compile Include= "NotificationTests\Xbmc\OnDownloadFixture.cs" />
<Compile Include= "OrganizerTests\BuildFilePathFixture.cs" />
<Compile Include= "ParserTests\ParsingServiceTests\GetEpisodesFixture.cs" />
<Compile Include= "ParserTests\ParsingServiceTests\GetSeriesFixture.cs" />
@ -0,0 +1,16 @@
using System ;
using System.Collections.Generic ;
namespace NzbDrone.Core.MediaFiles
{
public class EpisodeFileMoveResult
{
public EpisodeFileMoveResult ( )
{
OldFiles = new List < EpisodeFile > ( ) ;
}
public String Path { get ; set ; }
public List < EpisodeFile > OldFiles { get ; set ; }
}
}
@ -44,6 +44,7 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport
foreach ( var importDecision in qualifiedImports . OrderByDescending ( e = > e . LocalEpisode . Size ) )
{
var localEpisode = importDecision . LocalEpisode ;
var oldFiles = new List < EpisodeFile > ( ) ;
try
{
@ -65,11 +66,12 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport
episodeFile . SeasonNumber = localEpisode . SeasonNumber ;
episodeFile . Episodes = localEpisode . Episodes ;
if ( newDownload )
{
episodeFile . SceneName = Path . GetFileNameWithoutExtension ( localEpisode . Path . CleanFilePath ( ) ) ;
episodeFile . Path = _episodeFileUpgrader . UpgradeEpisodeFile ( episodeFile , localEpisode ) ;
var moveResult = _episodeFileUpgrader . UpgradeEpisodeFile ( episodeFile , localEpisode ) ;
episodeFile . Path = moveResult . Path ;
oldFiles = moveResult . OldFiles ;
}
_mediaFileService . Add ( episodeFile ) ;
@ -78,7 +80,7 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport
if ( newDownload )
{
_eventAggregator . PublishEvent ( new EpisodeImportedEvent ( localEpisode , episodeFile ) ) ;
_eventAggregator . PublishEvent ( new EpisodeDownloadedEvent ( localEpisode )) ;
_eventAggregator . PublishEvent ( new EpisodeDownloadedEvent ( localEpisode , episodeFile , oldFiles )) ;
}
}
catch ( Exception e )
@ -1,4 +1,5 @@
using NzbDrone.Common.Messaging ;
using System.Collections.Generic ;
using NzbDrone.Common.Messaging ;
using NzbDrone.Core.Parser.Model ;
namespace NzbDrone.Core.MediaFiles.Events
@ -6,10 +7,14 @@ namespace NzbDrone.Core.MediaFiles.Events
public class EpisodeDownloadedEvent : IEvent
{
public LocalEpisode Episode { get ; private set ; }
public EpisodeFile EpisodeFile { get ; private set ; }
public List < EpisodeFile > OldFiles { get ; private set ; }
public EpisodeDownloadedEvent ( LocalEpisode episode )
public EpisodeDownloadedEvent ( LocalEpisode episode , EpisodeFile episodeFile , List < EpisodeFile > oldFiles )
{
Episode = episode ;
EpisodeFile = episodeFile ;
OldFiles = oldFiles ;
}
}
}
@ -7,7 +7,7 @@ namespace NzbDrone.Core.MediaFiles
{
public interface IUpgradeMediaFiles
{
string UpgradeEpisodeFile ( EpisodeFile episodeFile , LocalEpisode localEpisode ) ;
EpisodeFileMoveResult UpgradeEpisodeFile ( EpisodeFile episodeFile , LocalEpisode localEpisode ) ;
}
public class UpgradeMediaFileService : IUpgradeMediaFiles
@ -31,8 +31,9 @@ namespace NzbDrone.Core.MediaFiles
_logger = logger ;
}
public string UpgradeEpisodeFile ( EpisodeFile episodeFile , LocalEpisode localEpisode )
public EpisodeFileMoveResult UpgradeEpisodeFile ( EpisodeFile episodeFile , LocalEpisode localEpisode )
{
var moveFileResult = new EpisodeFileMoveResult ( ) ;
var existingFiles = localEpisode . Episodes
. Where ( e = > e . EpisodeFileId > 0 )
. Select ( e = > e . EpisodeFile . Value )
@ -48,11 +49,14 @@ namespace NzbDrone.Core.MediaFiles
_recycleBinProvider . DeleteFile ( file . Path ) ;
}
moveFileResult . OldFiles . Add ( file ) ;
_mediaFileService . Delete ( file , true ) ;
}
_logger . Trace ( "Moving episode file: {0}" , episodeFile ) ;
return _episodeFileMover . MoveEpisodeFile ( episodeFile , localEpisode ) ;
moveFileResult . Path = _episodeFileMover . MoveEpisodeFile ( episodeFile , localEpisode ) ;
return moveFileResult ;
}
}
}
@ -0,0 +1,20 @@
using System ;
using System.Collections.Generic ;
using NzbDrone.Core.MediaFiles ;
using NzbDrone.Core.Tv ;
namespace NzbDrone.Core.Notifications
{
public class DownloadMessage
{
public String Message { get ; set ; }
public Series Series { get ; set ; }
public EpisodeFile EpisodeFile { get ; set ; }
public List < EpisodeFile > OldFiles { get ; set ; }
public override string ToString ( )
{
return Message ;
}
}
}
@ -25,10 +25,10 @@ namespace NzbDrone.Core.Notifications.Email
_smtpProvider . SendEmail ( Settings , subject , body ) ;
}
public override void OnDownload ( string message , Series series )
public override void OnDownload ( DownloadMessage message )
{
const string subject = "NzbDrone [TV] - Downloaded" ;
var body = String . Format ( "{0} Downloaded and sorted." , message );
var body = String . Format ( "{0} Downloaded and sorted." , message .Message );
_smtpProvider . SendEmail ( Settings , subject , body ) ;
}
@ -23,11 +23,11 @@ namespace NzbDrone.Core.Notifications.Growl
_growlProvider . SendNotification ( title , message , "GRAB" , Settings . Host , Settings . Port , Settings . Password ) ;
}
public override void OnDownload ( string message , Series series )
public override void OnDownload ( DownloadMessage message )
{
const string title = "Episode Downloaded" ;
_growlProvider . SendNotification ( title , message , "DOWNLOAD" , Settings . Host , Settings . Port , Settings . Password ) ;
_growlProvider . SendNotification ( title , message .Message , "DOWNLOAD" , Settings . Host , Settings . Port , Settings . Password ) ;
}
public override void AfterRename ( Series series )
@ -8,7 +8,7 @@ namespace NzbDrone.Core.Notifications
string Link { get ; }
void OnGrab ( string message ) ;
void OnDownload ( string message , Series series ) ;
void OnDownload ( DownloadMessage message ) ;
void AfterRename ( Series series ) ;
}
}
@ -28,7 +28,7 @@ namespace NzbDrone.Core.Notifications
public abstract string Link { get ; }
public abstract void OnGrab ( string message ) ;
public abstract void OnDownload ( string message , Series series ) ;
public abstract void OnDownload ( DownloadMessage message ) ;
public abstract void AfterRename ( Series series ) ;
protected TSettings Settings
@ -73,13 +73,17 @@ namespace NzbDrone.Core.Notifications
public void Handle ( EpisodeDownloadedEvent message )
{
var messageBody = GetMessage ( message . Episode . Series , message . Episode . Episodes , message . Episode . ParsedEpisodeInfo . Quality ) ;
var downloadMessage = new DownloadMessage ( ) ;
downloadMessage . Message = GetMessage ( message . Episode . Series , message . Episode . Episodes , message . Episode . ParsedEpisodeInfo . Quality ) ;
downloadMessage . Series = message . Episode . Series ;
downloadMessage . EpisodeFile = message . EpisodeFile ;
downloadMessage . OldFiles = message . OldFiles ;
foreach ( var notification in _notificationFactory . OnDownloadEnabled ( ) )
{
try
{
notification . OnDownload ( messageBody, message . Episode . Series ) ;
notification . OnDownload ( downloadMessage ) ;
}
catch ( Exception ex )
@ -23,11 +23,11 @@ namespace NzbDrone.Core.Notifications.NotifyMyAndroid
_notifyMyAndroidProxy . SendNotification ( title , message , Settings . ApiKey , ( NotifyMyAndroidPriority ) Settings . Priority ) ;
}
public override void OnDownload ( string message , Series series )
public override void OnDownload ( DownloadMessage message )
{
const string title = "Episode Downloaded" ;
_notifyMyAndroidProxy . SendNotification ( title , message , Settings . ApiKey , ( NotifyMyAndroidPriority ) Settings . Priority ) ;
_notifyMyAndroidProxy . SendNotification ( title , message .Message , Settings . ApiKey , ( NotifyMyAndroidPriority ) Settings . Priority ) ;
}
public override void AfterRename ( Series series )
@ -22,10 +22,10 @@ namespace NzbDrone.Core.Notifications.Plex
_plexProvider . Notify ( Settings , header , message ) ;
}
public override void OnDownload ( string message , Series series )
public override void OnDownload ( DownloadMessage message )
{
const string header = "NzbDrone [TV] - Downloaded" ;
_plexProvider . Notify ( Settings , header , message );
_plexProvider . Notify ( Settings , header , message .Message );
}
public override void AfterRename ( Series series )
@ -20,7 +20,7 @@ namespace NzbDrone.Core.Notifications.Plex
{
}
public override void OnDownload ( string message , Series series )
public override void OnDownload ( DownloadMessage message )
{
UpdateIfEnabled ( ) ;
}
@ -24,11 +24,11 @@ namespace NzbDrone.Core.Notifications.Prowl
_prowlProvider . SendNotification ( title , message , Settings . ApiKey , ( NotificationPriority ) Settings . Priority ) ;
}
public override void OnDownload ( string message , Series series )
public override void OnDownload ( DownloadMessage message )
{
const string title = "Episode Downloaded" ;
_prowlProvider . SendNotification ( title , message , Settings . ApiKey , ( NotificationPriority ) Settings . Priority ) ;
_prowlProvider . SendNotification ( title , message .Message , Settings . ApiKey , ( NotificationPriority ) Settings . Priority ) ;
}
public override void AfterRename ( Series series )
@ -23,11 +23,11 @@ namespace NzbDrone.Core.Notifications.PushBullet
_pushBulletProxy . SendNotification ( title , message , Settings . ApiKey , Settings . DeviceId ) ;
}
public override void OnDownload ( string message , Series series )
public override void OnDownload ( DownloadMessage message )
{
const string title = "Episode Downloaded" ;
_pushBulletProxy . SendNotification ( title , message , Settings . ApiKey , Settings . DeviceId ) ;
_pushBulletProxy . SendNotification ( title , message .Message , Settings . ApiKey , Settings . DeviceId ) ;
}
public override void AfterRename ( Series series )
@ -23,11 +23,11 @@ namespace NzbDrone.Core.Notifications.Pushover
_pushoverProxy . SendNotification ( title , message , Settings . UserKey , ( PushoverPriority ) Settings . Priority ) ;
}
public override void OnDownload ( string message , Series series )
public override void OnDownload ( DownloadMessage message )
{
const string title = "Episode Downloaded" ;
_pushoverProxy . SendNotification ( title , message , Settings . UserKey , ( PushoverPriority ) Settings . Priority ) ;
_pushoverProxy . SendNotification ( title , message .Message , Settings . UserKey , ( PushoverPriority ) Settings . Priority ) ;
}
public override void AfterRename ( Series series )
@ -1,4 +1,5 @@
using NzbDrone.Core.Tv ;
using System.Linq ;
using NzbDrone.Core.Tv ;
namespace NzbDrone.Core.Notifications.Xbmc
{
@ -26,16 +27,16 @@ namespace NzbDrone.Core.Notifications.Xbmc
}
}
public override void OnDownload ( string message , Series series )
public override void OnDownload ( DownloadMessage message )
{
const string header = "NzbDrone [TV] - Downloaded" ;
if ( Settings . Notify )
{
_xbmcProvider . Notify ( Settings , header , message );
_xbmcProvider . Notify ( Settings , header , message .Message );
}
UpdateAndClean ( series) ;
UpdateAndClean ( me ssage. S eries, message . OldFiles . Any ( ) ) ;
}
public override void AfterRename ( Series series )
@ -43,14 +44,14 @@ namespace NzbDrone.Core.Notifications.Xbmc
UpdateAndClean ( series ) ;
}
private void UpdateAndClean ( Series series )
private void UpdateAndClean ( Series series , bool clean = true )
{
if ( Settings . UpdateLibrary )
{
_xbmcProvider . Update ( Settings , series ) ;
}
if ( Settings. CleanLibrary )
if ( clean & & Settings. CleanLibrary )
{
_xbmcProvider . Clean ( Settings ) ;
}
@ -275,6 +275,7 @@
<Compile Include= "Instrumentation\Commands\DeleteLogFilesCommand.cs" />
<Compile Include= "Instrumentation\Commands\TrimLogCommand.cs" />
<Compile Include= "Instrumentation\DeleteLogFilesService.cs" />
<Compile Include= "MediaFiles\EpisodeFileMoveResult.cs" />
<Compile Include= "MediaFiles\MediaFileExtensions.cs" />
<Compile Include= "MediaFiles\MediaInfo\VideoFileInfoReader.cs" />
<Compile Include= "Messaging\Commands\CommandExecutor.cs" />
@ -290,6 +291,7 @@
<Compile Include= "MetadataSource\Trakt\TraktException.cs" />
<Compile Include= "Notifications\NotificationFactory.cs" />
<Compile Include= "Notifications\NotificationService.cs" />
<Compile Include= "Notifications\DownloadMessage.cs" />
<Compile Include= "Notifications\PushBullet\PushBullet.cs" />
<Compile Include= "Notifications\PushBullet\PushBulletProxy.cs" />
<Compile Include= "Notifications\PushBullet\PushBulletSettings.cs" />