aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Api
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.Api')
-rw-r--r--MediaBrowser.Api/Images/ImageService.cs11
-rw-r--r--MediaBrowser.Api/MediaBrowser.Api.csproj3
-rw-r--r--MediaBrowser.Api/Playback/BaseStreamingService.cs19
-rw-r--r--MediaBrowser.Api/Playback/Progressive/BaseProgressiveStreamingService.cs65
-rw-r--r--MediaBrowser.Api/Playback/StaticRemoteStreamWriter.cs75
-rw-r--r--MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs2
-rw-r--r--MediaBrowser.Api/UserLibrary/ItemsService.cs2
7 files changed, 170 insertions, 7 deletions
diff --git a/MediaBrowser.Api/Images/ImageService.cs b/MediaBrowser.Api/Images/ImageService.cs
index 3f5b9da2a..51608a899 100644
--- a/MediaBrowser.Api/Images/ImageService.cs
+++ b/MediaBrowser.Api/Images/ImageService.cs
@@ -361,7 +361,7 @@ namespace MediaBrowser.Api.Images
index++;
}
-
+
index = 0;
foreach (var image in item.ScreenshotImagePaths)
@@ -422,7 +422,7 @@ namespace MediaBrowser.Api.Images
return list;
}
-
+
/// <summary>
/// Gets the specified request.
/// </summary>
@@ -765,7 +765,7 @@ namespace MediaBrowser.Api.Images
}
// Don't save locally if there's no parent (special feature, trailer, etc)
- var saveLocally = (!(entity is Audio) && entity.Parent != null && !string.IsNullOrEmpty(entity.MetaLocation)) || entity is User;
+ var saveLocally = !(entity is Audio) && entity.Parent != null && !string.IsNullOrEmpty(entity.MetaLocation) || entity is User;
if (imageType != ImageType.Primary)
{
@@ -775,6 +775,11 @@ namespace MediaBrowser.Api.Images
}
}
+ if (entity.LocationType != LocationType.FileSystem)
+ {
+ saveLocally = false;
+ }
+
var imagePath = _providerManager.GetSavePath(entity, filename + "." + extension, saveLocally);
// Save to file system
diff --git a/MediaBrowser.Api/MediaBrowser.Api.csproj b/MediaBrowser.Api/MediaBrowser.Api.csproj
index 2819a649a..fb06e35ea 100644
--- a/MediaBrowser.Api/MediaBrowser.Api.csproj
+++ b/MediaBrowser.Api/MediaBrowser.Api.csproj
@@ -56,6 +56,8 @@
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
+ <Reference Include="System.Net.Http" />
+ <Reference Include="System.Net.Http.WebRequest" />
<Reference Include="System.XML" />
</ItemGroup>
<ItemGroup>
@@ -82,6 +84,7 @@
<Compile Include="Playback\Progressive\BaseProgressiveStreamingService.cs" />
<Compile Include="Playback\BaseStreamingService.cs" />
<Compile Include="Playback\Progressive\ProgressiveStreamWriter.cs" />
+ <Compile Include="Playback\StaticRemoteStreamWriter.cs" />
<Compile Include="Playback\StreamRequest.cs" />
<Compile Include="Playback\StreamState.cs" />
<Compile Include="Playback\Progressive\VideoService.cs" />
diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs
index 04b6a656d..19b339cd7 100644
--- a/MediaBrowser.Api/Playback/BaseStreamingService.cs
+++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs
@@ -622,9 +622,26 @@ namespace MediaBrowser.Api.Playback
/// <returns>System.String.</returns>
protected string GetUserAgentParam(BaseItem item)
{
+ var useragent = GetUserAgent(item);
+
+ if (!string.IsNullOrEmpty(useragent))
+ {
+ return "-user-agent \"" + useragent + "\"";
+ }
+
+ return string.Empty;
+ }
+
+ /// <summary>
+ /// Gets the user agent.
+ /// </summary>
+ /// <param name="item">The item.</param>
+ /// <returns>System.String.</returns>
+ protected string GetUserAgent(BaseItem item)
+ {
if (item.Path.IndexOf("apple.com", StringComparison.OrdinalIgnoreCase) != -1)
{
- return "-user-agent \"QuickTime/7.6.2\"";
+ return "QuickTime/7.6.2";
}
return string.Empty;
diff --git a/MediaBrowser.Api/Playback/Progressive/BaseProgressiveStreamingService.cs b/MediaBrowser.Api/Playback/Progressive/BaseProgressiveStreamingService.cs
index 9bcce87c8..ab1fb4f90 100644
--- a/MediaBrowser.Api/Playback/Progressive/BaseProgressiveStreamingService.cs
+++ b/MediaBrowser.Api/Playback/Progressive/BaseProgressiveStreamingService.cs
@@ -1,4 +1,7 @@
-using MediaBrowser.Api.Images;
+using System.Net;
+using System.Net.Cache;
+using System.Net.Http;
+using MediaBrowser.Api.Images;
using MediaBrowser.Common.IO;
using MediaBrowser.Common.MediaInfo;
using MediaBrowser.Common.Net;
@@ -188,6 +191,11 @@ namespace MediaBrowser.Api.Playback.Progressive
var responseHeaders = new Dictionary<string, string>();
+ if (request.Static && state.Item.LocationType == LocationType.Remote)
+ {
+ return GetStaticRemoteStreamResult(state.Item, responseHeaders, isHeadRequest).Result;
+ }
+
var outputPath = GetOutputFilePath(state);
var outputPathExists = File.Exists(outputPath);
@@ -210,6 +218,61 @@ namespace MediaBrowser.Api.Playback.Progressive
}
/// <summary>
+ /// Gets the static remote stream result.
+ /// </summary>
+ /// <param name="item">The item.</param>
+ /// <param name="responseHeaders">The response headers.</param>
+ /// <param name="isHeadRequest">if set to <c>true</c> [is head request].</param>
+ /// <returns>Task{System.Object}.</returns>
+ private async Task<object> GetStaticRemoteStreamResult(BaseItem item, Dictionary<string, string> responseHeaders, bool isHeadRequest)
+ {
+ responseHeaders["Accept-Ranges"] = "none";
+
+ var httpClient = new HttpClient(new WebRequestHandler
+ {
+ CachePolicy = new RequestCachePolicy(RequestCacheLevel.BypassCache),
+ AutomaticDecompression = DecompressionMethods.None
+ });
+
+ using (var message = new HttpRequestMessage(HttpMethod.Get, item.Path))
+ {
+ var useragent = GetUserAgent(item);
+
+ if (!string.IsNullOrEmpty(useragent))
+ {
+ message.Headers.Add("User-Agent", useragent);
+ }
+
+ var response = await httpClient.SendAsync(message, HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false);
+
+ response.EnsureSuccessStatusCode();
+
+ var contentType = response.Content.Headers.ContentType.MediaType;
+
+ // Headers only
+ if (isHeadRequest)
+ {
+ response.Dispose();
+ httpClient.Dispose();
+
+ return ResultFactory.GetResult(null, contentType, responseHeaders);
+ }
+
+ var result = new StaticRemoteStreamWriter(response, httpClient);
+
+ result.Options["Content-Type"] = contentType;
+
+ // Add the response headers to the result object
+ foreach (var header in responseHeaders)
+ {
+ result.Options[header.Key] = header.Value;
+ }
+
+ return result;
+ }
+ }
+
+ /// <summary>
/// Gets the album art response.
/// </summary>
/// <param name="state">The state.</param>
diff --git a/MediaBrowser.Api/Playback/StaticRemoteStreamWriter.cs b/MediaBrowser.Api/Playback/StaticRemoteStreamWriter.cs
new file mode 100644
index 000000000..89e13acb3
--- /dev/null
+++ b/MediaBrowser.Api/Playback/StaticRemoteStreamWriter.cs
@@ -0,0 +1,75 @@
+using ServiceStack.Service;
+using ServiceStack.ServiceHost;
+using System.Collections.Generic;
+using System.IO;
+using System.Net.Http;
+using System.Threading.Tasks;
+
+namespace MediaBrowser.Api.Playback
+{
+ /// <summary>
+ /// Class StaticRemoteStreamWriter
+ /// </summary>
+ public class StaticRemoteStreamWriter : IStreamWriter, IHasOptions
+ {
+ /// <summary>
+ /// The _input stream
+ /// </summary>
+ private readonly HttpResponseMessage _msg;
+
+ private readonly HttpClient _client;
+
+ /// <summary>
+ /// The _options
+ /// </summary>
+ private readonly IDictionary<string, string> _options = new Dictionary<string, string>();
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="StaticRemoteStreamWriter"/> class.
+ /// </summary>
+ public StaticRemoteStreamWriter(HttpResponseMessage msg, HttpClient client)
+ {
+ _msg = msg;
+ _client = client;
+ }
+
+ /// <summary>
+ /// Gets the options.
+ /// </summary>
+ /// <value>The options.</value>
+ public IDictionary<string, string> Options
+ {
+ get { return _options; }
+ }
+
+ /// <summary>
+ /// Writes to.
+ /// </summary>
+ /// <param name="responseStream">The response stream.</param>
+ public void WriteTo(Stream responseStream)
+ {
+ var task = WriteToAsync(responseStream);
+
+ Task.WaitAll(task);
+ }
+
+ /// <summary>
+ /// Writes to async.
+ /// </summary>
+ /// <param name="responseStream">The response stream.</param>
+ /// <returns>Task.</returns>
+ public async Task WriteToAsync(Stream responseStream)
+ {
+ using (_client)
+ {
+ using (_msg)
+ {
+ using (var input = await _msg.Content.ReadAsStreamAsync().ConfigureAwait(false))
+ {
+ await input.CopyToAsync(responseStream).ConfigureAwait(false);
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs b/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs
index 22098a368..26b0aa192 100644
--- a/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs
+++ b/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs
@@ -135,7 +135,7 @@ namespace MediaBrowser.Api.UserLibrary
{
if (!string.IsNullOrEmpty(request.NameStartsWithOrGreater))
{
- items = items.Where(i => string.Compare(request.NameStartsWithOrGreater, i.Name, StringComparison.OrdinalIgnoreCase) < 1);
+ items = items.Where(i => string.Compare(request.NameStartsWithOrGreater, i.Name, StringComparison.CurrentCultureIgnoreCase) < 1);
}
var filters = request.GetFilters().ToList();
diff --git a/MediaBrowser.Api/UserLibrary/ItemsService.cs b/MediaBrowser.Api/UserLibrary/ItemsService.cs
index c57778fd6..fbf41eb38 100644
--- a/MediaBrowser.Api/UserLibrary/ItemsService.cs
+++ b/MediaBrowser.Api/UserLibrary/ItemsService.cs
@@ -456,7 +456,7 @@ namespace MediaBrowser.Api.UserLibrary
if (!string.IsNullOrEmpty(request.NameStartsWithOrGreater))
{
- items = items.Where(i => string.Compare(request.NameStartsWithOrGreater, i.SortName, StringComparison.OrdinalIgnoreCase) < 1);
+ items = items.Where(i => string.Compare(request.NameStartsWithOrGreater, i.SortName, StringComparison.CurrentCultureIgnoreCase) < 1);
}
// Filter by Series Status