@ -14,15 +14,17 @@ namespace NzbDrone.Core.Providers
public class MediaFileProvider : IMediaFileProvider
public class MediaFileProvider : IMediaFileProvider
{
{
private readonly IRepository _repository ;
private readonly IRepository _repository ;
private readonly IConfigProvider _configProvider ;
private readonly IDiskProvider _diskProvider ;
private readonly IDiskProvider _diskProvider ;
private readonly IEpisodeProvider _episodeProvider ;
private readonly IEpisodeProvider _episodeProvider ;
private static readonly Logger Logger = LogManager . GetCurrentClassLogger ( ) ;
private static readonly Logger Logger = LogManager . GetCurrentClassLogger ( ) ;
private static readonly string [ ] MediaExtentions = new [ ] { "*.mkv" , "*.avi" , "*.wmv" } ;
private static readonly string [ ] MediaExtentions = new [ ] { "*.mkv" , "*.avi" , "*.wmv" } ;
public MediaFileProvider ( IRepository repository , I DiskProvider diskProvider , IEpisodeProvider episodeProvider )
public MediaFileProvider ( IRepository repository , I ConfigProvider _configProvider , I DiskProvider diskProvider , IEpisodeProvider episodeProvider )
{
{
_repository = repository ;
_repository = repository ;
this . _configProvider = _configProvider ;
_diskProvider = diskProvider ;
_diskProvider = diskProvider ;
_episodeProvider = episodeProvider ;
_episodeProvider = episodeProvider ;
}
}
@ -55,21 +57,21 @@ namespace NzbDrone.Core.Providers
var episode = _episodeProvider . GetEpisode ( series . SeriesId , closureEpisode . SeasonNumber , closureEpisode . EpisodeNumber ) ;
var episode = _episodeProvider . GetEpisode ( series . SeriesId , closureEpisode . SeasonNumber , closureEpisode . EpisodeNumber ) ;
if ( episode ! = null )
if ( episode ! = null )
{
{
var ep File = new EpisodeFile ( ) ;
var ep isode File = new EpisodeFile ( ) ;
ep File. DateAdded = DateTime . Now ;
ep isode File. DateAdded = DateTime . Now ;
ep File. SeriesId = series . SeriesId ;
ep isode File. SeriesId = series . SeriesId ;
ep File. EpisodeId = episode . EpisodeId ;
ep isode File. EpisodeId = episode . EpisodeId ;
ep File. Path = Parser . NormalizePath ( filePath ) ;
ep isode File. Path = Parser . NormalizePath ( filePath ) ;
ep File. Size = _diskProvider . GetSize ( filePath ) ;
ep isode File. Size = _diskProvider . GetSize ( filePath ) ;
ep File. Quality = Parser . ParseQuality ( filePath ) ;
ep isode File. Quality = Parser . ParseQuality ( filePath ) ;
ep File. Proper = Parser . ParseProper ( filePath ) ;
ep isode File. Proper = Parser . ParseProper ( filePath ) ;
_repository . Add ( ep File) ;
_repository . Add ( ep isode File) ;
Logger . Info( "File '{0}' successfully attached to {1}" , episode . EpisodeId ) ;
Logger . Trace( "File {0}:{1} attached to '{2}'" , episodeFile . FileId , filePath , episode . EpisodeId ) ;
return ep File;
return ep isode File;
}
}
Logger . Warn ( "Unable to find Series:{0} Season:{1} Episode:{2} in the database. ", series . Title , closureEpisode . SeasonNumber , closureEpisode . EpisodeNumber ) ;
Logger . Warn ( "Unable to find Series:{0} Season:{1} Episode:{2} in the database. File:{3} ", series . Title , closureEpisode . SeasonNumber , closureEpisode . EpisodeNumber , filePath ) ;
}
}
}
}
else
else
@ -96,9 +98,23 @@ namespace NzbDrone.Core.Providers
}
}
}
}
public string GenerateEpisodePath ( EpisodeModel episode )
{
var episodeNamePattern = _configProvider . EpisodeNameFormat ;
episodeNamePattern = episodeNamePattern . Replace ( "{series}" , "{0}" ) ;
episodeNamePattern = episodeNamePattern . Replace ( "{episode" , "{1" ) ;
episodeNamePattern = episodeNamePattern . Replace ( "{season" , "{2" ) ;
episodeNamePattern = episodeNamePattern . Replace ( "{title}" , "{3}" ) ;
episodeNamePattern = episodeNamePattern . Replace ( "{quality}" , "{4}" ) ;
return String . Format ( episodeNamePattern , episode . SeriesTitle , episode . EpisodeNumber , episode . SeasonNumber , episode . EpisodeTitle , episode . Quality ) ;
}
private List < string > GetMediaFileList ( string path )
private List < string > GetMediaFileList ( string path )
{
{
Logger . Info ( "Scanning '{0}' for episodes" , path ) ;
Logger . Debug ( "Scanning '{0}' for episodes" , path ) ;
var mediaFileList = new List < string > ( ) ;
var mediaFileList = new List < string > ( ) ;
@ -107,8 +123,9 @@ namespace NzbDrone.Core.Providers
mediaFileList . AddRange ( _diskProvider . GetFiles ( path , ext , SearchOption . AllDirectories ) ) ;
mediaFileList . AddRange ( _diskProvider . GetFiles ( path , ext , SearchOption . AllDirectories ) ) ;
}
}
Logger . Info ( "{0} media files were found in {1}" , mediaFileList . Count , path ) ;
Logger . Trace ( "{0} media files were found in {1}" , mediaFileList . Count , path ) ;
return mediaFileList ;
return mediaFileList ;
}
}
}
}
}
}