mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-20 13:33:34 -07:00
Rework DiscSpaceService, Misc Cleanup
This commit is contained in:
parent
9b62c0cb75
commit
d6efae537f
7 changed files with 56 additions and 96 deletions
|
@ -9,7 +9,7 @@ using NzbDrone.Common.Disk;
|
|||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.DiskSpace;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.DiskSpace
|
||||
|
@ -17,16 +17,14 @@ namespace NzbDrone.Core.Test.DiskSpace
|
|||
[TestFixture]
|
||||
public class DiskSpaceServiceFixture : CoreTest<DiskSpaceService>
|
||||
{
|
||||
private string _seriesFolder;
|
||||
private string _seriesFolder2;
|
||||
private string _droneFactoryFolder;
|
||||
private string _artistFolder;
|
||||
private string _artostFolder2;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_seriesFolder = @"G:\fasdlfsdf\series".AsOsAgnostic();
|
||||
_seriesFolder2 = @"G:\fasdlfsdf\series2".AsOsAgnostic();
|
||||
_droneFactoryFolder = @"G:\dronefactory".AsOsAgnostic();
|
||||
_artistFolder = @"G:\fasdlfsdf\artist".AsOsAgnostic();
|
||||
_artostFolder2 = @"G:\fasdlfsdf\artist2".AsOsAgnostic();
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(v => v.GetMounts())
|
||||
|
@ -44,14 +42,14 @@ namespace NzbDrone.Core.Test.DiskSpace
|
|||
.Setup(v => v.GetTotalSize(It.IsAny<string>()))
|
||||
.Returns(0);
|
||||
|
||||
GivenSeries();
|
||||
GivenArtist();
|
||||
}
|
||||
|
||||
private void GivenSeries(params Series[] series)
|
||||
private void GivenArtist(params Artist[] artist)
|
||||
{
|
||||
Mocker.GetMock<ISeriesService>()
|
||||
.Setup(v => v.GetAllSeries())
|
||||
.Returns(series.ToList());
|
||||
Mocker.GetMock<IArtistService>()
|
||||
.Setup(v => v.GetAllArtists())
|
||||
.Returns(artist.ToList());
|
||||
}
|
||||
|
||||
private void GivenExistingFolder(string folder)
|
||||
|
@ -62,11 +60,11 @@ namespace NzbDrone.Core.Test.DiskSpace
|
|||
}
|
||||
|
||||
[Test]
|
||||
public void should_check_diskspace_for_series_folders()
|
||||
public void should_check_diskspace_for_artist_folders()
|
||||
{
|
||||
GivenSeries(new Series { Path = _seriesFolder });
|
||||
GivenArtist(new Artist { Path = _artistFolder });
|
||||
|
||||
GivenExistingFolder(_seriesFolder);
|
||||
GivenExistingFolder(_artistFolder);
|
||||
|
||||
var freeSpace = Subject.GetFreeSpace();
|
||||
|
||||
|
@ -76,10 +74,10 @@ namespace NzbDrone.Core.Test.DiskSpace
|
|||
[Test]
|
||||
public void should_check_diskspace_for_same_root_folder_only_once()
|
||||
{
|
||||
GivenSeries(new Series { Path = _seriesFolder }, new Series { Path = _seriesFolder2 });
|
||||
GivenArtist(new Artist { Path = _artistFolder }, new Artist { Path = _artostFolder2 });
|
||||
|
||||
GivenExistingFolder(_seriesFolder);
|
||||
GivenExistingFolder(_seriesFolder2);
|
||||
GivenExistingFolder(_artistFolder);
|
||||
GivenExistingFolder(_artostFolder2);
|
||||
|
||||
var freeSpace = Subject.GetFreeSpace();
|
||||
|
||||
|
@ -90,9 +88,9 @@ namespace NzbDrone.Core.Test.DiskSpace
|
|||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_check_diskspace_for_missing_series_folders()
|
||||
public void should_not_check_diskspace_for_missing_artist_folders()
|
||||
{
|
||||
GivenSeries(new Series { Path = _seriesFolder });
|
||||
GivenArtist(new Artist { Path = _artistFolder });
|
||||
|
||||
var freeSpace = Subject.GetFreeSpace();
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
|
@ -10,7 +10,7 @@ using NzbDrone.Core.History;
|
|||
using NzbDrone.Core.Messaging.Events;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.Download
|
||||
|
@ -27,21 +27,21 @@ namespace NzbDrone.Core.Test.Download
|
|||
var completed = Builder<DownloadClientItem>.CreateNew()
|
||||
.With(h => h.Status = DownloadItemStatus.Completed)
|
||||
.With(h => h.OutputPath = new OsPath(@"C:\DropFolder\MyDownload".AsOsAgnostic()))
|
||||
.With(h => h.Title = "Drone.S01E01.HDTV")
|
||||
.With(h => h.Title = "Drone.DroneTheAlbum.FLAC")
|
||||
.Build();
|
||||
|
||||
_grabHistory = Builder<History.History>.CreateListOfSize(2).BuildList();
|
||||
|
||||
var remoteEpisode = new RemoteEpisode
|
||||
var remoteAlbum = new RemoteAlbum
|
||||
{
|
||||
Series = new Series(),
|
||||
Episodes = new List<Episode> { new Episode { Id = 1 } }
|
||||
Artist = new Artist(),
|
||||
Albums = new List<Album> { new Album { Id = 1 } }
|
||||
};
|
||||
|
||||
_trackedDownload = Builder<TrackedDownload>.CreateNew()
|
||||
.With(c => c.State = TrackedDownloadStage.Downloading)
|
||||
.With(c => c.DownloadItem = completed)
|
||||
.With(c => c.RemoteEpisode = remoteEpisode)
|
||||
.With(c => c.RemoteAlbum = remoteAlbum)
|
||||
.Build();
|
||||
|
||||
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Disk;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Music;
|
||||
|
||||
namespace NzbDrone.Core.DiskSpace
|
||||
{
|
||||
|
@ -16,22 +16,22 @@ namespace NzbDrone.Core.DiskSpace
|
|||
|
||||
public class DiskSpaceService : IDiskSpaceService
|
||||
{
|
||||
private readonly ISeriesService _seriesService;
|
||||
private readonly IArtistService _artistService;
|
||||
private readonly IDiskProvider _diskProvider;
|
||||
private readonly Logger _logger;
|
||||
|
||||
private static readonly Regex _regexSpecialDrive = new Regex("^/var/lib/(docker|rancher|kubelet)(/|$)|^/boot(/|$)|/docker(/var)?/aufs(/|$)", RegexOptions.Compiled);
|
||||
|
||||
public DiskSpaceService(ISeriesService seriesService, IDiskProvider diskProvider, Logger logger)
|
||||
public DiskSpaceService(IArtistService artistService, IDiskProvider diskProvider, Logger logger)
|
||||
{
|
||||
_seriesService = seriesService;
|
||||
_artistService = artistService;
|
||||
_diskProvider = diskProvider;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public List<DiskSpace> GetFreeSpace()
|
||||
{
|
||||
var importantRootFolders = GetSeriesRootPaths().Distinct().ToList();
|
||||
var importantRootFolders = GetArtistRootPaths().Distinct().ToList();
|
||||
|
||||
var optionalRootFolders = GetFixedDisksRootPaths().Except(importantRootFolders).Distinct().ToList();
|
||||
|
||||
|
@ -40,9 +40,9 @@ namespace NzbDrone.Core.DiskSpace
|
|||
return diskSpace;
|
||||
}
|
||||
|
||||
private IEnumerable<string> GetSeriesRootPaths()
|
||||
private IEnumerable<string> GetArtistRootPaths()
|
||||
{
|
||||
return _seriesService.GetAllSeries()
|
||||
return _artistService.GetAllArtists()
|
||||
.Where(s => _diskProvider.FolderExists(s.Path))
|
||||
.Select(s => _diskProvider.GetPathRoot(s.Path))
|
||||
.Distinct();
|
||||
|
|
|
@ -37,15 +37,9 @@ namespace NzbDrone.Core.Organizer
|
|||
private static readonly Regex TitleRegex = new Regex(@"\{(?<prefix>[- ._\[(]*)(?<token>(?:[a-z0-9]+)(?:(?<separator>[- ._]+)(?:[a-z0-9]+))?)(?::(?<customFormat>[a-z0-9]+))?(?<suffix>[- ._)\]]*)\}",
|
||||
RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||
|
||||
private static readonly Regex EpisodeRegex = new Regex(@"(?<episode>\{episode(?:\:0+)?})",
|
||||
RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||
|
||||
private static readonly Regex TrackRegex = new Regex(@"(?<track>\{track(?:\:0+)?})",
|
||||
RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||
|
||||
private static readonly Regex SeasonRegex = new Regex(@"(?<season>\{season(?:\:0+)?})",
|
||||
RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||
|
||||
private static readonly Regex AbsoluteEpisodeRegex = new Regex(@"(?<absolute>\{absolute(?:\:0+)?})",
|
||||
RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||
|
||||
|
@ -300,18 +294,6 @@ namespace NzbDrone.Core.Organizer
|
|||
tokenHandlers["{Release Group}"] = m => trackFile.ReleaseGroup ?? m.DefaultValue("Lidarr");
|
||||
}
|
||||
|
||||
private void AddQualityTokens(Dictionary<string, Func<TokenMatch, string>> tokenHandlers, Series series, EpisodeFile episodeFile)
|
||||
{
|
||||
var qualityTitle = _qualityDefinitionService.Get(episodeFile.Quality.Quality).Title;
|
||||
var qualityProper = GetQualityProper(series, episodeFile.Quality);
|
||||
var qualityReal = GetQualityReal(series, episodeFile.Quality);
|
||||
|
||||
tokenHandlers["{Quality Full}"] = m => String.Format("{0} {1} {2}", qualityTitle, qualityProper, qualityReal);
|
||||
tokenHandlers["{Quality Title}"] = m => qualityTitle;
|
||||
tokenHandlers["{Quality Proper}"] = m => qualityProper;
|
||||
tokenHandlers["{Quality Real}"] = m => qualityReal;
|
||||
}
|
||||
|
||||
private void AddQualityTokens(Dictionary<string, Func<TokenMatch, string>> tokenHandlers, Artist artist, TrackFile trackFile)
|
||||
{
|
||||
var qualityTitle = _qualityDefinitionService.Get(trackFile.Quality.Quality).Title;
|
||||
|
@ -515,40 +497,31 @@ namespace NzbDrone.Core.Organizer
|
|||
return MultiPartCleanupRegex.Replace(title, string.Empty).Trim();
|
||||
}
|
||||
|
||||
private string GetQualityProper(Series series, QualityModel quality)
|
||||
{
|
||||
if (quality.Revision.Version > 1)
|
||||
{
|
||||
if (series.SeriesType == SeriesTypes.Anime)
|
||||
{
|
||||
return "v" + quality.Revision.Version;
|
||||
}
|
||||
// TODO: DO WE NEED FOR MUSIC?
|
||||
//private string GetQualityProper(Series series, QualityModel quality)
|
||||
//{
|
||||
// if (quality.Revision.Version > 1)
|
||||
// {
|
||||
// if (series.SeriesType == SeriesTypes.Anime)
|
||||
// {
|
||||
// return "v" + quality.Revision.Version;
|
||||
// }
|
||||
|
||||
return "Proper";
|
||||
}
|
||||
// return "Proper";
|
||||
// }
|
||||
|
||||
return String.Empty;
|
||||
}
|
||||
// return String.Empty;
|
||||
//}
|
||||
|
||||
private string GetQualityReal(Series series, QualityModel quality)
|
||||
{
|
||||
if (quality.Revision.Real > 0)
|
||||
{
|
||||
return "REAL";
|
||||
}
|
||||
//private string GetQualityReal(Series series, QualityModel quality)
|
||||
//{
|
||||
// if (quality.Revision.Real > 0)
|
||||
// {
|
||||
// return "REAL";
|
||||
// }
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
private string GetOriginalTitle(EpisodeFile episodeFile)
|
||||
{
|
||||
if (episodeFile.SceneName.IsNullOrWhiteSpace())
|
||||
{
|
||||
return GetOriginalFileName(episodeFile);
|
||||
}
|
||||
|
||||
return episodeFile.SceneName;
|
||||
}
|
||||
// return string.Empty;
|
||||
//}
|
||||
|
||||
private string GetOriginalTitle(TrackFile trackFile)
|
||||
{
|
||||
|
@ -560,16 +533,6 @@ namespace NzbDrone.Core.Organizer
|
|||
return trackFile.SceneName;
|
||||
}
|
||||
|
||||
private string GetOriginalFileName(EpisodeFile episodeFile)
|
||||
{
|
||||
if (episodeFile.RelativePath.IsNullOrWhiteSpace())
|
||||
{
|
||||
return Path.GetFileNameWithoutExtension(episodeFile.Path);
|
||||
}
|
||||
|
||||
return Path.GetFileNameWithoutExtension(episodeFile.RelativePath);
|
||||
}
|
||||
|
||||
private string GetOriginalFileName(TrackFile trackFile)
|
||||
{
|
||||
if (trackFile.RelativePath.IsNullOrWhiteSpace())
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Music;
|
||||
|
@ -8,7 +8,6 @@ namespace NzbDrone.Core.Organizer
|
|||
public class SampleResult
|
||||
{
|
||||
public string FileName { get; set; }
|
||||
public Series Series { get; set; }
|
||||
public Artist Artist { get; set; }
|
||||
public Album Album { get; set; }
|
||||
public List<Episode> Episodes { get; set; }
|
||||
|
|
|
@ -86,7 +86,7 @@
|
|||
<Compile Include="SignalrDependencyResolver.cs" />
|
||||
<Compile Include="SignalRJsonSerializer.cs" />
|
||||
<Compile Include="SignalRMessage.cs" />
|
||||
<Compile Include="SonarrPerformanceCounterManager.cs" />
|
||||
<Compile Include="LidarrPerformanceCounterManager.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\NzbDrone.Common\NzbDrone.Common.csproj">
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue