diff --git a/MediaBrowser.ApiInteraction.Metro/MediaBrowser.ApiInteraction.Metro.csproj b/MediaBrowser.ApiInteraction.Metro/MediaBrowser.ApiInteraction.Metro.csproj
index f29871d94c..8b59cfbfe2 100644
--- a/MediaBrowser.ApiInteraction.Metro/MediaBrowser.ApiInteraction.Metro.csproj
+++ b/MediaBrowser.ApiInteraction.Metro/MediaBrowser.ApiInteraction.Metro.csproj
@@ -42,6 +42,9 @@
ApiClient.cs
+
+ BaseApiClient.cs
+
SerializationFormats.cs
diff --git a/MediaBrowser.ApiInteraction.Portable/ApiClient.cs b/MediaBrowser.ApiInteraction.Portable/ApiClient.cs
new file mode 100644
index 0000000000..40e3e27a72
--- /dev/null
+++ b/MediaBrowser.ApiInteraction.Portable/ApiClient.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Net;
+using System.IO;
+
+namespace MediaBrowser.ApiInteraction.Portable
+{
+ public class ApiClient : BaseApiClient
+ {
+ private HttpWebRequest GetNewRequest(string url)
+ {
+ HttpWebRequest request = HttpWebRequest.CreateHttp(url);
+ }
+ }
+}
diff --git a/MediaBrowser.ApiInteraction.Portable/MediaBrowser.ApiInteraction.Portable.csproj b/MediaBrowser.ApiInteraction.Portable/MediaBrowser.ApiInteraction.Portable.csproj
new file mode 100644
index 0000000000..a329746c0a
--- /dev/null
+++ b/MediaBrowser.ApiInteraction.Portable/MediaBrowser.ApiInteraction.Portable.csproj
@@ -0,0 +1,69 @@
+
+
+
+
+ Debug
+ AnyCPU
+ {756B93D2-5FFA-4B8D-BDCA-127476F1E6FB}
+ Library
+ Properties
+ MediaBrowser.ApiInteraction.Portable
+ MediaBrowser.ApiInteraction.Portable
+ v4.0
+ Profile4
+ 512
+ {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
+
+
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+
+
+
+ BaseApiClient.cs
+
+
+ DataSerializer.cs
+
+
+ SerializationFormats.cs
+
+
+
+
+
+
+ ..\Json.Net\Portable\Newtonsoft.Json.dll
+
+
+ ..\protobuf-net\Full\portable\protobuf-net.dll
+
+
+
+
+ {7eeeb4bb-f3e8-48fc-b4c5-70f0fff8329b}
+ MediaBrowser.Model
+
+
+
+
+
\ No newline at end of file
diff --git a/MediaBrowser.ApiInteraction.Portable/Properties/AssemblyInfo.cs b/MediaBrowser.ApiInteraction.Portable/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000000..c7628135dc
--- /dev/null
+++ b/MediaBrowser.ApiInteraction.Portable/Properties/AssemblyInfo.cs
@@ -0,0 +1,30 @@
+using System.Resources;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("MediaBrowser.ApiInteraction.Portable")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("MediaBrowser.ApiInteraction.Portable")]
+[assembly: AssemblyCopyright("Copyright © 2012")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+[assembly: NeutralResourcesLanguage("en")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/MediaBrowser.ApiInteraction.sln b/MediaBrowser.ApiInteraction.sln
index 4484801a2b..b5bcc1cddb 100644
--- a/MediaBrowser.ApiInteraction.sln
+++ b/MediaBrowser.ApiInteraction.sln
@@ -12,12 +12,18 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{F0E0E6
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MediaBrowser.ApiInteraction.Metro", "MediaBrowser.ApiInteraction.Metro\MediaBrowser.ApiInteraction.Metro.csproj", "{94CEA07A-307C-4663-AA43-7BD852808574}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MediaBrowser.ApiInteraction.Portable", "MediaBrowser.ApiInteraction.Portable\MediaBrowser.ApiInteraction.Portable.csproj", "{756B93D2-5FFA-4B8D-BDCA-127476F1E6FB}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {756B93D2-5FFA-4B8D-BDCA-127476F1E6FB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {756B93D2-5FFA-4B8D-BDCA-127476F1E6FB}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {756B93D2-5FFA-4B8D-BDCA-127476F1E6FB}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {756B93D2-5FFA-4B8D-BDCA-127476F1E6FB}.Release|Any CPU.Build.0 = Release|Any CPU
{7EEEB4BB-F3E8-48FC-B4C5-70F0FFF8329B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7EEEB4BB-F3E8-48FC-B4C5-70F0FFF8329B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7EEEB4BB-F3E8-48FC-B4C5-70F0FFF8329B}.Release|Any CPU.ActiveCfg = Release|Any CPU
diff --git a/MediaBrowser.ApiInteraction/ApiClient.cs b/MediaBrowser.ApiInteraction/ApiClient.cs
index 518b8e31c8..4e519ce4fb 100644
--- a/MediaBrowser.ApiInteraction/ApiClient.cs
+++ b/MediaBrowser.ApiInteraction/ApiClient.cs
@@ -11,352 +11,17 @@ using MediaBrowser.Model.Weather;
namespace MediaBrowser.ApiInteraction
{
- public class ApiClient : IDisposable
+ public class ApiClient : BaseApiClient
{
public ApiClient(HttpClientHandler handler)
+ : base()
{
handler.AutomaticDecompression = DecompressionMethods.Deflate;
HttpClient = new HttpClient(handler);
-
- DataSerializer.Configure();
}
- ///
- /// Gets or sets the server host name (myserver or 192.168.x.x)
- ///
- public string ServerHostName { get; set; }
-
- ///
- /// Gets or sets the port number used by the API
- ///
- public int ServerApiPort { get; set; }
-
- ///
- /// Gets the current api url based on hostname and port.
- ///
- protected string ApiUrl
- {
- get
- {
- return string.Format("http://{0}:{1}/mediabrowser/api", ServerHostName, ServerApiPort);
- }
- }
-
- ///
- /// Gets the data format to request from the server
- ///
- private SerializationFormats SerializationFormat
- {
- get
- {
- return ApiInteraction.SerializationFormats.Protobuf;
- }
- }
-
- public HttpClient HttpClient { get; private set; }
-
- ///
- /// Gets an image url that can be used to download an image from the api
- ///
- /// The Id of the item
- /// The type of image requested
- /// The image index, if there are multiple. Currently only applies to backdrops. Supply null or 0 for first backdrop.
- /// Use if a fixed width is required. Aspect ratio will be preserved.
- /// Use if a fixed height is required. Aspect ratio will be preserved.
- /// Use if a max width is required. Aspect ratio will be preserved.
- /// Use if a max height is required. Aspect ratio will be preserved.
- /// Quality level, from 0-100. Currently only applies to JPG. The default value should suffice.
- public string GetImageUrl(Guid itemId, ImageType imageType, int? imageIndex = null, int? width = null, int? height = null, int? maxWidth = null, int? maxHeight = null, int? quality = null)
- {
- string url = ApiUrl + "/image";
-
- url += "?id=" + itemId.ToString();
- url += "&type=" + imageType.ToString();
-
- if (imageIndex.HasValue)
- {
- url += "&index=" + imageIndex;
- }
- if (width.HasValue)
- {
- url += "&width=" + width;
- }
- if (height.HasValue)
- {
- url += "&height=" + height;
- }
- if (maxWidth.HasValue)
- {
- url += "&maxWidth=" + maxWidth;
- }
- if (maxHeight.HasValue)
- {
- url += "&maxHeight=" + maxHeight;
- }
- if (quality.HasValue)
- {
- url += "&quality=" + quality;
- }
-
- return url;
- }
-
- ///
- /// Gets an image url that can be used to download an image from the api
- ///
- /// The Id of the user
- /// Use if a fixed width is required. Aspect ratio will be preserved.
- /// Use if a fixed height is required. Aspect ratio will be preserved.
- /// Use if a max width is required. Aspect ratio will be preserved.
- /// Use if a max height is required. Aspect ratio will be preserved.
- /// Quality level, from 0-100. Currently only applies to JPG. The default value should suffice.
- public string GetUserImageUrl(Guid userId, int? width = null, int? height = null, int? maxWidth = null, int? maxHeight = null, int? quality = null)
- {
- string url = ApiUrl + "/image";
-
- url += "?userId=" + userId.ToString();
-
- if (width.HasValue)
- {
- url += "&width=" + width;
- }
- if (height.HasValue)
- {
- url += "&height=" + height;
- }
- if (maxWidth.HasValue)
- {
- url += "&maxWidth=" + maxWidth;
- }
- if (maxHeight.HasValue)
- {
- url += "&maxHeight=" + maxHeight;
- }
- if (quality.HasValue)
- {
- url += "&quality=" + quality;
- }
-
- return url;
- }
-
- ///
- /// Gets an image url that can be used to download an image from the api
- ///
- /// The name of the person
- /// Use if a fixed width is required. Aspect ratio will be preserved.
- /// Use if a fixed height is required. Aspect ratio will be preserved.
- /// Use if a max width is required. Aspect ratio will be preserved.
- /// Use if a max height is required. Aspect ratio will be preserved.
- /// Quality level, from 0-100. Currently only applies to JPG. The default value should suffice.
- public string GetPersonImageUrl(string name, int? width = null, int? height = null, int? maxWidth = null, int? maxHeight = null, int? quality = null)
- {
- string url = ApiUrl + "/image";
-
- url += "?personname=" + name;
-
- if (width.HasValue)
- {
- url += "&width=" + width;
- }
- if (height.HasValue)
- {
- url += "&height=" + height;
- }
- if (maxWidth.HasValue)
- {
- url += "&maxWidth=" + maxWidth;
- }
- if (maxHeight.HasValue)
- {
- url += "&maxHeight=" + maxHeight;
- }
- if (quality.HasValue)
- {
- url += "&quality=" + quality;
- }
-
- return url;
- }
-
- ///
- /// Gets an image url that can be used to download an image from the api
- ///
- /// The year
- /// Use if a fixed width is required. Aspect ratio will be preserved.
- /// Use if a fixed height is required. Aspect ratio will be preserved.
- /// Use if a max width is required. Aspect ratio will be preserved.
- /// Use if a max height is required. Aspect ratio will be preserved.
- /// Quality level, from 0-100. Currently only applies to JPG. The default value should suffice.
- public string GetYearImageUrl(int year, int? width = null, int? height = null, int? maxWidth = null, int? maxHeight = null, int? quality = null)
- {
- string url = ApiUrl + "/image";
-
- url += "?year=" + year;
-
- if (width.HasValue)
- {
- url += "&width=" + width;
- }
- if (height.HasValue)
- {
- url += "&height=" + height;
- }
- if (maxWidth.HasValue)
- {
- url += "&maxWidth=" + maxWidth;
- }
- if (maxHeight.HasValue)
- {
- url += "&maxHeight=" + maxHeight;
- }
- if (quality.HasValue)
- {
- url += "&quality=" + quality;
- }
-
- return url;
- }
-
- ///
- /// Gets an image url that can be used to download an image from the api
- ///
- /// The name of the genre
- /// Use if a fixed width is required. Aspect ratio will be preserved.
- /// Use if a fixed height is required. Aspect ratio will be preserved.
- /// Use if a max width is required. Aspect ratio will be preserved.
- /// Use if a max height is required. Aspect ratio will be preserved.
- /// Quality level, from 0-100. Currently only applies to JPG. The default value should suffice.
- public string GetGenreImageUrl(string name, int? width = null, int? height = null, int? maxWidth = null, int? maxHeight = null, int? quality = null)
- {
- string url = ApiUrl + "/image";
-
- url += "?genre=" + name;
-
- if (width.HasValue)
- {
- url += "&width=" + width;
- }
- if (height.HasValue)
- {
- url += "&height=" + height;
- }
- if (maxWidth.HasValue)
- {
- url += "&maxWidth=" + maxWidth;
- }
- if (maxHeight.HasValue)
- {
- url += "&maxHeight=" + maxHeight;
- }
- if (quality.HasValue)
- {
- url += "&quality=" + quality;
- }
-
- return url;
- }
-
- ///
- /// Gets an image url that can be used to download an image from the api
- ///
- /// The name of the studio
- /// Use if a fixed width is required. Aspect ratio will be preserved.
- /// Use if a fixed height is required. Aspect ratio will be preserved.
- /// Use if a max width is required. Aspect ratio will be preserved.
- /// Use if a max height is required. Aspect ratio will be preserved.
- /// Quality level, from 0-100. Currently only applies to JPG. The default value should suffice.
- public string GetStudioImageUrl(string name, int? width = null, int? height = null, int? maxWidth = null, int? maxHeight = null, int? quality = null)
- {
- string url = ApiUrl + "/image";
-
- url += "?studio=" + name;
-
- if (width.HasValue)
- {
- url += "&width=" + width;
- }
- if (height.HasValue)
- {
- url += "&height=" + height;
- }
- if (maxWidth.HasValue)
- {
- url += "&maxWidth=" + maxWidth;
- }
- if (maxHeight.HasValue)
- {
- url += "&maxHeight=" + maxHeight;
- }
- if (quality.HasValue)
- {
- url += "&quality=" + quality;
- }
-
- return url;
- }
-
- ///
- /// This is a helper to get a list of backdrop url's from a given ApiBaseItemWrapper. If the actual item does not have any backdrops it will return backdrops from the first parent that does.
- ///
- /// A given item.
- /// Use if a fixed width is required. Aspect ratio will be preserved.
- /// Use if a fixed height is required. Aspect ratio will be preserved.
- /// Use if a max width is required. Aspect ratio will be preserved.
- /// Use if a max height is required. Aspect ratio will be preserved.
- /// Quality level, from 0-100. Currently only applies to JPG. The default value should suffice.
- public string[] GetBackdropImageUrls(DTOBaseItem item, int? width = null, int? height = null, int? maxWidth = null, int? maxHeight = null, int? quality = null)
- {
- Guid? backdropItemId = null;
- int backdropCount = 0;
-
- if (item.BackdropCount == 0)
- {
- backdropItemId = item.ParentBackdropItemId;
- backdropCount = item.ParentBackdropCount ?? 0;
- }
- else
- {
- backdropItemId = item.Id;
- backdropCount = item.BackdropCount;
- }
-
- if (backdropItemId == null)
- {
- return new string[] { };
- }
-
- string[] files = new string[backdropCount];
-
- for (int i = 0; i < backdropCount; i++)
- {
- files[i] = GetImageUrl(backdropItemId.Value, ImageType.Backdrop, i, width, height, maxWidth, maxHeight, quality);
- }
-
- return files;
- }
-
- ///
- /// This is a helper to get the logo image url from a given ApiBaseItemWrapper. If the actual item does not have a logo, it will return the logo from the first parent that does, or null.
- ///
- /// A given item.
- /// Use if a fixed width is required. Aspect ratio will be preserved.
- /// Use if a fixed height is required. Aspect ratio will be preserved.
- /// Use if a max width is required. Aspect ratio will be preserved.
- /// Use if a max height is required. Aspect ratio will be preserved.
- /// Quality level, from 0-100. Currently only applies to JPG. The default value should suffice.
- public string GetLogoImageUrl(DTOBaseItem item, int? width = null, int? height = null, int? maxWidth = null, int? maxHeight = null, int? quality = null)
- {
- Guid? logoItemId = item.HasLogo ? item.Id : item.ParentLogoItemId;
-
- if (logoItemId.HasValue)
- {
- return GetImageUrl(logoItemId.Value, ImageType.Logo, null, width, height, maxWidth, maxHeight, quality);
- }
-
- return null;
- }
+ private HttpClient HttpClient { get; set; }
///
/// Gets an image stream based on a url
@@ -397,6 +62,35 @@ namespace MediaBrowser.ApiInteraction
}
}
+ public void GetAllUsersAsync(Action callback)
+ {
+ string url = ApiUrl + "/users";
+
+ HttpWebRequest request = HttpWebRequest.CreateHttp(url);
+
+ request.BeginGetResponse(new AsyncCallback(result =>
+ {
+ HttpWebResponse response = (result.AsyncState as HttpWebRequest).EndGetResponse(result) as HttpWebResponse;
+
+ Stream stream = response.GetResponseStream();
+
+ }), request);
+ }
+
+ public void GetData(string url, SerializationFormats serializationFormat, Action callback)
+ {
+ HttpWebRequest request = HttpWebRequest.CreateHttp(url);
+ //request.AutomaticDecompression = DecompressionMethods.Deflate;
+
+ request.BeginGetResponse(new AsyncCallback(result =>
+ {
+ HttpWebResponse response = (result.AsyncState as HttpWebRequest).EndGetResponse(result) as HttpWebResponse;
+
+ Stream stream = response.GetResponseStream();
+
+ }), request);
+ }
+
///
/// Gets all Genres
///
@@ -694,11 +388,6 @@ namespace MediaBrowser.ApiInteraction
return GetStreamAsync(url);
}
- private T DeserializeFromStream(Stream stream)
- {
- return DataSerializer.DeserializeFromStream(stream, SerializationFormat);
- }
-
///
/// This is just a helper around HttpClient
///
@@ -707,7 +396,7 @@ namespace MediaBrowser.ApiInteraction
return HttpClient.GetStreamAsync(url);
}
- public void Dispose()
+ public override void Dispose()
{
HttpClient.Dispose();
}
diff --git a/MediaBrowser.ApiInteraction/BaseApiClient.cs b/MediaBrowser.ApiInteraction/BaseApiClient.cs
new file mode 100644
index 0000000000..805ba353a0
--- /dev/null
+++ b/MediaBrowser.ApiInteraction/BaseApiClient.cs
@@ -0,0 +1,358 @@
+using System;
+using System.IO;
+using MediaBrowser.Model.DTO;
+using MediaBrowser.Model.Entities;
+
+namespace MediaBrowser.ApiInteraction
+{
+ public abstract class BaseApiClient : IDisposable
+ {
+ public BaseApiClient()
+ {
+ DataSerializer.Configure();
+ }
+
+ ///
+ /// Gets or sets the server host name (myserver or 192.168.x.x)
+ ///
+ public string ServerHostName { get; set; }
+
+ ///
+ /// Gets or sets the port number used by the API
+ ///
+ public int ServerApiPort { get; set; }
+
+ ///
+ /// Gets the current api url based on hostname and port.
+ ///
+ protected string ApiUrl
+ {
+ get
+ {
+ return string.Format("http://{0}:{1}/mediabrowser/api", ServerHostName, ServerApiPort);
+ }
+ }
+
+ ///
+ /// Gets the default data format to request from the server
+ ///
+ protected SerializationFormats SerializationFormat
+ {
+ get
+ {
+ return ApiInteraction.SerializationFormats.Protobuf;
+ }
+ }
+
+ ///
+ /// Gets an image url that can be used to download an image from the api
+ ///
+ /// The Id of the item
+ /// The type of image requested
+ /// The image index, if there are multiple. Currently only applies to backdrops. Supply null or 0 for first backdrop.
+ /// Use if a fixed width is required. Aspect ratio will be preserved.
+ /// Use if a fixed height is required. Aspect ratio will be preserved.
+ /// Use if a max width is required. Aspect ratio will be preserved.
+ /// Use if a max height is required. Aspect ratio will be preserved.
+ /// Quality level, from 0-100. Currently only applies to JPG. The default value should suffice.
+ public string GetImageUrl(Guid itemId, ImageType imageType, int? imageIndex = null, int? width = null, int? height = null, int? maxWidth = null, int? maxHeight = null, int? quality = null)
+ {
+ string url = ApiUrl + "/image";
+
+ url += "?id=" + itemId.ToString();
+ url += "&type=" + imageType.ToString();
+
+ if (imageIndex.HasValue)
+ {
+ url += "&index=" + imageIndex;
+ }
+ if (width.HasValue)
+ {
+ url += "&width=" + width;
+ }
+ if (height.HasValue)
+ {
+ url += "&height=" + height;
+ }
+ if (maxWidth.HasValue)
+ {
+ url += "&maxWidth=" + maxWidth;
+ }
+ if (maxHeight.HasValue)
+ {
+ url += "&maxHeight=" + maxHeight;
+ }
+ if (quality.HasValue)
+ {
+ url += "&quality=" + quality;
+ }
+
+ return url;
+ }
+
+ ///
+ /// Gets an image url that can be used to download an image from the api
+ ///
+ /// The Id of the user
+ /// Use if a fixed width is required. Aspect ratio will be preserved.
+ /// Use if a fixed height is required. Aspect ratio will be preserved.
+ /// Use if a max width is required. Aspect ratio will be preserved.
+ /// Use if a max height is required. Aspect ratio will be preserved.
+ /// Quality level, from 0-100. Currently only applies to JPG. The default value should suffice.
+ public string GetUserImageUrl(Guid userId, int? width = null, int? height = null, int? maxWidth = null, int? maxHeight = null, int? quality = null)
+ {
+ string url = ApiUrl + "/image";
+
+ url += "?userId=" + userId.ToString();
+
+ if (width.HasValue)
+ {
+ url += "&width=" + width;
+ }
+ if (height.HasValue)
+ {
+ url += "&height=" + height;
+ }
+ if (maxWidth.HasValue)
+ {
+ url += "&maxWidth=" + maxWidth;
+ }
+ if (maxHeight.HasValue)
+ {
+ url += "&maxHeight=" + maxHeight;
+ }
+ if (quality.HasValue)
+ {
+ url += "&quality=" + quality;
+ }
+
+ return url;
+ }
+
+ ///
+ /// Gets an image url that can be used to download an image from the api
+ ///
+ /// The name of the person
+ /// Use if a fixed width is required. Aspect ratio will be preserved.
+ /// Use if a fixed height is required. Aspect ratio will be preserved.
+ /// Use if a max width is required. Aspect ratio will be preserved.
+ /// Use if a max height is required. Aspect ratio will be preserved.
+ /// Quality level, from 0-100. Currently only applies to JPG. The default value should suffice.
+ public string GetPersonImageUrl(string name, int? width = null, int? height = null, int? maxWidth = null, int? maxHeight = null, int? quality = null)
+ {
+ string url = ApiUrl + "/image";
+
+ url += "?personname=" + name;
+
+ if (width.HasValue)
+ {
+ url += "&width=" + width;
+ }
+ if (height.HasValue)
+ {
+ url += "&height=" + height;
+ }
+ if (maxWidth.HasValue)
+ {
+ url += "&maxWidth=" + maxWidth;
+ }
+ if (maxHeight.HasValue)
+ {
+ url += "&maxHeight=" + maxHeight;
+ }
+ if (quality.HasValue)
+ {
+ url += "&quality=" + quality;
+ }
+
+ return url;
+ }
+
+ ///
+ /// Gets an image url that can be used to download an image from the api
+ ///
+ /// The year
+ /// Use if a fixed width is required. Aspect ratio will be preserved.
+ /// Use if a fixed height is required. Aspect ratio will be preserved.
+ /// Use if a max width is required. Aspect ratio will be preserved.
+ /// Use if a max height is required. Aspect ratio will be preserved.
+ /// Quality level, from 0-100. Currently only applies to JPG. The default value should suffice.
+ public string GetYearImageUrl(int year, int? width = null, int? height = null, int? maxWidth = null, int? maxHeight = null, int? quality = null)
+ {
+ string url = ApiUrl + "/image";
+
+ url += "?year=" + year;
+
+ if (width.HasValue)
+ {
+ url += "&width=" + width;
+ }
+ if (height.HasValue)
+ {
+ url += "&height=" + height;
+ }
+ if (maxWidth.HasValue)
+ {
+ url += "&maxWidth=" + maxWidth;
+ }
+ if (maxHeight.HasValue)
+ {
+ url += "&maxHeight=" + maxHeight;
+ }
+ if (quality.HasValue)
+ {
+ url += "&quality=" + quality;
+ }
+
+ return url;
+ }
+
+ ///
+ /// Gets an image url that can be used to download an image from the api
+ ///
+ /// The name of the genre
+ /// Use if a fixed width is required. Aspect ratio will be preserved.
+ /// Use if a fixed height is required. Aspect ratio will be preserved.
+ /// Use if a max width is required. Aspect ratio will be preserved.
+ /// Use if a max height is required. Aspect ratio will be preserved.
+ /// Quality level, from 0-100. Currently only applies to JPG. The default value should suffice.
+ public string GetGenreImageUrl(string name, int? width = null, int? height = null, int? maxWidth = null, int? maxHeight = null, int? quality = null)
+ {
+ string url = ApiUrl + "/image";
+
+ url += "?genre=" + name;
+
+ if (width.HasValue)
+ {
+ url += "&width=" + width;
+ }
+ if (height.HasValue)
+ {
+ url += "&height=" + height;
+ }
+ if (maxWidth.HasValue)
+ {
+ url += "&maxWidth=" + maxWidth;
+ }
+ if (maxHeight.HasValue)
+ {
+ url += "&maxHeight=" + maxHeight;
+ }
+ if (quality.HasValue)
+ {
+ url += "&quality=" + quality;
+ }
+
+ return url;
+ }
+
+ ///
+ /// Gets an image url that can be used to download an image from the api
+ ///
+ /// The name of the studio
+ /// Use if a fixed width is required. Aspect ratio will be preserved.
+ /// Use if a fixed height is required. Aspect ratio will be preserved.
+ /// Use if a max width is required. Aspect ratio will be preserved.
+ /// Use if a max height is required. Aspect ratio will be preserved.
+ /// Quality level, from 0-100. Currently only applies to JPG. The default value should suffice.
+ public string GetStudioImageUrl(string name, int? width = null, int? height = null, int? maxWidth = null, int? maxHeight = null, int? quality = null)
+ {
+ string url = ApiUrl + "/image";
+
+ url += "?studio=" + name;
+
+ if (width.HasValue)
+ {
+ url += "&width=" + width;
+ }
+ if (height.HasValue)
+ {
+ url += "&height=" + height;
+ }
+ if (maxWidth.HasValue)
+ {
+ url += "&maxWidth=" + maxWidth;
+ }
+ if (maxHeight.HasValue)
+ {
+ url += "&maxHeight=" + maxHeight;
+ }
+ if (quality.HasValue)
+ {
+ url += "&quality=" + quality;
+ }
+
+ return url;
+ }
+
+ ///
+ /// This is a helper to get a list of backdrop url's from a given ApiBaseItemWrapper. If the actual item does not have any backdrops it will return backdrops from the first parent that does.
+ ///
+ /// A given item.
+ /// Use if a fixed width is required. Aspect ratio will be preserved.
+ /// Use if a fixed height is required. Aspect ratio will be preserved.
+ /// Use if a max width is required. Aspect ratio will be preserved.
+ /// Use if a max height is required. Aspect ratio will be preserved.
+ /// Quality level, from 0-100. Currently only applies to JPG. The default value should suffice.
+ public string[] GetBackdropImageUrls(DTOBaseItem item, int? width = null, int? height = null, int? maxWidth = null, int? maxHeight = null, int? quality = null)
+ {
+ Guid? backdropItemId = null;
+ int backdropCount = 0;
+
+ if (item.BackdropCount == 0)
+ {
+ backdropItemId = item.ParentBackdropItemId;
+ backdropCount = item.ParentBackdropCount ?? 0;
+ }
+ else
+ {
+ backdropItemId = item.Id;
+ backdropCount = item.BackdropCount;
+ }
+
+ if (backdropItemId == null)
+ {
+ return new string[] { };
+ }
+
+ string[] files = new string[backdropCount];
+
+ for (int i = 0; i < backdropCount; i++)
+ {
+ files[i] = GetImageUrl(backdropItemId.Value, ImageType.Backdrop, i, width, height, maxWidth, maxHeight, quality);
+ }
+
+ return files;
+ }
+
+ ///
+ /// This is a helper to get the logo image url from a given ApiBaseItemWrapper. If the actual item does not have a logo, it will return the logo from the first parent that does, or null.
+ ///
+ /// A given item.
+ /// Use if a fixed width is required. Aspect ratio will be preserved.
+ /// Use if a fixed height is required. Aspect ratio will be preserved.
+ /// Use if a max width is required. Aspect ratio will be preserved.
+ /// Use if a max height is required. Aspect ratio will be preserved.
+ /// Quality level, from 0-100. Currently only applies to JPG. The default value should suffice.
+ public string GetLogoImageUrl(DTOBaseItem item, int? width = null, int? height = null, int? maxWidth = null, int? maxHeight = null, int? quality = null)
+ {
+ Guid? logoItemId = item.HasLogo ? item.Id : item.ParentLogoItemId;
+
+ if (logoItemId.HasValue)
+ {
+ return GetImageUrl(logoItemId.Value, ImageType.Logo, null, width, height, maxWidth, maxHeight, quality);
+ }
+
+ return null;
+ }
+
+ protected T DeserializeFromStream(Stream stream)
+ {
+ return DataSerializer.DeserializeFromStream(stream, SerializationFormat);
+ }
+
+ public virtual void Dispose()
+ {
+ }
+ }
+}
diff --git a/MediaBrowser.ApiInteraction/MediaBrowser.ApiInteraction.csproj b/MediaBrowser.ApiInteraction/MediaBrowser.ApiInteraction.csproj
index 228ee6754f..0d1f25b05d 100644
--- a/MediaBrowser.ApiInteraction/MediaBrowser.ApiInteraction.csproj
+++ b/MediaBrowser.ApiInteraction/MediaBrowser.ApiInteraction.csproj
@@ -47,6 +47,7 @@
+