No more dupes and house cleaner added
This commit is contained in:
parent
3ca5e478ff
commit
409e1cca94
|
@ -0,0 +1,86 @@
|
||||||
|
using System.Linq;
|
||||||
|
using FizzWare.NBuilder;
|
||||||
|
using FluentAssertions;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using NzbDrone.Core.Housekeeping.Housekeepers;
|
||||||
|
using NzbDrone.Core.MediaFiles;
|
||||||
|
using NzbDrone.Core.Metadata.Files;
|
||||||
|
using NzbDrone.Core.Test.Framework;
|
||||||
|
using NzbDrone.Core.Tv;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Test.Housekeeping.Housekeepers
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class CleanupOrphanedMetadataFilesFixture : DbTest<CleanupOrphanedMetadataFiles, MetadataFile>
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void should_delete_metadata_files_that_dont_have_a_coresponding_series()
|
||||||
|
{
|
||||||
|
var metadataFile = Builder<MetadataFile>.CreateNew()
|
||||||
|
.With(m => m.EpisodeFileId = null)
|
||||||
|
.BuildNew();
|
||||||
|
|
||||||
|
Db.Insert(metadataFile);
|
||||||
|
Subject.Clean();
|
||||||
|
AllStoredModels.Should().BeEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_not_delete_metadata_files_that_have_a_coresponding_series()
|
||||||
|
{
|
||||||
|
var series = Builder<Series>.CreateNew()
|
||||||
|
.BuildNew();
|
||||||
|
|
||||||
|
Db.Insert(series);
|
||||||
|
|
||||||
|
var metadataFile = Builder<MetadataFile>.CreateNew()
|
||||||
|
.With(m => m.SeriesId = series.Id)
|
||||||
|
.With(m => m.EpisodeFileId = null)
|
||||||
|
.BuildNew();
|
||||||
|
|
||||||
|
Db.Insert(metadataFile);
|
||||||
|
Subject.Clean();
|
||||||
|
AllStoredModels.Should().HaveCount(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_delete_metadata_files_that_dont_have_a_coresponding_episode_file()
|
||||||
|
{
|
||||||
|
var series = Builder<Series>.CreateNew()
|
||||||
|
.BuildNew();
|
||||||
|
|
||||||
|
Db.Insert(series);
|
||||||
|
|
||||||
|
var metadataFile = Builder<MetadataFile>.CreateNew()
|
||||||
|
.With(m => m.SeriesId = series.Id)
|
||||||
|
.With(m => m.EpisodeFileId = 10)
|
||||||
|
.BuildNew();
|
||||||
|
|
||||||
|
Db.Insert(metadataFile);
|
||||||
|
Subject.Clean();
|
||||||
|
AllStoredModels.Should().BeEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_not_delete_metadata_files_that_have_a_coresponding_episode_file()
|
||||||
|
{
|
||||||
|
var series = Builder<Series>.CreateNew()
|
||||||
|
.BuildNew();
|
||||||
|
|
||||||
|
var episodeFile = Builder<EpisodeFile>.CreateNew()
|
||||||
|
.BuildNew();
|
||||||
|
|
||||||
|
Db.Insert(series);
|
||||||
|
Db.Insert(episodeFile);
|
||||||
|
|
||||||
|
var metadataFile = Builder<MetadataFile>.CreateNew()
|
||||||
|
.With(m => m.SeriesId = series.Id)
|
||||||
|
.With(m => m.EpisodeFileId = episodeFile.Id)
|
||||||
|
.BuildNew();
|
||||||
|
|
||||||
|
Db.Insert(metadataFile);
|
||||||
|
Subject.Clean();
|
||||||
|
AllStoredModels.Should().HaveCount(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -135,6 +135,7 @@
|
||||||
<Compile Include="Housekeeping\Housekeepers\CleanupOrphanedHistoryItemsFixture.cs" />
|
<Compile Include="Housekeeping\Housekeepers\CleanupOrphanedHistoryItemsFixture.cs" />
|
||||||
<Compile Include="Housekeeping\Housekeepers\CleanupOrphanedEpisodeFilesFixture.cs" />
|
<Compile Include="Housekeeping\Housekeepers\CleanupOrphanedEpisodeFilesFixture.cs" />
|
||||||
<Compile Include="Housekeeping\Housekeepers\CleanupAdditionalNamingSpecsFixture.cs" />
|
<Compile Include="Housekeeping\Housekeepers\CleanupAdditionalNamingSpecsFixture.cs" />
|
||||||
|
<Compile Include="Housekeeping\Housekeepers\CleanupOrphanedMetadataFilesFixture.cs" />
|
||||||
<Compile Include="Housekeeping\Housekeepers\FixFutureRunScheduledTasksFixture.cs" />
|
<Compile Include="Housekeeping\Housekeepers\FixFutureRunScheduledTasksFixture.cs" />
|
||||||
<Compile Include="IndexerSearchTests\SearchDefinitionFixture.cs" />
|
<Compile Include="IndexerSearchTests\SearchDefinitionFixture.cs" />
|
||||||
<Compile Include="IndexerTests\BasicRssParserFixture.cs" />
|
<Compile Include="IndexerTests\BasicRssParserFixture.cs" />
|
||||||
|
|
|
@ -120,7 +120,7 @@ namespace NzbDrone.Core.History
|
||||||
|
|
||||||
public void Handle(EpisodeImportedEvent message)
|
public void Handle(EpisodeImportedEvent message)
|
||||||
{
|
{
|
||||||
if (message.NewDownload)
|
if (!message.NewDownload)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
using NLog;
|
||||||
|
using NzbDrone.Core.Datastore;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Housekeeping.Housekeepers
|
||||||
|
{
|
||||||
|
public class CleanupOrphanedMetadataFiles : IHousekeepingTask
|
||||||
|
{
|
||||||
|
private readonly IDatabase _database;
|
||||||
|
private readonly Logger _logger;
|
||||||
|
|
||||||
|
public CleanupOrphanedMetadataFiles(IDatabase database, Logger logger)
|
||||||
|
{
|
||||||
|
_database = database;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Clean()
|
||||||
|
{
|
||||||
|
_logger.Trace("Running orphaned episode files cleanup");
|
||||||
|
|
||||||
|
DeleteOrphanedBySeries();
|
||||||
|
DeleteOrphanedByEpisodeFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DeleteOrphanedBySeries()
|
||||||
|
{
|
||||||
|
var mapper = _database.GetDataMapper();
|
||||||
|
|
||||||
|
mapper.ExecuteNonQuery(@"DELETE FROM MetadataFiles
|
||||||
|
WHERE Id IN (
|
||||||
|
SELECT MetadataFiles.Id FROM MetadataFiles
|
||||||
|
LEFT OUTER JOIN Series
|
||||||
|
ON MetadataFiles.SeriesId = Series.Id
|
||||||
|
WHERE Series.Id IS NULL)");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DeleteOrphanedByEpisodeFile()
|
||||||
|
{
|
||||||
|
var mapper = _database.GetDataMapper();
|
||||||
|
|
||||||
|
mapper.ExecuteNonQuery(@"DELETE FROM MetadataFiles
|
||||||
|
WHERE Id IN (
|
||||||
|
SELECT MetadataFiles.Id FROM MetadataFiles
|
||||||
|
LEFT OUTER JOIN EpisodeFiles
|
||||||
|
ON MetadataFiles.EpisodeFileId = EpisodeFiles.Id
|
||||||
|
WHERE MetadataFiles.EpisodeFileId > 0
|
||||||
|
AND EpisodeFiles.Id IS NULL)");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -17,6 +17,7 @@ namespace NzbDrone.Core.MediaCover
|
||||||
{
|
{
|
||||||
void ConvertToLocalUrls(int seriesId, IEnumerable<MediaCover> covers);
|
void ConvertToLocalUrls(int seriesId, IEnumerable<MediaCover> covers);
|
||||||
string GetCoverPath(int seriesId, MediaCoverTypes mediaCoverTypes);
|
string GetCoverPath(int seriesId, MediaCoverTypes mediaCoverTypes);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class MediaCoverService :
|
public class MediaCoverService :
|
||||||
|
@ -28,17 +29,24 @@ namespace NzbDrone.Core.MediaCover
|
||||||
private readonly IDiskProvider _diskProvider;
|
private readonly IDiskProvider _diskProvider;
|
||||||
private readonly ICoverExistsSpecification _coverExistsSpecification;
|
private readonly ICoverExistsSpecification _coverExistsSpecification;
|
||||||
private readonly IConfigFileProvider _configFileProvider;
|
private readonly IConfigFileProvider _configFileProvider;
|
||||||
|
private readonly IEventAggregator _eventAggregator;
|
||||||
private readonly Logger _logger;
|
private readonly Logger _logger;
|
||||||
|
|
||||||
private readonly string _coverRootFolder;
|
private readonly string _coverRootFolder;
|
||||||
|
|
||||||
public MediaCoverService(IHttpProvider httpProvider, IDiskProvider diskProvider, IAppFolderInfo appFolderInfo,
|
public MediaCoverService(IHttpProvider httpProvider,
|
||||||
ICoverExistsSpecification coverExistsSpecification, IConfigFileProvider configFileProvider, Logger logger)
|
IDiskProvider diskProvider,
|
||||||
|
IAppFolderInfo appFolderInfo,
|
||||||
|
ICoverExistsSpecification coverExistsSpecification,
|
||||||
|
IConfigFileProvider configFileProvider,
|
||||||
|
IEventAggregator eventAggregator,
|
||||||
|
Logger logger)
|
||||||
{
|
{
|
||||||
_httpProvider = httpProvider;
|
_httpProvider = httpProvider;
|
||||||
_diskProvider = diskProvider;
|
_diskProvider = diskProvider;
|
||||||
_coverExistsSpecification = coverExistsSpecification;
|
_coverExistsSpecification = coverExistsSpecification;
|
||||||
_configFileProvider = configFileProvider;
|
_configFileProvider = configFileProvider;
|
||||||
|
_eventAggregator = eventAggregator;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
|
||||||
_coverRootFolder = appFolderInfo.GetMediaCoverPath();
|
_coverRootFolder = appFolderInfo.GetMediaCoverPath();
|
||||||
|
@ -99,12 +107,12 @@ namespace NzbDrone.Core.MediaCover
|
||||||
|
|
||||||
_logger.Info("Downloading {0} for {1} {2}", cover.CoverType, series, cover.Url);
|
_logger.Info("Downloading {0} for {1} {2}", cover.CoverType, series, cover.Url);
|
||||||
_httpProvider.DownloadFile(cover.Url, fileName);
|
_httpProvider.DownloadFile(cover.Url, fileName);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void HandleAsync(SeriesUpdatedEvent message)
|
public void HandleAsync(SeriesUpdatedEvent message)
|
||||||
{
|
{
|
||||||
EnsureCovers(message.Series);
|
EnsureCovers(message.Series);
|
||||||
|
_eventAggregator.PublishEvent(new MediaCoversUpdatedEvent(message.Series));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void HandleAsync(SeriesDeletedEvent message)
|
public void HandleAsync(SeriesDeletedEvent message)
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
using NzbDrone.Common.Messaging;
|
||||||
|
using NzbDrone.Core.Tv;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.MediaCover
|
||||||
|
{
|
||||||
|
public class MediaCoversUpdatedEvent : IEvent
|
||||||
|
{
|
||||||
|
public Series Series { get; set; }
|
||||||
|
|
||||||
|
public MediaCoversUpdatedEvent(Series series)
|
||||||
|
{
|
||||||
|
Series = series;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,7 +1,4 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using NzbDrone.Core.Datastore;
|
using NzbDrone.Core.Datastore;
|
||||||
using NzbDrone.Core.Messaging.Events;
|
using NzbDrone.Core.Messaging.Events;
|
||||||
|
|
||||||
|
@ -12,7 +9,6 @@ namespace NzbDrone.Core.MediaFiles
|
||||||
{
|
{
|
||||||
List<EpisodeFile> GetFilesBySeries(int seriesId);
|
List<EpisodeFile> GetFilesBySeries(int seriesId);
|
||||||
List<EpisodeFile> GetFilesBySeason(int seriesId, int seasonNumber);
|
List<EpisodeFile> GetFilesBySeason(int seriesId, int seasonNumber);
|
||||||
EpisodeFile FindFileByPath(string path, bool includeExtension = true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -34,15 +30,5 @@ namespace NzbDrone.Core.MediaFiles
|
||||||
.AndWhere(c => c.SeasonNumber == seasonNumber)
|
.AndWhere(c => c.SeasonNumber == seasonNumber)
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public EpisodeFile FindFileByPath(string path, bool includeExtension = true)
|
|
||||||
{
|
|
||||||
if (includeExtension)
|
|
||||||
{
|
|
||||||
return Query.SingleOrDefault(c => c.Path == path);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Query.SingleOrDefault(c => c.Path.StartsWith(Path.ChangeExtension(path, "")));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,4 +1,3 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using NLog;
|
using NLog;
|
||||||
|
@ -19,7 +18,6 @@ namespace NzbDrone.Core.MediaFiles
|
||||||
List<string> FilterExistingFiles(List<string> files, int seriesId);
|
List<string> FilterExistingFiles(List<string> files, int seriesId);
|
||||||
EpisodeFile Get(int id);
|
EpisodeFile Get(int id);
|
||||||
List<EpisodeFile> Get(IEnumerable<int> ids);
|
List<EpisodeFile> Get(IEnumerable<int> ids);
|
||||||
EpisodeFile FindByPath(string path, bool includeExtension = true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class MediaFileService : IMediaFileService, IHandleAsync<SeriesDeletedEvent>
|
public class MediaFileService : IMediaFileService, IHandleAsync<SeriesDeletedEvent>
|
||||||
|
@ -83,11 +81,6 @@ namespace NzbDrone.Core.MediaFiles
|
||||||
return _mediaFileRepository.Get(ids).ToList();
|
return _mediaFileRepository.Get(ids).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public EpisodeFile FindByPath(string path, bool includeExtension = true)
|
|
||||||
{
|
|
||||||
return _mediaFileRepository.FindFileByPath(path, includeExtension);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void HandleAsync(SeriesDeletedEvent message)
|
public void HandleAsync(SeriesDeletedEvent message)
|
||||||
{
|
{
|
||||||
var files = GetFilesBySeries(message.Series.Id);
|
var files = GetFilesBySeries(message.Series.Id);
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
@ -26,17 +27,17 @@ namespace NzbDrone.Core.Metadata.Consumers.Fake
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnSeriesUpdated(Tv.Series series)
|
public override void OnSeriesUpdated(Series series, List<MetadataFile> existingMetadataFiles)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnEpisodeImport(Tv.Series series, EpisodeFile episodeFile, bool newDownload)
|
public override void OnEpisodeImport(Series series, EpisodeFile episodeFile, bool newDownload)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void AfterRename(Tv.Series series)
|
public override void AfterRename(Series series)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
@ -47,24 +48,24 @@ namespace NzbDrone.Core.Metadata.Consumers.Xbmc
|
||||||
private static readonly Regex SeasonImagesRegex = new Regex(@"^season(?<season>\d{2,}|-all|-specials)-(?<type>poster|banner|fanart)\.(?:png|jpg)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
private static readonly Regex SeasonImagesRegex = new Regex(@"^season(?<season>\d{2,}|-all|-specials)-(?<type>poster|banner|fanart)\.(?:png|jpg)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||||
private static readonly Regex EpisodeImageRegex = new Regex(@"-thumb\.(?:png|jpg)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
private static readonly Regex EpisodeImageRegex = new Regex(@"-thumb\.(?:png|jpg)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||||
|
|
||||||
public override void OnSeriesUpdated(Series series)
|
public override void OnSeriesUpdated(Series series, List<MetadataFile> existingMetadataFiles)
|
||||||
{
|
{
|
||||||
if (Settings.SeriesMetadata)
|
if (Settings.SeriesMetadata)
|
||||||
{
|
{
|
||||||
EnsureFolder(series.Path);
|
EnsureFolder(series.Path);
|
||||||
WriteTvShowNfo(series);
|
WriteTvShowNfo(series, existingMetadataFiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Settings.SeriesImages)
|
if (Settings.SeriesImages)
|
||||||
{
|
{
|
||||||
EnsureFolder(series.Path);
|
EnsureFolder(series.Path);
|
||||||
WriteSeriesImages(series);
|
WriteSeriesImages(series, existingMetadataFiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Settings.SeasonImages)
|
if (Settings.SeasonImages)
|
||||||
{
|
{
|
||||||
EnsureFolder(series.Path);
|
EnsureFolder(series.Path);
|
||||||
WriteSeasonImages(series);
|
WriteSeasonImages(series, existingMetadataFiles);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,7 +177,7 @@ namespace NzbDrone.Core.Metadata.Consumers.Xbmc
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void WriteTvShowNfo(Series series)
|
private void WriteTvShowNfo(Series series, List<MetadataFile> existingMetadataFiles)
|
||||||
{
|
{
|
||||||
_logger.Trace("Generating tvshow.nfo for: {0}", series.Title);
|
_logger.Trace("Generating tvshow.nfo for: {0}", series.Title);
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
|
@ -228,7 +229,8 @@ namespace NzbDrone.Core.Metadata.Consumers.Xbmc
|
||||||
|
|
||||||
_diskProvider.WriteAllText(path, doc.ToString());
|
_diskProvider.WriteAllText(path, doc.ToString());
|
||||||
|
|
||||||
var metadata = new MetadataFile
|
var metadata = existingMetadataFiles.SingleOrDefault(c => c.Type == MetadataType.SeriesMetadata) ??
|
||||||
|
new MetadataFile
|
||||||
{
|
{
|
||||||
SeriesId = series.Id,
|
SeriesId = series.Id,
|
||||||
Consumer = GetType().Name,
|
Consumer = GetType().Name,
|
||||||
|
@ -240,7 +242,7 @@ namespace NzbDrone.Core.Metadata.Consumers.Xbmc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void WriteSeriesImages(Series series)
|
private void WriteSeriesImages(Series series, List<MetadataFile> existingMetadataFiles)
|
||||||
{
|
{
|
||||||
foreach (var image in series.Images)
|
foreach (var image in series.Images)
|
||||||
{
|
{
|
||||||
|
@ -256,7 +258,8 @@ namespace NzbDrone.Core.Metadata.Consumers.Xbmc
|
||||||
|
|
||||||
_diskProvider.CopyFile(source, destination, false);
|
_diskProvider.CopyFile(source, destination, false);
|
||||||
|
|
||||||
var metadata = new MetadataFile
|
var metadata = existingMetadataFiles.SingleOrDefault(c => c.Type == MetadataType.SeriesImage) ??
|
||||||
|
new MetadataFile
|
||||||
{
|
{
|
||||||
SeriesId = series.Id,
|
SeriesId = series.Id,
|
||||||
Consumer = GetType().Name,
|
Consumer = GetType().Name,
|
||||||
|
@ -268,7 +271,7 @@ namespace NzbDrone.Core.Metadata.Consumers.Xbmc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void WriteSeasonImages(Series series)
|
private void WriteSeasonImages(Series series, List<MetadataFile> existingMetadataFiles)
|
||||||
{
|
{
|
||||||
foreach (var season in series.Seasons)
|
foreach (var season in series.Seasons)
|
||||||
{
|
{
|
||||||
|
@ -285,12 +288,14 @@ namespace NzbDrone.Core.Metadata.Consumers.Xbmc
|
||||||
|
|
||||||
DownloadImage(series, image.Url, path);
|
DownloadImage(series, image.Url, path);
|
||||||
|
|
||||||
var metadata = new MetadataFile
|
var metadata = existingMetadataFiles.SingleOrDefault(c => c.Type == MetadataType.SeasonImage &&
|
||||||
|
c.SeasonNumber == season.SeasonNumber) ??
|
||||||
|
new MetadataFile
|
||||||
{
|
{
|
||||||
SeriesId = series.Id,
|
SeriesId = series.Id,
|
||||||
SeasonNumber = season.SeasonNumber,
|
SeasonNumber = season.SeasonNumber,
|
||||||
Consumer = GetType().Name,
|
Consumer = GetType().Name,
|
||||||
Type = MetadataType.SeasonImage,
|
Type = MetadataType.SeriesMetadata,
|
||||||
RelativePath = DiskProvider.GetRelativePath(series.Path, path)
|
RelativePath = DiskProvider.GetRelativePath(series.Path, path)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -327,11 +332,11 @@ namespace NzbDrone.Core.Metadata.Consumers.Xbmc
|
||||||
details.Add(new XElement("displayepisode", episode.EpisodeNumber));
|
details.Add(new XElement("displayepisode", episode.EpisodeNumber));
|
||||||
details.Add(new XElement("thumb", episode.Images.Single(i => i.CoverType == MediaCoverTypes.Screenshot).Url));
|
details.Add(new XElement("thumb", episode.Images.Single(i => i.CoverType == MediaCoverTypes.Screenshot).Url));
|
||||||
details.Add(new XElement("watched", "false"));
|
details.Add(new XElement("watched", "false"));
|
||||||
// details.Add(new XElement("credits", tvdbEpisode.Writer.FirstOrDefault()));
|
|
||||||
// details.Add(new XElement("director", tvdbEpisode.Directors.FirstOrDefault()));
|
|
||||||
details.Add(new XElement("rating", episode.Ratings.Percentage));
|
details.Add(new XElement("rating", episode.Ratings.Percentage));
|
||||||
|
|
||||||
//Todo: get guest stars, will need trakt to have them
|
//Todo: get guest stars, writer and director
|
||||||
|
//details.Add(new XElement("credits", tvdbEpisode.Writer.FirstOrDefault()));
|
||||||
|
//details.Add(new XElement("director", tvdbEpisode.Directors.FirstOrDefault()));
|
||||||
|
|
||||||
doc.Add(details);
|
doc.Add(details);
|
||||||
doc.Save(xw);
|
doc.Save(xw);
|
||||||
|
@ -360,7 +365,7 @@ namespace NzbDrone.Core.Metadata.Consumers.Xbmc
|
||||||
{
|
{
|
||||||
var screenshot = episodeFile.Episodes.Value.First().Images.Single(i => i.CoverType == MediaCoverTypes.Screenshot);
|
var screenshot = episodeFile.Episodes.Value.First().Images.Single(i => i.CoverType == MediaCoverTypes.Screenshot);
|
||||||
|
|
||||||
var filename = Path.GetFileNameWithoutExtension(episodeFile.Path) + "-thumb.jpg";
|
var filename = Path.ChangeExtension(episodeFile.Path, "").Trim('.') + "-thumb.jpg";
|
||||||
|
|
||||||
DownloadImage(series, screenshot.Url, filename);
|
DownloadImage(series, screenshot.Url, filename);
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using NzbDrone.Core.MediaFiles;
|
using System.Collections.Generic;
|
||||||
|
using NzbDrone.Core.MediaFiles;
|
||||||
using NzbDrone.Core.Metadata.Files;
|
using NzbDrone.Core.Metadata.Files;
|
||||||
using NzbDrone.Core.ThingiProvider;
|
using NzbDrone.Core.ThingiProvider;
|
||||||
using NzbDrone.Core.Tv;
|
using NzbDrone.Core.Tv;
|
||||||
|
@ -7,7 +8,7 @@ namespace NzbDrone.Core.Metadata
|
||||||
{
|
{
|
||||||
public interface IMetadata : IProvider
|
public interface IMetadata : IProvider
|
||||||
{
|
{
|
||||||
void OnSeriesUpdated(Series series);
|
void OnSeriesUpdated(Series series, List<MetadataFile> existingMetadataFiles);
|
||||||
void OnEpisodeImport(Series series, EpisodeFile episodeFile, bool newDownload);
|
void OnEpisodeImport(Series series, EpisodeFile episodeFile, bool newDownload);
|
||||||
void AfterRename(Series series);
|
void AfterRename(Series series);
|
||||||
MetadataFile FindMetadataFile(Series series, string path);
|
MetadataFile FindMetadataFile(Series series, string path);
|
||||||
|
|
|
@ -1,31 +1,38 @@
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using NLog;
|
using NLog;
|
||||||
using NzbDrone.Common;
|
using NzbDrone.Common;
|
||||||
|
using NzbDrone.Core.MediaCover;
|
||||||
using NzbDrone.Core.MediaFiles.Events;
|
using NzbDrone.Core.MediaFiles.Events;
|
||||||
using NzbDrone.Core.Messaging.Events;
|
using NzbDrone.Core.Messaging.Events;
|
||||||
|
using NzbDrone.Core.Metadata.Files;
|
||||||
using NzbDrone.Core.Tv.Events;
|
using NzbDrone.Core.Tv.Events;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Metadata
|
namespace NzbDrone.Core.Metadata
|
||||||
{
|
{
|
||||||
public class NotificationService
|
public class NotificationService
|
||||||
: IHandle<SeriesUpdatedEvent>,
|
: IHandle<MediaCoversUpdatedEvent>,
|
||||||
IHandle<EpisodeImportedEvent>,
|
IHandle<EpisodeImportedEvent>,
|
||||||
IHandle<SeriesRenamedEvent>
|
IHandle<SeriesRenamedEvent>
|
||||||
{
|
{
|
||||||
private readonly IMetadataFactory _metadataFactory;
|
private readonly IMetadataFactory _metadataFactory;
|
||||||
|
private readonly MetadataFileService _metadataFileService;
|
||||||
private readonly Logger _logger;
|
private readonly Logger _logger;
|
||||||
|
|
||||||
public NotificationService(IMetadataFactory metadataFactory, Logger logger)
|
public NotificationService(IMetadataFactory metadataFactory, MetadataFileService metadataFileService, Logger logger)
|
||||||
{
|
{
|
||||||
_metadataFactory = metadataFactory;
|
_metadataFactory = metadataFactory;
|
||||||
|
_metadataFileService = metadataFileService;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Handle(SeriesUpdatedEvent message)
|
public void Handle(MediaCoversUpdatedEvent message)
|
||||||
{
|
{
|
||||||
|
var seriesMetadata = _metadataFileService.GetFilesBySeries(message.Series.Id);
|
||||||
|
|
||||||
foreach (var consumer in _metadataFactory.Enabled())
|
foreach (var consumer in _metadataFactory.Enabled())
|
||||||
{
|
{
|
||||||
consumer.OnSeriesUpdated(message.Series);
|
consumer.OnSeriesUpdated(message.Series, seriesMetadata.Where(c => c.Consumer == consumer.GetType().Name).ToList());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,10 +4,11 @@ namespace NzbDrone.Core.Metadata
|
||||||
{
|
{
|
||||||
public enum MetadataType
|
public enum MetadataType
|
||||||
{
|
{
|
||||||
SeriesMetadata = 0,
|
Unknown = 0,
|
||||||
EpisodeMetadata = 1,
|
SeriesMetadata = 1,
|
||||||
SeriesImage = 2,
|
EpisodeMetadata = 2,
|
||||||
SeasonImage = 3,
|
SeriesImage = 3,
|
||||||
EpisodeImage = 4
|
SeasonImage = 4,
|
||||||
|
EpisodeImage = 5
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ using NzbDrone.Common;
|
||||||
using NzbDrone.Core.MediaFiles;
|
using NzbDrone.Core.MediaFiles;
|
||||||
using NzbDrone.Core.Messaging.Events;
|
using NzbDrone.Core.Messaging.Events;
|
||||||
using NzbDrone.Core.Metadata.Files;
|
using NzbDrone.Core.Metadata.Files;
|
||||||
|
using NzbDrone.Core.Parser;
|
||||||
using NzbDrone.Core.Tv.Events;
|
using NzbDrone.Core.Tv.Events;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Metadata
|
namespace NzbDrone.Core.Metadata
|
||||||
|
@ -14,19 +15,19 @@ namespace NzbDrone.Core.Metadata
|
||||||
{
|
{
|
||||||
private readonly IDiskProvider _diskProvider;
|
private readonly IDiskProvider _diskProvider;
|
||||||
private readonly IMetadataFileService _metadataFileService;
|
private readonly IMetadataFileService _metadataFileService;
|
||||||
private readonly IMediaFileService _mediaFileService;
|
private readonly IParsingService _parsingService;
|
||||||
private readonly Logger _logger;
|
private readonly Logger _logger;
|
||||||
private readonly List<IMetadata> _consumers;
|
private readonly List<IMetadata> _consumers;
|
||||||
|
|
||||||
public ExistingMetadataService(IDiskProvider diskProvider,
|
public ExistingMetadataService(IDiskProvider diskProvider,
|
||||||
IEnumerable<IMetadata> consumers,
|
IEnumerable<IMetadata> consumers,
|
||||||
IMetadataFileService metadataFileService,
|
IMetadataFileService metadataFileService,
|
||||||
IMediaFileService mediaFileService,
|
IParsingService parsingService,
|
||||||
Logger logger)
|
Logger logger)
|
||||||
{
|
{
|
||||||
_diskProvider = diskProvider;
|
_diskProvider = diskProvider;
|
||||||
_metadataFileService = metadataFileService;
|
_metadataFileService = metadataFileService;
|
||||||
_mediaFileService = mediaFileService;
|
_parsingService = parsingService;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_consumers = consumers.ToList();
|
_consumers = consumers.ToList();
|
||||||
}
|
}
|
||||||
|
@ -52,14 +53,21 @@ namespace NzbDrone.Core.Metadata
|
||||||
if (metadata.Type == MetadataType.EpisodeImage ||
|
if (metadata.Type == MetadataType.EpisodeImage ||
|
||||||
metadata.Type == MetadataType.EpisodeMetadata)
|
metadata.Type == MetadataType.EpisodeMetadata)
|
||||||
{
|
{
|
||||||
//TODO: replace this with parser lookup, otherwise its impossible to link thumbs without knowing too much about the consumers
|
var localEpisode = _parsingService.GetEpisodes(possibleMetadataFile, message.Series, false);
|
||||||
//We might want to resort to parsing the file name and
|
|
||||||
//then finding it via episodes incase the file names get out of sync
|
|
||||||
var episodeFile = _mediaFileService.FindByPath(possibleMetadataFile, false);
|
|
||||||
|
|
||||||
if (episodeFile == null) break;
|
if (localEpisode == null)
|
||||||
|
{
|
||||||
|
_logger.Trace("Cannot find related episodes for: {0}", possibleMetadataFile);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
metadata.EpisodeFileId = episodeFile.Id;
|
if (localEpisode.Episodes.DistinctBy(e => e.EpisodeFileId).Count() > 1)
|
||||||
|
{
|
||||||
|
_logger.Trace("Metadata file: {0} does not match existing files.", possibleMetadataFile);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
metadata.EpisodeFileId = localEpisode.Episodes.First().EpisodeFileId;
|
||||||
}
|
}
|
||||||
|
|
||||||
_metadataFileService.Upsert(metadata);
|
_metadataFileService.Upsert(metadata);
|
||||||
|
|
|
@ -41,7 +41,7 @@ namespace NzbDrone.Core.Metadata
|
||||||
|
|
||||||
public ProviderDefinition Definition { get; set; }
|
public ProviderDefinition Definition { get; set; }
|
||||||
|
|
||||||
public abstract void OnSeriesUpdated(Series series);
|
public abstract void OnSeriesUpdated(Series series, List<MetadataFile> existingMetadataFiles);
|
||||||
public abstract void OnEpisodeImport(Series series, EpisodeFile episodeFile, bool newDownload);
|
public abstract void OnEpisodeImport(Series series, EpisodeFile episodeFile, bool newDownload);
|
||||||
public abstract void AfterRename(Series series);
|
public abstract void AfterRename(Series series);
|
||||||
public abstract MetadataFile FindMetadataFile(Series series, string path);
|
public abstract MetadataFile FindMetadataFile(Series series, string path);
|
||||||
|
|
|
@ -261,9 +261,10 @@
|
||||||
<Compile Include="Exceptions\StatusCodeToExceptions.cs" />
|
<Compile Include="Exceptions\StatusCodeToExceptions.cs" />
|
||||||
<Compile Include="Housekeeping\Housekeepers\CleanupOrphanedEpisodes.cs" />
|
<Compile Include="Housekeeping\Housekeepers\CleanupOrphanedEpisodes.cs" />
|
||||||
<Compile Include="Housekeeping\Housekeepers\CleanupOrphanedHistoryItems.cs" />
|
<Compile Include="Housekeeping\Housekeepers\CleanupOrphanedHistoryItems.cs" />
|
||||||
<Compile Include="Housekeeping\Housekeepers\CleanupOrphanedEpisodeFiles.cs" />
|
<Compile Include="Housekeeping\Housekeepers\CleanupOrphanedMetadataFiles.cs" />
|
||||||
<Compile Include="Housekeeping\Housekeepers\CleanupAdditionalNamingSpecs.cs" />
|
<Compile Include="Housekeeping\Housekeepers\CleanupAdditionalNamingSpecs.cs" />
|
||||||
<Compile Include="Housekeeping\Housekeepers\UpdateCleanTitleForSeries.cs" />
|
<Compile Include="Housekeeping\Housekeepers\UpdateCleanTitleForSeries.cs" />
|
||||||
|
<Compile Include="Housekeeping\Housekeepers\CleanupOrphanedEpisodeFiles.cs" />
|
||||||
<Compile Include="Housekeeping\Housekeepers\FixFutureRunScheduledTasks.cs" />
|
<Compile Include="Housekeeping\Housekeepers\FixFutureRunScheduledTasks.cs" />
|
||||||
<Compile Include="Housekeeping\HousekeepingCommand.cs" />
|
<Compile Include="Housekeeping\HousekeepingCommand.cs" />
|
||||||
<Compile Include="Housekeeping\HousekeepingService.cs" />
|
<Compile Include="Housekeeping\HousekeepingService.cs" />
|
||||||
|
@ -296,6 +297,7 @@
|
||||||
<Compile Include="Lifecycle\Commands\ShutdownCommand.cs" />
|
<Compile Include="Lifecycle\Commands\ShutdownCommand.cs" />
|
||||||
<Compile Include="Lifecycle\Commands\RestartCommand.cs" />
|
<Compile Include="Lifecycle\Commands\RestartCommand.cs" />
|
||||||
<Compile Include="Lifecycle\LifecycleService.cs" />
|
<Compile Include="Lifecycle\LifecycleService.cs" />
|
||||||
|
<Compile Include="MediaCover\MediaCoversUpdatedEvent.cs" />
|
||||||
<Compile Include="MediaFiles\Commands\RenameFilesCommand.cs" />
|
<Compile Include="MediaFiles\Commands\RenameFilesCommand.cs" />
|
||||||
<Compile Include="MediaFiles\EpisodeFileMoveResult.cs" />
|
<Compile Include="MediaFiles\EpisodeFileMoveResult.cs" />
|
||||||
<Compile Include="MediaFiles\EpisodeImport\Specifications\FullSeasonSpecification.cs" />
|
<Compile Include="MediaFiles\EpisodeImport\Specifications\FullSeasonSpecification.cs" />
|
||||||
|
|
Loading…
Reference in New Issue