Skip to content

Commit

Permalink
update startup wizard
Browse files Browse the repository at this point in the history
  • Loading branch information
LukePulverenti committed Jun 23, 2016
1 parent e3a4e41 commit 8d34070
Show file tree
Hide file tree
Showing 36 changed files with 442 additions and 154 deletions.
20 changes: 19 additions & 1 deletion MediaBrowser.Api/ConfigurationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using CommonIO;
using MediaBrowser.Controller.MediaEncoding;

namespace MediaBrowser.Api
{
Expand Down Expand Up @@ -71,6 +73,14 @@ public class AutoSetMetadataOptions : IReturnVoid

}

[Route("/System/MediaEncoder/Path", "POST", Summary = "Updates the path to the media encoder")]
[Authenticated(Roles = "Admin", AllowBeforeStartupWizard = true)]
public class UpdateMediaEncoderPath : IReturnVoid
{
[ApiMember(Name = "Path", Description = "Path", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
public string Path { get; set; }
}

public class ConfigurationService : BaseApiService
{
/// <summary>
Expand All @@ -86,14 +96,22 @@ public class ConfigurationService : BaseApiService
private readonly IFileSystem _fileSystem;
private readonly IProviderManager _providerManager;
private readonly ILibraryManager _libraryManager;
private readonly IMediaEncoder _mediaEncoder;

public ConfigurationService(IJsonSerializer jsonSerializer, IServerConfigurationManager configurationManager, IFileSystem fileSystem, IProviderManager providerManager, ILibraryManager libraryManager)
public ConfigurationService(IJsonSerializer jsonSerializer, IServerConfigurationManager configurationManager, IFileSystem fileSystem, IProviderManager providerManager, ILibraryManager libraryManager, IMediaEncoder mediaEncoder)
{
_jsonSerializer = jsonSerializer;
_configurationManager = configurationManager;
_fileSystem = fileSystem;
_providerManager = providerManager;
_libraryManager = libraryManager;
_mediaEncoder = mediaEncoder;
}

public void Post(UpdateMediaEncoderPath request)
{
var task = _mediaEncoder.UpdateEncoderPath(request.Path);
Task.WaitAll(task);
}

/// <summary>
Expand Down
13 changes: 13 additions & 0 deletions MediaBrowser.Api/ItemLookupService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ public class GetMovieRemoteSearchResults : RemoteSearchQuery<MovieInfo>, IReturn
{
}

[Route("/Items/RemoteSearch/Trailer", "POST")]
[Authenticated]
public class GetTrailerRemoteSearchResults : RemoteSearchQuery<TrailerInfo>, IReturn<List<RemoteSearchResult>>
{
}

[Route("/Items/RemoteSearch/AdultVideo", "POST")]
[Authenticated]
public class GetAdultVideoRemoteSearchResults : RemoteSearchQuery<ItemLookupInfo>, IReturn<List<RemoteSearchResult>>
Expand Down Expand Up @@ -132,6 +138,13 @@ public object Get(GetExternalIdInfos request)
return ToOptimizedResult(infos);
}

public async Task<object> Post(GetTrailerRemoteSearchResults request)
{
var result = await _providerManager.GetRemoteSearchResults<Trailer, TrailerInfo>(request, CancellationToken.None).ConfigureAwait(false);

return ToOptimizedResult(result);
}

public async Task<object> Post(GetMovieRemoteSearchResults request)
{
var result = await _providerManager.GetRemoteSearchResults<Movie, MovieInfo>(request, CancellationToken.None).ConfigureAwait(false);
Expand Down
9 changes: 7 additions & 2 deletions MediaBrowser.Api/StartupWizardService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using MediaBrowser.Controller.MediaEncoding;

namespace MediaBrowser.Api
{
Expand Down Expand Up @@ -52,14 +53,16 @@ public class StartupWizardService : BaseApiService
private readonly IUserManager _userManager;
private readonly IConnectManager _connectManager;
private readonly ILiveTvManager _liveTvManager;
private readonly IMediaEncoder _mediaEncoder;

public StartupWizardService(IServerConfigurationManager config, IServerApplicationHost appHost, IUserManager userManager, IConnectManager connectManager, ILiveTvManager liveTvManager)
public StartupWizardService(IServerConfigurationManager config, IServerApplicationHost appHost, IUserManager userManager, IConnectManager connectManager, ILiveTvManager liveTvManager, IMediaEncoder mediaEncoder)
{
_config = config;
_appHost = appHost;
_userManager = userManager;
_connectManager = connectManager;
_liveTvManager = liveTvManager;
_mediaEncoder = mediaEncoder;
}

public void Post(ReportStartupWizardComplete request)
Expand All @@ -75,7 +78,8 @@ public async Task<object> Get(GetStartupInfo request)

return new StartupInfo
{
SupportsRunningAsService = info.SupportsRunningAsService
SupportsRunningAsService = info.SupportsRunningAsService,
HasMediaEncoder = !string.IsNullOrWhiteSpace(_mediaEncoder.EncoderPath)
};
}

Expand Down Expand Up @@ -231,6 +235,7 @@ public class StartupConfiguration
public class StartupInfo
{
public bool SupportsRunningAsService { get; set; }
public bool HasMediaEncoder { get; set; }
}

public class StartupUser
Expand Down
6 changes: 3 additions & 3 deletions MediaBrowser.Api/System/SystemService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace MediaBrowser.Api.System
/// Class GetSystemInfo
/// </summary>
[Route("/System/Info", "GET", Summary = "Gets information about the server")]
[Authenticated(EscapeParentalControl = true)]
[Authenticated(EscapeParentalControl = true, AllowBeforeStartupWizard = true)]
public class GetSystemInfo : IReturn<SystemInfo>
{

Expand Down Expand Up @@ -120,7 +120,7 @@ public object Get(GetServerLogs request)

try
{
files = _fileSystem.GetFiles(_appPaths.LogDirectoryPath)
files = _fileSystem.GetFiles(_appPaths.LogDirectoryPath)
.Where(i => string.Equals(i.Extension, ".txt", StringComparison.OrdinalIgnoreCase))
.ToList();
}
Expand All @@ -146,7 +146,7 @@ public object Get(GetServerLogs request)

public Task<object> Get(GetLogFile request)
{
var file = _fileSystem.GetFiles(_appPaths.LogDirectoryPath)
var file = _fileSystem.GetFiles(_appPaths.LogDirectoryPath)
.First(i => string.Equals(i.Name, request.Name, StringComparison.OrdinalIgnoreCase));

return ResultFactory.GetStaticFileResult(Request, file.FullName, FileShare.ReadWrite);
Expand Down
16 changes: 11 additions & 5 deletions MediaBrowser.Api/UserLibrary/ItemsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,17 @@ private async Task<QueryResult<BaseItem>> GetItemsToSerialize(GetItems request,

// Default list type = children

var folder = item as Folder;
if (folder == null)
{
folder = user == null ? _libraryManager.RootFolder : _libraryManager.GetUserRootFolder();
}

if (!string.IsNullOrEmpty(request.Ids))
{
request.Recursive = true;
var query = GetItemsQuery(request, user);
var result = await ((Folder)item).GetItems(query).ConfigureAwait(false);
var result = await folder.GetItems(query).ConfigureAwait(false);

if (string.IsNullOrWhiteSpace(request.SortBy))
{
Expand All @@ -138,22 +144,22 @@ private async Task<QueryResult<BaseItem>> GetItemsToSerialize(GetItems request,

if (request.Recursive)
{
return await ((Folder)item).GetItems(GetItemsQuery(request, user)).ConfigureAwait(false);
return await folder.GetItems(GetItemsQuery(request, user)).ConfigureAwait(false);
}

if (user == null)
{
return await ((Folder)item).GetItems(GetItemsQuery(request, null)).ConfigureAwait(false);
return await folder.GetItems(GetItemsQuery(request, null)).ConfigureAwait(false);
}

var userRoot = item as UserRootFolder;

if (userRoot == null)
{
return await ((Folder)item).GetItems(GetItemsQuery(request, user)).ConfigureAwait(false);
return await folder.GetItems(GetItemsQuery(request, user)).ConfigureAwait(false);
}

IEnumerable<BaseItem> items = ((Folder)item).GetChildren(user, true);
IEnumerable<BaseItem> items = folder.GetChildren(user, true);

var itemsArray = items.ToArray();

Expand Down
2 changes: 2 additions & 0 deletions MediaBrowser.Controller/MediaEncoding/IMediaEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,7 @@ Task<string> EncodeVideo(EncodingJobOptions options,
string EscapeSubtitleFilterPath(string path);

void Init();

Task UpdateEncoderPath(string path);
}
}
72 changes: 58 additions & 14 deletions MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using CommonIO;
using MediaBrowser.Model.Configuration;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Extensions;

namespace MediaBrowser.MediaEncoding.Encoder
{
Expand Down Expand Up @@ -118,6 +119,35 @@ public void Init()
}
}

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)
Expand All @@ -131,46 +161,60 @@ private void ConfigureEncoderPaths()
{
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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,9 @@
<Compile Include="..\MediaBrowser.Model\Sync\SyncTarget.cs">
<Link>Sync\SyncTarget.cs</Link>
</Compile>
<Compile Include="..\MediaBrowser.Model\System\Architecture.cs">
<Link>System\Architecture.cs</Link>
</Compile>
<Compile Include="..\MediaBrowser.Model\System\LogFile.cs">
<Link>System\LogFile.cs</Link>
</Compile>
Expand Down
3 changes: 3 additions & 0 deletions MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,9 @@
<Compile Include="..\MediaBrowser.Model\Sync\SyncTarget.cs">
<Link>Sync\SyncTarget.cs</Link>
</Compile>
<Compile Include="..\MediaBrowser.Model\System\Architecture.cs">
<Link>System\Architecture.cs</Link>
</Compile>
<Compile Include="..\MediaBrowser.Model\System\LogFile.cs">
<Link>System\LogFile.cs</Link>
</Compile>
Expand Down
1 change: 1 addition & 0 deletions MediaBrowser.Model/MediaBrowser.Model.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@
<Compile Include="Sync\SyncProfileOption.cs" />
<Compile Include="Sync\SyncQualityOption.cs" />
<Compile Include="Sync\SyncTarget.cs" />
<Compile Include="System\Architecture.cs" />
<Compile Include="System\LogFile.cs" />
<Compile Include="System\PublicSystemInfo.cs" />
<Compile Include="Updates\CheckForUpdateResult.cs" />
Expand Down
9 changes: 9 additions & 0 deletions MediaBrowser.Model/System/Architecture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace MediaBrowser.Model.System
{
public enum Architecture
{
X86 = 0,
X64 = 1,
Arm = 2
}
}
2 changes: 2 additions & 0 deletions MediaBrowser.Model/System/SystemInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ public class SystemInfo : PublicSystemInfo

public bool HasExternalEncoder { get; set; }

public Architecture SystemArchitecture { get; set; }

/// <summary>
/// Initializes a new instance of the <see cref="SystemInfo" /> class.
/// </summary>
Expand Down
Loading

0 comments on commit 8d34070

Please sign in to comment.