Skip to content

Commit

Permalink
Merge pull request #971 from MediaBrowser/dev
Browse files Browse the repository at this point in the history
3.0.5482.4
  • Loading branch information
LukePulverenti committed Jan 10, 2015
2 parents 8bc85da + 3552f81 commit 95365c8
Show file tree
Hide file tree
Showing 116 changed files with 2,038 additions and 1,122 deletions.
8 changes: 5 additions & 3 deletions MediaBrowser.Api/ItemUpdateService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,13 @@ public object Get(GetMetadataEditorInfo request)
{
if (!(item is ICollectionFolder) && !(item is UserView) && !(item is AggregateFolder) && !(item is LiveTvChannel) && !(item is IItemByName))
{
var collectionType = _libraryManager.GetInheritedContentType(item);
if (string.IsNullOrWhiteSpace(collectionType))
var inheritedContentType = _libraryManager.GetInheritedContentType(item);
var configuredContentType = _libraryManager.GetConfiguredContentType(item);

if (string.IsNullOrWhiteSpace(inheritedContentType) || string.Equals(inheritedContentType, CollectionType.TvShows, StringComparison.OrdinalIgnoreCase) || !string.IsNullOrWhiteSpace(configuredContentType))
{
info.ContentTypeOptions = GetContentTypeOptions(true);
info.ContentType = _libraryManager.GetContentType(item);
info.ContentType = configuredContentType;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions MediaBrowser.Api/PackageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,9 @@ public object Get(GetPackage request)
/// </summary>
/// <param name="request">The request.</param>
/// <returns>System.Object.</returns>
public object Get(GetPackages request)
public async Task<object> Get(GetPackages request)
{
var packages = _installationManager.GetAvailablePackages(CancellationToken.None, request.PackageType, _appHost.ApplicationVersion).Result;
var packages = await _installationManager.GetAvailablePackages(CancellationToken.None, request.PackageType, _appHost.ApplicationVersion).ConfigureAwait(false);

if (!string.IsNullOrEmpty(request.TargetSystems))
{
Expand Down
27 changes: 25 additions & 2 deletions MediaBrowser.Api/PluginService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using MediaBrowser.Common;
using System.Threading;
using MediaBrowser.Common;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.Security;
using MediaBrowser.Common.Updates;
Expand All @@ -13,6 +14,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;

namespace MediaBrowser.Api
{
Expand Down Expand Up @@ -155,10 +157,31 @@ public object Get(GetRegistrationStatus request)
/// </summary>
/// <param name="request">The request.</param>
/// <returns>System.Object.</returns>
public object Get(GetPlugins request)
public async Task<object> Get(GetPlugins request)
{
var result = _appHost.Plugins.OrderBy(p => p.Name).Select(p => p.GetPluginInfo()).ToList();

// Don't fail just on account of image url's
try
{
var packages = (await _installationManager.GetAvailablePackagesWithoutRegistrationInfo(CancellationToken.None))
.ToList();

foreach (var plugin in result)
{
var pkg = packages.FirstOrDefault(i => !string.IsNullOrWhiteSpace(i.guid) && new Guid(plugin.Id).Equals(new Guid(i.guid)));

if (pkg != null)
{
plugin.ImageUrl = pkg.thumbImage;
}
}
}
catch
{

}

return ToOptimizedSerializedResultUsingCache(result);
}

Expand Down
2 changes: 1 addition & 1 deletion MediaBrowser.Common.Implementations/BaseApplicationHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public string SystemId
{
if (_deviceId == null)
{
_deviceId = new DeviceId(ApplicationPaths, LogManager.GetLogger("SystemId"), NetworkManager);
_deviceId = new DeviceId(ApplicationPaths, LogManager.GetLogger("SystemId"));
}

return _deviceId.Value;
Expand Down
24 changes: 2 additions & 22 deletions MediaBrowser.Common.Implementations/Devices/DeviceId.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.Net;
using MediaBrowser.Model.Logging;
using System;
using System.IO;
Expand All @@ -11,7 +9,6 @@ namespace MediaBrowser.Common.Implementations.Devices
public class DeviceId
{
private readonly IApplicationPaths _appPaths;
private readonly INetworkManager _networkManager;
private readonly ILogger _logger;

private readonly object _syncLock = new object();
Expand Down Expand Up @@ -73,23 +70,7 @@ private void SaveId(string id)

private string GetNewId()
{
// When generating an Id, base it off of the app path + mac address
// But we can't fail here, so if we can't get the mac address then just use a random guid

string mac;

try
{
mac = _networkManager.GetMacAddress();
}
catch
{
mac = Guid.NewGuid().ToString("N");
}

mac += "-" + _appPaths.ApplicationPath;

return mac.GetMD5().ToString("N");
return Guid.NewGuid().ToString("N");
}

private string GetDeviceId()
Expand All @@ -107,11 +88,10 @@ private string GetDeviceId()

private string _id;

public DeviceId(IApplicationPaths appPaths, ILogger logger, INetworkManager networkManager)
public DeviceId(IApplicationPaths appPaths, ILogger logger)
{
_appPaths = appPaths;
_logger = logger;
_networkManager = networkManager;
}

public string Value
Expand Down
14 changes: 14 additions & 0 deletions MediaBrowser.Controller/Library/ILibraryManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,20 @@ IEnumerable<BaseItem> Sort(IEnumerable<BaseItem> items, User user, IEnumerable<s
/// <param name="item">The item.</param>
/// <returns>System.String.</returns>
string GetInheritedContentType(BaseItem item);

/// <summary>
/// Gets the type of the configured content.
/// </summary>
/// <param name="item">The item.</param>
/// <returns>System.String.</returns>
string GetConfiguredContentType(BaseItem item);

/// <summary>
/// Gets the type of the configured content.
/// </summary>
/// <param name="path">The path.</param>
/// <returns>System.String.</returns>
string GetConfiguredContentType(string path);

/// <summary>
/// Normalizes the root path list.
Expand Down
8 changes: 8 additions & 0 deletions MediaBrowser.LocalMetadata/BaseXmlProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ public string Name
}
}

public int Order
{
get
{
// After Nfo
return 1;
}
}
}

static class XmlProviderUtils
Expand Down
9 changes: 0 additions & 9 deletions MediaBrowser.LocalMetadata/Savers/MovieXmlSaver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,6 @@ public bool IsEnabledFor(IHasMetadata item, ItemUpdateType updateType)
// Check parent for null to avoid running this against things like video backdrops
if (video != null && !(item is Episode) && !video.IsOwnedItem)
{
// If it's a plain video, skip if content type is unset (unless editing)
if (video.GetType() == typeof(Video))
{
if (updateType < ItemUpdateType.MetadataEdit && string.IsNullOrEmpty(_libraryManager.GetContentType(video)))
{
return false;
}
}

return updateType >= ItemUpdateType.MetadataDownload;
}

Expand Down
5 changes: 5 additions & 0 deletions MediaBrowser.MediaEncoding/Encoder/AudioEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,10 @@ protected override string GetOutputFileExtension(EncodingJob state)

return null;
}

protected override bool IsVideoEncoder
{
get { return false; }
}
}
}
68 changes: 58 additions & 10 deletions MediaBrowser.MediaEncoding/Encoder/BaseEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ public async Task<EncodingJob> Start(EncodingJobOptions options,
throw;
}

cancellationToken.Register(() => Cancel(process, encodingJob));

// MUST read both stdout and stderr asynchronously or a deadlock may occurr
process.BeginOutputReadLine();

Expand All @@ -157,6 +159,16 @@ public async Task<EncodingJob> Start(EncodingJobOptions options,
return encodingJob;
}

private void Cancel(Process process, EncodingJob job)
{
Logger.Info("Killing ffmpeg process for {0}", job.OutputFilePath);

//process.Kill();
process.StandardInput.WriteLine("q");

job.IsCancelled = true;
}

/// <summary>
/// Processes the exited.
/// </summary>
Expand All @@ -169,25 +181,53 @@ private void OnFfMpegProcessExited(Process process, EncodingJob job)
Logger.Debug("Disposing stream resources");
job.Dispose();

var isSuccesful = false;

try
{
Logger.Info("FFMpeg exited with code {0}", process.ExitCode);
var exitCode = process.ExitCode;
Logger.Info("FFMpeg exited with code {0}", exitCode);

isSuccesful = exitCode == 0;
}
catch
{
Logger.Error("FFMpeg exited with an error.");
}

if (isSuccesful && !job.IsCancelled)
{
job.TaskCompletionSource.TrySetResult(true);
}
else if (job.IsCancelled)
{
try
{
job.TaskCompletionSource.TrySetResult(true);
DeleteFiles(job);
}
catch
{
}
try
{
job.TaskCompletionSource.TrySetException(new OperationCanceledException());
}
catch
{
}
}
catch
else
{
Logger.Error("FFMpeg exited with an error.");

try
{
job.TaskCompletionSource.TrySetException(new ApplicationException());
DeleteFiles(job);
}
catch
{
}
try
{
job.TaskCompletionSource.TrySetException(new ApplicationException("Encoding failed"));
}
catch
{
Expand All @@ -206,6 +246,11 @@ private void OnFfMpegProcessExited(Process process, EncodingJob job)
//}
}

protected virtual void DeleteFiles(EncodingJob job)
{
File.Delete(job.OutputFilePath);
}

private void OnTranscodeBeginning(EncodingJob job)
{
job.ReportTranscodingProgress(null, null, null, null);
Expand All @@ -219,10 +264,7 @@ private void OnTranscodeFailedToStart(string path, EncodingJob job)
}
}

protected virtual bool IsVideoEncoder
{
get { return false; }
}
protected abstract bool IsVideoEncoder { get; }

protected virtual string GetWorkingDirectory(EncodingJobOptions options)
{
Expand Down Expand Up @@ -263,6 +305,12 @@ protected virtual string GetOutputFileExtension(EncodingJob state)
/// <returns>System.Int32.</returns>
protected int GetNumberOfThreads(EncodingJob job, bool isWebm)
{
// Only need one thread for sync
if (job.Options.Context == EncodingContext.Static)
{
return 1;
}

if (isWebm)
{
// Recommended per docs
Expand Down
7 changes: 7 additions & 0 deletions MediaBrowser.MediaEncoding/Encoder/EncodingJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
public class EncodingJob : IDisposable
{
public bool HasExited { get; internal set; }
public bool IsCancelled { get; internal set; }

public Stream LogFileStream { get; set; }
public IProgress<double> Progress { get; set; }
Expand Down Expand Up @@ -399,6 +400,12 @@ public void ReportTranscodingProgress(TimeSpan? transcodingPosition, float? fram

// job.Framerate = framerate;

if (!percentComplete.HasValue && ticks.HasValue && RunTimeTicks.HasValue)
{
var pct = ticks.Value/RunTimeTicks.Value;
percentComplete = pct*100;
}

if (percentComplete.HasValue)
{
Progress.Report(percentComplete.Value);
Expand Down
5 changes: 5 additions & 0 deletions MediaBrowser.MediaEncoding/Encoder/VideoEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,5 +173,10 @@ protected override string GetOutputFileExtension(EncodingJob state)

return null;
}

protected override bool IsVideoEncoder
{
get { return true; }
}
}
}
3 changes: 3 additions & 0 deletions MediaBrowser.Model/Configuration/ServerConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ public class ServerConfiguration : BaseApplicationConfiguration

public NameValuePair[] ContentTypes { get; set; }

public bool EnableAudioArchiveFiles { get; set; }
public bool EnableVideoArchiveFiles { get; set; }

/// <summary>
/// Initializes a new instance of the <see cref="ServerConfiguration" /> class.
/// </summary>
Expand Down
8 changes: 6 additions & 2 deletions MediaBrowser.Model/Plugins/PluginInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using MediaBrowser.Model.Updates;
using System;
using System;

namespace MediaBrowser.Model.Plugins
{
Expand Down Expand Up @@ -49,5 +48,10 @@ public class PluginInfo
/// </summary>
/// <value>The unique id.</value>
public string Id { get; set; }
/// <summary>
/// Gets or sets the image URL.
/// </summary>
/// <value>The image URL.</value>
public string ImageUrl { get; set; }
}
}
5 changes: 5 additions & 0 deletions MediaBrowser.Model/Sync/SyncJobItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,10 @@ public class SyncJobItem
/// </summary>
/// <value>The primary image tag.</value>
public string PrimaryImageTag { get; set; }
/// <summary>
/// Gets or sets a value indicating whether [requires conversion].
/// </summary>
/// <value><c>true</c> if [requires conversion]; otherwise, <c>false</c>.</value>
public bool RequiresConversion { get; set; }
}
}
Loading

0 comments on commit 95365c8

Please sign in to comment.