Reformated some files

This commit is contained in:
kay.one 2011-06-19 20:25:04 -07:00
parent 63bd972af9
commit 8b7c624d09
2 changed files with 19 additions and 44 deletions

View File

@ -2,33 +2,28 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Ninject;
using NLog;
using NzbDrone.Core.Helpers;
using NzbDrone.Core.Model.Notification;
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Repository;
using NzbDrone.Core.Repository.Quality;
using PetaPoco;
namespace NzbDrone.Core.Providers
{
public class DiskScanProvider
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private static readonly string[] MediaExtentions = new[] { ".mkv", ".avi", ".wmv", ".mp4" };
private static readonly string[] MediaExtentions = new[] {".mkv", ".avi", ".wmv", ".mp4"};
private readonly IDatabase _database;
private readonly DiskProvider _diskProvider;
private readonly EpisodeProvider _episodeProvider;
private readonly SeriesProvider _seriesProvider;
private readonly MediaFileProvider _mediaFileProvider;
private readonly IDatabase _database;
private readonly SeriesProvider _seriesProvider;
[Inject]
public DiskScanProvider(DiskProvider diskProvider, EpisodeProvider episodeProvider,
SeriesProvider seriesProvider, MediaFileProvider mediaFileProvider,
IDatabase database)
SeriesProvider seriesProvider, MediaFileProvider mediaFileProvider,
IDatabase database)
{
_diskProvider = diskProvider;
_episodeProvider = episodeProvider;
@ -40,7 +35,6 @@ namespace NzbDrone.Core.Providers
public DiskScanProvider()
{
}
/// <summary>
@ -92,7 +86,7 @@ namespace NzbDrone.Core.Providers
return null;
}
var size = _diskProvider.GetSize(filePath);
long 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
if (size < 40000000 && filePath.ToLower().Contains("sample"))
@ -106,7 +100,7 @@ namespace NzbDrone.Core.Providers
if (parseResult == null)
return null;
parseResult.CleanTitle = series.Title;//replaces the nasty path as title to help with logging
parseResult.CleanTitle = series.Title; //replaces the nasty path as title to help with logging
//Stores the list of episodes to add to the EpisodeFile
var episodes = new List<Episode>();
@ -155,7 +149,7 @@ namespace NzbDrone.Core.Providers
episodeFile.Quality = parseResult.Quality.QualityType;
episodeFile.Proper = parseResult.Quality.Proper;
episodeFile.SeasonNumber = parseResult.SeasonNumber;
var fileId = Convert.ToInt32(_database.Insert(episodeFile));
int fileId = Convert.ToInt32(_database.Insert(episodeFile));
//This is for logging + updating the episodes that are linked to this EpisodeFile
string episodeList = String.Empty;
@ -169,21 +163,18 @@ namespace NzbDrone.Core.Providers
episodeList);
return episodeFile;
}
public virtual bool RenameEpisodeFile(EpisodeFile episodeFile)
{
if (episodeFile == null)
throw new ArgumentNullException("episodeFile");
var series = _seriesProvider.GetSeries(episodeFile.SeriesId);
var ext = _diskProvider.GetExtension(episodeFile.Path);
string ext = _diskProvider.GetExtension(episodeFile.Path);
var episodes = _episodeProvider.GetEpisodesByFileId(episodeFile.EpisodeFileId);
var newFileName = _mediaFileProvider.GetNewFilename(episodes, series.Title, episodeFile.Quality);
string newFileName = _mediaFileProvider.GetNewFilename(episodes, series.Title, episodeFile.Quality);
var newFile = _mediaFileProvider.CalculateFilePath(series, episodes.First().SeasonNumber, newFileName, ext);
@ -199,9 +190,8 @@ namespace NzbDrone.Core.Providers
}
/// <summary>
/// Removes files that no longer exist from the database
/// Removes files that no longer exist on disk from the database
/// </summary>
/// <param name = "files">list of files to verify</param>
public virtual void CleanUp(List<EpisodeFile> files)
@ -238,6 +228,5 @@ namespace NzbDrone.Core.Providers
Logger.Debug("{0} media files were found in {1}", mediaFileList.Count, path);
return mediaFileList;
}
}
}
}

View File

@ -5,7 +5,6 @@ using System.Linq;
using Ninject;
using NLog;
using NzbDrone.Core.Helpers;
using NzbDrone.Core.Model.Notification;
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Repository;
using NzbDrone.Core.Repository.Quality;
@ -16,9 +15,9 @@ namespace NzbDrone.Core.Providers
public class MediaFileProvider
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private readonly EpisodeProvider _episodeProvider;
private readonly ConfigProvider _configProvider;
private readonly IDatabase _database;
private readonly EpisodeProvider _episodeProvider;
[Inject]
public MediaFileProvider(EpisodeProvider episodeProvider, ConfigProvider configProvider, IDatabase database)
@ -28,15 +27,9 @@ namespace NzbDrone.Core.Providers
_database = database;
}
public MediaFileProvider() { }
public MediaFileProvider()
{
}
public virtual void Update(EpisodeFile episodeFile)
{
@ -70,7 +63,7 @@ namespace NzbDrone.Core.Providers
public virtual FileInfo CalculateFilePath(Series series, int seasonNumber, string fileName, string extention)
{
var path = series.Path;
string path = series.Path;
if (series.SeasonFolder)
{
path = Path.Combine(path, "Season " + seasonNumber);
@ -81,15 +74,14 @@ namespace NzbDrone.Core.Providers
return new FileInfo(path);
}
public virtual string GetNewFilename(IList<Episode> episodes, string seriesTitle, QualityTypes quality)
{
var separatorStyle = EpisodeSortingHelper.GetSeparatorStyle(_configProvider.SeparatorStyle);
var numberStyle = EpisodeSortingHelper.GetNumberStyle(_configProvider.NumberStyle);
var episodeNames = episodes[0].Title;
string episodeNames = episodes[0].Title;
var result = String.Empty;
string result = String.Empty;
if (_configProvider.SeriesName)
{
@ -139,11 +131,5 @@ namespace NzbDrone.Core.Providers
Logger.Debug("New File Name is: {0}", result.Trim());
return result.Trim();
}
}
}