1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-10-30 15:32:31 +01:00

Metadata will be called when needed #ND-21

Import/Rename episode files
Import series/update series info
This commit is contained in:
Mark McDowall 2012-07-12 14:08:21 -07:00
parent eee24aff1d
commit b122f1135e
11 changed files with 172 additions and 37 deletions

View File

@ -212,7 +212,7 @@ namespace NzbDrone.Core.Test.ProviderTests
var result = Mocker.Resolve<DiskScanProvider>().MoveEpisodeFile(file, false); var result = Mocker.Resolve<DiskScanProvider>().MoveEpisodeFile(file, false);
//Assert //Assert
result.Should().BeFalse(); result.Should().BeNull();
} }
[Test] [Test]
@ -368,7 +368,7 @@ namespace NzbDrone.Core.Test.ProviderTests
var result = Mocker.Resolve<DiskScanProvider>().MoveEpisodeFile(file, true); var result = Mocker.Resolve<DiskScanProvider>().MoveEpisodeFile(file, true);
//Assert //Assert
result.Should().BeTrue(); result.Should().NotBeNull();
Mocker.GetMock<ExternalNotificationProvider>() Mocker.GetMock<ExternalNotificationProvider>()
.Verify(e => e.OnDownload("30 Rock - 1x01 - [WEBDL]", It.IsAny<Series>()), Times.Once()); .Verify(e => e.OnDownload("30 Rock - 1x01 - [WEBDL]", It.IsAny<Series>()), Times.Once());
} }

View File

@ -123,14 +123,14 @@ namespace NzbDrone.Core.Test.ProviderTests.Metadata
public void should_not_blowup() public void should_not_blowup()
{ {
WithSingleEpisodeFile(); WithSingleEpisodeFile();
Mocker.Resolve<Xbmc>().ForEpisodeFile(episodeFile, tvdbSeries); Mocker.Resolve<Xbmc>().CreateForEpisodeFile(episodeFile, tvdbSeries);
} }
[Test] [Test]
public void should_call_diskprovider_writeAllText_once_for_single_episode() public void should_call_diskprovider_writeAllText_once_for_single_episode()
{ {
WithSingleEpisodeFile(); WithSingleEpisodeFile();
Mocker.Resolve<Xbmc>().ForEpisodeFile(episodeFile, tvdbSeries); Mocker.Resolve<Xbmc>().CreateForEpisodeFile(episodeFile, tvdbSeries);
Mocker.GetMock<DiskProvider>().Verify(v => v.WriteAllText(episodeFile.Path.Replace("avi", "nfo"), It.IsAny<string>()), Times.Once()); Mocker.GetMock<DiskProvider>().Verify(v => v.WriteAllText(episodeFile.Path.Replace("avi", "nfo"), It.IsAny<string>()), Times.Once());
} }
@ -138,7 +138,7 @@ namespace NzbDrone.Core.Test.ProviderTests.Metadata
public void should_call_diskprovider_writeAllText_once_for_multi_episode() public void should_call_diskprovider_writeAllText_once_for_multi_episode()
{ {
WithMultiEpisodeFile(); WithMultiEpisodeFile();
Mocker.Resolve<Xbmc>().ForEpisodeFile(episodeFile, tvdbSeries); Mocker.Resolve<Xbmc>().CreateForEpisodeFile(episodeFile, tvdbSeries);
Mocker.GetMock<DiskProvider>().Verify(v => v.WriteAllText(episodeFile.Path.Replace("avi", "nfo"), It.IsAny<string>()), Times.Once()); Mocker.GetMock<DiskProvider>().Verify(v => v.WriteAllText(episodeFile.Path.Replace("avi", "nfo"), It.IsAny<string>()), Times.Once());
} }
@ -146,7 +146,7 @@ namespace NzbDrone.Core.Test.ProviderTests.Metadata
public void should_download_thumbnail_when_thumbnail_path_is_not_null() public void should_download_thumbnail_when_thumbnail_path_is_not_null()
{ {
WithSingleEpisodeFile(); WithSingleEpisodeFile();
Mocker.Resolve<Xbmc>().ForEpisodeFile(episodeFile, tvdbSeries); Mocker.Resolve<Xbmc>().CreateForEpisodeFile(episodeFile, tvdbSeries);
Mocker.GetMock<BannerProvider>().Verify(v => v.Download(tvdbSeries.Episodes.First().BannerPath, episodeFile.Path.Replace("avi", "tbn")), Times.Once()); Mocker.GetMock<BannerProvider>().Verify(v => v.Download(tvdbSeries.Episodes.First().BannerPath, episodeFile.Path.Replace("avi", "tbn")), Times.Once());
} }
} }

View File

@ -78,27 +78,27 @@ namespace NzbDrone.Core.Test.ProviderTests.Metadata
[Test] [Test]
public void should_not_blowup() public void should_not_blowup()
{ {
Mocker.Resolve<Xbmc>().ForSeries(series, tvdbSeries); Mocker.Resolve<Xbmc>().CreateForSeries(series, tvdbSeries);
} }
[Test] [Test]
public void should_call_diskprovider_writeAllText() public void should_call_diskprovider_writeAllText()
{ {
Mocker.Resolve<Xbmc>().ForSeries(series, tvdbSeries); Mocker.Resolve<Xbmc>().CreateForSeries(series, tvdbSeries);
Mocker.GetMock<DiskProvider>().Verify(v => v.WriteAllText(Path.Combine(series.Path, "tvshow.nfo"), It.IsAny<string>()), Times.Once()); Mocker.GetMock<DiskProvider>().Verify(v => v.WriteAllText(Path.Combine(series.Path, "tvshow.nfo"), It.IsAny<string>()), Times.Once());
} }
[Test] [Test]
public void should_download_fanart() public void should_download_fanart()
{ {
Mocker.Resolve<Xbmc>().ForSeries(series, tvdbSeries); Mocker.Resolve<Xbmc>().CreateForSeries(series, tvdbSeries);
Mocker.GetMock<BannerProvider>().Verify(v => v.Download(tvdbSeries.FanartPath, Path.Combine(series.Path, "fanart.jpg")), Times.Once()); Mocker.GetMock<BannerProvider>().Verify(v => v.Download(tvdbSeries.FanartPath, Path.Combine(series.Path, "fanart.jpg")), Times.Once());
} }
[Test] [Test]
public void should_download_poster_when_useBanners_is_false() public void should_download_poster_when_useBanners_is_false()
{ {
Mocker.Resolve<Xbmc>().ForSeries(series, tvdbSeries); Mocker.Resolve<Xbmc>().CreateForSeries(series, tvdbSeries);
Mocker.GetMock<BannerProvider>().Verify(v => v.Download(tvdbSeries.PosterPath, Path.Combine(series.Path, "folder.jpg")), Times.Once()); Mocker.GetMock<BannerProvider>().Verify(v => v.Download(tvdbSeries.PosterPath, Path.Combine(series.Path, "folder.jpg")), Times.Once());
} }
@ -106,14 +106,14 @@ namespace NzbDrone.Core.Test.ProviderTests.Metadata
public void should_download_banner_when_useBanners_is_true() public void should_download_banner_when_useBanners_is_true()
{ {
WithUseBanners(); WithUseBanners();
Mocker.Resolve<Xbmc>().ForSeries(series, tvdbSeries); Mocker.Resolve<Xbmc>().CreateForSeries(series, tvdbSeries);
Mocker.GetMock<BannerProvider>().Verify(v => v.Download(tvdbSeries.BannerPath, Path.Combine(series.Path, "folder.jpg")), Times.Once()); Mocker.GetMock<BannerProvider>().Verify(v => v.Download(tvdbSeries.BannerPath, Path.Combine(series.Path, "folder.jpg")), Times.Once());
} }
[Test] [Test]
public void should_download_season_poster_when_useBanners_is_false() public void should_download_season_poster_when_useBanners_is_false()
{ {
Mocker.Resolve<Xbmc>().ForSeries(series, tvdbSeries); Mocker.Resolve<Xbmc>().CreateForSeries(series, tvdbSeries);
Mocker.GetMock<BannerProvider>().Verify(v => v.Download(It.Is<string>(s => !s.Contains("banners")), It.IsRegex(@"season\d{2}\.tbn")), Times.Exactly(2)); Mocker.GetMock<BannerProvider>().Verify(v => v.Download(It.Is<string>(s => !s.Contains("banners")), It.IsRegex(@"season\d{2}\.tbn")), Times.Exactly(2));
} }
@ -121,7 +121,7 @@ namespace NzbDrone.Core.Test.ProviderTests.Metadata
public void should_download_season_banner_when_useBanners_is_true() public void should_download_season_banner_when_useBanners_is_true()
{ {
WithUseBanners(); WithUseBanners();
Mocker.Resolve<Xbmc>().ForSeries(series, tvdbSeries); Mocker.Resolve<Xbmc>().CreateForSeries(series, tvdbSeries);
Mocker.GetMock<BannerProvider>().Verify(v => v.Download(It.Is<string>(s => s.Contains("banners")), It.IsRegex(@"season\d{2}\.tbn")), Times.Exactly(2)); Mocker.GetMock<BannerProvider>().Verify(v => v.Download(It.Is<string>(s => s.Contains("banners")), It.IsRegex(@"season\d{2}\.tbn")), Times.Exactly(2));
} }
} }

View File

@ -210,7 +210,7 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
Mocker.GetMock<DiskProvider>().Setup(s => s.MoveDirectory(droppedFolder.FullName, taggedFolder)); Mocker.GetMock<DiskProvider>().Setup(s => s.MoveDirectory(droppedFolder.FullName, taggedFolder));
Mocker.GetMock<DiskProvider>().Setup(s => s.GetDirectorySize(droppedFolder.FullName)).Returns(Constants.IgnoreFileSize + 10.Megabytes()); Mocker.GetMock<DiskProvider>().Setup(s => s.GetDirectorySize(droppedFolder.FullName)).Returns(Constants.IgnoreFileSize + 10.Megabytes());
Mocker.GetMock<DiskScanProvider>().Setup(s => s.Scan(fakeSeries, droppedFolder.FullName)).Returns(fakeEpisodeFiles); Mocker.GetMock<DiskScanProvider>().Setup(s => s.Scan(fakeSeries, droppedFolder.FullName)).Returns(fakeEpisodeFiles);
Mocker.GetMock<DiskScanProvider>().Setup(s => s.MoveEpisodeFile(It.IsAny<EpisodeFile>(), true)).Returns(true); Mocker.GetMock<DiskScanProvider>().Setup(s => s.MoveEpisodeFile(It.IsAny<EpisodeFile>(), true)).Returns(new EpisodeFile());
Mocker.Resolve<PostDownloadProvider>().ProcessDownload(droppedFolder); Mocker.Resolve<PostDownloadProvider>().ProcessDownload(droppedFolder);
@ -281,9 +281,10 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
Mocker.GetMock<SeriesProvider>().Setup(s => s.FindSeries("office")).Returns(fakeSeries); Mocker.GetMock<SeriesProvider>().Setup(s => s.FindSeries("office")).Returns(fakeSeries);
Mocker.GetMock<DiskScanProvider>().Setup(s => s.CleanUpDropFolder(droppedFolder.FullName)); Mocker.GetMock<DiskScanProvider>().Setup(s => s.CleanUpDropFolder(droppedFolder.FullName));
Mocker.GetMock<DiskScanProvider>().Setup(s => s.Scan(fakeSeries, droppedFolder.FullName)).Returns(fakeEpisodeFiles); Mocker.GetMock<DiskScanProvider>().Setup(s => s.Scan(fakeSeries, droppedFolder.FullName)).Returns(fakeEpisodeFiles);
Mocker.GetMock<DiskScanProvider>().Setup(s => s.MoveEpisodeFile(It.IsAny<EpisodeFile>(), true)).Returns(true); Mocker.GetMock<DiskScanProvider>().Setup(s => s.MoveEpisodeFile(It.IsAny<EpisodeFile>(), true)).Returns(new EpisodeFile());
Mocker.GetMock<DiskProvider>().Setup(s => s.GetDirectorySize(droppedFolder.FullName)).Returns(Constants.IgnoreFileSize - 1.Megabytes()); Mocker.GetMock<DiskProvider>().Setup(s => s.GetDirectorySize(droppedFolder.FullName)).Returns(Constants.IgnoreFileSize - 1.Megabytes());
Mocker.GetMock<DiskProvider>().Setup(s => s.DeleteFolder(droppedFolder.FullName, true)); Mocker.GetMock<DiskProvider>().Setup(s => s.DeleteFolder(droppedFolder.FullName, true));
Mocker.GetMock<MetadataProvider>().Setup(s => s.CreateForEpisodeFiles(It.IsAny<List<EpisodeFile>>()));
//Act //Act
Mocker.Resolve<PostDownloadProvider>().ProcessDownload(droppedFolder); Mocker.Resolve<PostDownloadProvider>().ProcessDownload(droppedFolder);

View File

@ -1,9 +1,11 @@
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System; using System;
using NLog; using NLog;
using Ninject; using Ninject;
using NzbDrone.Core.Model.Notification; using NzbDrone.Core.Model.Notification;
using NzbDrone.Core.Providers; using NzbDrone.Core.Providers;
using NzbDrone.Core.Repository;
namespace NzbDrone.Core.Jobs namespace NzbDrone.Core.Jobs
{ {
@ -13,17 +15,20 @@ namespace NzbDrone.Core.Jobs
private readonly DiskScanProvider _diskScanProvider; private readonly DiskScanProvider _diskScanProvider;
private readonly ExternalNotificationProvider _externalNotificationProvider; private readonly ExternalNotificationProvider _externalNotificationProvider;
private readonly SeriesProvider _seriesProvider; private readonly SeriesProvider _seriesProvider;
private readonly MetadataProvider _metadataProvider;
private static readonly Logger logger = LogManager.GetCurrentClassLogger(); private static readonly Logger logger = LogManager.GetCurrentClassLogger();
[Inject] [Inject]
public RenameSeasonJob(MediaFileProvider mediaFileProvider, DiskScanProvider diskScanProvider, public RenameSeasonJob(MediaFileProvider mediaFileProvider, DiskScanProvider diskScanProvider,
ExternalNotificationProvider externalNotificationProvider, SeriesProvider seriesProvider) ExternalNotificationProvider externalNotificationProvider, SeriesProvider seriesProvider,
MetadataProvider metadataProvider)
{ {
_mediaFileProvider = mediaFileProvider; _mediaFileProvider = mediaFileProvider;
_diskScanProvider = diskScanProvider; _diskScanProvider = diskScanProvider;
_externalNotificationProvider = externalNotificationProvider; _externalNotificationProvider = externalNotificationProvider;
_seriesProvider = seriesProvider; _seriesProvider = seriesProvider;
_metadataProvider = metadataProvider;
} }
public string Name public string Name
@ -57,18 +62,32 @@ namespace NzbDrone.Core.Jobs
return; return;
} }
var newEpisodeFiles = new List<EpisodeFile>();
var oldEpisodeFiles = new List<EpisodeFile>();
foreach (var episodeFile in episodeFiles) foreach (var episodeFile in episodeFiles)
{ {
try try
{ {
_diskScanProvider.MoveEpisodeFile(episodeFile); var newFile = _diskScanProvider.MoveEpisodeFile(episodeFile);
if (newFile != null)
{
newEpisodeFiles.Add(newFile);
oldEpisodeFiles.Add(episodeFile);
}
} }
catch (Exception exception)
catch (Exception e)
{ {
logger.WarnException("An error has occurred while renaming file", exception); logger.WarnException("An error has occurred while renaming file", e);
} }
} }
//Remove & Create Metadata for episode files
_metadataProvider.RemoveForEpisodeFiles(oldEpisodeFiles);
_metadataProvider.CreateForEpisodeFiles(newEpisodeFiles);
//Start AfterRename //Start AfterRename
var message = String.Format("Renamed: Series {0}, Season: {1}", series.Title, secondaryTargetId); var message = String.Format("Renamed: Series {0}, Season: {1}", series.Title, secondaryTargetId);

View File

@ -1,9 +1,11 @@
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System; using System;
using NLog; using NLog;
using Ninject; using Ninject;
using NzbDrone.Core.Model.Notification; using NzbDrone.Core.Model.Notification;
using NzbDrone.Core.Providers; using NzbDrone.Core.Providers;
using NzbDrone.Core.Repository;
namespace NzbDrone.Core.Jobs namespace NzbDrone.Core.Jobs
{ {
@ -13,17 +15,20 @@ namespace NzbDrone.Core.Jobs
private readonly DiskScanProvider _diskScanProvider; private readonly DiskScanProvider _diskScanProvider;
private readonly ExternalNotificationProvider _externalNotificationProvider; private readonly ExternalNotificationProvider _externalNotificationProvider;
private readonly SeriesProvider _seriesProvider; private readonly SeriesProvider _seriesProvider;
private readonly MetadataProvider _metadataProvider;
private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
[Inject] [Inject]
public RenameSeriesJob(MediaFileProvider mediaFileProvider, DiskScanProvider diskScanProvider, public RenameSeriesJob(MediaFileProvider mediaFileProvider, DiskScanProvider diskScanProvider,
ExternalNotificationProvider externalNotificationProvider, SeriesProvider seriesProvider) ExternalNotificationProvider externalNotificationProvider, SeriesProvider seriesProvider,
MetadataProvider metadataProvider)
{ {
_mediaFileProvider = mediaFileProvider; _mediaFileProvider = mediaFileProvider;
_diskScanProvider = diskScanProvider; _diskScanProvider = diskScanProvider;
_externalNotificationProvider = externalNotificationProvider; _externalNotificationProvider = externalNotificationProvider;
_seriesProvider = seriesProvider; _seriesProvider = seriesProvider;
_metadataProvider = metadataProvider;
} }
public string Name public string Name
@ -54,19 +59,32 @@ namespace NzbDrone.Core.Jobs
return; return;
} }
var newEpisodeFiles = new List<EpisodeFile>();
var oldEpisodeFiles = new List<EpisodeFile>();
foreach (var episodeFile in episodeFiles) foreach (var episodeFile in episodeFiles)
{ {
try try
{ {
_diskScanProvider.MoveEpisodeFile(episodeFile); var newFile = _diskScanProvider.MoveEpisodeFile(episodeFile);
if (newFile != null)
{
newEpisodeFiles.Add(newFile);
oldEpisodeFiles.Add(episodeFile);
}
} }
catch(Exception e) catch(Exception e)
{ {
Logger.WarnException("An error has occurred while renaming file", e); Logger.WarnException("An error has occurred while renaming file", e);
} }
} }
//Remove & Create Metadata for episode files
_metadataProvider.RemoveForEpisodeFiles(oldEpisodeFiles);
_metadataProvider.CreateForEpisodeFiles(newEpisodeFiles);
//Start AfterRename //Start AfterRename
var message = String.Format("Renamed: Series {0}", series.Title); var message = String.Format("Renamed: Series {0}", series.Title);

View File

@ -168,7 +168,7 @@ namespace NzbDrone.Core.Providers
return episodeFile; return episodeFile;
} }
public virtual bool MoveEpisodeFile(EpisodeFile episodeFile, bool newDownload = false) public virtual EpisodeFile MoveEpisodeFile(EpisodeFile episodeFile, bool newDownload = false)
{ {
if (episodeFile == null) if (episodeFile == null)
throw new ArgumentNullException("episodeFile"); throw new ArgumentNullException("episodeFile");
@ -182,14 +182,14 @@ namespace NzbDrone.Core.Providers
if (DiskProvider.PathEquals(episodeFile.Path, newFile.FullName)) if (DiskProvider.PathEquals(episodeFile.Path, newFile.FullName))
{ {
Logger.Debug("Skipping file rename, source and destination are the same: {0}", episodeFile.Path); Logger.Debug("Skipping file rename, source and destination are the same: {0}", episodeFile.Path);
return false; return null;
} }
_diskProvider.CreateDirectory(newFile.DirectoryName); _diskProvider.CreateDirectory(newFile.DirectoryName);
Logger.Debug("Moving [{0}] > [{1}]", episodeFile.Path, newFile.FullName); Logger.Debug("Moving [{0}] > [{1}]", episodeFile.Path, newFile.FullName);
_diskProvider.MoveFile(episodeFile.Path, newFile.FullName); _diskProvider.MoveFile(episodeFile.Path, newFile.FullName);
_diskProvider.InheritFolderPermissions(newFile.FullName); _diskProvider.InheritFolderPermissions(newFile.FullName);
episodeFile.Path = newFile.FullName; episodeFile.Path = newFile.FullName;
@ -213,7 +213,7 @@ namespace NzbDrone.Core.Providers
_externalNotificationProvider.OnRename(message, series); _externalNotificationProvider.OnRename(message, series);
} }
return true; return episodeFile;
} }
/// <summary> /// <summary>

View File

@ -36,14 +36,26 @@ namespace NzbDrone.Core.Providers.Metadata
/// </summary> /// </summary>
/// <param name = "series">The series to create the metadata for</param> /// <param name = "series">The series to create the metadata for</param>
/// <param name = "tvDbSeries">Series information from TheTvDb</param> /// <param name = "tvDbSeries">Series information from TheTvDb</param>
public abstract void ForSeries(Series series, TvdbSeries tvDbSeries); public abstract void CreateForSeries(Series series, TvdbSeries tvDbSeries);
/// <summary> /// <summary>
/// Creates metadata for the episode file /// Creates metadata for the episode file
/// </summary> /// </summary>
/// <param name = "episodeFile">The episode file to create the metadata</param> /// <param name = "episodeFile">The episode file to create the metadata</param>
/// <param name = "tvDbSeries">Series information from TheTvDb</param> /// <param name = "tvDbSeries">Series information from TheTvDb</param>
public abstract void ForEpisodeFile(EpisodeFile episodeFile, TvdbSeries tvDbSeries); public abstract void CreateForEpisodeFile(EpisodeFile episodeFile, TvdbSeries tvDbSeries);
/// <summary>
/// Removes metadata for a series
/// </summary>
/// <param name = "series">The series to create the metadata for</param>
public abstract void RemoveForSeries(Series series);
/// <summary>
/// Removes metadata for the episode file
/// </summary>
/// <param name = "episodeFile">The episode file to create the metadata</param>
public abstract void RemoveForEpisodeFile(EpisodeFile episodeFile);
public virtual string GetEpisodeGuideUrl(int seriesId) public virtual string GetEpisodeGuideUrl(int seriesId)
{ {

View File

@ -28,9 +28,9 @@ namespace NzbDrone.Core.Providers.Metadata
get { return "XBMC"; } get { return "XBMC"; }
} }
public override void ForSeries(Series series, TvdbSeries tvDbSeries) public override void CreateForSeries(Series series, TvdbSeries tvDbSeries)
{ {
//Create tvshow.nfo, fanart.jpg, folder.jpg and searon##.tbn //Create tvshow.nfo, fanart.jpg, folder.jpg and season##.tbn
var episodeGuideUrl = GetEpisodeGuideUrl(series.SeriesId); var episodeGuideUrl = GetEpisodeGuideUrl(series.SeriesId);
_logger.Debug("Generating tvshow.nfo for: {0}", series.Title); _logger.Debug("Generating tvshow.nfo for: {0}", series.Title);
@ -90,10 +90,9 @@ namespace NzbDrone.Core.Providers.Metadata
} }
} }
public override void ForEpisodeFile(EpisodeFile episodeFile, TvdbSeries tvDbSeries) public override void CreateForEpisodeFile(EpisodeFile episodeFile, TvdbSeries tvDbSeries)
{ {
//Download filename.tbn and filename.nfo //Create filename.tbn and filename.nfo
//Use BannerPath for Thumbnail
var episodes = _episodeProvider.GetEpisodesByFileId(episodeFile.EpisodeFileId); var episodes = _episodeProvider.GetEpisodesByFileId(episodeFile.EpisodeFileId);
if (!episodes.Any()) if (!episodes.Any())
@ -191,6 +190,37 @@ namespace NzbDrone.Core.Providers.Metadata
_diskProvider.WriteAllText(filename, xmlResult); _diskProvider.WriteAllText(filename, xmlResult);
} }
public override void RemoveForSeries(Series series)
{
//Remove tvshow.nfo, fanart.jpg, folder.jpg and season##.tbn
_logger.Debug("Deleting series metadata for: ", series.Title);
_diskProvider.DeleteFile(Path.Combine(series.Path, "tvshow.nfo"));
_diskProvider.DeleteFile(Path.Combine(series.Path, "fanart.jpg"));
_diskProvider.DeleteFile(Path.Combine(series.Path, "fanart.jpg"));
foreach (var file in _diskProvider.GetFiles(series.Path, SearchOption.TopDirectoryOnly))
{
if (Path.GetExtension(file) != ".tbn")
continue;
if (!Path.GetFileName(file).StartsWith("season"))
continue;
_logger.Debug("Deleting season thumbnail: {0}", file);
_diskProvider.DeleteFile(file);
}
}
public override void RemoveForEpisodeFile(EpisodeFile episodeFile)
{
//Remove filename.tbn and filename.nfo
_logger.Debug("Deleting episode metadata for: {0}", episodeFile);
_diskProvider.DeleteFile(episodeFile.Path.Replace(Path.GetExtension(episodeFile.Path), ".nfo"));
_diskProvider.DeleteFile(episodeFile.Path.Replace(Path.GetExtension(episodeFile.Path), ".tbn"));
}
private void DownloadSeasonThumbnails(Series series, TvdbSeries tvDbSeries, TvdbSeasonBanner.Type bannerType) private void DownloadSeasonThumbnails(Series series, TvdbSeries tvDbSeries, TvdbSeasonBanner.Type bannerType)
{ {
var seasons = tvDbSeries.SeasonBanners.Where(s => s.BannerType == bannerType).Select(s => s.Season); var seasons = tvDbSeries.SeasonBanners.Where(s => s.BannerType == bannerType).Select(s => s.Season);

View File

@ -100,7 +100,7 @@ namespace NzbDrone.Core.Providers
{ {
foreach (var provider in _metadataProviders.Where(i => GetSettings(i.GetType()).Enable)) foreach (var provider in _metadataProviders.Where(i => GetSettings(i.GetType()).Enable))
{ {
provider.ForSeries(series, tvDbSeries); provider.CreateForSeries(series, tvDbSeries);
} }
} }
@ -108,10 +108,60 @@ namespace NzbDrone.Core.Providers
{ {
var tvDbSeries = _tvDbProvider.GetSeries(episodeFile.SeriesId, true, true); var tvDbSeries = _tvDbProvider.GetSeries(episodeFile.SeriesId, true, true);
CreateForEpisodeFile(episodeFile, tvDbSeries);
}
public virtual void CreateForEpisodeFile(EpisodeFile episodeFile, TvdbSeries tvDbSeries)
{
foreach (var provider in _metadataProviders.Where(i => GetSettings(i.GetType()).Enable)) foreach (var provider in _metadataProviders.Where(i => GetSettings(i.GetType()).Enable))
{ {
provider.ForEpisodeFile(episodeFile, tvDbSeries); provider.CreateForEpisodeFile(episodeFile, tvDbSeries);
} }
} }
public virtual void CreateForEpisodeFiles(List<EpisodeFile> episodeFiles)
{
var tvDbSeries = _tvDbProvider.GetSeries(episodeFiles.First().SeriesId, true, true);
foreach(var episodeFile in episodeFiles)
{
foreach (var provider in _metadataProviders.Where(i => GetSettings(i.GetType()).Enable))
{
provider.CreateForEpisodeFile(episodeFile, tvDbSeries);
}
}
}
public virtual void RemoveForSeries(Series series)
{
foreach (var provider in _metadataProviders.Where(i => GetSettings(i.GetType()).Enable))
{
provider.RemoveForSeries(series);
}
}
public virtual void RemoveForEpisodeFile(EpisodeFile episodeFile)
{
foreach (var provider in _metadataProviders.Where(i => GetSettings(i.GetType()).Enable))
{
provider.RemoveForEpisodeFile(episodeFile);
}
}
public virtual void RemoveForEpisodeFiles(List<EpisodeFile> episodeFiles)
{
foreach (var episodeFile in episodeFiles)
{
foreach (var provider in _metadataProviders.Where(i => GetSettings(i.GetType()).Enable))
{
provider.RemoveForEpisodeFile(episodeFile);
}
}
}
public virtual void RenameForEpisodeFile(EpisodeFile episodeFile)
{
}
} }
} }

View File

@ -16,14 +16,16 @@ namespace NzbDrone.Core.Providers
private readonly DiskProvider _diskProvider; private readonly DiskProvider _diskProvider;
private readonly DiskScanProvider _diskScanProvider; private readonly DiskScanProvider _diskScanProvider;
private readonly SeriesProvider _seriesProvider; private readonly SeriesProvider _seriesProvider;
private readonly MetadataProvider _metadataProvider;
[Inject] [Inject]
public PostDownloadProvider(DiskProvider diskProvider, DiskScanProvider diskScanProvider, public PostDownloadProvider(DiskProvider diskProvider, DiskScanProvider diskScanProvider,
SeriesProvider seriesProvider) SeriesProvider seriesProvider, MetadataProvider metadataProvider)
{ {
_diskProvider = diskProvider; _diskProvider = diskProvider;
_diskScanProvider = diskScanProvider; _diskScanProvider = diskScanProvider;
_seriesProvider = seriesProvider; _seriesProvider = seriesProvider;
_metadataProvider = metadataProvider;
} }
public PostDownloadProvider() public PostDownloadProvider()
@ -71,6 +73,9 @@ namespace NzbDrone.Core.Providers
var importedFiles = _diskScanProvider.Scan(series, subfolderInfo.FullName); var importedFiles = _diskScanProvider.Scan(series, subfolderInfo.FullName);
importedFiles.ForEach(file => _diskScanProvider.MoveEpisodeFile(file, true)); importedFiles.ForEach(file => _diskScanProvider.MoveEpisodeFile(file, true));
//Create Metadata for all the episode files found
_metadataProvider.CreateForEpisodeFiles(importedFiles);
//Delete the folder only if folder is small enough //Delete the folder only if folder is small enough
if (_diskProvider.GetDirectorySize(subfolderInfo.FullName) < Constants.IgnoreFileSize) if (_diskProvider.GetDirectorySize(subfolderInfo.FullName) < Constants.IgnoreFileSize)
{ {