parent
9f689c0233
commit
405e7f981d
@ -1,270 +0,0 @@
|
|||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using NLog;
|
|
||||||
using NzbDrone.Common.Disk;
|
|
||||||
using NzbDrone.Core.DecisionEngine;
|
|
||||||
using NzbDrone.Core.Parser;
|
|
||||||
using NzbDrone.Core.Tv;
|
|
||||||
using NzbDrone.Core.Download;
|
|
||||||
using NzbDrone.Core.Parser.Model;
|
|
||||||
using NzbDrone.Core.MediaFiles.TrackImport;
|
|
||||||
|
|
||||||
namespace NzbDrone.Core.MediaFiles
|
|
||||||
{
|
|
||||||
public interface IDownloadedEpisodesImportService
|
|
||||||
{
|
|
||||||
List<ImportResult> ProcessRootFolder(DirectoryInfo directoryInfo);
|
|
||||||
List<ImportResult> ProcessPath(string path, ImportMode importMode = ImportMode.Auto, Series series = null, DownloadClientItem downloadClientItem = null);
|
|
||||||
bool ShouldDeleteFolder(DirectoryInfo directoryInfo, Series series);
|
|
||||||
}
|
|
||||||
|
|
||||||
public class DownloadedEpisodesImportService : IDownloadedEpisodesImportService
|
|
||||||
{
|
|
||||||
private readonly IDiskProvider _diskProvider;
|
|
||||||
private readonly IDiskScanService _diskScanService;
|
|
||||||
private readonly ISeriesService _seriesService;
|
|
||||||
private readonly IParsingService _parsingService;
|
|
||||||
private readonly IMakeImportDecision _importDecisionMaker;
|
|
||||||
private readonly IImportApprovedEpisodes _importApprovedEpisodes;
|
|
||||||
private readonly IDetectSample _detectSample;
|
|
||||||
private readonly Logger _logger;
|
|
||||||
|
|
||||||
public DownloadedEpisodesImportService(IDiskProvider diskProvider,
|
|
||||||
IDiskScanService diskScanService,
|
|
||||||
ISeriesService seriesService,
|
|
||||||
IParsingService parsingService,
|
|
||||||
IMakeImportDecision importDecisionMaker,
|
|
||||||
IImportApprovedEpisodes importApprovedEpisodes,
|
|
||||||
IDetectSample detectSample,
|
|
||||||
Logger logger)
|
|
||||||
{
|
|
||||||
_diskProvider = diskProvider;
|
|
||||||
_diskScanService = diskScanService;
|
|
||||||
_seriesService = seriesService;
|
|
||||||
_parsingService = parsingService;
|
|
||||||
_importDecisionMaker = importDecisionMaker;
|
|
||||||
_importApprovedEpisodes = importApprovedEpisodes;
|
|
||||||
_detectSample = detectSample;
|
|
||||||
_logger = logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<ImportResult> ProcessRootFolder(DirectoryInfo directoryInfo)
|
|
||||||
{
|
|
||||||
var results = new List<ImportResult>();
|
|
||||||
|
|
||||||
foreach (var subFolder in _diskProvider.GetDirectories(directoryInfo.FullName))
|
|
||||||
{
|
|
||||||
var folderResults = ProcessFolder(new DirectoryInfo(subFolder), ImportMode.Auto, null);
|
|
||||||
results.AddRange(folderResults);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var videoFile in _diskScanService.GetNonAudioFiles(directoryInfo.FullName, false))
|
|
||||||
{
|
|
||||||
var fileResults = ProcessFile(new FileInfo(videoFile), ImportMode.Auto, null);
|
|
||||||
results.AddRange(fileResults);
|
|
||||||
}
|
|
||||||
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<ImportResult> ProcessPath(string path, ImportMode importMode = ImportMode.Auto, Series series = null, DownloadClientItem downloadClientItem = null)
|
|
||||||
{
|
|
||||||
if (_diskProvider.FolderExists(path))
|
|
||||||
{
|
|
||||||
var directoryInfo = new DirectoryInfo(path);
|
|
||||||
|
|
||||||
if (series == null)
|
|
||||||
{
|
|
||||||
return ProcessFolder(directoryInfo, importMode, downloadClientItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ProcessFolder(directoryInfo, importMode, series, downloadClientItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_diskProvider.FileExists(path))
|
|
||||||
{
|
|
||||||
var fileInfo = new FileInfo(path);
|
|
||||||
|
|
||||||
if (series == null)
|
|
||||||
{
|
|
||||||
return ProcessFile(fileInfo, importMode, downloadClientItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ProcessFile(fileInfo, importMode, series, downloadClientItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
_logger.Error("Import failed, path does not exist or is not accessible by Lidarr: {0}", path);
|
|
||||||
return new List<ImportResult>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool ShouldDeleteFolder(DirectoryInfo directoryInfo, Series series)
|
|
||||||
{
|
|
||||||
var videoFiles = _diskScanService.GetNonAudioFiles(directoryInfo.FullName);
|
|
||||||
var rarFiles = _diskProvider.GetFiles(directoryInfo.FullName, SearchOption.AllDirectories).Where(f => Path.GetExtension(f) == ".rar");
|
|
||||||
|
|
||||||
foreach (var videoFile in videoFiles)
|
|
||||||
{
|
|
||||||
var episodeParseResult = Parser.Parser.ParseTitle(Path.GetFileName(videoFile));
|
|
||||||
|
|
||||||
if (episodeParseResult == null)
|
|
||||||
{
|
|
||||||
_logger.Warn("Unable to parse file on import: [{0}]", videoFile);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
var size = _diskProvider.GetFileSize(videoFile);
|
|
||||||
var quality = QualityParser.ParseQuality(videoFile);
|
|
||||||
|
|
||||||
if (!_detectSample.IsSample(series, quality, videoFile, size, episodeParseResult.IsPossibleSpecialEpisode))
|
|
||||||
{
|
|
||||||
_logger.Warn("Non-sample file detected: [{0}]", videoFile);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rarFiles.Any(f => _diskProvider.GetFileSize(f) > 10.Megabytes()))
|
|
||||||
{
|
|
||||||
_logger.Warn("RAR file detected, will require manual cleanup");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<ImportResult> ProcessFolder(DirectoryInfo directoryInfo, ImportMode importMode, DownloadClientItem downloadClientItem)
|
|
||||||
{
|
|
||||||
var cleanedUpName = GetCleanedUpFolderName(directoryInfo.Name);
|
|
||||||
var series = _parsingService.GetSeries(cleanedUpName);
|
|
||||||
|
|
||||||
if (series == null)
|
|
||||||
{
|
|
||||||
_logger.Debug("Unknown Series {0}", cleanedUpName);
|
|
||||||
|
|
||||||
return new List<ImportResult>
|
|
||||||
{
|
|
||||||
UnknownSeriesResult("Unknown Series")
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return ProcessFolder(directoryInfo, importMode, series, downloadClientItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<ImportResult> ProcessFolder(DirectoryInfo directoryInfo, ImportMode importMode, Series series, DownloadClientItem downloadClientItem)
|
|
||||||
{
|
|
||||||
throw new System.NotImplementedException("Will be removed");
|
|
||||||
|
|
||||||
//if (_seriesService.SeriesPathExists(directoryInfo.FullName))
|
|
||||||
//{
|
|
||||||
// _logger.Warn("Unable to process folder that is mapped to an existing show");
|
|
||||||
// return new List<ImportResult>();
|
|
||||||
//}
|
|
||||||
|
|
||||||
//var cleanedUpName = GetCleanedUpFolderName(directoryInfo.Name);
|
|
||||||
//var folderInfo = Parser.Parser.ParseTitle(directoryInfo.Name);
|
|
||||||
|
|
||||||
//if (folderInfo != null)
|
|
||||||
//{
|
|
||||||
// _logger.Debug("{0} folder quality: {1}", cleanedUpName, folderInfo.Quality);
|
|
||||||
//}
|
|
||||||
|
|
||||||
//var videoFiles = _diskScanService.GetVideoFiles(directoryInfo.FullName);
|
|
||||||
|
|
||||||
//if (downloadClientItem == null)
|
|
||||||
//{
|
|
||||||
// foreach (var videoFile in videoFiles)
|
|
||||||
// {
|
|
||||||
// if (_diskProvider.IsFileLocked(videoFile))
|
|
||||||
// {
|
|
||||||
// return new List<ImportResult>
|
|
||||||
// {
|
|
||||||
// FileIsLockedResult(videoFile)
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
//var decisions = _importDecisionMaker.GetImportDecisions(videoFiles.ToList(), series, folderInfo, true);
|
|
||||||
//var importResults = _importApprovedEpisodes.Import(decisions, true, downloadClientItem, importMode);
|
|
||||||
|
|
||||||
//if ((downloadClientItem == null || !downloadClientItem.IsReadOnly) &&
|
|
||||||
// importResults.Any(i => i.Result == ImportResultType.Imported) &&
|
|
||||||
// ShouldDeleteFolder(directoryInfo, series))
|
|
||||||
//{
|
|
||||||
// _logger.Debug("Deleting folder after importing valid files");
|
|
||||||
// _diskProvider.DeleteFolder(directoryInfo.FullName, true);
|
|
||||||
//}
|
|
||||||
|
|
||||||
//return importResults;
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<ImportResult> ProcessFile(FileInfo fileInfo, ImportMode importMode, DownloadClientItem downloadClientItem)
|
|
||||||
{
|
|
||||||
var series = _parsingService.GetSeries(Path.GetFileNameWithoutExtension(fileInfo.Name));
|
|
||||||
|
|
||||||
if (series == null)
|
|
||||||
{
|
|
||||||
_logger.Debug("Unknown Series for file: {0}", fileInfo.Name);
|
|
||||||
|
|
||||||
return new List<ImportResult>
|
|
||||||
{
|
|
||||||
UnknownSeriesResult(string.Format("Unknown Series for file: {0}", fileInfo.Name), fileInfo.FullName)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return ProcessFile(fileInfo, importMode, series, downloadClientItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<ImportResult> ProcessFile(FileInfo fileInfo, ImportMode importMode, Series series, DownloadClientItem downloadClientItem)
|
|
||||||
{
|
|
||||||
throw new System.NotImplementedException("Will be removed");
|
|
||||||
//if (Path.GetFileNameWithoutExtension(fileInfo.Name).StartsWith("._"))
|
|
||||||
//{
|
|
||||||
// _logger.Debug("[{0}] starts with '._', skipping", fileInfo.FullName);
|
|
||||||
|
|
||||||
// return new List<ImportResult>
|
|
||||||
// {
|
|
||||||
// new ImportResult(new ImportDecision(new LocalTrack { Path = fileInfo.FullName }, new Rejection("Invalid music file, filename starts with '._'")), "Invalid music file, filename starts with '._'")
|
|
||||||
// };
|
|
||||||
//}
|
|
||||||
|
|
||||||
//if (downloadClientItem == null)
|
|
||||||
//{
|
|
||||||
// if (_diskProvider.IsFileLocked(fileInfo.FullName))
|
|
||||||
// {
|
|
||||||
// return new List<ImportResult>
|
|
||||||
// {
|
|
||||||
// FileIsLockedResult(fileInfo.FullName)
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
//var decisions = _importDecisionMaker.GetImportDecisions(new List<string>() { fileInfo.FullName }, series, null, true);
|
|
||||||
|
|
||||||
//return _importApprovedEpisodes.Import(decisions, true, downloadClientItem, importMode);
|
|
||||||
}
|
|
||||||
|
|
||||||
private string GetCleanedUpFolderName(string folder)
|
|
||||||
{
|
|
||||||
folder = folder.Replace("_UNPACK_", "")
|
|
||||||
.Replace("_FAILED_", "");
|
|
||||||
|
|
||||||
return folder;
|
|
||||||
}
|
|
||||||
|
|
||||||
private ImportResult FileIsLockedResult(string videoFile)
|
|
||||||
{
|
|
||||||
throw new System.NotImplementedException("Will be removed");
|
|
||||||
//_logger.Debug("[{0}] is currently locked by another process, skipping", videoFile);
|
|
||||||
//return new ImportResult(new ImportDecision(new LocalEpisode { Path = videoFile }, new Rejection("Locked file, try again later")), "Locked file, try again later");
|
|
||||||
}
|
|
||||||
|
|
||||||
private ImportResult UnknownSeriesResult(string message, string videoFile = null)
|
|
||||||
{
|
|
||||||
throw new System.NotImplementedException("Will be removed");
|
|
||||||
//var localEpisode = videoFile == null ? null : new LocalEpisode { Path = videoFile };
|
|
||||||
|
|
||||||
//return new ImportResult(new ImportDecision(localEpisode, new Rejection("Unknown Series")), message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,279 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using NLog;
|
||||||
|
using NzbDrone.Common.Disk;
|
||||||
|
using NzbDrone.Core.DecisionEngine;
|
||||||
|
using NzbDrone.Core.MediaFiles.TrackImport;
|
||||||
|
using NzbDrone.Core.Parser;
|
||||||
|
using NzbDrone.Core.Music;
|
||||||
|
using NzbDrone.Core.Download;
|
||||||
|
using NzbDrone.Core.Parser.Model;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.MediaFiles
|
||||||
|
{
|
||||||
|
public interface IDownloadedTracksImportService
|
||||||
|
{
|
||||||
|
List<ImportResult> ProcessRootFolder(DirectoryInfo directoryInfo);
|
||||||
|
List<ImportResult> ProcessPath(string path, ImportMode importMode = ImportMode.Auto, Artist artist = null, DownloadClientItem downloadClientItem = null);
|
||||||
|
bool ShouldDeleteFolder(DirectoryInfo directoryInfo, Artist artist);
|
||||||
|
}
|
||||||
|
|
||||||
|
public class DownloadedTracksImportService : IDownloadedTracksImportService
|
||||||
|
{
|
||||||
|
private readonly IDiskProvider _diskProvider;
|
||||||
|
private readonly IDiskScanService _diskScanService;
|
||||||
|
private readonly IArtistService _artistService;
|
||||||
|
private readonly IParsingService _parsingService;
|
||||||
|
private readonly IMakeImportDecision _importDecisionMaker;
|
||||||
|
private readonly IImportApprovedTracks _importApprovedTracks;
|
||||||
|
private readonly IDetectSample _detectSample;
|
||||||
|
private readonly Logger _logger;
|
||||||
|
|
||||||
|
public DownloadedTracksImportService(IDiskProvider diskProvider,
|
||||||
|
IDiskScanService diskScanService,
|
||||||
|
IArtistService artistService,
|
||||||
|
IParsingService parsingService,
|
||||||
|
IMakeImportDecision importDecisionMaker,
|
||||||
|
IImportApprovedTracks importApprovedTracks,
|
||||||
|
IDetectSample detectSample,
|
||||||
|
Logger logger)
|
||||||
|
{
|
||||||
|
_diskProvider = diskProvider;
|
||||||
|
_diskScanService = diskScanService;
|
||||||
|
_artistService = artistService;
|
||||||
|
_parsingService = parsingService;
|
||||||
|
_importDecisionMaker = importDecisionMaker;
|
||||||
|
_importApprovedTracks = importApprovedTracks;
|
||||||
|
_detectSample = detectSample;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ImportResult> ProcessRootFolder(DirectoryInfo directoryInfo)
|
||||||
|
{
|
||||||
|
var results = new List<ImportResult>();
|
||||||
|
|
||||||
|
foreach (var subFolder in _diskProvider.GetDirectories(directoryInfo.FullName))
|
||||||
|
{
|
||||||
|
var folderResults = ProcessFolder(new DirectoryInfo(subFolder), ImportMode.Auto, null);
|
||||||
|
results.AddRange(folderResults);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var videoFile in _diskScanService.GetNonAudioFiles(directoryInfo.FullName, false))
|
||||||
|
{
|
||||||
|
var fileResults = ProcessFile(new FileInfo(videoFile), ImportMode.Auto, null);
|
||||||
|
results.AddRange(fileResults);
|
||||||
|
}
|
||||||
|
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ImportResult> ProcessPath(string path, ImportMode importMode = ImportMode.Auto, Artist artist = null, DownloadClientItem downloadClientItem = null)
|
||||||
|
{
|
||||||
|
if (_diskProvider.FolderExists(path))
|
||||||
|
{
|
||||||
|
var directoryInfo = new DirectoryInfo(path);
|
||||||
|
|
||||||
|
if (artist == null)
|
||||||
|
{
|
||||||
|
return ProcessFolder(directoryInfo, importMode, downloadClientItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ProcessFolder(directoryInfo, importMode, artist, downloadClientItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_diskProvider.FileExists(path))
|
||||||
|
{
|
||||||
|
var fileInfo = new FileInfo(path);
|
||||||
|
|
||||||
|
if (artist == null)
|
||||||
|
{
|
||||||
|
return ProcessFile(fileInfo, importMode, downloadClientItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ProcessFile(fileInfo, importMode, artist, downloadClientItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.Error("Import failed, path does not exist or is not accessible by Lidarr: {0}", path);
|
||||||
|
return new List<ImportResult>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool ShouldDeleteFolder(DirectoryInfo directoryInfo, Artist artist)
|
||||||
|
{
|
||||||
|
var audioFiles = _diskScanService.GetNonAudioFiles(directoryInfo.FullName);
|
||||||
|
var rarFiles = _diskProvider.GetFiles(directoryInfo.FullName, SearchOption.AllDirectories).Where(f => Path.GetExtension(f) == ".rar");
|
||||||
|
|
||||||
|
foreach (var audioFile in audioFiles)
|
||||||
|
{
|
||||||
|
var albumParseResult = Parser.Parser.ParseMusicTitle(Path.GetFileName(audioFile));
|
||||||
|
|
||||||
|
if (albumParseResult == null)
|
||||||
|
{
|
||||||
|
_logger.Warn("Unable to parse file on import: [{0}]", audioFile);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var size = _diskProvider.GetFileSize(audioFile);
|
||||||
|
var quality = QualityParser.ParseQuality(audioFile);
|
||||||
|
|
||||||
|
//if (!_detectSample.IsSample(artist, quality, audioFile, size, albumParseResult.IsPossibleSpecialEpisode))
|
||||||
|
//{
|
||||||
|
// _logger.Warn("Non-sample file detected: [{0}]", audioFile);
|
||||||
|
// return false;
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rarFiles.Any(f => _diskProvider.GetFileSize(f) > 10.Megabytes()))
|
||||||
|
{
|
||||||
|
_logger.Warn("RAR file detected, will require manual cleanup");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<ImportResult> ProcessFolder(DirectoryInfo directoryInfo, ImportMode importMode, DownloadClientItem downloadClientItem)
|
||||||
|
{
|
||||||
|
var cleanedUpName = GetCleanedUpFolderName(directoryInfo.Name);
|
||||||
|
|
||||||
|
var files = _diskScanService.GetAudioFiles(directoryInfo.FullName);
|
||||||
|
var artist = _parsingService.GetArtist(files.First());
|
||||||
|
|
||||||
|
if (artist == null)
|
||||||
|
{
|
||||||
|
_logger.Debug("Unknown Artist {0}", cleanedUpName);
|
||||||
|
|
||||||
|
return new List<ImportResult>
|
||||||
|
{
|
||||||
|
UnknownArtistResult("Unknown Artist")
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return ProcessFolder(directoryInfo, importMode, artist, downloadClientItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<ImportResult> ProcessFolder(DirectoryInfo 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,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
var audioFiles = _diskScanService.GetAudioFiles(directoryInfo.FullName);
|
||||||
|
|
||||||
|
if (downloadClientItem == null)
|
||||||
|
{
|
||||||
|
foreach (var audioFile in audioFiles)
|
||||||
|
{
|
||||||
|
if (_diskProvider.IsFileLocked(audioFile))
|
||||||
|
{
|
||||||
|
return new List<ImportResult>
|
||||||
|
{
|
||||||
|
FileIsLockedResult(audioFile)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var decisions = _importDecisionMaker.GetImportDecisions(audioFiles.ToList(), artist, trackInfo);
|
||||||
|
var importResults = _importApprovedTracks.Import(decisions, true, downloadClientItem, importMode);
|
||||||
|
|
||||||
|
if ((downloadClientItem == null || !downloadClientItem.IsReadOnly) &&
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<ImportResult> ProcessFile(FileInfo fileInfo, ImportMode importMode, DownloadClientItem downloadClientItem)
|
||||||
|
{
|
||||||
|
var artist = _parsingService.GetArtist(Path.GetFileNameWithoutExtension(fileInfo.Name));
|
||||||
|
|
||||||
|
if (artist == null)
|
||||||
|
{
|
||||||
|
_logger.Debug("Unknown Artist for file: {0}", fileInfo.Name);
|
||||||
|
|
||||||
|
return new List<ImportResult>
|
||||||
|
{
|
||||||
|
UnknownArtistResult(string.Format("Unknown Artist for file: {0}", fileInfo.Name), fileInfo.FullName)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return ProcessFile(fileInfo, importMode, artist, downloadClientItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<ImportResult> ProcessFile(FileInfo fileInfo, ImportMode importMode, Artist artist, DownloadClientItem downloadClientItem)
|
||||||
|
{
|
||||||
|
if (Path.GetFileNameWithoutExtension(fileInfo.Name).StartsWith("._"))
|
||||||
|
{
|
||||||
|
_logger.Debug("[{0}] starts with '._', skipping", fileInfo.FullName);
|
||||||
|
|
||||||
|
return new List<ImportResult>
|
||||||
|
{
|
||||||
|
new ImportResult(new ImportDecision(new LocalTrack { Path = fileInfo.FullName }, new Rejection("Invalid music file, filename starts with '._'")), "Invalid music file, filename starts with '._'")
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (downloadClientItem == null)
|
||||||
|
{
|
||||||
|
if (_diskProvider.IsFileLocked(fileInfo.FullName))
|
||||||
|
{
|
||||||
|
return new List<ImportResult>
|
||||||
|
{
|
||||||
|
FileIsLockedResult(fileInfo.FullName)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var decisions = _importDecisionMaker.GetImportDecisions(new List<string>() { fileInfo.FullName }, artist, null);
|
||||||
|
|
||||||
|
return _importApprovedTracks.Import(decisions, true, downloadClientItem, importMode);
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GetCleanedUpFolderName(string folder)
|
||||||
|
{
|
||||||
|
folder = folder.Replace("_UNPACK_", "")
|
||||||
|
.Replace("_FAILED_", "");
|
||||||
|
|
||||||
|
return folder;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ImportResult FileIsLockedResult(string audioFile)
|
||||||
|
{
|
||||||
|
_logger.Debug("[{0}] is currently locked by another process, skipping", audioFile);
|
||||||
|
return new ImportResult(new ImportDecision(new LocalTrack { Path = audioFile }, new Rejection("Locked file, try again later")), "Locked file, try again later");
|
||||||
|
}
|
||||||
|
|
||||||
|
private ImportResult UnknownArtistResult(string message, string audioFile = null)
|
||||||
|
{
|
||||||
|
var localTrack = audioFile == null ? null : new LocalTrack { Path = audioFile };
|
||||||
|
|
||||||
|
return new ImportResult(new ImportDecision(localTrack, new Rejection("Unknown Artist")), message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue