fix mac ffmpeg build

This commit is contained in:
Luke Pulverenti 2014-09-28 12:50:33 -04:00
parent 3be25f8bfb
commit c05cb1dcb1
17 changed files with 196 additions and 75 deletions

View File

@ -1,4 +1,5 @@
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.IO;
using MediaBrowser.Common.Net;
using MediaBrowser.Model.Logging;
@ -156,6 +157,20 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
}
}
/// <summary>
/// The _semaphoreLocks
/// </summary>
private readonly ConcurrentDictionary<string, SemaphoreSlim> _semaphoreLocks = new ConcurrentDictionary<string, SemaphoreSlim>(StringComparer.OrdinalIgnoreCase);
/// <summary>
/// Gets the lock.
/// </summary>
/// <param name="url">The filename.</param>
/// <returns>System.Object.</returns>
private SemaphoreSlim GetLock(string url)
{
return _semaphoreLocks.GetOrAdd(url, key => new SemaphoreSlim(1, 1));
}
/// <summary>
/// Gets the response internal.
/// </summary>
@ -215,6 +230,107 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
/// <exception cref="HttpException">
/// </exception>
public async Task<HttpResponseInfo> SendAsync(HttpRequestOptions options, string httpMethod)
{
if (!options.EnableUnconditionalCache)
{
return await SendAsyncInternal(options, httpMethod).ConfigureAwait(false);
}
var url = options.Url;
var urlHash = url.ToLower().GetMD5().ToString("N");
var semaphore = GetLock(url);
var responseCachePath = Path.Combine(_appPaths.CachePath, "httpclient", urlHash);
var response = await GetCachedResponse(responseCachePath, options.CacheLength, url).ConfigureAwait(false);
if (response != null)
{
return response;
}
await semaphore.WaitAsync(options.CancellationToken).ConfigureAwait(false);
try
{
response = await GetCachedResponse(responseCachePath, options.CacheLength, url).ConfigureAwait(false);
if (response != null)
{
return response;
}
response = await SendAsyncInternal(options, httpMethod).ConfigureAwait(false);
if (response.StatusCode == HttpStatusCode.OK)
{
await CacheResponse(response, responseCachePath).ConfigureAwait(false);
}
return response;
}
finally
{
semaphore.Release();
}
}
private async Task<HttpResponseInfo> GetCachedResponse(string responseCachePath, TimeSpan cacheLength, string url)
{
try
{
if (_fileSystem.GetLastWriteTimeUtc(responseCachePath).Add(cacheLength) > DateTime.UtcNow)
{
using (var stream = _fileSystem.GetFileStream(responseCachePath, FileMode.Open, FileAccess.Read, FileShare.Read, true))
{
var memoryStream = new MemoryStream();
await stream.CopyToAsync(memoryStream).ConfigureAwait(false);
memoryStream.Position = 0;
return new HttpResponseInfo
{
ResponseUrl = url,
Content = memoryStream,
StatusCode = HttpStatusCode.OK,
Headers = new NameValueCollection(),
ContentLength = memoryStream.Length
};
}
}
}
catch (FileNotFoundException)
{
}
catch (DirectoryNotFoundException)
{
}
return null;
}
private async Task CacheResponse(HttpResponseInfo response, string responseCachePath)
{
Directory.CreateDirectory(Path.GetDirectoryName(responseCachePath));
using (var responseStream = response.Content)
{
using (var fileStream = _fileSystem.GetFileStream(responseCachePath, FileMode.Create, FileAccess.Write, FileShare.Read, true))
{
var memoryStream = new MemoryStream();
await responseStream.CopyToAsync(memoryStream).ConfigureAwait(false);
memoryStream.Position = 0;
await memoryStream.CopyToAsync(fileStream).ConfigureAwait(false);
memoryStream.Position = 0;
response.Content = memoryStream;
}
}
}
private async Task<HttpResponseInfo> SendAsyncInternal(HttpRequestOptions options, string httpMethod)
{
ValidateParams(options);
@ -236,11 +352,11 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
!string.IsNullOrEmpty(options.RequestContent) ||
string.Equals(httpMethod, "post", StringComparison.OrdinalIgnoreCase))
{
var bytes = options.RequestContentBytes ??
var bytes = options.RequestContentBytes ??
Encoding.UTF8.GetBytes(options.RequestContent ?? string.Empty);
httpWebRequest.ContentType = options.RequestContentType ?? "application/x-www-form-urlencoded";
httpWebRequest.ContentLength = bytes.Length;
httpWebRequest.GetRequestStream().Write(bytes, 0, bytes.Length);
}

