@ -15,6 +15,7 @@ using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.Parser ;
using NzbDrone.Core.Parser ;
using NzbDrone.Core.Parser.Model ;
using NzbDrone.Core.Parser.Model ;
using NzbDrone.Core.Tv ;
using NzbDrone.Core.Tv ;
using NzbDrone.Core.MediaFiles.TrackImport ;
namespace NzbDrone.Core.MediaFiles.EpisodeImport.Manual
namespace NzbDrone.Core.MediaFiles.EpisodeImport.Manual
{
{
@ -94,65 +95,67 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Manual
private List < ManualImportItem > ProcessFolder ( string folder , string downloadId )
private List < ManualImportItem > ProcessFolder ( string folder , string downloadId )
{
{
var directoryInfo = new DirectoryInfo ( folder ) ;
throw new System . NotImplementedException ( "TODO: This will be rewritten for Music" ) ;
var series = _parsingService . GetSeries ( directoryInfo . Name ) ;
//var directoryInfo = new DirectoryInfo(folder);
//var series = _parsingService.GetSeries(directoryInfo.Name);
if ( series = = null & & downloadId . IsNotNullOrWhiteSpace ( ) )
//if (series == null && downloadId.IsNotNullOrWhiteSpace() )
{
// {
var trackedDownload = _trackedDownloadService . Find ( downloadId ) ;
// var trackedDownload = _trackedDownloadService.Find(downloadId);
series = trackedDownload . RemoteEpisode . Series ;
// series = trackedDownload.RemoteEpisode.Series;
}
// }
if ( series = = null )
//if (series == null )
{
// {
var files = _diskScanService . GetVideoFiles ( folder ) ;
// var files = _diskScanService.GetVideoFiles(folder);
return files . Select ( file = > ProcessFile ( file , downloadId , folder ) ) . Where ( i = > i ! = null ) . ToList ( ) ;
// return files.Select(file => ProcessFile(file, downloadId, folder)).Where(i => i != null).ToList();
}
// }
var folderInfo = Parser . Parser . ParseTitle ( directoryInfo . Name ) ;
//var folderInfo = Parser.Parser.ParseTitle(directoryInfo.Name) ;
var seriesFiles = _diskScanService . GetVideoFiles ( folder ) . ToList ( ) ;
//var seriesFiles = _diskScanService.GetVideoFiles(folder).ToList() ;
var decisions = _importDecisionMaker . GetImportDecisions ( seriesFiles , series , folderInfo , SceneSource ( series , folder ) ) ;
//var decisions = _importDecisionMaker.GetImportDecisions(seriesFiles, series, folderInfo, SceneSource(series, folder)) ;
return decisions . Select ( decision = > MapItem ( decision , folder , downloadId ) ) . ToList ( ) ;
//return decisions.Select(decision => MapItem(decision, folder, downloadId)).ToList() ;
}
}
private ManualImportItem ProcessFile ( string file , string downloadId , string folder = null )
private ManualImportItem ProcessFile ( string file , string downloadId , string folder = null )
{
{
if ( folder . IsNullOrWhiteSpace ( ) )
throw new System . NotImplementedException ( "TODO: This will be rewritten for Music" ) ;
{
//if (folder.IsNullOrWhiteSpace())
folder = new FileInfo ( file ) . Directory . FullName ;
//{
}
// folder = new FileInfo(file).Directory.FullName;
//}
var relativeFile = folder . GetRelativePath ( file ) ;
//var relativeFile = folder.GetRelativePath(file) ;
var series = _parsingService . GetSeries ( relativeFile . Split ( '\\' , '/' ) [ 0 ] ) ;
//var series = _parsingService.GetSeries(relativeFile.Split('\\', '/')[0]) ;
if ( series = = null )
//if (series == null )
{
// {
series = _parsingService . GetSeries ( relativeFile ) ;
// series = _parsingService.GetSeries(relativeFile);
}
// }
if ( series = = null & & downloadId . IsNotNullOrWhiteSpace ( ) )
//if (series == null && downloadId.IsNotNullOrWhiteSpace() )
{
// {
var trackedDownload = _trackedDownloadService . Find ( downloadId ) ;
// var trackedDownload = _trackedDownloadService.Find(downloadId);
series = trackedDownload . RemoteEpisode . Series ;
// series = trackedDownload.RemoteEpisode.Series;
}
// }
if ( series = = null )
//if (series == null )
{
// {
var localEpisode = new LocalEpisode ( ) ;
// var localEpisode = new LocalEpisode();
localEpisode . Path = file ;
// localEpisode.Path = file;
localEpisode . Quality = QualityParser . ParseQuality ( file ) ;
// localEpisode.Quality = QualityParser.ParseQuality(file);
localEpisode . Size = _diskProvider . GetFileSize ( file ) ;
// localEpisode.Size = _diskProvider.GetFileSize(file);
return MapItem ( new ImportDecision ( localEpisode , new Rejection ( "Unknown Series" ) ) , folder , downloadId ) ;
// return MapItem(new ImportDecision(localEpisode, new Rejection("Unknown Series")), folder, downloadId);
}
// }
var importDecisions = _importDecisionMaker . GetImportDecisions ( new List < string > { file } ,
//var importDecisions = _importDecisionMaker.GetImportDecisions(new List<string> {file} ,
series , null , SceneSource ( series , folder ) ) ;
// series, null, SceneSource(series, folder));
return importDecisions . Any ( ) ? MapItem ( importDecisions . First ( ) , folder , downloadId ) : null ;
//return importDecisions.Any() ? MapItem(importDecisions.First(), folder, downloadId) : null ;
}
}
private bool SceneSource ( Series series , string folder )
private bool SceneSource ( Series series , string folder )
@ -162,107 +165,109 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Manual
private ManualImportItem MapItem ( ImportDecision decision , string folder , string downloadId )
private ManualImportItem MapItem ( ImportDecision decision , string folder , string downloadId )
{
{
var item = new ManualImportItem ( ) ;
throw new System . NotImplementedException ( "TODO: This will be rewritten for Music" ) ;
//var item = new ManualImportItem();
item . Path = decision . LocalEpisode . Path ;
item . RelativePath = folder . GetRelativePath ( decision . LocalEpisode . Path ) ;
//item.Path = decision.LocalEpisode.Path;
item . Name = Path . GetFileNameWithoutExtension ( decision . LocalEpisode . Path ) ;
//item.RelativePath = folder.GetRelativePath(decision.LocalEpisode.Path);
item . DownloadId = downloadId ;
//item.Name = Path.GetFileNameWithoutExtension(decision.LocalEpisode.Path);
//item.DownloadId = downloadId;
if ( decision . LocalEpisode . Series ! = null )
{
//if (decision.LocalEpisode.Series != null)
item . Series = decision . LocalEpisode . Series ;
//{
}
// item.Series = decision.LocalEpisode.Series;
//}
if ( decision . LocalEpisode . Episodes . Any ( ) )
{
//if (decision.LocalEpisode.Episodes.Any())
item . SeasonNumber = decision . LocalEpisode . SeasonNumber ;
//{
item . Episodes = decision . LocalEpisode . Episodes ;
// item.SeasonNumber = decision.LocalEpisode.SeasonNumber;
}
// item.Episodes = decision.LocalEpisode.Episodes;
//}
item . Quality = decision . LocalEpisode . Quality ;
item . Size = _diskProvider . GetFileSize ( decision . LocalEpisode . Path ) ;
//item.Quality = decision.LocalEpisode.Quality;
item . Rejections = decision . Rejections ;
//item.Size = _diskProvider.GetFileSize(decision.LocalEpisode.Path);
//item.Rejections = decision.Rejections;
return item ;
//return item;
}
}
public void Execute ( ManualImportCommand message )
public void Execute ( ManualImportCommand message )
{
{
_logger . ProgressTrace ( "Manually importing {0} files using mode {1}" , message . Files . Count , message . ImportMode ) ;
_logger . ProgressTrace ( "Manually importing {0} files using mode {1}" , message . Files . Count , message . ImportMode ) ;
throw new System . NotImplementedException ( "TODO: This will be rewritten for Music" ) ;
var imported = new List < ImportResult > ( ) ;
var importedTrackedDownload = new List < ManuallyImportedFile > ( ) ;
//var imported = new List<ImportResult>();
//var importedTrackedDownload = new List<ManuallyImportedFile>();
for ( int i = 0 ; i < message . Files . Count ; i + + )
{
//for (int i = 0; i < message.Files.Count; i++)
_logger . ProgressTrace ( "Processing file {0} of {1}" , i + 1 , message . Files . Count ) ;
//{
// _logger.ProgressTrace("Processing file {0} of {1}", i + 1, message.Files.Count);
var file = message . Files [ i ] ;
var series = _seriesService . GetSeries ( file . SeriesId ) ;
// var file = message.Files[i];
var episodes = _episodeService . GetEpisodes ( file . EpisodeIds ) ;
// var series = _seriesService.GetSeries(file.SeriesId);
var parsedEpisodeInfo = Parser . Parser . ParsePath ( file . Path ) ? ? new ParsedEpisodeInfo ( ) ;
// var episodes = _episodeService.GetEpisodes(file.EpisodeIds);
var mediaInfo = _videoFileInfoReader . GetMediaInfo ( file . Path ) ;
// var parsedEpisodeInfo = Parser.Parser.ParsePath(file.Path) ?? new ParsedEpisodeInfo();
var existingFile = series . Path . IsParentPath ( file . Path ) ;
// var mediaInfo = _videoFileInfoReader.GetMediaInfo(file.Path);
// var existingFile = series.Path.IsParentPath(file.Path);
var localEpisode = new LocalEpisode
{
// var localEpisode = new LocalEpisode
ExistingFile = false ,
// {
Episodes = episodes ,
// ExistingFile = false,
MediaInfo = mediaInfo ,
// Episodes = episodes,
ParsedEpisodeInfo = parsedEpisodeInfo ,
// MediaInfo = mediaInfo,
Path = file . Path ,
// ParsedEpisodeInfo = parsedEpisodeInfo,
Quality = file . Quality ,
// Path = file.Path,
Series = series ,
// Quality = file.Quality,
Size = 0
// Series = series,
} ;
// Size = 0
// };
//TODO: Cleanup non-tracked downloads
// //TODO: Cleanup non-tracked downloads
var importDecision = new ImportDecision ( localEpisode ) ;
// var importDecision = new ImportDecision(localEpisode);
if ( file . DownloadId . IsNullOrWhiteSpace ( ) )
{
// if (file.DownloadId.IsNullOrWhiteSpace())
imported . AddRange ( _importApprovedEpisodes . Import ( new List < ImportDecision > { importDecision } , ! existingFile , null , message . ImportMode ) ) ;
// {
}
// imported.AddRange(_importApprovedEpisodes.Import(new List<ImportDecision> { importDecision }, !existingFile, null, message.ImportMode));
// }
else
{
// else
var trackedDownload = _trackedDownloadService . Find ( file . DownloadId ) ;
// {
var importResult = _importApprovedEpisodes . Import ( new List < ImportDecision > { importDecision } , true , trackedDownload . DownloadItem , message . ImportMode ) . First ( ) ;
// var trackedDownload = _trackedDownloadService.Find(file.DownloadId);
// var importResult = _importApprovedEpisodes.Import(new List<ImportDecision> { importDecision }, true, trackedDownload.DownloadItem, message.ImportMode).First();
imported . Add ( importResult ) ;
// imported.Add(importResult);
importedTrackedDownload . Add ( new ManuallyImportedFile
{
// importedTrackedDownload.Add(new ManuallyImportedFile
TrackedDownload = trackedDownload ,
// {
ImportResult = importResult
// TrackedDownload = trackedDownload,
} ) ;
// ImportResult = importResult
}
// });
}
// }
//}
_logger . ProgressTrace ( "Manually imported {0} files" , imported . Count ) ;
//_logger.ProgressTrace("Manually imported {0} files", imported.Count);
foreach ( var groupedTrackedDownload in importedTrackedDownload . GroupBy ( i = > i . TrackedDownload . DownloadItem . DownloadId ) . ToList ( ) )
{
//foreach (var groupedTrackedDownload in importedTrackedDownload.GroupBy(i => i.TrackedDownload.DownloadItem.DownloadId).ToList())
var trackedDownload = groupedTrackedDownload . First ( ) . TrackedDownload ;
//{
// var trackedDownload = groupedTrackedDownload.First().TrackedDownload;
if ( _diskProvider . FolderExists ( trackedDownload . DownloadItem . OutputPath . FullPath ) )
{
// if (_diskProvider.FolderExists(trackedDownload.DownloadItem.OutputPath.FullPath))
if ( _downloadedEpisodesImportService . ShouldDeleteFolder (
// {
new DirectoryInfo ( trackedDownload . DownloadItem . OutputPath . FullPath ) ,
// if (_downloadedEpisodesImportService.ShouldDeleteFolder(
trackedDownload . RemoteEpisode . Series ) & & ! trackedDownload . DownloadItem . IsReadOnly )
// new DirectoryInfo(trackedDownload.DownloadItem.OutputPath.FullPath),
{
// trackedDownload.RemoteEpisode.Series) && !trackedDownload.DownloadItem.IsReadOnly)
_diskProvider . DeleteFolder ( trackedDownload . DownloadItem . OutputPath . FullPath , true ) ;
// {
}
// _diskProvider.DeleteFolder(trackedDownload.DownloadItem.OutputPath.FullPath, true);
}
// }
// }
if ( groupedTrackedDownload . Select ( c = > c . ImportResult ) . Count ( c = > c . Result = = ImportResultType . Imported ) > = Math . Max ( 1 , trackedDownload . RemoteEpisode . Episodes . Count ) )
{
// if (groupedTrackedDownload.Select(c => c.ImportResult).Count(c => c.Result == ImportResultType.Imported) >= Math.Max(1, trackedDownload.RemoteEpisode.Episodes.Count))
trackedDownload . State = TrackedDownloadStage . Imported ;
// {
_eventAggregator . PublishEvent ( new DownloadCompletedEvent ( trackedDownload ) ) ;
// trackedDownload.State = TrackedDownloadStage.Imported;
}
// _eventAggregator.PublishEvent(new DownloadCompletedEvent(trackedDownload));
}
// }
//}
}
}
}
}
}
}