1
0
Fork 0
mirror of https://github.com/Sonarr/Sonarr synced 2024-12-26 09:47:39 +00:00

Force Refresh added to Series Editor

This commit is contained in:
Mark McDowall 2012-07-14 21:27:40 -07:00
parent 2982e79065
commit 9d5c942cbf
5 changed files with 136 additions and 21 deletions

View file

@ -0,0 +1,81 @@
using System.Collections.Generic;
using System.Linq;
using System;
using NLog;
using Ninject;
using NzbDrone.Core.Model.Notification;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Repository;
namespace NzbDrone.Core.Jobs
{
public class RefreshEpisodeMetadata : IJob
{
private readonly MediaFileProvider _mediaFileProvider;
private readonly SeriesProvider _seriesProvider;
private readonly MetadataProvider _metadataProvider;
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
[Inject]
public RefreshEpisodeMetadata(MediaFileProvider mediaFileProvider, SeriesProvider seriesProvider,
MetadataProvider metadataProvider)
{
_mediaFileProvider = mediaFileProvider;
_seriesProvider = seriesProvider;
_metadataProvider = metadataProvider;
}
public string Name
{
get { return "Refresh Episode Metadata"; }
}
public TimeSpan DefaultInterval
{
get { return TimeSpan.FromTicks(0); }
}
public void Start(ProgressNotification notification, int targetId, int secondaryTargetId)
{
if (targetId <= 0)
{
var allSeries = _seriesProvider.GetAllSeries();
foreach(var s in allSeries)
{
RefreshMetadata(notification, s);
}
}
var series = _seriesProvider.GetSeries(targetId);
RefreshMetadata(notification, series);
}
private void RefreshMetadata(ProgressNotification notification, Series series)
{
notification.CurrentMessage = String.Format("Refreshing episode metadata for '{0}'", series.Title);
Logger.Debug("Getting episodes from database for series: {0}", series.SeriesId);
var episodeFiles = _mediaFileProvider.GetSeriesFiles(series.SeriesId);
if (episodeFiles == null || episodeFiles.Count == 0)
{
Logger.Warn("No episodes in database found for series: {0}", series.SeriesId);
return;
}
try
{
_metadataProvider.CreateForEpisodeFiles(episodeFiles.ToList());
}
catch (Exception e)
{
Logger.WarnException("An error has occurred while refreshing episode metadata", e);
}
notification.CurrentMessage = String.Format("Epsiode metadata refresh completed for {0}", series.Title);
}
}
}

View file

@ -249,6 +249,7 @@
<Compile Include="Helpers\SortHelper.cs" />
<Compile Include="Helpers\SabnzbdPriorityTypeConverter.cs" />
<Compile Include="Jobs\CheckpointJob.cs" />
<Compile Include="Jobs\RefreshEpsiodeMetadata.cs" />
<Compile Include="Jobs\PastWeekBacklogSearchJob.cs" />
<Compile Include="Jobs\SearchHistoryCleanupJob.cs" />
<Compile Include="Model\DownloadClientType.cs" />

View file