View File

@ -91,6 +91,9 @@ namespace MediaBrowser.Common.Net
public bool LogErrorResponseBody { get; set; }
public bool EnableKeepAlive { get; set; }
public bool EnableUnconditionalCache { get; set; }
public TimeSpan CacheLength { get; set; }
private string GetHeaderValue(string name)
{
string value;

View File

@ -74,13 +74,15 @@ namespace MediaBrowser.Model.Channels
/// </summary>
/// <value>The extra types.</value>
public ExtraType[] ExtraTypes { get; set; }
public TrailerType[] TrailerTypes { get; set; }
public AllChannelMediaQuery()
{
ChannelIds = new string[] { };
ContentTypes = new ChannelMediaContentType[] { };
ExtraTypes = new ExtraType[] { };
TrailerTypes = new TrailerType[] { };
Filters = new ItemFilter[] { };
Fields = new List<ItemFields>();

View File

@ -38,6 +38,7 @@ namespace MediaBrowser.Providers.Music
var releaseId = searchInfo.GetReleaseId();
string url = null;
var isNameSearch = false;
if (!string.IsNullOrEmpty(releaseId))
{
@ -55,6 +56,8 @@ namespace MediaBrowser.Providers.Music
}
else
{
isNameSearch = true;
url = string.Format("http://www.musicbrainz.org/ws/2/release/?query=\"{0}\" AND artist:\"{1}\"",
WebUtility.UrlEncode(searchInfo.Name),
WebUtility.UrlEncode(searchInfo.GetAlbumArtist()));
@ -63,7 +66,7 @@ namespace MediaBrowser.Providers.Music
if (!string.IsNullOrWhiteSpace(url))
{
var doc = await GetMusicBrainzResponse(url, cancellationToken).ConfigureAwait(false);
var doc = await GetMusicBrainzResponse(url, isNameSearch, cancellationToken).ConfigureAwait(false);
return GetResultsFromResponse(doc);
}
@ -193,7 +196,7 @@ namespace MediaBrowser.Providers.Music
WebUtility.UrlEncode(albumName),
artistId);
var doc = await GetMusicBrainzResponse(url, cancellationToken).ConfigureAwait(false);
var doc = await GetMusicBrainzResponse(url, true, cancellationToken).ConfigureAwait(false);
return GetReleaseResult(doc);
}
@ -204,7 +207,7 @@ namespace MediaBrowser.Providers.Music
WebUtility.UrlEncode(albumName),
WebUtility.UrlEncode(artistName));
var doc = await GetMusicBrainzResponse(url, cancellationToken).ConfigureAwait(false);
var doc = await GetMusicBrainzResponse(url, true, cancellationToken).ConfigureAwait(false);
return GetReleaseResult(doc);
}
@ -252,7 +255,7 @@ namespace MediaBrowser.Providers.Music
{
var url = string.Format("http://www.musicbrainz.org/ws/2/release-group/?query=reid:{0}", releaseEntryId);
var doc = await GetMusicBrainzResponse(url, cancellationToken).ConfigureAwait(false);
var doc = await GetMusicBrainzResponse(url, false, cancellationToken).ConfigureAwait(false);
var ns = new XmlNamespaceManager(doc.NameTable);
ns.AddNamespace("mb", "http://musicbrainz.org/ns/mmd-2.0#");
@ -274,9 +277,10 @@ namespace MediaBrowser.Providers.Music
/// Gets the music brainz response.
/// </summary>
/// <param name="url">The URL.</param>
/// <param name="isSearch">if set to <c>true</c> [is search].</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{XmlDocument}.</returns>
internal async Task<XmlDocument> GetMusicBrainzResponse(string url, CancellationToken cancellationToken)
internal async Task<XmlDocument> GetMusicBrainzResponse(string url, bool isSearch, CancellationToken cancellationToken)
{
await _musicBrainzResourcePool.WaitAsync(cancellationToken).ConfigureAwait(false);
@ -294,15 +298,20 @@ namespace MediaBrowser.Providers.Music
var doc = new XmlDocument();
var userAgent = _appHost.Name + "/" + _appHost.ApplicationVersion;
using (var xml = await _httpClient.Get(new HttpRequestOptions
var options = new HttpRequestOptions
{
Url = url,
CancellationToken = cancellationToken,
UserAgent = userAgent
UserAgent = _appHost.Name + "/" + _appHost.ApplicationVersion
};
}).ConfigureAwait(false))
if (!isSearch)
{
options.EnableUnconditionalCache = true;
options.CacheLength = TimeSpan.FromDays(7);
}
using (var xml = await _httpClient.Get(options).ConfigureAwait(false))
{
using (var oReader = new StreamReader(xml, Encoding.UTF8))
{

View File

@ -25,7 +25,7 @@ namespace MediaBrowser.Providers.Music
{
var url = string.Format("http://www.musicbrainz.org/ws/2/artist/?query=arid:{0}", musicBrainzId);
var doc = await MusicBrainzAlbumProvider.Current.GetMusicBrainzResponse(url, cancellationToken)
var doc = await MusicBrainzAlbumProvider.Current.GetMusicBrainzResponse(url, false, cancellationToken)
.ConfigureAwait(false);
return GetResultsFromResponse(doc);
@ -37,7 +37,7 @@ namespace MediaBrowser.Providers.Music
var url = String.Format("http://www.musicbrainz.org/ws/2/artist/?query=artist:\"{0}\"", UrlEncode(nameToSearch));
var doc = await MusicBrainzAlbumProvider.Current.GetMusicBrainzResponse(url, cancellationToken).ConfigureAwait(false);
var doc = await MusicBrainzAlbumProvider.Current.GetMusicBrainzResponse(url, true, cancellationToken).ConfigureAwait(false);
var results = GetResultsFromResponse(doc).ToList();
@ -51,7 +51,7 @@ namespace MediaBrowser.Providers.Music
// Try again using the search with accent characters url
url = String.Format("http://www.musicbrainz.org/ws/2/artist/?query=artistaccent:\"{0}\"", UrlEncode(nameToSearch));
doc = await MusicBrainzAlbumProvider.Current.GetMusicBrainzResponse(url, cancellationToken).ConfigureAwait(false);
doc = await MusicBrainzAlbumProvider.Current.GetMusicBrainzResponse(url, true, cancellationToken).ConfigureAwait(false);
return GetResultsFromResponse(doc);
}

View File

@ -37,7 +37,9 @@ namespace MediaBrowser.Providers.Omdb
{
Url = url,
ResourcePool = ResourcePool,
CancellationToken = cancellationToken
CancellationToken = cancellationToken,
EnableUnconditionalCache = true,
CacheLength = TimeSpan.FromDays(7)
}).ConfigureAwait(false))
{

View File

@ -1,10 +1,10 @@
using System.Collections.Generic;
using MediaBrowser.Common.Progress;
using MediaBrowser.Common.Progress;
using MediaBrowser.Controller.Channels;
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Channels;
using MediaBrowser.Model.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
@ -61,6 +61,7 @@ namespace MediaBrowser.Server.Implementations.Channels
}, cancellationToken);
var numComplete = 0;
var numItems = channels.Items.Length;
foreach (var channel in channels.Items)
{
@ -71,9 +72,20 @@ namespace MediaBrowser.Server.Implementations.Channels
const int currentRefreshLevel = 1;
var maxRefreshLevel = features.AutoRefreshLevels ?? 1;
var innerProgress = new ActionableProgress<double>();
var startingNumberComplete = numComplete;
innerProgress.RegisterAction(p =>
{
double innerPercent = startingNumberComplete;
innerPercent += (p / 100);
innerPercent /= numItems;
progress.Report(innerPercent * 100);
});
try
{
await GetAllItems(user, channelId, null, currentRefreshLevel, maxRefreshLevel, cancellationToken).ConfigureAwait(false);
await GetAllItems(user, channelId, null, currentRefreshLevel, maxRefreshLevel, innerProgress, cancellationToken).ConfigureAwait(false);
}
catch (Exception ex)
{
@ -82,7 +94,7 @@ namespace MediaBrowser.Server.Implementations.Channels
numComplete++;
double percent = numComplete;
percent /= channels.Items.Length;
percent /= numItems;
progress.Report(percent * 100);
}
@ -90,7 +102,7 @@ namespace MediaBrowser.Server.Implementations.Channels
}
private async Task GetAllItems(string user, string channelId, string folderId, int currentRefreshLevel, int maxRefreshLevel, CancellationToken cancellationToken)
private async Task GetAllItems(string user, string channelId, string folderId, int currentRefreshLevel, int maxRefreshLevel, IProgress<double> progress, CancellationToken cancellationToken)
{
var folderItems = new List<string>();
@ -119,7 +131,7 @@ namespace MediaBrowser.Server.Implementations.Channels
}, cancellationToken);
folderItems.AddRange(result.Items.Where(i => i.IsFolder).Select(i => i.Id.ToString("N")));
totalRetrieved += result.Items.Length;
totalCount = result.TotalRecordCount;
}
@ -130,7 +142,9 @@ namespace MediaBrowser.Server.Implementations.Channels
{
try
{
await GetAllItems(user, channelId, folder, currentRefreshLevel + 1, maxRefreshLevel, cancellationToken).ConfigureAwait(false);
var innerProgress = new Progress<double>();
await GetAllItems(user, channelId, folder, currentRefreshLevel + 1, maxRefreshLevel, innerProgress, cancellationToken).ConfigureAwait(false);
}
catch (Exception ex)
{

View File

@ -63,16 +63,5 @@ namespace MediaBrowser.ServerApplication.Native
{
}
public static Task<CheckForUpdateResult> CheckForApplicationUpdate(Version currentVersion,
PackageVersionClass updateLevel,
IInstallationManager installationManager,
CancellationToken cancellationToken,
IProgress<double> progress)
{
var result = new CheckForUpdateResult { AvailableVersion = currentVersion.ToString(), IsUpdateAvailable = false };
return Task.FromResult(result);
}
}
}

View File

@ -123,7 +123,7 @@ namespace MediaBrowser.Server.Mono
// Allow all https requests
ServicePointManager.ServerCertificateValidationCallback = _ignoreCertificates;
_appHost = new ApplicationHost(appPaths, logManager, false, false, options);
_appHost = new ApplicationHost(appPaths, logManager, false, false, options, "MBServer.Mono");
Console.WriteLine ("appHost.Init");

View File

@ -219,7 +219,8 @@ namespace MediaBrowser.ServerApplication
private ISyncRepository SyncRepository { get; set; }
private ITVSeriesManager TVSeriesManager { get; set; }
private StartupOptions _startupOptions;
private readonly StartupOptions _startupOptions;
private readonly string _remotePackageName;
/// <summary>
/// Initializes a new instance of the <see cref="ApplicationHost" /> class.
@ -229,14 +230,16 @@ namespace MediaBrowser.ServerApplication
/// <param name="supportsRunningAsService">if set to <c>true</c> [supports running as service].</param>
/// <param name="isRunningAsService">if set to <c>true</c> [is running as service].</param>
/// <param name="options">The options.</param>
/// <param name="remotePackageName">Name of the remote package.</param>
public ApplicationHost(ServerApplicationPaths applicationPaths,
ILogManager logManager,
bool supportsRunningAsService,
bool isRunningAsService,
StartupOptions options)
StartupOptions options, string remotePackageName)
: base(applicationPaths, logManager)
{
_startupOptions = options;
_remotePackageName = remotePackageName;
_isRunningAsService = isRunningAsService;
SupportsRunningAsService = supportsRunningAsService;
}
@ -1091,9 +1094,17 @@ namespace MediaBrowser.ServerApplication
/// <returns>Task{CheckForUpdateResult}.</returns>
public override async Task<CheckForUpdateResult> CheckForApplicationUpdate(CancellationToken cancellationToken, IProgress<double> progress)
{
var result = await NativeApp.CheckForApplicationUpdate(ApplicationVersion,
ConfigurationManager.CommonConfiguration.SystemUpdateLevel, InstallationManager,
cancellationToken, progress).ConfigureAwait(false);
var availablePackages = await InstallationManager.GetAvailablePackagesWithoutRegistrationInfo(cancellationToken).ConfigureAwait(false);
var version = InstallationManager.GetLatestCompatibleVersion(availablePackages, _remotePackageName, null, ApplicationVersion, ConfigurationManager.CommonConfiguration.SystemUpdateLevel);
var versionObject = version == null || string.IsNullOrWhiteSpace(version.versionStr) ? null : new Version(version.versionStr);
var isUpdateAvailable = versionObject != null && versionObject > ApplicationVersion;
var result = versionObject != null ?
new CheckForUpdateResult { AvailableVersion = versionObject.ToString(), IsUpdateAvailable = isUpdateAvailable, Package = version } :
new CheckForUpdateResult { AvailableVersion = ApplicationVersion.ToString(), IsUpdateAvailable = false };
HasUpdateAvailable = result.IsUpdateAvailable;

View File

@ -57,7 +57,7 @@ namespace MediaBrowser.ServerApplication.FFMpeg
case "FFProbeFilename":
return "ffprobe";
case "ArchiveType":
return "gz";
return "7z";
}
}
if (PlatformDetection.IsX86)

View File

@ -209,7 +209,7 @@ namespace MediaBrowser.ServerApplication
/// <param name="options">The options.</param>
private static void RunApplication(ServerApplicationPaths appPaths, ILogManager logManager, bool runService, StartupOptions options)
{
_appHost = new ApplicationHost(appPaths, logManager, true, runService, options);
_appHost = new ApplicationHost(appPaths, logManager, true, runService, options, "MBServer");
var initProgress = new Progress<double>();

View File

@ -1,10 +1,4 @@
using System;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Common.Updates;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Updates;
using System.Runtime.InteropServices;
namespace MediaBrowser.ServerApplication.Native
{
@ -90,24 +84,5 @@ namespace MediaBrowser.ServerApplication.Native
EXECUTION_STATE es = SetThreadExecutionState(EXECUTION_STATE.ES_SYSTEM_REQUIRED);
}
}
public static async Task<CheckForUpdateResult> CheckForApplicationUpdate(Version currentVersion,
PackageVersionClass updateLevel,
IInstallationManager installationManager,
CancellationToken cancellationToken,
IProgress<double> progress)
{
var availablePackages = await installationManager.GetAvailablePackagesWithoutRegistrationInfo(cancellationToken).ConfigureAwait(false);
var version = installationManager.GetLatestCompatibleVersion(availablePackages, "MBServer", null, currentVersion, updateLevel);
var versionObject = version == null || string.IsNullOrWhiteSpace(version.versionStr) ? null : new Version(version.versionStr);
var isUpdateAvailable = versionObject != null && versionObject > currentVersion;
return versionObject != null ?
new CheckForUpdateResult { AvailableVersion = versionObject.ToString(), IsUpdateAvailable = isUpdateAvailable, Package = version } :
new CheckForUpdateResult { AvailableVersion = currentVersion.ToString(), IsUpdateAvailable = false };
}
}
}

View File

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>MediaBrowser.Common.Internal</id>
<version>3.0.443</version>
<version>3.0.445</version>
<title>MediaBrowser.Common.Internal</title>
<authors>Luke</authors>
<owners>ebr,Luke,scottisafool</owners>
@ -12,7 +12,7 @@
<description>Contains common components shared by Media Browser Theater and Media Browser Server. Not intended for plugin developer consumption.</description>
<copyright>Copyright © Media Browser 2013</copyright>
<dependencies>
<dependency id="MediaBrowser.Common" version="3.0.443" />
<dependency id="MediaBrowser.Common" version="3.0.445" />
<dependency id="NLog" version="3.1.0.0" />
<dependency id="SimpleInjector" version="2.5.2" />
<dependency id="sharpcompress" version="0.10.2" />

View File

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>MediaBrowser.Common</id>
<version>3.0.443</version>
<version>3.0.445</version>
<title>MediaBrowser.Common</title>
<authors>Media Browser Team</authors>
<owners>ebr,Luke,scottisafool</owners>

View File

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>MediaBrowser.Model.Signed</id>
<version>3.0.443</version>
<version>3.0.445</version>
<title>MediaBrowser.Model - Signed Edition</title>
<authors>Media Browser Team</authors>
<owners>ebr,Luke,scottisafool</owners>

View File

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>MediaBrowser.Server.Core</id>
<version>3.0.443</version>
<version>3.0.445</version>
<title>Media Browser.Server.Core</title>
<authors>Media Browser Team</authors>
<owners>ebr,Luke,scottisafool</owners>
@ -12,7 +12,7 @@
<description>Contains core components required to build plugins for Media Browser Server.</description>
<copyright>Copyright © Media Browser 2013</copyright>
<dependencies>
<dependency id="MediaBrowser.Common" version="3.0.443" />
<dependency id="MediaBrowser.Common" version="3.0.445" />
</dependencies>
</metadata>
<files>