1
0
Fork 0
mirror of https://github.com/Sonarr/Sonarr synced 2024-12-28 02:37:40 +00:00
Sonarr/NzbDrone.Core/Providers/MisnamedProvider.cs

63 lines
2.4 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using NzbDrone.Core.Organizer;
using NzbDrone.Core.Tv;
using NzbDrone.Core.Model;
2013-03-07 01:51:47 +00:00
namespace NzbDrone.Core.Providers
{
public class MisnamedProvider
{
private readonly IEpisodeService _episodeService;
private readonly IBuildFileNames _buildFileNames;
public MisnamedProvider(IEpisodeService episodeService, IBuildFileNames buildFileNames)
{
_episodeService = episodeService;
_buildFileNames = buildFileNames;
}
public virtual List<MisnamedEpisodeModel> MisnamedFiles(int pageNumber, int pageSize, out int totalItems)
2013-03-06 21:35:39 +00:00
{
var misnamedFiles = new List<MisnamedEpisodeModel>();
var episodesWithFiles = _episodeService.EpisodesWithFiles().GroupBy(e => e.EpisodeFileId).ToList();
totalItems = episodesWithFiles.Count();
var misnamedFilesSelect = episodesWithFiles.AsParallel().Where(
w =>
w.First().EpisodeFile.Path !=
2013-03-06 21:35:39 +00:00
_buildFileNames.BuildFilename(w.Select(e => e).ToList(), w.First().Series, w.First().EpisodeFile)).Skip(Math.Max(pageSize * (pageNumber - 1), 0)).Take(pageSize);
//Process the episodes
misnamedFilesSelect.AsParallel().ForAll(f =>
2013-04-17 23:32:53 +00:00
{
var episodes = f.Select(e => e).ToList();
var firstEpisode = episodes[0];
var properName = _buildFileNames.BuildFilename(episodes, firstEpisode.Series,
firstEpisode.EpisodeFile);
var currentName = Path.GetFileNameWithoutExtension(firstEpisode.EpisodeFile.Path);
if (properName != currentName)
{
misnamedFiles.Add(new MisnamedEpisodeModel
{
CurrentName = currentName,
EpisodeFileId = firstEpisode.EpisodeFileId,
ProperName = properName,
SeriesId = firstEpisode.SeriesId,
SeriesTitle = firstEpisode.Series.Title
});
}
});
return misnamedFiles.OrderBy(e => e.SeriesTitle).ToList();
}
}
}