1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-07-07 04:19:25 +02:00

New: Use Movie Folder Format to improve unmapped folders within root folders

(cherry picked from commit 81d2b18ce1c079c2a9dc3de037c9dceea16733fd)

Closes #8065
This commit is contained in:
Mark McDowall 2023-02-04 15:18:32 -08:00 committed by Bogdan
parent 7198aa24a6
commit c9da7ee0c9
8 changed files with 81 additions and 6 deletions

View File

@ -10,6 +10,7 @@ import styles from './ImportMovieRow.css';
function ImportMovieRow(props) { function ImportMovieRow(props) {
const { const {
id, id,
relativePath,
monitor, monitor,
qualityProfileId, qualityProfileId,
minimumAvailability, minimumAvailability,
@ -31,7 +32,7 @@ function ImportMovieRow(props) {
/> />
<VirtualTableRowCell className={styles.folder}> <VirtualTableRowCell className={styles.folder}>
{id} {relativePath}
</VirtualTableRowCell> </VirtualTableRowCell>
<VirtualTableRowCell className={styles.movie}> <VirtualTableRowCell className={styles.movie}>
@ -73,6 +74,7 @@ function ImportMovieRow(props) {
ImportMovieRow.propTypes = { ImportMovieRow.propTypes = {
id: PropTypes.string.isRequired, id: PropTypes.string.isRequired,
relativePath: PropTypes.string.isRequired,
monitor: PropTypes.string.isRequired, monitor: PropTypes.string.isRequired,
qualityProfileId: PropTypes.number.isRequired, qualityProfileId: PropTypes.number.isRequired,
minimumAvailability: PropTypes.string.isRequired, minimumAvailability: PropTypes.string.isRequired,

View File

@ -30,7 +30,7 @@ class ImportMovieTable extends Component {
unmappedFolders.forEach((unmappedFolder) => { unmappedFolders.forEach((unmappedFolder) => {
const id = unmappedFolder.name; const id = unmappedFolder.name;
onMovieLookup(id, unmappedFolder.path); onMovieLookup(id, unmappedFolder.path, unmappedFolder.relativePath);
onSetImportMovieValue({ onSetImportMovieValue({
id, id,

View File

@ -25,10 +25,11 @@ function createMapStateToProps() {
function createMapDispatchToProps(dispatch, props) { function createMapDispatchToProps(dispatch, props) {
return { return {
onMovieLookup(name, path) { onMovieLookup(name, path, relativePath) {
dispatch(queueLookupMovie({ dispatch(queueLookupMovie({
name, name,
path, path,
relativePath,
term: name term: name
})); }));
}, },

View File

@ -66,6 +66,7 @@ export const actionHandlers = handleThunks({
const { const {
name, name,
path, path,
relativePath,
term, term,
topOfQueue = false topOfQueue = false
} = payload; } = payload;
@ -75,6 +76,7 @@ export const actionHandlers = handleThunks({
id: name, id: name,
term, term,
path, path,
relativePath,
isFetching: false, isFetching: false,
isPopulated: false, isPopulated: false,
error: null error: null

View File

@ -10,6 +10,7 @@
using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Core.Configuration; using NzbDrone.Core.Configuration;
using NzbDrone.Core.Movies; using NzbDrone.Core.Movies;
using NzbDrone.Core.Organizer;
using NzbDrone.Core.RootFolders; using NzbDrone.Core.RootFolders;
using NzbDrone.Core.Test.Framework; using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common; using NzbDrone.Test.Common;
@ -19,9 +20,13 @@ namespace NzbDrone.Core.Test.RootFolderTests
[TestFixture] [TestFixture]
public class RootFolderServiceFixture : CoreTest<RootFolderService> public class RootFolderServiceFixture : CoreTest<RootFolderService>
{ {
private NamingConfig _namingConfig;
[SetUp] [SetUp]
public void Setup() public void Setup()
{ {
_namingConfig = NamingConfig.Default;
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Setup(m => m.FolderExists(It.IsAny<string>())) .Setup(m => m.FolderExists(It.IsAny<string>()))
.Returns(true); .Returns(true);
@ -33,6 +38,10 @@ public void Setup()
Mocker.GetMock<IRootFolderRepository>() Mocker.GetMock<IRootFolderRepository>()
.Setup(s => s.All()) .Setup(s => s.All())
.Returns(new List<RootFolder>()); .Returns(new List<RootFolder>());
Mocker.GetMock<INamingConfigService>()
.Setup(c => c.GetConfig())
.Returns(_namingConfig);
} }
private void WithNonExistingFolder() private void WithNonExistingFolder()
@ -254,5 +263,47 @@ public void should_exclude_recycle_bin()
unmappedFolders.Count.Should().Be(3); unmappedFolders.Count.Should().Be(3);
unmappedFolders.Should().NotContain(u => u.Name == "BIN"); unmappedFolders.Should().NotContain(u => u.Name == "BIN");
} }
[Test]
public void should_get_unmapped_folders_inside_letter_subfolder()
{
_namingConfig.MovieFolderFormat = "{Movie TitleFirstCharacter}\\{Movie Title}".AsOsAgnostic();
var rootFolderPath = @"C:\Test\Movies".AsOsAgnostic();
var rootFolder = Builder<RootFolder>.CreateNew()
.With(r => r.Path = rootFolderPath)
.Build();
var subFolderPath = Path.Combine(rootFolderPath, "M");
var subFolders = new[]
{
"Movie1",
"Movie2",
"Movie3",
};
var folders = subFolders.Select(f => Path.Combine(subFolderPath, f)).ToArray();
Mocker.GetMock<IRootFolderRepository>()
.Setup(s => s.Get(It.IsAny<int>()))
.Returns(rootFolder);
Mocker.GetMock<IMovieRepository>()
.Setup(s => s.AllMoviePaths())
.Returns(new Dictionary<int, string>());
Mocker.GetMock<IDiskProvider>()
.Setup(s => s.GetDirectories(rootFolder.Path))
.Returns(new[] { subFolderPath });
Mocker.GetMock<IDiskProvider>()
.Setup(s => s.GetDirectories(subFolderPath))
.Returns(folders);
var unmappedFolders = Subject.Get(rootFolder.Id, false).UnmappedFolders;
unmappedFolders.Count.Should().Be(3);
}
} }
} }

View File

@ -6,7 +6,6 @@ namespace NzbDrone.Core.RootFolders
public class RootFolder : ModelBase public class RootFolder : ModelBase
{ {
public string Path { get; set; } public string Path { get; set; }
public bool Accessible { get; set; } public bool Accessible { get; set; }
public long? FreeSpace { get; set; } public long? FreeSpace { get; set; }
public long? TotalSpace { get; set; } public long? TotalSpace { get; set; }

View File

@ -9,6 +9,7 @@
using NzbDrone.Common.Extensions; using NzbDrone.Common.Extensions;
using NzbDrone.Core.Configuration; using NzbDrone.Core.Configuration;
using NzbDrone.Core.Movies; using NzbDrone.Core.Movies;
using NzbDrone.Core.Organizer;
namespace NzbDrone.Core.RootFolders namespace NzbDrone.Core.RootFolders
{ {
@ -28,6 +29,7 @@ public class RootFolderService : IRootFolderService
private readonly IDiskProvider _diskProvider; private readonly IDiskProvider _diskProvider;
private readonly IMovieRepository _movieRepository; private readonly IMovieRepository _movieRepository;
private readonly IConfigService _configService; private readonly IConfigService _configService;
private readonly INamingConfigService _namingConfigService;
private readonly Logger _logger; private readonly Logger _logger;
private static readonly HashSet<string> SpecialFolders = new HashSet<string> private static readonly HashSet<string> SpecialFolders = new HashSet<string>
@ -47,12 +49,14 @@ public RootFolderService(IRootFolderRepository rootFolderRepository,
IDiskProvider diskProvider, IDiskProvider diskProvider,
IMovieRepository movieRepository, IMovieRepository movieRepository,
IConfigService configService, IConfigService configService,
INamingConfigService namingConfigService,
Logger logger) Logger logger)
{ {
_rootFolderRepository = rootFolderRepository; _rootFolderRepository = rootFolderRepository;
_diskProvider = diskProvider; _diskProvider = diskProvider;
_movieRepository = movieRepository; _movieRepository = movieRepository;
_configService = configService; _configService = configService;
_namingConfigService = namingConfigService;
_logger = logger; _logger = logger;
} }
@ -145,7 +149,17 @@ private List<UnmappedFolder> GetUnmappedFolders(string path, Dictionary<int, str
return results; return results;
} }
var subFolderDepth = _namingConfigService.GetConfig().MovieFolderFormat.Count(f => f == Path.DirectorySeparatorChar);
var possibleMovieFolders = _diskProvider.GetDirectories(path).ToList(); var possibleMovieFolders = _diskProvider.GetDirectories(path).ToList();
if (subFolderDepth > 0)
{
for (var i = 0; i < subFolderDepth; i++)
{
possibleMovieFolders = possibleMovieFolders.SelectMany(_diskProvider.GetDirectories).ToList();
}
}
var unmappedFolders = possibleMovieFolders.Except(moviePaths.Select(s => s.Value), PathEqualityComparer.Instance).ToList(); var unmappedFolders = possibleMovieFolders.Except(moviePaths.Select(s => s.Value), PathEqualityComparer.Instance).ToList();
var recycleBinPath = _configService.RecycleBin; var recycleBinPath = _configService.RecycleBin;
@ -158,7 +172,12 @@ private List<UnmappedFolder> GetUnmappedFolders(string path, Dictionary<int, str
{ {
if (string.IsNullOrWhiteSpace(recycleBinPath) || di.FullName.PathNotEquals(recycleBinPath)) if (string.IsNullOrWhiteSpace(recycleBinPath) || di.FullName.PathNotEquals(recycleBinPath))
{ {
results.Add(new UnmappedFolder { Name = di.Name, Path = di.FullName }); results.Add(new UnmappedFolder
{
Name = di.Name,
Path = di.FullName,
RelativePath = path.GetRelativePath(di.FullName)
});
} }
} }
} }

View File

@ -1,8 +1,9 @@
namespace NzbDrone.Core.RootFolders namespace NzbDrone.Core.RootFolders
{ {
public class UnmappedFolder public class UnmappedFolder
{ {
public string Name { get; set; } public string Name { get; set; }
public string Path { get; set; } public string Path { get; set; }
public string RelativePath { get; set; }
} }
} }