Merge pull request #2367 from MediaBrowser/dev

Dev
This commit is contained in:
Luke 2016-12-27 03:16:41 -05:00 committed by GitHub
commit 6f2cb0b0d9
11 changed files with 128 additions and 126 deletions

View File

@ -490,38 +490,13 @@ namespace Emby.Common.Implementations.IO
var temp1 = Path.GetTempFileName();
// Copying over will fail against hidden files
RemoveHiddenAttribute(file1);
RemoveHiddenAttribute(file2);
SetHidden(file1, false);
SetHidden(file2, false);
CopyFile(file1, temp1, true);
CopyFile(file2, file1, true);
CopyFile(temp1, file2, true);
DeleteFile(temp1);
}
/// <summary>
/// Removes the hidden attribute.
/// </summary>
/// <param name="path">The path.</param>
private void RemoveHiddenAttribute(string path)
{
if (string.IsNullOrEmpty(path))
{
throw new ArgumentNullException("path");
}
var currentFile = new FileInfo(path);
// This will fail if the file is hidden
if (currentFile.Exists)
{
if ((currentFile.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
{
currentFile.Attributes &= ~FileAttributes.Hidden;
}
}
}
public bool ContainsSubPath(string parentPath, string path)

View File

@ -570,9 +570,9 @@ namespace Emby.Server.Implementations.Connect
}
catch (HttpException ex)
{
if (!ex.StatusCode.HasValue)
if (!ex.StatusCode.HasValue || ex.IsTimedOut)
{
throw;
throw new Exception("Unable to invite guest, " + ex.Message, ex);
}
// If they entered a username, then whatever the error is just throw it, for example, user not found

View File

@ -424,6 +424,9 @@
<ItemGroup>
<EmbeddedResource Include="Localization\Ratings\us.txt" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Localization\Ratings\uk.txt" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

View File

@ -91,16 +91,12 @@ namespace Emby.Server.Implementations.HttpServer
readonly Dictionary<Type, int> _mapExceptionToStatusCode = new Dictionary<Type, int>
{
{typeof (InvalidOperationException), 500},
{typeof (NotImplementedException), 500},
{typeof (ResourceNotFoundException), 404},
{typeof (FileNotFoundException), 404},
//{typeof (DirectoryNotFoundException), 404},
{typeof (SecurityException), 401},
{typeof (PaymentRequiredException), 402},
{typeof (UnauthorizedAccessException), 500},
{typeof (PlatformNotSupportedException), 500},
{typeof (NotSupportedException), 500}
{typeof (ArgumentException), 400}
};
public override void Configure()
@ -228,6 +224,22 @@ namespace Emby.Server.Implementations.HttpServer
}
}
private int GetStatusCode(Exception ex)
{
if (ex is ArgumentException)
{
return 400;
}
int statusCode;
if (!_mapExceptionToStatusCode.TryGetValue(ex.GetType(), out statusCode))
{
statusCode = 500;
}
return statusCode;
}
private void ErrorHandler(Exception ex, IRequest httpReq, bool logException = true)
{
try
@ -244,11 +256,7 @@ namespace Emby.Server.Implementations.HttpServer
return;
}
int statusCode;
if (!_mapExceptionToStatusCode.TryGetValue(ex.GetType(), out statusCode))
{
statusCode = 500;
}
var statusCode = GetStatusCode(ex);
httpRes.StatusCode = statusCode;
httpRes.ContentType = "text/html";

View File

@ -0,0 +1,7 @@
UK-U,1
UK-PG,5
UK-12,7
UK-12A,7
UK-15,9
UK-18,10
UK-R18,15

View File

@ -870,33 +870,47 @@ namespace MediaBrowser.Api.Playback
inputChannels = null;
}
int? resultChannels = null;
int? transcoderChannelLimit = null;
var codec = outputAudioCodec ?? string.Empty;
if (codec.IndexOf("wma", StringComparison.OrdinalIgnoreCase) != -1)
{
// wmav2 currently only supports two channel output
resultChannels = Math.Min(2, inputChannels ?? 2);
transcoderChannelLimit = 2;
}
else if (request.MaxAudioChannels.HasValue)
else if (codec.IndexOf("mp3", StringComparison.OrdinalIgnoreCase) != -1)
{
var channelLimit = codec.IndexOf("mp3", StringComparison.OrdinalIgnoreCase) != -1
? 2
: 6;
if (inputChannels.HasValue)
{
channelLimit = Math.Min(channelLimit, inputChannels.Value);
}
// If we don't have any media info then limit it to 5 to prevent encoding errors due to asking for too many channels
resultChannels = Math.Min(request.MaxAudioChannels.Value, channelLimit);
// libmp3lame currently only supports two channel output
transcoderChannelLimit = 2;
}
else
{
// If we don't have any media info then limit it to 6 to prevent encoding errors due to asking for too many channels
transcoderChannelLimit = 6;
}
if (request.TranscodingMaxAudioChannels.HasValue && !string.Equals(codec, "copy", StringComparison.OrdinalIgnoreCase))
var isTranscodingAudio = !string.Equals(codec, "copy", StringComparison.OrdinalIgnoreCase);
int? resultChannels = null;
if (isTranscodingAudio)
{
resultChannels = Math.Min(request.TranscodingMaxAudioChannels.Value, resultChannels ?? inputChannels ?? request.TranscodingMaxAudioChannels.Value);
resultChannels = request.TranscodingMaxAudioChannels;
}
resultChannels = resultChannels ?? request.MaxAudioChannels ?? request.AudioChannels;
if (inputChannels.HasValue)
{
resultChannels = resultChannels.HasValue
? Math.Min(resultChannels.Value, inputChannels.Value)
: inputChannels.Value;
}
if (isTranscodingAudio && transcoderChannelLimit.HasValue)
{
resultChannels = resultChannels.HasValue
? Math.Min(resultChannels.Value, transcoderChannelLimit.Value)
: transcoderChannelLimit.Value;
}
return resultChannels ?? request.AudioChannels;
@ -1054,7 +1068,19 @@ namespace MediaBrowser.Api.Playback
arg += string.Format(" -canvas_size {0}:{1}", state.VideoStream.Width.Value.ToString(CultureInfo.InvariantCulture), Convert.ToInt32(height).ToString(CultureInfo.InvariantCulture));
}
arg += " -i \"" + state.SubtitleStream.Path + "\"";
var subtitlePath = state.SubtitleStream.Path;
if (string.Equals(Path.GetExtension(subtitlePath), ".sub", StringComparison.OrdinalIgnoreCase))
{
var idxFile = Path.ChangeExtension(subtitlePath, ".idx");
if (FileSystem.FileExists(idxFile))
{
subtitlePath = idxFile;
}
}
arg += " -i \"" + subtitlePath + "\"";
}
}

View File

@ -35,6 +35,7 @@ namespace MediaBrowser.Controller.MediaEncoding
public string VideoCodec { get; set; }
public int? TranscodingMaxAudioChannels { get; set; }
public int? VideoBitRate { get; set; }
public int? AudioStreamIndex { get; set; }
public int? VideoStreamIndex { get; set; }
@ -86,6 +87,7 @@ namespace MediaBrowser.Controller.MediaEncoding
MaxVideoBitDepth = info.MaxVideoBitDepth;
SubtitleMethod = info.SubtitleDeliveryMethod;
Context = info.Context;
TranscodingMaxAudioChannels = info.TranscodingMaxAudioChannels;
if (info.SubtitleDeliveryMethod != SubtitleDeliveryMethod.External)
{

View File

@ -474,7 +474,19 @@ namespace MediaBrowser.MediaEncoding.Encoder
arg += string.Format(" -canvas_size {0}:{1}", state.VideoStream.Width.Value.ToString(CultureInfo.InvariantCulture), Convert.ToInt32(height).ToString(CultureInfo.InvariantCulture));
}
arg += " -i \"" + state.SubtitleStream.Path + "\"";
var subtitlePath = state.SubtitleStream.Path;
if (string.Equals(Path.GetExtension(subtitlePath), ".sub", StringComparison.OrdinalIgnoreCase))
{
var idxFile = Path.ChangeExtension(subtitlePath, ".idx");
if (FileSystem.FileExists(idxFile))
{
subtitlePath = idxFile;
}
}
arg += " -i \"" + subtitlePath + "\"";
}
}

View File

