コード例 #1
0
        private Artist SetPropertiesAndValidate(Artist newArtist)
        {
            var path = newArtist.Path;

            if (string.IsNullOrWhiteSpace(path))
            {
                var folderName = _fileNameBuilder.GetArtistFolder(newArtist);
                path = Path.Combine(newArtist.RootFolderPath, folderName);
            }

            // Disambiguate artist path if it exists already
            if (_artistService.ArtistPathExists(path))
            {
                if (newArtist.Metadata.Value.Disambiguation.IsNotNullOrWhiteSpace())
                {
                    path += $" ({newArtist.Metadata.Value.Disambiguation})";
                }

                if (_artistService.ArtistPathExists(path))
                {
                    var basepath = path;
                    int i        = 0;
                    do
                    {
                        i++;
                        path = basepath + $" ({i})";
                    }while (_artistService.ArtistPathExists(path));
                }
            }

            newArtist.Path      = path;
            newArtist.CleanName = newArtist.Metadata.Value.Name.CleanArtistName();
            newArtist.SortName  = Parser.Parser.NormalizeTitle(newArtist.Metadata.Value.Name).ToLower();
            newArtist.Added     = DateTime.UtcNow;

            if (newArtist.AddOptions != null && newArtist.AddOptions.Monitor == MonitorTypes.None)
            {
                newArtist.Monitored = false;
            }

            var validationResult = _addArtistValidator.Validate(newArtist);

            if (!validationResult.IsValid)
            {
                throw new ValidationException(validationResult.Errors);
            }

            return(newArtist);
        }
コード例 #2
0
        private List <ImportResult> ProcessFolder(IDirectoryInfo directoryInfo, ImportMode importMode, Artist artist, DownloadClientItem downloadClientItem)
        {
            if (_artistService.ArtistPathExists(directoryInfo.FullName))
            {
                _logger.Warn("Unable to process folder that is mapped to an existing artist");
                return(new List <ImportResult>());
            }

            var cleanedUpName = GetCleanedUpFolderName(directoryInfo.Name);
            var folderInfo    = Parser.Parser.ParseAlbumTitle(directoryInfo.Name);
            var trackInfo     = new ParsedTrackInfo {
            };

            if (folderInfo != null)
            {
                _logger.Debug("{0} folder quality: {1}", cleanedUpName, folderInfo.Quality);

                trackInfo = new ParsedTrackInfo
                {
                    AlbumTitle   = folderInfo.AlbumTitle,
                    ArtistTitle  = folderInfo.ArtistName,
                    Quality      = folderInfo.Quality,
                    ReleaseGroup = folderInfo.ReleaseGroup,
                    ReleaseHash  = folderInfo.ReleaseHash,
                };
            }
            else
            {
                trackInfo = null;
            }

            var audioFiles = _diskScanService.FilterFiles(directoryInfo.FullName, _diskScanService.GetAudioFiles(directoryInfo.FullName));

            if (downloadClientItem == null)
            {
                foreach (var audioFile in audioFiles)
                {
                    if (_diskProvider.IsFileLocked(audioFile.FullName))
                    {
                        return(new List <ImportResult>
                        {
                            FileIsLockedResult(audioFile.FullName)
                        });
                    }
                }
            }

            var idOverrides = new IdentificationOverrides
            {
                Artist = artist
            };
            var idInfo = new ImportDecisionMakerInfo
            {
                DownloadClientItem = downloadClientItem,
                ParsedTrackInfo    = trackInfo
            };
            var idConfig = new ImportDecisionMakerConfig
            {
                Filter          = FilterFilesType.None,
                NewDownload     = true,
                SingleRelease   = false,
                IncludeExisting = false,
                AddNewArtists   = false
            };

            var decisions     = _importDecisionMaker.GetImportDecisions(audioFiles, idOverrides, idInfo, idConfig);
            var importResults = _importApprovedTracks.Import(decisions, true, downloadClientItem, importMode);

            if (importMode == ImportMode.Auto)
            {
                importMode = (downloadClientItem == null || downloadClientItem.CanMoveFiles) ? ImportMode.Move : ImportMode.Copy;
            }

            if (importMode == ImportMode.Move &&
                importResults.Any(i => i.Result == ImportResultType.Imported) &&
                ShouldDeleteFolder(directoryInfo, artist))
            {
                _logger.Debug("Deleting folder after importing valid files");
                _diskProvider.DeleteFolder(directoryInfo.FullName, true);
            }

            return(importResults);
        }