2011-12-02 02:33:17 +01:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System;
|
2011-10-07 06:36:47 +02:00
|
|
|
|
using Ninject;
|
|
|
|
|
using NLog;
|
|
|
|
|
using NzbDrone.Core.Model.Notification;
|
2011-12-02 02:33:17 +01:00
|
|
|
|
using NzbDrone.Core.Providers;
|
2011-10-07 06:36:47 +02:00
|
|
|
|
using NzbDrone.Core.Providers.Converting;
|
|
|
|
|
|
2011-12-02 02:33:17 +01:00
|
|
|
|
namespace NzbDrone.Core.Jobs
|
2011-10-07 06:36:47 +02:00
|
|
|
|
{
|
|
|
|
|
public class ConvertEpisodeJob : IJob
|
|
|
|
|
{
|
|
|
|
|
private readonly HandbrakeProvider _handbrakeProvider;
|
|
|
|
|
private readonly AtomicParsleyProvider _atomicParsleyProvider;
|
|
|
|
|
private readonly EpisodeProvider _episodeProvider;
|
|
|
|
|
|
|
|
|
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
|
|
|
|
|
|
|
|
|
[Inject]
|
|
|
|
|
public ConvertEpisodeJob(HandbrakeProvider handbrakeProvider, AtomicParsleyProvider atomicParsleyProvider,
|
|
|
|
|
EpisodeProvider episodeProvider)
|
|
|
|
|
{
|
|
|
|
|
_handbrakeProvider = handbrakeProvider;
|
|
|
|
|
_atomicParsleyProvider = atomicParsleyProvider;
|
|
|
|
|
_episodeProvider = episodeProvider;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Name
|
|
|
|
|
{
|
|
|
|
|
get { return "Convert Episode"; }
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-15 03:47:23 +01:00
|
|
|
|
public TimeSpan DefaultInterval
|
2011-10-07 06:36:47 +02:00
|
|
|
|
{
|
2012-01-15 03:47:23 +01:00
|
|
|
|
get { return TimeSpan.FromTicks(0); }
|
2011-10-07 06:36:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Start(ProgressNotification notification, int targetId, int secondaryTargetId)
|
|
|
|
|
{
|
|
|
|
|
if (targetId <= 0)
|
|
|
|
|
throw new ArgumentOutOfRangeException("targetId");
|
|
|
|
|
|
|
|
|
|
var episode = _episodeProvider.GetEpisode(targetId);
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|