@ -370,30 +370,50 @@ namespace MediaBrowser.MediaEncoding.Encoder
inputChannels = null;
}
int? transcoderChannelLimit = null;
var codec = outputAudioCodec ?? string.Empty;
if (codec.IndexOf("wma", StringComparison.OrdinalIgnoreCase) != -1)
{
// wmav2 currently only supports two channel output
return Math.Min(2, inputChannels ?? 2);
transcoderChannelLimit = 2;
}
if (request.MaxAudioChannels.HasValue)
else if (codec.IndexOf("mp3", StringComparison.OrdinalIgnoreCase) != -1)
{
var channelLimit = codec.IndexOf("mp3", StringComparison.OrdinalIgnoreCase) != -1
? 2
: 6;
if (inputChannels.HasValue)
{
channelLimit = Math.Min(channelLimit, inputChannels.Value);
}
// If we don't have any media info then limit it to 5 to prevent encoding errors due to asking for too many channels
return Math.Min(request.MaxAudioChannels.Value, channelLimit);
// libmp3lame currently only supports two channel output
transcoderChannelLimit = 2;
}
else
{
// If we don't have any media info then limit it to 6 to prevent encoding errors due to asking for too many channels
transcoderChannelLimit = 6;
}
return request.AudioChannels;
var isTranscodingAudio = !string.Equals(codec, "copy", StringComparison.OrdinalIgnoreCase);
int? resultChannels = null;
if (isTranscodingAudio)
{
resultChannels = request.TranscodingMaxAudioChannels;
}
resultChannels = resultChannels ?? request.MaxAudioChannels ?? request.AudioChannels;
if (inputChannels.HasValue)
{
resultChannels = resultChannels.HasValue
? Math.Min(resultChannels.Value, inputChannels.Value)
: inputChannels.Value;
}
if (isTranscodingAudio && transcoderChannelLimit.HasValue)
{
resultChannels = resultChannels.HasValue
? Math.Min(resultChannels.Value, transcoderChannelLimit.Value)
: transcoderChannelLimit.Value;
}
return resultChannels ?? request.AudioChannels;
}
private int? GetVideoBitrateParamValue(EncodingJobOptions request, MediaStream videoStream, string outputVideoCodec)

View File

@ -27,7 +27,6 @@ namespace MediaBrowser.Model.Configuration
public bool DisplayMissingEpisodes { get; set; }
public bool DisplayUnairedEpisodes { get; set; }
public string[] ExcludeFoldersFromGrouping { get; set; }
public string[] GroupedFolders { get; set; }
public SubtitlePlaybackMode SubtitleMode { get; set; }

View File

@ -37,7 +37,9 @@ namespace OpenSubtitlesHandler
public static IHttpClient HttpClient { get; set; }
public static ITextEncoding EncodingHelper { get; set; }
private const string XML_RPC_SERVER = "https://api.opensubtitles.org/xml-rpc";
//private static string XML_RPC_SERVER = "https://api.opensubtitles.org/xml-rpc";
private static string XML_RPC_SERVER = "https://92.240.234.122/xml-rpc";
private static string HostHeader = "api.opensubtitles.org:443";
/// <summary>
/// Compute movie hash
@ -142,32 +144,6 @@ namespace OpenSubtitlesHandler
public static Stream SendRequest(byte[] request, string userAgent)
{
return SendRequestAsync(request, userAgent, CancellationToken.None).Result;
//HttpWebRequest req = (HttpWebRequest)WebRequest.Create(XML_RPC_SERVER);
//req.ContentType = "text/xml";
//req.Host = "api.opensubtitles.org:80";
//req.Method = "POST";
//req.UserAgent = "xmlrpc-epi-php/0.2 (PHP)";
//req.ContentLength = request.Length;
//ServicePointManager.Expect100Continue = false;
//try
//{
// using (Stream stm = req.GetRequestStream())
// {
// stm.Write(request, 0, request.Length);
// }
// WebResponse response = req.GetResponse();
// return response.GetResponseStream();
//}
//catch (Exception ex)
//{
// Stream errorStream = new MemoryStream();
// byte[] dd = Encoding.ASCII.GetBytes("ERROR: " + ex.Message);
// errorStream.Write(dd, 0, dd.Length);
// errorStream.Position = 0;
// return errorStream;
//}
}
public static async Task<Stream> SendRequestAsync(byte[] request, string userAgent, CancellationToken cancellationToken)
@ -177,7 +153,7 @@ namespace OpenSubtitlesHandler
RequestContentBytes = request,
RequestContentType = "text/xml",
UserAgent = userAgent,
Host = "api.opensubtitles.org:443",
Host = HostHeader,
Url = XML_RPC_SERVER,
// Response parsing will fail with this enabled
@ -195,32 +171,6 @@ namespace OpenSubtitlesHandler
var result = await HttpClient.Post(options).ConfigureAwait(false);
return result.Content;
//HttpWebRequest req = (HttpWebRequest)WebRequest.Create(XML_RPC_SERVER);
//req.ContentType = "text/xml";
//req.Host = "api.opensubtitles.org:80";
//req.Method = "POST";
//req.UserAgent = "xmlrpc-epi-php/0.2 (PHP)";
//req.ContentLength = request.Length;
//ServicePointManager.Expect100Continue = false;
//try
//{
// using (Stream stm = req.GetRequestStream())
// {
// stm.Write(request, 0, request.Length);
// }
// WebResponse response = req.GetResponse();
// return response.GetResponseStream();
//}
//catch (Exception ex)
//{
// Stream errorStream = new MemoryStream();
// byte[] dd = Encoding.ASCII.GetBytes("ERROR: " + ex.Message);
// errorStream.Write(dd, 0, dd.Length);
// errorStream.Position = 0;
// return errorStream;
//}
}
}