You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
2.3 KiB
69 lines
2.3 KiB
12 years ago
|
using System;
|
||
13 years ago
|
using System.Collections.Generic;
|
||
|
using System.Linq;
|
||
|
using NLog;
|
||
12 years ago
|
using NzbDrone.Core.MediaFiles;
|
||
13 years ago
|
using NzbDrone.Core.Model.Notification;
|
||
12 years ago
|
using NzbDrone.Core.Tv;
|
||
13 years ago
|
|
||
12 years ago
|
namespace NzbDrone.Core.Jobs.Implementations
|
||
13 years ago
|
{
|
||
|
public class RefreshEpisodeMetadata : IJob
|
||
|
{
|
||
12 years ago
|
private readonly IMediaFileService _mediaFileService;
|
||
12 years ago
|
private readonly ISeriesService _seriesService;
|
||
|
private readonly ISeriesRepository _seriesRepository;
|
||
13 years ago
|
|
||
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||
|
|
||
12 years ago
|
public RefreshEpisodeMetadata(IMediaFileService mediaFileService, ISeriesService seriesService,
|
||
12 years ago
|
ISeriesRepository seriesRepository)
|
||
13 years ago
|
{
|
||
12 years ago
|
_mediaFileService = mediaFileService;
|
||
12 years ago
|
_seriesService = seriesService;
|
||
|
_seriesRepository = seriesRepository;
|
||
13 years ago
|
}
|
||
|
|
||
|
public string Name
|
||
|
{
|
||
|
get { return "Refresh Episode Metadata"; }
|
||
|
}
|
||
|
|
||
|
public TimeSpan DefaultInterval
|
||
|
{
|
||
|
get { return TimeSpan.FromTicks(0); }
|
||
|
}
|
||
|
|
||
12 years ago
|
public void Start(ProgressNotification notification, dynamic options)
|
||
13 years ago
|
{
|
||
12 years ago
|
List<Series> seriesToRefresh;
|
||
|
|
||
12 years ago
|
if (options == null || options.SeriesId <= 0)
|
||
12 years ago
|
seriesToRefresh = _seriesRepository.All().ToList();
|
||
13 years ago
|
|
||
12 years ago
|
else
|
||
12 years ago
|
seriesToRefresh = new List<Series> { _seriesRepository.Get(options.SeriesId) };
|
||
13 years ago
|
|
||
12 years ago
|
foreach(var series in seriesToRefresh)
|
||
|
{
|
||
|
RefreshMetadata(notification, series);
|
||
|
}
|
||
13 years ago
|
}
|
||
|
|
||
|
private void RefreshMetadata(ProgressNotification notification, Series series)
|
||
|
{
|
||
|
notification.CurrentMessage = String.Format("Refreshing episode metadata for '{0}'", series.Title);
|
||
|
|
||
12 years ago
|
Logger.Debug("Getting episodes from database for series: {0}", series.Id);
|
||
12 years ago
|
var episodeFiles = _mediaFileService.GetFilesBySeries(series.Id);
|
||
13 years ago
|
|
||
|
if (episodeFiles == null || episodeFiles.Count == 0)
|
||
|
{
|
||
12 years ago
|
Logger.Warn("No episodes in database found for series: {0}", series.Id);
|
||
13 years ago
|
return;
|
||
|
}
|
||
|
|
||
|
notification.CurrentMessage = String.Format("Epsiode metadata refresh completed for {0}", series.Title);
|
||
|
}
|
||
|
}
|
||
|
}
|