aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2016-06-23 13:04:18 -0400
committerLuke Pulverenti <luke.pulverenti@gmail.com>2016-06-23 13:04:18 -0400
commitcffc9417c7a25263a194615096685bd8ef1e37b2 (patch)
tree7b524ef331f06c2ff66abd6c0dfad6dfebac0a28 /MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs
parent82e80857472b94ea73798276ef76829a86f5c2e5 (diff)
update startup wizard
Diffstat (limited to 'MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs')
-rw-r--r--MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs72
1 files changed, 58 insertions, 14 deletions
diff --git a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs
index 39a233856..f8321f6cd 100644
--- a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs
+++ b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs
@@ -23,6 +23,7 @@ using System.Threading.Tasks;
using CommonIO;
using MediaBrowser.Model.Configuration;
using MediaBrowser.Common.Configuration;
+using MediaBrowser.Common.Extensions;
namespace MediaBrowser.MediaEncoding.Encoder
{
@@ -118,6 +119,35 @@ namespace MediaBrowser.MediaEncoding.Encoder
}
}
+ public async Task UpdateEncoderPath(string path)
+ {
+ if (string.IsNullOrWhiteSpace(path))
+ {
+ throw new ArgumentNullException("path");
+ }
+
+ if (!File.Exists(path) && !Directory.Exists(path))
+ {
+ throw new ResourceNotFoundException();
+ }
+
+ var newPaths = GetEncoderPaths(path);
+ if (string.IsNullOrWhiteSpace(newPaths.Item1))
+ {
+ throw new ResourceNotFoundException("ffmpeg not found");
+ }
+ if (string.IsNullOrWhiteSpace(newPaths.Item2))
+ {
+ throw new ResourceNotFoundException("ffprobe not found");
+ }
+
+ var config = GetEncodingOptions();
+ config.EncoderAppPath = path;
+ ConfigurationManager.SaveConfiguration("encoding", config);
+
+ Init();
+ }
+
private void ConfigureEncoderPaths()
{
if (_hasExternalEncoder)
@@ -131,46 +161,60 @@ namespace MediaBrowser.MediaEncoding.Encoder
{
appPath = Path.Combine(ConfigurationManager.ApplicationPaths.ProgramDataPath, "ffmpeg");
}
+ var newPaths = GetEncoderPaths(appPath);
+
+ if (!string.IsNullOrWhiteSpace(newPaths.Item1) && !string.IsNullOrWhiteSpace(newPaths.Item2))
+ {
+ FFMpegPath = newPaths.Item1;
+ FFProbePath = newPaths.Item2;
+ }
+
+ LogPaths();
+ }
+
+ private Tuple<string, string> GetEncoderPaths(string configuredPath)
+ {
+ var appPath = configuredPath;
if (!string.IsNullOrWhiteSpace(appPath))
{
if (Directory.Exists(appPath))
{
- SetPathsFromDirectory(appPath);
+ return GetPathsFromDirectory(appPath);
}
- else if (File.Exists(appPath))
+ if (File.Exists(appPath))
{
- FFMpegPath = appPath;
-
- SetProbePathFromEncoderPath(appPath);
+ return new Tuple<string, string>(appPath, GetProbePathFromEncoderPath(appPath));
}
}
- LogPaths();
+ return new Tuple<string, string>(null, null);
}
- private void SetPathsFromDirectory(string path)
+ private Tuple<string,string> GetPathsFromDirectory(string path)
{
// Since we can't predict the file extension, first try directly within the folder
// If that doesn't pan out, then do a recursive search
var files = Directory.GetFiles(path);
- FFMpegPath = files.FirstOrDefault(i => string.Equals(Path.GetFileNameWithoutExtension(i), "ffmpeg", StringComparison.OrdinalIgnoreCase));
- FFProbePath = files.FirstOrDefault(i => string.Equals(Path.GetFileNameWithoutExtension(i), "ffprobe", StringComparison.OrdinalIgnoreCase));
+ var ffmpegPath = files.FirstOrDefault(i => string.Equals(Path.GetFileNameWithoutExtension(i), "ffmpeg", StringComparison.OrdinalIgnoreCase));
+ var ffprobePath = files.FirstOrDefault(i => string.Equals(Path.GetFileNameWithoutExtension(i), "ffprobe", StringComparison.OrdinalIgnoreCase));
- if (string.IsNullOrWhiteSpace(FFMpegPath) || !File.Exists(FFMpegPath))
+ if (string.IsNullOrWhiteSpace(ffmpegPath) || !File.Exists(ffmpegPath))
{
files = Directory.GetFiles(path, "*", SearchOption.AllDirectories);
- FFMpegPath = files.FirstOrDefault(i => string.Equals(Path.GetFileNameWithoutExtension(i), "ffmpeg", StringComparison.OrdinalIgnoreCase));
- SetProbePathFromEncoderPath(FFMpegPath);
+ ffmpegPath = files.FirstOrDefault(i => string.Equals(Path.GetFileNameWithoutExtension(i), "ffmpeg", StringComparison.OrdinalIgnoreCase));
+ ffprobePath = GetProbePathFromEncoderPath(ffmpegPath);
}
+
+ return new Tuple<string, string>(ffmpegPath, ffprobePath);
}
- private void SetProbePathFromEncoderPath(string appPath)
+ private string GetProbePathFromEncoderPath(string appPath)
{
- FFProbePath = Directory.GetFiles(Path.GetDirectoryName(appPath))
+ return Directory.GetFiles(Path.GetDirectoryName(appPath))
.FirstOrDefault(i => string.Equals(Path.GetFileNameWithoutExtension(i), "ffprobe", StringComparison.OrdinalIgnoreCase));
}