@ -66,25 +66,31 @@ namespace NzbDrone.Core.Providers.Metadata
_diskProvider.WriteAllText(Path.Combine(series.Path, "tvshow.nfo"), doc.ToString());
}
_logger.Debug("Downloading fanart for: {0}", series.Title);
_bannerProvider.Download(tvDbSeries.FanartPath, Path.Combine(series.Path, "fanart.jpg"));
if (_configProvider.MetadataUseBanners)
if (!_diskProvider.FileExists(Path.Combine(series.Path, "fanart.jpg")))
{
_logger.Debug("Downloading series banner for: {0}", series.Title);
_bannerProvider.Download(tvDbSeries.BannerPath, Path.Combine(series.Path, "folder.jpg"));
_logger.Debug("Downloading Season banners for {0}", series.Title);
DownloadSeasonThumbnails(series, tvDbSeries, TvdbSeasonBanner.Type.seasonwide);
_logger.Debug("Downloading fanart for: {0}", series.Title);
_bannerProvider.Download(tvDbSeries.FanartPath, Path.Combine(series.Path, "fanart.jpg"));
}
else
if (!_diskProvider.FileExists(Path.Combine(series.Path, "folder.jpg")))
{
_logger.Debug("Downloading series thumbnail for: {0}", series.Title);
_bannerProvider.Download(tvDbSeries.PosterPath, Path.Combine(series.Path, "folder.jpg"));
if(_configProvider.MetadataUseBanners)
{
_logger.Debug("Downloading series banner for: {0}", series.Title);
_bannerProvider.Download(tvDbSeries.BannerPath, Path.Combine(series.Path, "folder.jpg"));
_logger.Debug("Downloading Season posters for {0}", series.Title);
DownloadSeasonThumbnails(series, tvDbSeries, TvdbSeasonBanner.Type.season);
_logger.Debug("Downloading Season banners for {0}", series.Title);
DownloadSeasonThumbnails(series, tvDbSeries, TvdbSeasonBanner.Type.seasonwide);
}
else
{
_logger.Debug("Downloading series thumbnail for: {0}", series.Title);
_bannerProvider.Download(tvDbSeries.PosterPath, Path.Combine(series.Path, "folder.jpg"));
_logger.Debug("Downloading Season posters for {0}", series.Title);
DownloadSeasonThumbnails(series, tvDbSeries, TvdbSeasonBanner.Type.season);
}
}
}
@ -109,9 +115,13 @@ namespace NzbDrone.Core.Providers.Metadata
_logger.Debug("No thumbnail is available for this episode");
return;
}
_logger.Debug("Downloading episode thumbnail for: {0}", episodeFile.EpisodeFileId);
_bannerProvider.Download(episodeFileThumbnail.BannerPath, episodeFile.Path.Replace(Path.GetExtension(episodeFile.Path), ".tbn"));
if (!_diskProvider.FileExists(episodeFile.Path.Replace(Path.GetExtension(episodeFile.Path), ".tbn")))
{
_logger.Debug("Downloading episode thumbnail for: {0}", episodeFile.EpisodeFileId);
_bannerProvider.Download(episodeFileThumbnail.BannerPath,
episodeFile.Path.Replace(Path.GetExtension(episodeFile.Path), ".tbn"));
}
_logger.Debug("Generating filename.nfo for: {0}", episodeFile.EpisodeFileId);
@ -231,14 +241,20 @@ namespace NzbDrone.Core.Providers.Metadata
if (season == 0)
{
_bannerProvider.Download(banner.BannerPath,
Path.Combine(series.Path, "season-specials.tbn"));
if (!_diskProvider.FileExists(Path.Combine(series.Path, "season-specials.tbn")))
{
_bannerProvider.Download(banner.BannerPath,
Path.Combine(series.Path, "season-specials.tbn"));
}
}
else
{
_bannerProvider.Download(banner.BannerPath,
Path.Combine(series.Path, String.Format("season{0:00}.tbn", season)));
if (!_diskProvider.FileExists(Path.Combine(series.Path, String.Format("season{0:00}.tbn", season))))
{
_bannerProvider.Download(banner.BannerPath,
Path.Combine(series.Path, String.Format("season{0:00}.tbn", season)));
}
}
}
}

View file

@ -62,6 +62,16 @@ namespace NzbDrone.Web.Controllers
{
_jobProvider.QueueJob(typeof(UpdateInfoJob), seriesId);
_jobProvider.QueueJob(typeof(DiskScanJob), seriesId);
_jobProvider.QueueJob(typeof(RefreshEpisodeMetadata), seriesId);
return JsonNotificationResult.Queued("Episode update/Disk scan");
}
public JsonResult ForceRefreshAll()
{
_jobProvider.QueueJob(typeof(UpdateInfoJob));
_jobProvider.QueueJob(typeof(DiskScanJob));
_jobProvider.QueueJob(typeof(RefreshEpisodeMetadata));
return JsonNotificationResult.Queued("Episode update/Disk scan");
}

View file

@ -54,6 +54,13 @@
</style>
}
@section ActionMenu
{
<ul class="sub-menu">
<li>@Ajax.ActionLink("Force Refresh", "ForceRefreshAll", "Command", null, null, new { Title = "Refresh episode and series information and scan for new episodes for all series" })</li>
</ul>
}
@using (Html.BeginForm("SaveEditor", "Series", FormMethod.Post, new { id = "SeriesEditor", name = "SeriesEditor" }))
{
<table id ="seriesEditorGrid" class="dataTable dataTablesGrid no-details">