mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-19 21:13:28 -07:00
parent
71c1edd47c
commit
b230faaa34
3 changed files with 34 additions and 3 deletions
|
@ -1,5 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using NLog;
|
using NLog;
|
||||||
using NzbDrone.Common.Disk;
|
using NzbDrone.Common.Disk;
|
||||||
|
@ -147,13 +148,28 @@ namespace NzbDrone.Core.MediaFiles
|
||||||
{
|
{
|
||||||
if (message.DeleteFiles)
|
if (message.DeleteFiles)
|
||||||
{
|
{
|
||||||
var files = _mediaFileService.GetFilesByAlbum(message.Album.Id);
|
var files = message.TrackFilesToDelete;
|
||||||
|
|
||||||
foreach (var file in files)
|
foreach (var file in files)
|
||||||
{
|
{
|
||||||
_recycleBinProvider.DeleteFile(file.Path);
|
_recycleBinProvider.DeleteFile(file.Path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_configService.DeleteEmptyFolders)
|
||||||
|
{
|
||||||
|
var artist = message.Album.Artist.Value;
|
||||||
|
var albumFolder = message.TrackFilesToDelete.FirstOrDefault()?.Path.GetParentPath();
|
||||||
|
|
||||||
|
if (_diskProvider.GetFiles(artist.Path, SearchOption.AllDirectories).Empty())
|
||||||
|
{
|
||||||
|
_diskProvider.DeleteFolder(artist.Path, true);
|
||||||
|
}
|
||||||
|
else if (_diskProvider.GetFiles(albumFolder, SearchOption.AllDirectories).Empty())
|
||||||
|
{
|
||||||
|
_diskProvider.RemoveEmptySubfolders(albumFolder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_eventAggregator.PublishEvent(new DeleteCompletedEvent());
|
_eventAggregator.PublishEvent(new DeleteCompletedEvent());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
using NzbDrone.Common.Messaging;
|
using System.Collections.Generic;
|
||||||
|
using NzbDrone.Common.Messaging;
|
||||||
|
using NzbDrone.Core.MediaFiles;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Music.Events
|
namespace NzbDrone.Core.Music.Events
|
||||||
{
|
{
|
||||||
|
@ -7,6 +9,7 @@ namespace NzbDrone.Core.Music.Events
|
||||||
public Album Album { get; private set; }
|
public Album Album { get; private set; }
|
||||||
public bool DeleteFiles { get; private set; }
|
public bool DeleteFiles { get; private set; }
|
||||||
public bool AddImportListExclusion { get; private set; }
|
public bool AddImportListExclusion { get; private set; }
|
||||||
|
public List<TrackFile> TrackFilesToDelete { get; set; }
|
||||||
|
|
||||||
public AlbumDeletedEvent(Album album, bool deleteFiles, bool addImportListExclusion)
|
public AlbumDeletedEvent(Album album, bool deleteFiles, bool addImportListExclusion)
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,6 +4,7 @@ using System.Linq;
|
||||||
using NLog;
|
using NLog;
|
||||||
using NzbDrone.Common.Extensions;
|
using NzbDrone.Common.Extensions;
|
||||||
using NzbDrone.Core.Datastore;
|
using NzbDrone.Core.Datastore;
|
||||||
|
using NzbDrone.Core.MediaFiles;
|
||||||
using NzbDrone.Core.Messaging.Events;
|
using NzbDrone.Core.Messaging.Events;
|
||||||
using NzbDrone.Core.Music.Events;
|
using NzbDrone.Core.Music.Events;
|
||||||
using NzbDrone.Core.Parser;
|
using NzbDrone.Core.Parser;
|
||||||
|
@ -46,14 +47,17 @@ namespace NzbDrone.Core.Music
|
||||||
{
|
{
|
||||||
private readonly IAlbumRepository _albumRepository;
|
private readonly IAlbumRepository _albumRepository;
|
||||||
private readonly IEventAggregator _eventAggregator;
|
private readonly IEventAggregator _eventAggregator;
|
||||||
|
private readonly IMediaFileService _mediaFileService;
|
||||||
private readonly Logger _logger;
|
private readonly Logger _logger;
|
||||||
|
|
||||||
public AlbumService(IAlbumRepository albumRepository,
|
public AlbumService(IAlbumRepository albumRepository,
|
||||||
IEventAggregator eventAggregator,
|
IEventAggregator eventAggregator,
|
||||||
|
IMediaFileService mediaFileService,
|
||||||
Logger logger)
|
Logger logger)
|
||||||
{
|
{
|
||||||
_albumRepository = albumRepository;
|
_albumRepository = albumRepository;
|
||||||
_eventAggregator = eventAggregator;
|
_eventAggregator = eventAggregator;
|
||||||
|
_mediaFileService = mediaFileService;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,7 +75,15 @@ namespace NzbDrone.Core.Music
|
||||||
var album = _albumRepository.Get(albumId);
|
var album = _albumRepository.Get(albumId);
|
||||||
album.Artist.LazyLoad();
|
album.Artist.LazyLoad();
|
||||||
_albumRepository.Delete(albumId);
|
_albumRepository.Delete(albumId);
|
||||||
_eventAggregator.PublishEvent(new AlbumDeletedEvent(album, deleteFiles, addImportListExclusion));
|
|
||||||
|
var deleteEvent = new AlbumDeletedEvent(album, deleteFiles, addImportListExclusion);
|
||||||
|
|
||||||
|
if (deleteFiles)
|
||||||
|
{
|
||||||
|
deleteEvent.TrackFilesToDelete = _mediaFileService.GetFilesByAlbum(albumId);
|
||||||
|
}
|
||||||
|
|
||||||
|
_eventAggregator.PublishEvent(deleteEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Album FindById(string foreignId)
|
public Album FindById(string foreignId)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue