mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-21 14:03:29 -07:00
ConfigFileProvider will now add missing config values automatically, with a default value.
Added Handbrake and AtomicParsley wrappers for iPod video conversion.
This commit is contained in:
parent
d9b2c72125
commit
f973c74c87
9 changed files with 376 additions and 20 deletions
74
NzbDrone.Core/Providers/Converting/AtomicParsleyProvider.cs
Normal file
74
NzbDrone.Core/Providers/Converting/AtomicParsleyProvider.cs
Normal file
|
@ -0,0 +1,74 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using NLog;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Providers.Core;
|
||||
using NzbDrone.Core.Repository;
|
||||
|
||||
namespace NzbDrone.Core.Providers.Converting
|
||||
{
|
||||
public class AtomicParsleyProvider
|
||||
{
|
||||
private readonly ConfigProvider _configProvider;
|
||||
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public AtomicParsleyProvider(ConfigProvider configProvider)
|
||||
{
|
||||
_configProvider = configProvider;
|
||||
}
|
||||
|
||||
public AtomicParsleyProvider()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual bool RunAtomicParsley(Episode episode, string outputFile)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
|
||||
var atomicParsleyLocation = _configProvider.GetValue("AtomicParsleyLocation", "");
|
||||
var atomicParsleyTitleType = (AtomicParsleyTitleType) System.Convert.ToInt32(_configProvider.GetValue("AtomicParsley", 0));
|
||||
|
||||
var atomicParsleyCommand = String.Format("\"{0}\" --overWrite --title \"{1}\" --genre \"TV Shows\" --stik \"TV Show\" --TVShowName \"{2}\" --TVEpisodeNum \"{3}\" --TVSeason \"{4}\"",
|
||||
outputFile, episode.Title, episode.Series.Title, episode.EpisodeNumber, episode.SeasonNumber);
|
||||
|
||||
//If Episode Number + Name should be in Episode Title (Number - Title)
|
||||
if (atomicParsleyTitleType == AtomicParsleyTitleType.EpisodeNumber)
|
||||
{
|
||||
atomicParsleyCommand = String.Format("\"{0}\" --overWrite --title \"{3} - {1}\" --genre \"TV Shows\" --stik \"TV Show\" --TVShowName \"{2}\" --TVEpisodeNum \"{3}\" --TVSeason \"{4}\"",
|
||||
outputFile, episode.Title, episode.Series.Title, episode.EpisodeNumber, episode.SeasonNumber);
|
||||
}
|
||||
|
||||
//If Season/Episode Number + Name should be in Episode Title (SeasonNumber'x'EpisodeNumber - Title)
|
||||
else if (atomicParsleyTitleType == AtomicParsleyTitleType.Both)
|
||||
{
|
||||
atomicParsleyCommand = String.Format("\"{0}\" --overWrite --title \"{4}x{3:00} - {1}\" --genre \"TV Shows\" --stik \"TV Show\" --TVShowName \"{2}\" --TVEpisodeNum \"{3}\" --TVSeason \"{4}\"",
|
||||
outputFile, episode.Title, episode.Series.Title, episode.EpisodeNumber, episode.SeasonNumber);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var process = new Process();
|
||||
process.StartInfo.FileName = Path.Combine(atomicParsleyLocation, "AtomicParsley.exe");
|
||||
process.StartInfo.Arguments = atomicParsleyCommand;
|
||||
process.StartInfo.UseShellExecute = false;
|
||||
process.StartInfo.CreateNoWindow = true;
|
||||
process.StartInfo.RedirectStandardOutput = true;
|
||||
//process.OutputDataReceived += new DataReceivedEventHandler(HandBrakeOutputDataReceived);
|
||||
process.Start();
|
||||
//process.BeginOutputReadLine();
|
||||
process.WaitForExit();
|
||||
}
|
||||
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.DebugException(ex.Message, ex);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
105
NzbDrone.Core/Providers/Converting/HandbrakeProvider.cs
Normal file
105
NzbDrone.Core/Providers/Converting/HandbrakeProvider.cs
Normal file
|
@ -0,0 +1,105 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Text.RegularExpressions;
|
||||
using NLog;
|
||||
using NzbDrone.Core.Model.Notification;
|
||||
using NzbDrone.Core.Providers.Core;
|
||||
using NzbDrone.Core.Repository;
|
||||
|
||||
namespace NzbDrone.Core.Providers.Converting
|
||||
{
|
||||
public class HandbrakeProvider
|
||||
{
|
||||
//Interacts with Handbrake
|
||||
private readonly ConfigProvider _configProvider;
|
||||
private ProgressNotification _notification;
|
||||
private Episode _currentEpisode;
|
||||
|
||||
private Regex _processingRegex =
|
||||
new Regex(@"^(?:Encoding).+?(?:\,\s(?<percent>\d{1,3}\.\d{2})\s\%)(?:.+?ETA\s(?<hours>\d{2})h(?<minutes>\d{2})m(?<seconds>\d{2})s)?",
|
||||
RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
||||
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public HandbrakeProvider(ConfigProvider configProvider)
|
||||
{
|
||||
_configProvider = configProvider;
|
||||
}
|
||||
|
||||
public HandbrakeProvider()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual string ConvertFile(Episode episode, ProgressNotification notification)
|
||||
{
|
||||
_notification = notification;
|
||||
_currentEpisode = episode;
|
||||
|
||||
var outputFile = _configProvider.GetValue("iPodConvertDir", "");
|
||||
|
||||
var handBrakePreset = _configProvider.GetValue("HandBrakePreset", "iPhone & iPod Touch");
|
||||
var handBrakeCommand = String.Format("-i \"{0}\" -o \"{1}\" --preset=\"{2}\"", episode.EpisodeFile.Path, outputFile, handBrakePreset);
|
||||
var handBrakeFile = @"C:\Program Files (x86)\Handbrake\HandBrakeCLI.exe";
|
||||
|
||||
try
|
||||
{
|
||||
var process = new Process();
|
||||
process.StartInfo.FileName = handBrakeFile;
|
||||
process.StartInfo.Arguments = handBrakeCommand;
|
||||
process.StartInfo.UseShellExecute = false;
|
||||
process.StartInfo.CreateNoWindow = true;
|
||||
process.StartInfo.RedirectStandardOutput = true;
|
||||
process.OutputDataReceived += new DataReceivedEventHandler(HandBrakeOutputDataReceived);
|
||||
process.Start();
|
||||
process.BeginOutputReadLine();
|
||||
process.WaitForExit();
|
||||
}
|
||||
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.DebugException(ex.Message, ex);
|
||||
return String.Empty;
|
||||
}
|
||||
|
||||
return outputFile;
|
||||
}
|
||||
|
||||
private void HandBrakeOutputDataReceived(object obj, DataReceivedEventArgs args)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
|
||||
//args.Data contains the line writen
|
||||
|
||||
var match = _processingRegex.Matches(args.Data);
|
||||
|
||||
if (match.Count != 1)
|
||||
return;
|
||||
|
||||
var episodeString = String.Format("{0} - {1}x{2:00}",
|
||||
_currentEpisode.Series.Title,
|
||||
_currentEpisode.SeasonNumber,
|
||||
_currentEpisode.EpisodeNumber);
|
||||
|
||||
var percent = System.Convert.ToDecimal(match[0].Groups["percent"].Value);
|
||||
int hours;
|
||||
int minutes;
|
||||
int seconds;
|
||||
|
||||
Int32.TryParse(match[0].Groups["hours"].Value, out hours);
|
||||
Int32.TryParse(match[0].Groups["minutes"].Value, out minutes);
|
||||
Int32.TryParse(match[0].Groups["seconds"].Value, out seconds);
|
||||
|
||||
if (seconds > 0 || minutes > 0 || hours > 0)
|
||||
{
|
||||
var eta = DateTime.Now.Add(new TimeSpan(0, hours, minutes, seconds));
|
||||
_notification.CurrentMessage = String.Format("Converting: {0}, {1}%. ETA: {2}", episodeString, percent, eta);
|
||||
}
|
||||
|
||||
else
|
||||
_notification.CurrentMessage = String.Format("Converting: {0}, {1}%.", episodeString, percent);
|
||||
|
||||
Console.WriteLine(args.Data);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue