|
|
|
@ -69,8 +69,12 @@ namespace NzbDrone.Core.Providers
|
|
|
|
|
{
|
|
|
|
|
Logger.Trace("Importing file to database [{0}]", filePath);
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
if (_database.Exists<EpisodeFile>("Path =@0", Parser.NormalizePath(filePath)))
|
|
|
|
|
{
|
|
|
|
|
Logger.Trace("[{0}] already exists in the database. skipping.", filePath);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var size = _diskProvider.GetSize(filePath);
|
|
|
|
|
|
|
|
|
|
//If Size is less than 50MB and contains sample. Check for Size to ensure its not an episode with sample in the title
|
|
|
|
@ -80,9 +84,6 @@ namespace NzbDrone.Core.Providers
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Check to see if file already exists in the database
|
|
|
|
|
if (!_database.Exists<EpisodeFile>("Path =@0", Parser.NormalizePath(filePath)))
|
|
|
|
|
{
|
|
|
|
|
var parseResult = Parser.ParseEpisodeInfo(filePath);
|
|
|
|
|
|
|
|
|
|
if (parseResult == null)
|
|
|
|
@ -151,16 +152,7 @@ namespace NzbDrone.Core.Providers
|
|
|
|
|
episodeList);
|
|
|
|
|
|
|
|
|
|
return episodeFile;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Logger.Trace("[{0}] already exists in the database. skipping.", filePath);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Logger.ErrorException("An error has occurred while importing file " + filePath, ex);
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -311,7 +303,7 @@ namespace NzbDrone.Core.Providers
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual string GetNewFilename(IList<Episode> episodes, string seriesName, QualityTypes quality)
|
|
|
|
|
public virtual string GetNewFilename(IList<Episode> episodes, string seriesTitle, QualityTypes quality)
|
|
|
|
|
{
|
|
|
|
|
var separatorStyle = EpisodeSortingHelper.GetSeparatorStyle(_configProvider.SeparatorStyle);
|
|
|
|
|
var numberStyle = EpisodeSortingHelper.GetNumberStyle(_configProvider.NumberStyle);
|
|
|
|
@ -322,7 +314,7 @@ namespace NzbDrone.Core.Providers
|
|
|
|
|
|
|
|
|
|
if (_configProvider.SeriesName)
|
|
|
|
|
{
|
|
|
|
|
result += seriesName + separatorStyle.Pattern;
|
|
|
|
|
result += seriesTitle + separatorStyle.Pattern;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result += numberStyle.Pattern.Replace("%0e", String.Format("{0:00}", episodes[0].EpisodeNumber));
|
|
|
|
@ -369,25 +361,36 @@ namespace NzbDrone.Core.Providers
|
|
|
|
|
return result.Trim();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual FileInfo CalculateFilePath(Series series, int seasonNumber, string fileName, string extention)
|
|
|
|
|
{
|
|
|
|
|
var path = series.Path;
|
|
|
|
|
if (series.SeasonFolder)
|
|
|
|
|
{
|
|
|
|
|
path = Path.Combine(path, "Season " + seasonNumber);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
path = Path.Combine(path, fileName + extention);
|
|
|
|
|
|
|
|
|
|
return new FileInfo(path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual bool RenameEpisodeFile(EpisodeFile episodeFile)
|
|
|
|
|
{
|
|
|
|
|
if (episodeFile == null)
|
|
|
|
|
throw new ArgumentNullException("episodeFile");
|
|
|
|
|
|
|
|
|
|
var series = _seriesProvider.GetSeries(episodeFile.SeriesId);
|
|
|
|
|
var folder = new FileInfo(episodeFile.Path).DirectoryName;
|
|
|
|
|
var ext = _diskProvider.GetExtension(episodeFile.Path);
|
|
|
|
|
var episodes = _episodeProvider.GetEpisodesByFileId(episodeFile.EpisodeFileId);
|
|
|
|
|
|
|
|
|
|
var newFileName = GetNewFilename(episodes, series.Title, episodeFile.Quality);
|
|
|
|
|
|
|
|
|
|
var newFile = folder + Path.DirectorySeparatorChar + newFileName + ext;
|
|
|
|
|
var newFile = CalculateFilePath(series, episodes.First().SeasonNumber, newFileName, ext);
|
|
|
|
|
|
|
|
|
|
//Do the rename
|
|
|
|
|
_diskProvider.RenameFile(episodeFile.Path, newFile);
|
|
|
|
|
_diskProvider.RenameFile(episodeFile.Path, newFile.FullName);
|
|
|
|
|
|
|
|
|
|
//Update the filename in the DB
|
|
|
|
|
episodeFile.Path = newFile;
|
|
|
|
|
episodeFile.Path = newFile.FullName;
|
|
|
|
|
Update(episodeFile);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|