2011-12-02 01:33:17 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System;
|
2011-10-07 04:36:47 +00:00
|
|
|
|
using NLog;
|
2013-02-19 06:01:03 +00:00
|
|
|
|
using NzbDrone.Core.Tv;
|
2011-10-07 04:36:47 +00:00
|
|
|
|
using NzbDrone.Core.Model.Notification;
|
2011-12-02 01:33:17 +00:00
|
|
|
|
using NzbDrone.Core.Providers;
|
2011-10-07 04:36:47 +00:00
|
|
|
|
using NzbDrone.Core.Providers.Converting;
|
2012-10-22 07:05:27 +00:00
|
|
|
|
using NzbDrone.Core.Repository;
|
2011-10-07 04:36:47 +00:00
|
|
|
|
|
2011-12-02 01:33:17 +00:00
|
|
|
|
namespace NzbDrone.Core.Jobs
|
2011-10-07 04:36:47 +00:00
|
|
|
|
{
|
|
|
|
|
public class ConvertEpisodeJob : IJob
|
|
|
|
|
{
|
|
|
|
|
private readonly HandbrakeProvider _handbrakeProvider;
|
|
|
|
|
private readonly AtomicParsleyProvider _atomicParsleyProvider;
|
2013-02-20 02:05:15 +00:00
|
|
|
|
private readonly EpisodeService _episodeService;
|
2011-10-07 04:36:47 +00:00
|
|
|
|
|
|
|
|
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
|
|
|
|
|
|
|
|
|
public ConvertEpisodeJob(HandbrakeProvider handbrakeProvider, AtomicParsleyProvider atomicParsleyProvider,
|
2013-02-20 02:05:15 +00:00
|
|
|
|
EpisodeService episodeService)
|
2011-10-07 04:36:47 +00:00
|
|
|
|
{
|
|
|
|
|
_handbrakeProvider = handbrakeProvider;
|
|
|
|
|
_atomicParsleyProvider = atomicParsleyProvider;
|
2013-02-20 02:05:15 +00:00
|
|
|
|
_episodeService = episodeService;
|
2011-10-07 04:36:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Name
|
|
|
|
|
{
|
|
|
|
|
get { return "Convert Episode"; }
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-15 02:47:23 +00:00
|
|
|
|
public TimeSpan DefaultInterval
|
2011-10-07 04:36:47 +00:00
|
|
|
|
{
|
2012-01-15 02:47:23 +00:00
|
|
|
|
get { return TimeSpan.FromTicks(0); }
|
2011-10-07 04:36:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-09-10 19:04:17 +00:00
|
|
|
|
public void Start(ProgressNotification notification, dynamic options)
|
2011-10-07 04:36:47 +00:00
|
|
|
|
{
|
|
|
|
|
|
2012-09-10 19:04:17 +00:00
|
|
|
|
if (options == null || options.EpisodeId <= 0)
|
|
|
|
|
throw new ArgumentNullException(options);
|
|
|
|
|
|
2013-02-20 02:05:15 +00:00
|
|
|
|
Episode episode = _episodeService.GetEpisode(options.EpisodeId);
|
2011-10-07 04:36:47 +00:00
|
|
|
|
notification.CurrentMessage = String.Format("Starting Conversion for {0}", episode);
|
|
|
|
|
var outputFile = _handbrakeProvider.ConvertFile(episode, notification);
|
|
|
|
|
|
|
|
|
|
if (String.IsNullOrEmpty(outputFile))
|
|
|
|
|
notification.CurrentMessage = String.Format("Conversion failed for {0}", episode);
|
|
|
|
|
|
|
|
|
|
_atomicParsleyProvider.RunAtomicParsley(episode, outputFile);
|
|
|
|
|
|
|
|
|
|
notification.CurrentMessage = String.Format("Conversion completed for {0}", episode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|