diff --git a/MediaBrowser.ApiInteraction.Portable/MediaBrowser.ApiInteraction.Portable.csproj b/MediaBrowser.ApiInteraction.Portable/MediaBrowser.ApiInteraction.Portable.csproj deleted file mode 100644 index 22b1a030eb..0000000000 --- a/MediaBrowser.ApiInteraction.Portable/MediaBrowser.ApiInteraction.Portable.csproj +++ /dev/null @@ -1,112 +0,0 @@ - - - - - 10.0 - Debug - AnyCPU - {52E0C440-85C0-4A99-ACFE-07C87B2600BE} - Library - Properties - MediaBrowser.ApiInteraction.Portable - MediaBrowser.ApiInteraction.Portable - v4.0 - Profile104 - 512 - {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - ..\ - true - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - AsyncHttpClient.cs - - - NewtonsoftJsonSerializer.cs - - - SerializationFormats.cs - - - Properties\SharedVersion.cs - - - - BaseApiClient.cs - - - ApiClient.cs - - - IAsyncHttpClient.cs - - - - - ..\packages\Microsoft.Bcl.Async.1.0.14-rc\lib\portable-net40+sl4+win8+wp71\Microsoft.Threading.Tasks.dll - - - ..\packages\Microsoft.Bcl.Async.1.0.14-rc\lib\portable-net40+sl4+win8+wp71\Microsoft.Threading.Tasks.Extensions.dll - - - ..\packages\Newtonsoft.Json.4.5.11\lib\portable-net40+sl4+wp7+win8\Newtonsoft.Json.dll - - - ..\packages\Microsoft.Net.Http.2.1.3-beta\lib\portable-net40+sl4+win8+wp71\System.Net.Http.dll - - - ..\packages\Microsoft.Net.Http.2.1.3-beta\lib\portable-net40+sl4+win8+wp71\System.Net.Http.Extensions.dll - - - ..\packages\Microsoft.Net.Http.2.1.3-beta\lib\portable-net40+sl4+win8+wp71\System.Net.Http.Primitives.dll - - - ..\packages\Microsoft.Bcl.1.0.16-rc\lib\portable-net40+sl4+win8+wp71\System.Runtime.dll - - - ..\packages\Microsoft.Bcl.1.0.16-rc\lib\portable-net40+sl4+win8+wp71\System.Threading.Tasks.dll - - - - - {7eeeb4bb-f3e8-48fc-b4c5-70f0fff8329b} - MediaBrowser.Model - - - - - - - - - - - if $(ConfigurationName) == Release ( -xcopy "$(TargetPath)" "$(SolutionDir)\Nuget\dlls\" /y /d /r /i -) - - - \ No newline at end of file diff --git a/MediaBrowser.ApiInteraction.Portable/Properties/AssemblyInfo.cs b/MediaBrowser.ApiInteraction.Portable/Properties/AssemblyInfo.cs deleted file mode 100644 index e14673826e..0000000000 --- a/MediaBrowser.ApiInteraction.Portable/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System.Reflection; -using System.Resources; - -// 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 -// \ No newline at end of file diff --git a/MediaBrowser.ApiInteraction.Portable/app.config b/MediaBrowser.ApiInteraction.Portable/app.config deleted file mode 100644 index f356f9b87a..0000000000 --- a/MediaBrowser.ApiInteraction.Portable/app.config +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/MediaBrowser.ApiInteraction.Portable/packages.config b/MediaBrowser.ApiInteraction.Portable/packages.config deleted file mode 100644 index 795bf139cd..0000000000 --- a/MediaBrowser.ApiInteraction.Portable/packages.config +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/MediaBrowser.ApiInteraction/ApiClient.cs b/MediaBrowser.ApiInteraction/ApiClient.cs deleted file mode 100644 index 5268c7e1f7..0000000000 --- a/MediaBrowser.ApiInteraction/ApiClient.cs +++ /dev/null @@ -1,1029 +0,0 @@ -using MediaBrowser.Model.Configuration; -using MediaBrowser.Model.Dto; -using MediaBrowser.Model.Entities; -using MediaBrowser.Model.Globalization; -using MediaBrowser.Model.Logging; -using MediaBrowser.Model.Plugins; -using MediaBrowser.Model.System; -using MediaBrowser.Model.Tasks; -using MediaBrowser.Model.Weather; -using MediaBrowser.Model.Web; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; - -namespace MediaBrowser.ApiInteraction -{ - /// - /// Provides api methods centered around an HttpClient - /// - public class ApiClient : BaseApiClient - { - /// - /// Gets the HTTP client. - /// - /// The HTTP client. - protected IAsyncHttpClient HttpClient { get; private set; } - - /// - /// Initializes a new instance of the class. - /// - /// The logger. - /// The HTTP client. - /// httpClient - public ApiClient(ILogger logger, IAsyncHttpClient httpClient) - : base(logger) - { - if (httpClient == null) - { - throw new ArgumentNullException("httpClient"); - } - - HttpClient = httpClient; - } - - /// - /// Initializes a new instance of the class. - /// - /// The logger. - public ApiClient(ILogger logger) - : this(logger, new AsyncHttpClient()) - { - } - - /// - /// Sets the authorization header. - /// - /// The header. - protected override void SetAuthorizationHeader(string header) - { - HttpClient.SetAuthorizationHeader(header); - } - - /// - /// Gets an image stream based on a url - /// - /// The URL. - /// Task{Stream}. - /// url - public Task GetImageStreamAsync(string url) - { - if (string.IsNullOrEmpty(url)) - { - throw new ArgumentNullException("url"); - } - - return HttpClient.GetAsync(url, Logger, CancellationToken.None); - } - - /// - /// Gets a BaseItem - /// - /// The id. - /// The user id. - /// Task{BaseItemDto}. - /// id - public async Task GetItemAsync(string id, Guid userId) - { - if (string.IsNullOrEmpty(id)) - { - throw new ArgumentNullException("id"); - } - - if (userId == Guid.Empty) - { - throw new ArgumentNullException("userId"); - } - - var url = GetApiUrl("Users/" + userId + "/Items/" + id); - - using (var stream = await GetSerializedStreamAsync(url).ConfigureAwait(false)) - { - return DeserializeFromStream(stream); - } - } - - /// - /// Gets the intros async. - /// - /// The item id. - /// The user id. - /// Task{System.String[]}. - /// id - public async Task GetIntrosAsync(string itemId, Guid userId) - { - if (string.IsNullOrEmpty(itemId)) - { - throw new ArgumentNullException("itemId"); - } - - if (userId == Guid.Empty) - { - throw new ArgumentNullException("userId"); - } - - var url = GetApiUrl("Users/" + userId + "/Items/" + itemId + "/Intros"); - - using (var stream = await GetSerializedStreamAsync(url).ConfigureAwait(false)) - { - return DeserializeFromStream(stream); - } - } - - /// - /// Gets a BaseItem - /// - /// The user id. - /// Task{BaseItemDto}. - /// userId - public async Task GetRootFolderAsync(Guid userId) - { - if (userId == Guid.Empty) - { - throw new ArgumentNullException("userId"); - } - - var url = GetApiUrl("Users/" + userId + "/Items/Root"); - - using (var stream = await GetSerializedStreamAsync(url).ConfigureAwait(false)) - { - return DeserializeFromStream(stream); - } - } - - /// - /// Gets all Users - /// - /// Task{UserDto[]}. - public async Task GetAllUsersAsync() - { - var url = GetApiUrl("Users"); - - using (var stream = await GetSerializedStreamAsync(url).ConfigureAwait(false)) - { - return DeserializeFromStream(stream); - } - } - - /// - /// Queries for items - /// - /// The query. - /// Task{ItemsResult}. - /// query - public async Task GetItemsAsync(ItemQuery query) - { - if (query == null) - { - throw new ArgumentNullException("query"); - } - - var url = GetItemListUrl(query); - - using (var stream = await GetSerializedStreamAsync(url).ConfigureAwait(false)) - { - return DeserializeFromStream(stream); - } - } - - /// - /// Gets all People - /// - /// The user id. - /// Optional itemId, to localize the search to a specific item or folder - /// Use this to limit results to specific person types - /// Used to skip over a given number of items. Use if paging. - /// The maximum number of items to return - /// The sort order - /// if set to true items will be searched recursively. - /// Task{IbnItemsResult}. - /// userId - public async Task GetAllPeopleAsync( - Guid userId, - string itemId = null, - IEnumerable personTypes = null, - int? startIndex = null, - int? limit = null, - SortOrder? sortOrder = null, - bool recursive = false) - { - if (userId == Guid.Empty) - { - throw new ArgumentNullException("userId"); - } - - var dict = new QueryStringDictionary(); - - dict.AddIfNotNull("startIndex", startIndex); - dict.AddIfNotNull("limit", limit); - - dict.Add("recursive", recursive); - - if (sortOrder.HasValue) - { - dict["sortOrder"] = sortOrder.Value.ToString(); - } - - dict.AddIfNotNull("personTypes", personTypes); - - var url = string.IsNullOrEmpty(itemId) ? "Users/" + userId + "/Items/Root/Persons" : "Users/" + userId + "/Items/" + itemId + "/Persons"; - url = GetApiUrl(url, dict); - - using (var stream = await GetSerializedStreamAsync(url).ConfigureAwait(false)) - { - return DeserializeFromStream(stream); - } - } - - /// - /// Gets a studio - /// - /// The name. - /// Task{BaseItemDto}. - /// userId - public async Task GetStudioAsync(string name) - { - if (string.IsNullOrEmpty(name)) - { - throw new ArgumentNullException("name"); - } - - var url = GetApiUrl("Library/Studios/" + name); - - using (var stream = await GetSerializedStreamAsync(url).ConfigureAwait(false)) - { - return DeserializeFromStream(stream); - } - } - - /// - /// Gets a genre - /// - /// The name. - /// Task{BaseItemDto}. - /// userId - public async Task GetGenreAsync(string name) - { - if (string.IsNullOrEmpty(name)) - { - throw new ArgumentNullException("name"); - } - - var url = GetApiUrl("Library/Genres/" + name); - - using (var stream = await GetSerializedStreamAsync(url).ConfigureAwait(false)) - { - return DeserializeFromStream(stream); - } - } - - /// - /// Restarts the kernel or the entire server if necessary - /// If the server application is restarting this request will fail to return, even if - /// the operation is successful. - /// - /// Task. - public Task PerformPendingRestartAsync() - { - var url = GetApiUrl("System/Restart"); - - return PostAsync(url, new QueryStringDictionary()); - } - - /// - /// Gets the system status async. - /// - /// Task{SystemInfo}. - public async Task GetSystemInfoAsync() - { - var url = GetApiUrl("System/Info"); - - using (var stream = await GetSerializedStreamAsync(url).ConfigureAwait(false)) - { - return DeserializeFromStream(stream); - } - } - - /// - /// Gets a person - /// - /// The name. - /// Task{BaseItemDto}. - /// userId - public async Task GetPersonAsync(string name) - { - if (string.IsNullOrEmpty(name)) - { - throw new ArgumentNullException("name"); - } - - var url = GetApiUrl("Library/Persons/" + name); - - using (var stream = await GetSerializedStreamAsync(url).ConfigureAwait(false)) - { - return DeserializeFromStream(stream); - } - } - - /// - /// Gets a year - /// - /// The year. - /// Task{BaseItemDto}. - /// userId - public async Task GetYearAsync(int year) - { - var url = GetApiUrl("Library/Years/" + year); - - using (var stream = await GetSerializedStreamAsync(url).ConfigureAwait(false)) - { - return DeserializeFromStream(stream); - } - } - - /// - /// Gets a list of plugins installed on the server - /// - /// Task{PluginInfo[]}. - public async Task GetInstalledPluginsAsync() - { - var url = GetApiUrl("Plugins"); - - using (var stream = await GetSerializedStreamAsync(url).ConfigureAwait(false)) - { - return DeserializeFromStream(stream); - } - } - - /// - /// Gets a list of plugins installed on the server - /// - /// The plugin. - /// Task{Stream}. - /// plugin - public Task GetPluginAssemblyAsync(PluginInfo plugin) - { - if (plugin == null) - { - throw new ArgumentNullException("plugin"); - } - - var url = GetApiUrl("Plugins/" + plugin.Id + "/Assembly"); - - return HttpClient.GetAsync(url, Logger, CancellationToken.None); - } - - /// - /// Gets the current server configuration - /// - /// Task{ServerConfiguration}. - public async Task GetServerConfigurationAsync() - { - var url = GetApiUrl("System/Configuration"); - - using (var stream = await GetSerializedStreamAsync(url).ConfigureAwait(false)) - { - return DeserializeFromStream(stream); - } - } - - /// - /// Gets the scheduled tasks. - /// - /// Task{TaskInfo[]}. - public async Task GetScheduledTasksAsync() - { - var url = GetApiUrl("ScheduledTasks"); - - using (var stream = await GetSerializedStreamAsync(url).ConfigureAwait(false)) - { - return DeserializeFromStream(stream); - } - } - - /// - /// Gets the scheduled task async. - /// - /// The id. - /// Task{TaskInfo}. - /// id - public async Task GetScheduledTaskAsync(Guid id) - { - if (id == Guid.Empty) - { - throw new ArgumentNullException("id"); - } - - var url = GetApiUrl("ScheduledTasks/" + id); - - using (var stream = await GetSerializedStreamAsync(url).ConfigureAwait(false)) - { - return DeserializeFromStream(stream); - } - } - - /// - /// Gets the plugin configuration file in plain text. - /// - /// The plugin id. - /// Task{Stream}. - /// assemblyFileName - public async Task GetPluginConfigurationFileAsync(Guid pluginId) - { - if (pluginId == Guid.Empty) - { - throw new ArgumentNullException("pluginId"); - } - - var url = GetApiUrl("Plugins/" + pluginId + "/ConfigurationFile"); - - return await HttpClient.GetAsync(url, Logger, CancellationToken.None).ConfigureAwait(false); - } - - /// - /// Gets a user by id - /// - /// The id. - /// Task{UserDto}. - /// id - public async Task GetUserAsync(Guid id) - { - if (id == Guid.Empty) - { - throw new ArgumentNullException("id"); - } - - var url = GetApiUrl("Users/" + id); - - using (var stream = await GetSerializedStreamAsync(url).ConfigureAwait(false)) - { - return DeserializeFromStream(stream); - } - } - - /// - /// Gets the parental ratings async. - /// - /// Task{List{ParentalRating}}. - public async Task> GetParentalRatingsAsync() - { - var url = GetApiUrl("Localization/ParentalRatings"); - - using (var stream = await GetSerializedStreamAsync(url).ConfigureAwait(false)) - { - return DeserializeFromStream>(stream); - } - } - - /// - /// Gets weather information for the default location as set in configuration - /// - /// Task{WeatherInfo}. - public async Task GetWeatherInfoAsync() - { - var url = GetApiUrl("Weather"); - - using (var stream = await GetSerializedStreamAsync(url).ConfigureAwait(false)) - { - return DeserializeFromStream(stream); - } - } - - /// - /// Gets weather information for a specific location - /// Location can be a US zipcode, or "city,state", "city,state,country", "city,country" - /// It can also be an ip address, or "latitude,longitude" - /// - /// The location. - /// Task{WeatherInfo}. - /// location - public async Task GetWeatherInfoAsync(string location) - { - if (string.IsNullOrEmpty(location)) - { - throw new ArgumentNullException("location"); - } - - var dict = new QueryStringDictionary(); - - dict.Add("location", location); - - var url = GetApiUrl("Weather", dict); - - using (var stream = await GetSerializedStreamAsync(url).ConfigureAwait(false)) - { - return DeserializeFromStream(stream); - } - } - - /// - /// Gets local trailers for an item - /// - /// The user id. - /// The item id. - /// Task{ItemsResult}. - /// query - public async Task GetLocalTrailersAsync(Guid userId, string itemId) - { - if (userId == Guid.Empty) - { - throw new ArgumentNullException("userId"); - } - if (string.IsNullOrEmpty(itemId)) - { - throw new ArgumentNullException("itemId"); - } - - var url = GetApiUrl("Users/" + userId + "/Items/" + itemId + "/LocalTrailers"); - - using (var stream = await GetSerializedStreamAsync(url).ConfigureAwait(false)) - { - return DeserializeFromStream(stream); - } - } - - /// - /// Gets special features for an item - /// - /// The user id. - /// The item id. - /// Task{BaseItemDto[]}. - /// userId - public async Task GetSpecialFeaturesAsync(Guid userId, string itemId) - { - if (userId == Guid.Empty) - { - throw new ArgumentNullException("userId"); - } - if (string.IsNullOrEmpty(itemId)) - { - throw new ArgumentNullException("itemId"); - } - - var url = GetApiUrl("Users/" + userId + "/Items/" + itemId + "/SpecialFeatures"); - - using (var stream = await GetSerializedStreamAsync(url).ConfigureAwait(false)) - { - return DeserializeFromStream(stream); - } - } - - /// - /// Gets the cultures async. - /// - /// Task{CultureDto[]}. - public async Task GetCulturesAsync() - { - var url = GetApiUrl("Localization/Cultures"); - - using (var stream = await GetSerializedStreamAsync(url).ConfigureAwait(false)) - { - return DeserializeFromStream(stream); - } - } - - /// - /// Gets the countries async. - /// - /// Task{CountryInfo[]}. - public async Task GetCountriesAsync() - { - var url = GetApiUrl("Localization/Countries"); - - using (var stream = await GetSerializedStreamAsync(url).ConfigureAwait(false)) - { - return DeserializeFromStream(stream); - } - } - - /// - /// Marks an item as played or unplayed. - /// This should not be used to update playstate following playback. - /// There are separate playstate check-in methods for that. This should be used for a - /// separate option to reset playstate. - /// - /// The item id. - /// The user id. - /// if set to true [was played]. - /// Task. - /// itemId - public Task UpdatePlayedStatusAsync(string itemId, Guid userId, bool wasPlayed) - { - if (string.IsNullOrEmpty(itemId)) - { - throw new ArgumentNullException("itemId"); - } - if (userId == Guid.Empty) - { - throw new ArgumentNullException("userId"); - } - - var url = GetApiUrl("Users/" + userId + "/PlayedItems/" + itemId); - - if (wasPlayed) - { - return PostAsync(url, new Dictionary()); - } - - return HttpClient.DeleteAsync(url, Logger, CancellationToken.None); - } - - /// - /// Updates the favorite status async. - /// - /// The item id. - /// The user id. - /// if set to true [is favorite]. - /// Task. - /// itemId - public Task UpdateFavoriteStatusAsync(string itemId, Guid userId, bool isFavorite) - { - if (string.IsNullOrEmpty(itemId)) - { - throw new ArgumentNullException("itemId"); - } - if (userId == Guid.Empty) - { - throw new ArgumentNullException("userId"); - } - - var url = GetApiUrl("Users/" + userId + "/FavoriteItems/" + itemId); - - if (isFavorite) - { - return PostAsync(url, new Dictionary()); - } - - return HttpClient.DeleteAsync(url, Logger, CancellationToken.None); - } - - /// - /// Reports to the server that the user has begun playing an item - /// - /// The item id. - /// The user id. - /// Task{UserItemDataDto}. - /// itemId - public Task ReportPlaybackStartAsync(string itemId, Guid userId) - { - if (string.IsNullOrEmpty(itemId)) - { - throw new ArgumentNullException("itemId"); - } - - if (userId == Guid.Empty) - { - throw new ArgumentNullException("userId"); - } - - var url = GetApiUrl("Users/" + userId + "/PlayingItems/" + itemId); - - return PostAsync(url, new Dictionary()); - } - - /// - /// Reports playback progress to the server - /// - /// The item id. - /// The user id. - /// The position ticks. - /// Task{UserItemDataDto}. - /// itemId - public Task ReportPlaybackProgressAsync(string itemId, Guid userId, long? positionTicks) - { - if (string.IsNullOrEmpty(itemId)) - { - throw new ArgumentNullException("itemId"); - } - - if (userId == Guid.Empty) - { - throw new ArgumentNullException("userId"); - } - - var dict = new QueryStringDictionary(); - dict.AddIfNotNull("positionTicks", positionTicks); - - var url = GetApiUrl("Users/" + userId + "/PlayingItems/" + itemId + "/Progress", dict); - - return PostAsync(url, new Dictionary()); - } - - /// - /// Reports to the server that the user has stopped playing an item - /// - /// The item id. - /// The user id. - /// The position ticks. - /// Task{UserItemDataDto}. - /// itemId - public Task ReportPlaybackStoppedAsync(string itemId, Guid userId, long? positionTicks) - { - if (string.IsNullOrEmpty(itemId)) - { - throw new ArgumentNullException("itemId"); - } - - if (userId == Guid.Empty) - { - throw new ArgumentNullException("userId"); - } - - var dict = new QueryStringDictionary(); - dict.AddIfNotNull("positionTicks", positionTicks); - - var url = GetApiUrl("Users/" + userId + "/PlayingItems/" + itemId, dict); - - return HttpClient.DeleteAsync(url, Logger, CancellationToken.None); - } - - /// - /// Clears a user's rating for an item - /// - /// The item id. - /// The user id. - /// Task{UserItemDataDto}. - /// itemId - public Task ClearUserItemRatingAsync(string itemId, Guid userId) - { - if (string.IsNullOrEmpty(itemId)) - { - throw new ArgumentNullException("itemId"); - } - - if (userId == Guid.Empty) - { - throw new ArgumentNullException("userId"); - } - - var url = GetApiUrl("Users/" + userId + "/Items/" + itemId + "/Rating"); - - return HttpClient.DeleteAsync(url, Logger, CancellationToken.None); - } - - /// - /// Updates a user's rating for an item, based on likes or dislikes - /// - /// The item id. - /// The user id. - /// if set to true [likes]. - /// Task{UserItemDataDto}. - /// itemId - public Task UpdateUserItemRatingAsync(string itemId, Guid userId, bool likes) - { - if (string.IsNullOrEmpty(itemId)) - { - throw new ArgumentNullException("itemId"); - } - - if (userId == Guid.Empty) - { - throw new ArgumentNullException("userId"); - } - - var dict = new QueryStringDictionary { }; - - dict.Add("likes", likes); - - var url = GetApiUrl("Users/" + userId + "/Items/" + itemId + "/Rating", dict); - - return PostAsync(url, new Dictionary()); - } - - /// - /// Authenticates a user and returns the result - /// - /// The user id. - /// The password. - /// userId - public Task AuthenticateUserAsync(Guid userId, string password) - { - if (userId == Guid.Empty) - { - throw new ArgumentNullException("userId"); - } - - var url = GetApiUrl("Users/" + userId + "/Authenticate"); - - var args = new Dictionary(); - - if (!string.IsNullOrEmpty(password)) - { - args["password"] = password; - } - - return PostAsync(url, args); - } - - /// - /// Uploads the user image async. - /// - /// The user id. - /// Type of the image. - /// The image. - /// Task{RequestResult}. - /// - public Task UploadUserImageAsync(Guid userId, ImageType imageType, Stream image) - { - // Implement when needed - throw new NotImplementedException(); - } - - /// - /// Updates the server configuration async. - /// - /// The configuration. - /// Task. - /// configuration - public Task UpdateServerConfigurationAsync(ServerConfiguration configuration) - { - if (configuration == null) - { - throw new ArgumentNullException("configuration"); - } - - var url = GetApiUrl("System/Configuration"); - - return PostAsync(url, configuration); - } - - /// - /// Updates the scheduled task triggers. - /// - /// The id. - /// The triggers. - /// Task{RequestResult}. - /// id - public Task UpdateScheduledTaskTriggersAsync(Guid id, TaskTriggerInfo[] triggers) - { - if (id == Guid.Empty) - { - throw new ArgumentNullException("id"); - } - - if (triggers == null) - { - throw new ArgumentNullException("triggers"); - } - - var url = GetApiUrl("ScheduledTasks/" + id + "/Triggers"); - - return PostAsync(url, triggers); - } - - /// - /// Updates display preferences for a user - /// - /// The user id. - /// The item id. - /// The display preferences. - /// Task{DisplayPreferences}. - /// userId - public Task UpdateDisplayPreferencesAsync(Guid userId, string itemId, DisplayPreferences displayPreferences) - { - if (userId == Guid.Empty) - { - throw new ArgumentNullException("userId"); - } - - if (string.IsNullOrEmpty(itemId)) - { - throw new ArgumentNullException("itemId"); - } - - if (displayPreferences == null) - { - throw new ArgumentNullException("displayPreferences"); - } - - var url = GetApiUrl("Users/" + userId + "/Items/" + itemId + "/DisplayPreferences"); - - return PostAsync(url, displayPreferences); - } - - /// - /// Posts a set of data to a url, and deserializes the return stream into T - /// - /// - /// The URL. - /// The args. - /// Task{``0}. - private Task PostAsync(string url, Dictionary args) - where T : class - { - return PostAsync(url, args, SerializationFormat); - } - - /// - /// Posts a set of data to a url, and deserializes the return stream into T - /// - /// - /// The URL. - /// The args. - /// The serialization format. - /// Task{``0}. - private async Task PostAsync(string url, Dictionary args, SerializationFormats serializationFormat) - where T : class - { - url = AddDataFormat(url, serializationFormat); - - // Create the post body - var strings = args.Keys.Select(key => string.Format("{0}={1}", key, args[key])); - var postContent = string.Join("&", strings.ToArray()); - - const string contentType = "application/x-www-form-urlencoded"; - - using (var stream = await HttpClient.PostAsync(url, contentType, postContent, Logger, CancellationToken.None).ConfigureAwait(false)) - { - return DeserializeFromStream(stream); - } - } - - /// - /// Posts an object of type TInputType to a given url, and deserializes the response into an object of type TOutputType - /// - /// The type of the T input type. - /// The type of the T output type. - /// The URL. - /// The obj. - /// Task{``1}. - private Task PostAsync(string url, TInputType obj) - where TOutputType : class - { - return PostAsync(url, obj, SerializationFormat); - } - - /// - /// Posts an object of type TInputType to a given url, and deserializes the response into an object of type TOutputType - /// - /// The type of the T input type. - /// The type of the T output type. - /// The URL. - /// The obj. - /// The serialization format. - /// Task{``1}. - private async Task PostAsync(string url, TInputType obj, SerializationFormats serializationFormat) - where TOutputType : class - { - url = AddDataFormat(url, serializationFormat); - - const string contentType = "application/x-www-form-urlencoded"; - - var postContent = SerializeToJson(obj); - - using (var stream = await HttpClient.PostAsync(url, contentType, postContent, Logger, CancellationToken.None).ConfigureAwait(false)) - { - return DeserializeFromStream(stream); - } - } - - /// - /// This is a helper around getting a stream from the server that contains serialized data - /// - /// The URL. - /// Task{Stream}. - public Task GetSerializedStreamAsync(string url) - { - return GetSerializedStreamAsync(url, SerializationFormat); - } - - /// - /// This is a helper around getting a stream from the server that contains serialized data - /// - /// The URL. - /// The serialization format. - /// Task{Stream}. - public Task GetSerializedStreamAsync(string url, SerializationFormats serializationFormat) - { - url = AddDataFormat(url, serializationFormat); - - return HttpClient.GetAsync(url, Logger, CancellationToken.None); - } - - - /// - /// Adds the data format. - /// - /// The URL. - /// The serialization format. - /// System.String. - private string AddDataFormat(string url, SerializationFormats serializationFormat) - { - var format = serializationFormat == SerializationFormats.Protobuf ? "x-protobuf" : serializationFormat.ToString(); - - if (url.IndexOf('?') == -1) - { - url += "?format=" + format; - } - else - { - url += "&format=" + format; - } - - return url; - } - } -} diff --git a/MediaBrowser.ApiInteraction/AsyncHttpClient.cs b/MediaBrowser.ApiInteraction/AsyncHttpClient.cs deleted file mode 100644 index c6701cac08..0000000000 --- a/MediaBrowser.ApiInteraction/AsyncHttpClient.cs +++ /dev/null @@ -1,234 +0,0 @@ -using MediaBrowser.Model.Logging; -using MediaBrowser.Model.Net; -using System; -using System.IO; -using System.Net.Http; -using System.Net.Http.Headers; -using System.Text; -using System.Threading; -using System.Threading.Tasks; - -namespace MediaBrowser.ApiInteraction -{ - /// - /// Class AsyncHttpClient - /// - public class AsyncHttpClient : IAsyncHttpClient - { - /// - /// Gets or sets the HTTP client. - /// - /// The HTTP client. - private HttpClient HttpClient { get; set; } - - /// - /// Initializes a new instance of the class. - /// - public AsyncHttpClient(HttpMessageHandler handler) - { - HttpClient = new HttpClient(handler); - } - - /// - /// Initializes a new instance of the class. - /// - public AsyncHttpClient() - { - HttpClient = new HttpClient(); - } - - /// - /// Gets the stream async. - /// - /// The URL. - /// The logger. - /// The cancellation token. - /// Task{Stream}. - /// - public async Task GetAsync(string url, ILogger logger, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - - logger.Debug("Sending Http Get to {0}", url); - - try - { - var msg = await HttpClient.GetAsync(url, cancellationToken).ConfigureAwait(false); - - EnsureSuccessStatusCode(msg); - - return await msg.Content.ReadAsStreamAsync().ConfigureAwait(false); - } - catch (HttpRequestException ex) - { - logger.ErrorException("Error getting response from " + url, ex); - - throw new HttpException(ex.Message, ex); - } - catch (OperationCanceledException ex) - { - throw GetCancellationException(url, cancellationToken, ex, logger); - } - catch (Exception ex) - { - logger.ErrorException("Error requesting {0}", ex, url); - - throw; - } - } - - /// - /// Posts the async. - /// - /// The URL. - /// Type of the content. - /// Content of the post. - /// The logger. - /// The cancellation token. - /// Task{Stream}. - /// - public async Task PostAsync(string url, string contentType, string postContent, ILogger logger, CancellationToken cancellationToken) - { - logger.Debug("Sending Http Post to {0}", url); - - var content = new StringContent(postContent, Encoding.UTF8, contentType); - - try - { - var msg = await HttpClient.PostAsync(url, content).ConfigureAwait(false); - - EnsureSuccessStatusCode(msg); - - return await msg.Content.ReadAsStreamAsync().ConfigureAwait(false); - } - catch (HttpRequestException ex) - { - logger.ErrorException("Error getting response from " + url, ex); - - throw new HttpException(ex.Message, ex); - } - catch (OperationCanceledException ex) - { - throw GetCancellationException(url, cancellationToken, ex, logger); - } - catch (Exception ex) - { - logger.ErrorException("Error posting {0}", ex, url); - - throw; - } - } - - /// - /// Deletes the async. - /// - /// The URL. - /// The logger. - /// The cancellation token. - /// Task. - public async Task DeleteAsync(string url, ILogger logger, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - - logger.Debug("Sending Http Delete to {0}", url); - - try - { - using (var msg = await HttpClient.DeleteAsync(url, cancellationToken).ConfigureAwait(false)) - { - EnsureSuccessStatusCode(msg); - } - } - catch (HttpRequestException ex) - { - logger.ErrorException("Error getting response from " + url, ex); - - throw new HttpException(ex.Message, ex); - } - catch (OperationCanceledException ex) - { - throw GetCancellationException(url, cancellationToken, ex, logger); - } - catch (Exception ex) - { - logger.ErrorException("Error requesting {0}", ex, url); - - throw; - } - } - - /// - /// Throws the cancellation exception. - /// - /// The URL. - /// The cancellation token. - /// The exception. - /// The logger. - /// Exception. - private Exception GetCancellationException(string url, CancellationToken cancellationToken, OperationCanceledException exception, ILogger logger) - { - // If the HttpClient's timeout is reached, it will cancel the Task internally - if (!cancellationToken.IsCancellationRequested) - { - var msg = string.Format("Connection to {0} timed out", url); - - logger.Error(msg); - - // Throw an HttpException so that the caller doesn't think it was cancelled by user code - return new HttpException(msg, exception) { IsTimedOut = true }; - } - - return exception; - } - - /// - /// Ensures the success status code. - /// - /// The response. - /// - private void EnsureSuccessStatusCode(HttpResponseMessage response) - { - if (!response.IsSuccessStatusCode) - { - throw new HttpException(response.ReasonPhrase) { StatusCode = response.StatusCode }; - } - } - - /// - /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. - /// - public void Dispose() - { - Dispose(true); - } - - /// - /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. - /// - /// true to release both managed and unmanaged resources; false to release only unmanaged resources. - protected virtual void Dispose(bool disposing) - { - if (disposing) - { - HttpClient.Dispose(); - } - } - - /// - /// Sets the authorization header that should be supplied on every request - /// - /// The header. - /// - public void SetAuthorizationHeader(string header) - { - if (string.IsNullOrEmpty(header)) - { - HttpClient.DefaultRequestHeaders.Remove("Authorization"); - } - else - { - HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("MediaBrowser", header); - } - } - } -} diff --git a/MediaBrowser.ApiInteraction/BaseApiClient.cs b/MediaBrowser.ApiInteraction/BaseApiClient.cs deleted file mode 100644 index 6d5a5e7cbd..0000000000 --- a/MediaBrowser.ApiInteraction/BaseApiClient.cs +++ /dev/null @@ -1,857 +0,0 @@ -using MediaBrowser.Model.Connectivity; -using MediaBrowser.Model.Dto; -using MediaBrowser.Model.Entities; -using MediaBrowser.Model.Logging; -using MediaBrowser.Model.Serialization; -using MediaBrowser.Model.Web; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; - -namespace MediaBrowser.ApiInteraction -{ - /// - /// Provides api methods that are usable on all platforms - /// - public abstract class BaseApiClient : IDisposable - { - /// - /// Gets the logger. - /// - /// The logger. - protected ILogger Logger { get; private set; } - - /// - /// Gets the protobuf serializer. - /// - /// The protobuf serializer. - public IProtobufSerializer ProtobufSerializer { get; set; } - - /// - /// Gets the json serializer. - /// - /// The json serializer. - public IJsonSerializer JsonSerializer { get; set; } - - /// - /// Initializes a new instance of the class. - /// - /// The logger. - /// The json serializer. - /// logger - protected BaseApiClient(ILogger logger) - { - if (logger == null) - { - throw new ArgumentNullException("logger"); - } - - JsonSerializer = new NewtonsoftJsonSerializer(); - Logger = logger; - SerializationFormat = SerializationFormats.Json; - } - - /// - /// Gets or sets the server host name (myserver or 192.168.x.x) - /// - /// The name of the server host. - public string ServerHostName { get; set; } - - /// - /// Gets or sets the port number used by the API - /// - /// The server API port. - public int ServerApiPort { get; set; } - - /// - /// Gets or sets the type of the client. - /// - /// The type of the client. - public ClientType ClientType { get; set; } - - /// - /// Gets or sets the name of the device. - /// - /// The name of the device. - public string DeviceName { get; set; } - - private Guid? _currentUserId; - - /// - /// Gets or sets the current user id. - /// - /// The current user id. - public virtual Guid? CurrentUserId - { - get { return _currentUserId; } - set - { - _currentUserId = value; - ResetAuthorizationHeader(); - } - } - - /// - /// Gets the current api url based on hostname and port. - /// - /// The API URL. - protected string ApiUrl - { - get - { - return string.Format("http://{0}:{1}/mediabrowser", ServerHostName, ServerApiPort); - } - } - - /// - /// Gets the default data format to request from the server - /// - /// The serialization format. - public SerializationFormats SerializationFormat { get; set; } - - /// - /// Resets the authorization header. - /// - private void ResetAuthorizationHeader() - { - if (!CurrentUserId.HasValue) - { - SetAuthorizationHeader(null); - return; - } - - var header = string.Format("UserId=\"{0}\", Client=\"{1}\"", CurrentUserId.Value, ClientType); - - if (!string.IsNullOrEmpty(DeviceName)) - { - header += string.Format(", Device=\"{0}\"", DeviceName); - } - - SetAuthorizationHeader(header); - } - - /// - /// Sets the authorization header. - /// - /// The header. - protected abstract void SetAuthorizationHeader(string header); - - /// - /// Gets the API URL. - /// - /// The handler. - /// System.String. - /// handler - protected string GetApiUrl(string handler) - { - return GetApiUrl(handler, new QueryStringDictionary()); - } - - /// - /// Gets the API URL. - /// - /// The handler. - /// The query string. - /// System.String. - /// handler - protected string GetApiUrl(string handler, QueryStringDictionary queryString) - { - if (string.IsNullOrEmpty(handler)) - { - throw new ArgumentNullException("handler"); - } - - if (queryString == null) - { - throw new ArgumentNullException("queryString"); - } - - return queryString.GetUrl(ApiUrl + "/" + handler); - } - - /// - /// Creates a url to return a list of items - /// - /// The query. - /// The type of list to retrieve. - /// System.String. - /// query - protected string GetItemListUrl(ItemQuery query, string listType = null) - { - if (query == null) - { - throw new ArgumentNullException("query"); - } - - var dict = new QueryStringDictionary { }; - - dict.AddIfNotNullOrEmpty("listtype", listType); - dict.AddIfNotNullOrEmpty("ParentId", query.ParentId); - - dict.AddIfNotNull("startindex", query.StartIndex); - - dict.AddIfNotNull("limit", query.Limit); - - if (query.SortBy != null) - { - dict["sortBy"] = string.Join(",", query.SortBy.Select(s => s.ToString())); - } - - if (query.SortOrder.HasValue) - { - dict["sortOrder"] = query.SortOrder.ToString(); - } - - if (query.Fields != null) - { - dict.Add("fields", query.Fields.Select(f => f.ToString())); - } - if (query.Filters != null) - { - dict.Add("Filters", query.Filters.Select(f => f.ToString())); - } - if (query.ImageTypes != null) - { - dict.Add("ImageTypes", query.ImageTypes.Select(f => f.ToString())); - } - - dict.Add("recursive", query.Recursive); - - dict.AddIfNotNull("genres", query.Genres); - dict.AddIfNotNull("studios", query.Studios); - dict.AddIfNotNull("ExcludeItemTypes", query.ExcludeItemTypes); - dict.AddIfNotNull("IncludeItemTypes", query.IncludeItemTypes); - - dict.AddIfNotNullOrEmpty("person", query.Person); - dict.AddIfNotNullOrEmpty("personType", query.PersonType); - - dict.AddIfNotNull("years", query.Years); - - dict.AddIfNotNullOrEmpty("indexBy", query.IndexBy); - dict.AddIfNotNullOrEmpty("dynamicSortBy", query.DynamicSortBy); - dict.AddIfNotNullOrEmpty("SearchTerm", query.SearchTerm); - - return GetApiUrl("Users/" + query.UserId + "/Items", dict); - } - - /// - /// Gets the image URL. - /// - /// The base URL. - /// The options. - /// The query params. - /// System.String. - /// options - private string GetImageUrl(string baseUrl, ImageOptions options, QueryStringDictionary queryParams) - { - if (options == null) - { - throw new ArgumentNullException("options"); - } - - if (queryParams == null) - { - throw new ArgumentNullException("queryParams"); - } - - if (options.ImageIndex.HasValue) - { - baseUrl += "/" + options.ImageIndex.Value; - } - - queryParams.AddIfNotNull("width", options.Width); - queryParams.AddIfNotNull("height", options.Height); - queryParams.AddIfNotNull("maxWidth", options.MaxWidth); - queryParams.AddIfNotNull("maxHeight", options.MaxHeight); - queryParams.AddIfNotNull("Quality", options.Quality); - - queryParams.AddIfNotNull("tag", options.Tag); - - return GetApiUrl(baseUrl, queryParams); - } - - /// - /// Gets the image URL. - /// - /// The item. - /// The options. - /// System.String. - /// item - public string GetImageUrl(BaseItemDto item, ImageOptions options) - { - if (item == null) - { - throw new ArgumentNullException("item"); - } - - if (options == null) - { - throw new ArgumentNullException("options"); - } - - var index = options.ImageIndex ?? 0; - - if (options.ImageType == ImageType.Backdrop) - { - options.Tag = item.BackdropImageTags[index]; - } - else if (options.ImageType == ImageType.ChapterImage) - { - options.Tag = item.Chapters[index].ImageTag; - } - else - { - options.Tag = item.ImageTags[options.ImageType]; - } - - return GetImageUrl(item.Id, options); - } - - /// - /// Gets an image url that can be used to download an image from the api - /// - /// The Id of the item - /// The options. - /// System.String. - /// itemId - public string GetImageUrl(string itemId, ImageOptions options) - { - if (string.IsNullOrEmpty(itemId)) - { - throw new ArgumentNullException("itemId"); - } - - var url = "Items/" + itemId + "/Images/" + options.ImageType; - - return GetImageUrl(url, options, new QueryStringDictionary()); - } - - /// - /// Gets the user image URL. - /// - /// The user. - /// The options. - /// System.String. - /// user - public string GetUserImageUrl(UserDto user, ImageOptions options) - { - if (user == null) - { - throw new ArgumentNullException("user"); - } - - if (options == null) - { - throw new ArgumentNullException("options"); - } - - options.Tag = user.PrimaryImageTag; - - return GetUserImageUrl(user.Id, options); - } - - /// - /// Gets an image url that can be used to download an image from the api - /// - /// The Id of the user - /// The options. - /// System.String. - /// userId - public string GetUserImageUrl(Guid userId, ImageOptions options) - { - if (userId == Guid.Empty) - { - throw new ArgumentNullException("userId"); - } - - var url = "Users/" + userId + "/Images/" + options.ImageType; - - return GetImageUrl(url, options, new QueryStringDictionary()); - } - - /// - /// Gets the person image URL. - /// - /// The item. - /// The options. - /// System.String. - /// item - public string GetPersonImageUrl(BaseItemPerson item, ImageOptions options) - { - if (item == null) - { - throw new ArgumentNullException("item"); - } - - if (options == null) - { - throw new ArgumentNullException("options"); - } - - options.Tag = item.PrimaryImageTag; - - return GetPersonImageUrl(item.Name, options); - } - - /// - /// Gets the person image URL. - /// - /// The item. - /// The options. - /// System.String. - /// item - public string GetPersonImageUrl(BaseItemDto item, ImageOptions options) - { - if (item == null) - { - throw new ArgumentNullException("item"); - } - - if (options == null) - { - throw new ArgumentNullException("options"); - } - - options.Tag = item.ImageTags[ImageType.Primary]; - - return GetPersonImageUrl(item.Name, options); - } - - /// - /// Gets an image url that can be used to download an image from the api - /// - /// The name of the person - /// The options. - /// System.String. - /// name - public string GetPersonImageUrl(string name, ImageOptions options) - { - if (string.IsNullOrEmpty(name)) - { - throw new ArgumentNullException("name"); - } - - var url = "Persons/" + name + "/Images/" + options.ImageType; - - return GetImageUrl(url, options, new QueryStringDictionary()); - } - - /// - /// Gets the year image URL. - /// - /// The item. - /// The options. - /// System.String. - /// item - public string GetYearImageUrl(BaseItemDto item, ImageOptions options) - { - if (item == null) - { - throw new ArgumentNullException("item"); - } - - if (options == null) - { - throw new ArgumentNullException("options"); - } - - options.Tag = item.ImageTags[ImageType.Primary]; - - return GetYearImageUrl(int.Parse(item.Name), options); - } - - /// - /// Gets an image url that can be used to download an image from the api - /// - /// The year. - /// The options. - /// System.String. - public string GetYearImageUrl(int year, ImageOptions options) - { - var url = "Years/" + year + "/Images/" + options.ImageType; - - return GetImageUrl(url, options, new QueryStringDictionary()); - } - - /// - /// Gets the genre image URL. - /// - /// The item. - /// The options. - /// System.String. - /// item - public string GetGenreImageUrl(BaseItemDto item, ImageOptions options) - { - if (item == null) - { - throw new ArgumentNullException("item"); - } - - if (options == null) - { - throw new ArgumentNullException("options"); - } - - options.Tag = item.ImageTags[ImageType.Primary]; - - return GetGenreImageUrl(item.Name, options); - } - - /// - /// Gets an image url that can be used to download an image from the api - /// - /// The name. - /// The options. - /// System.String. - /// name - public string GetGenreImageUrl(string name, ImageOptions options) - { - if (string.IsNullOrEmpty(name)) - { - throw new ArgumentNullException("name"); - } - - var url = "Genres/" + name + "/Images/" + options.ImageType; - - return GetImageUrl(url, options, new QueryStringDictionary()); - } - - /// - /// Gets the studio image URL. - /// - /// The item. - /// The options. - /// System.String. - /// item - public string GetStudioImageUrl(BaseItemDto item, ImageOptions options) - { - if (item == null) - { - throw new ArgumentNullException("item"); - } - - if (options == null) - { - throw new ArgumentNullException("options"); - } - - options.Tag = item.ImageTags[ImageType.Primary]; - - return GetStudioImageUrl(item.Name, options); - } - - /// - /// Gets an image url that can be used to download an image from the api - /// - /// The name. - /// The options. - /// System.String. - /// name - public string GetStudioImageUrl(string name, ImageOptions options) - { - if (string.IsNullOrEmpty(name)) - { - throw new ArgumentNullException("name"); - } - - var url = "Studios/" + name + "/Images/" + options.ImageType; - - return GetImageUrl(url, options, new QueryStringDictionary()); - } - - /// - /// 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. - /// The options. - /// System.String[][]. - /// item - public string[] GetBackdropImageUrls(BaseItemDto item, ImageOptions options) - { - if (item == null) - { - throw new ArgumentNullException("item"); - } - - if (options == null) - { - throw new ArgumentNullException("options"); - } - - options.ImageType = ImageType.Backdrop; - - string backdropItemId; - List backdropImageTags; - - if (item.BackdropCount == 0) - { - backdropItemId = item.ParentBackdropItemId; - backdropImageTags = item.ParentBackdropImageTags; - } - else - { - backdropItemId = item.Id; - backdropImageTags = item.BackdropImageTags; - } - - if (string.IsNullOrEmpty(backdropItemId)) - { - return new string[] { }; - } - - var files = new string[backdropImageTags.Count]; - - for (var i = 0; i < backdropImageTags.Count; i++) - { - options.ImageIndex = i; - options.Tag = backdropImageTags[i]; - - files[i] = GetImageUrl(backdropItemId, options); - } - - 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. - /// The options. - /// System.String. - /// item - public string GetLogoImageUrl(BaseItemDto item, ImageOptions options) - { - if (item == null) - { - throw new ArgumentNullException("item"); - } - - if (options == null) - { - throw new ArgumentNullException("options"); - } - - options.ImageType = ImageType.Logo; - - var logoItemId = item.HasLogo ? item.Id : item.ParentLogoItemId; - var imageTag = item.HasLogo ? item.ImageTags[ImageType.Logo] : item.ParentLogoImageTag; - - if (!string.IsNullOrEmpty(logoItemId)) - { - options.Tag = imageTag; - - return GetImageUrl(logoItemId, options); - } - - return null; - } - - /// - /// Gets the url needed to stream an audio file - /// - /// The options. - /// System.String. - /// options - public string GetAudioStreamUrl(StreamOptions options) - { - if (options == null) - { - throw new ArgumentNullException("options"); - } - - var handler = "Audio/" + options.ItemId + "/stream"; - - if (!string.IsNullOrEmpty(options.OutputFileExtension)) - { - handler += "." + options.OutputFileExtension.TrimStart('.'); - } - - return GetMediaStreamUrl(handler, options, new QueryStringDictionary()); - } - - /// - /// Gets the url needed to stream a video file - /// - /// The options. - /// System.String. - /// options - public string GetVideoStreamUrl(VideoStreamOptions options) - { - if (options == null) - { - throw new ArgumentNullException("options"); - } - - var handler = "Videos/" + options.ItemId + "/stream"; - - if (!string.IsNullOrEmpty(options.OutputFileExtension)) - { - handler += "." + options.OutputFileExtension.TrimStart('.'); - } - - return GetVideoStreamUrl(handler, options); - } - - /// - /// Formulates a url for streaming audio using the HLS protocol - /// - /// The options. - /// System.String. - /// options - public string GetHlsAudioStreamUrl(StreamOptions options) - { - if (options == null) - { - throw new ArgumentNullException("options"); - } - - return GetMediaStreamUrl("audio.m3u8", options, new QueryStringDictionary()); - } - - /// - /// Formulates a url for streaming video using the HLS protocol - /// - /// The options. - /// System.String. - /// options - public string GetHlsVideoStreamUrl(VideoStreamOptions options) - { - if (options == null) - { - throw new ArgumentNullException("options"); - } - - return GetVideoStreamUrl("video.m3u8", options); - } - - /// - /// Gets the video stream URL. - /// - /// The handler. - /// The options. - /// System.String. - private string GetVideoStreamUrl(string handler, VideoStreamOptions options) - { - var queryParams = new QueryStringDictionary(); - - if (options.VideoCodec.HasValue) - { - queryParams["VideoCodec"] = options.VideoCodec.Value.ToString(); - } - - queryParams.AddIfNotNull("VideoBitRate", options.VideoBitRate); - queryParams.AddIfNotNull("Width", options.Width); - queryParams.AddIfNotNull("Height", options.Height); - queryParams.AddIfNotNull("MaxWidth", options.MaxWidth); - queryParams.AddIfNotNull("MaxHeight", options.MaxHeight); - queryParams.AddIfNotNull("FrameRate", options.FrameRate); - queryParams.AddIfNotNull("AudioStreamIndex", options.AudioStreamIndex); - queryParams.AddIfNotNull("VideoStreamIndex", options.VideoStreamIndex); - queryParams.AddIfNotNull("SubtitleStreamIndex", options.SubtitleStreamIndex); - - return GetMediaStreamUrl(handler, options, queryParams); - } - - /// - /// Gets the media stream URL. - /// - /// The handler. - /// The options. - /// The query params. - /// System.String. - /// handler - private string GetMediaStreamUrl(string handler, StreamOptions options, QueryStringDictionary queryParams) - { - if (string.IsNullOrEmpty(handler)) - { - throw new ArgumentNullException("handler"); - } - - if (options == null) - { - throw new ArgumentNullException("options"); - } - - if (queryParams == null) - { - throw new ArgumentNullException("queryParams"); - } - - if (options.AudioCodec.HasValue) - { - queryParams["audioCodec"] = options.AudioCodec.Value.ToString(); - } - - queryParams.AddIfNotNull("audiochannels", options.MaxAudioChannels); - queryParams.AddIfNotNull("audiosamplerate", options.MaxAudioSampleRate); - queryParams.AddIfNotNull("AudioBitRate", options.AudioBitRate); - queryParams.AddIfNotNull("StartTimeTicks", options.StartTimeTicks); - queryParams.AddIfNotNull("Static", options.Static); - - return GetApiUrl(handler, queryParams); - } - - /// - /// Deserializes from stream. - /// - /// - /// The stream. - /// ``0. - protected T DeserializeFromStream(Stream stream) - where T : class - { - return (T)DeserializeFromStream(stream, typeof(T), SerializationFormat); - } - - /// - /// Deserializes from stream. - /// - /// The stream. - /// The type. - /// The format. - /// System.Object. - /// - protected object DeserializeFromStream(Stream stream, Type type, SerializationFormats format) - { - if (format == SerializationFormats.Protobuf) - { - return ProtobufSerializer.DeserializeFromStream(stream, type); - } - if (format == SerializationFormats.Json) - { - return JsonSerializer.DeserializeFromStream(stream, type); - } - - throw new NotImplementedException(); - } - - /// - /// Serializers to json. - /// - /// The obj. - /// System.String. - protected string SerializeToJson(object obj) - { - return JsonSerializer.SerializeToString(obj); - } - - /// - /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. - /// - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - /// - /// Releases unmanaged and - optionally - managed resources. - /// - /// true to release both managed and unmanaged resources; false to release only unmanaged resources. - protected virtual void Dispose(bool disposing) - { - - } - } -} diff --git a/MediaBrowser.ApiInteraction/IAsyncHttpClient.cs b/MediaBrowser.ApiInteraction/IAsyncHttpClient.cs deleted file mode 100644 index 0837f150fa..0000000000 --- a/MediaBrowser.ApiInteraction/IAsyncHttpClient.cs +++ /dev/null @@ -1,49 +0,0 @@ -using MediaBrowser.Model.Logging; -using System; -using System.IO; -using System.Threading; -using System.Threading.Tasks; - -namespace MediaBrowser.ApiInteraction -{ - /// - /// Interface IHttpClient - /// - public interface IAsyncHttpClient : IDisposable - { - /// - /// Sets the authorization header that should be supplied on every request - /// - /// - void SetAuthorizationHeader(string header); - - /// - /// Gets the stream async. - /// - /// The URL. - /// The logger. - /// The cancellation token. - /// Task{Stream}. - Task GetAsync(string url, ILogger logger, CancellationToken cancellationToken); - - /// - /// Deletes the async. - /// - /// The URL. - /// The logger. - /// The cancellation token. - /// Task. - Task DeleteAsync(string url, ILogger logger, CancellationToken cancellationToken); - - /// - /// Posts the async. - /// - /// The URL. - /// Type of the content. - /// Content of the post. - /// The logger. - /// The cancellation token. - /// Task{Stream}. - Task PostAsync(string url, string contentType, string postContent, ILogger logger, CancellationToken cancellationToken); - } -} diff --git a/MediaBrowser.ApiInteraction/MediaBrowser.ApiInteraction.csproj b/MediaBrowser.ApiInteraction/MediaBrowser.ApiInteraction.csproj deleted file mode 100644 index ceb8aaece7..0000000000 --- a/MediaBrowser.ApiInteraction/MediaBrowser.ApiInteraction.csproj +++ /dev/null @@ -1,83 +0,0 @@ - - - - - Debug - AnyCPU - {921C0F64-FDA7-4E9F-9E73-0CB0EEDB2422} - Library - Properties - MediaBrowser.ApiInteraction - MediaBrowser.ApiInteraction - v4.5 - 512 - ..\ - true - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - ..\packages\Newtonsoft.Json.4.5.11\lib\net40\Newtonsoft.Json.dll - - - - - - - - - - - - - - Properties\SharedVersion.cs - - - - - - - - - - - - {7eeeb4bb-f3e8-48fc-b4c5-70f0fff8329b} - MediaBrowser.Model - - - - - - - - - if $(ConfigurationName) == Release ( -xcopy "$(TargetPath)" "$(SolutionDir)\Nuget\dlls\" /y /d /r /i -) - - - \ No newline at end of file diff --git a/MediaBrowser.ApiInteraction/NewtonsoftJsonSerializer.cs b/MediaBrowser.ApiInteraction/NewtonsoftJsonSerializer.cs deleted file mode 100644 index f5b43669ea..0000000000 --- a/MediaBrowser.ApiInteraction/NewtonsoftJsonSerializer.cs +++ /dev/null @@ -1,141 +0,0 @@ -using MediaBrowser.Model.Serialization; -using Newtonsoft.Json; -using System; -using System.IO; - -namespace MediaBrowser.ApiInteraction -{ - /// - /// Class NewtonsoftJsonSerializer - /// - public class NewtonsoftJsonSerializer : IJsonSerializer - { - /// - /// Serializes to stream. - /// - /// The obj. - /// The stream. - /// - /// obj - public void SerializeToStream(object obj, Stream stream) - { - throw new NotImplementedException(); - } - - /// - /// Deserializes from stream. - /// - /// The stream. - /// The type. - /// System.Object. - public object DeserializeFromStream(Stream stream, Type type) - { - using (var streamReader = new StreamReader(stream)) - { - using (var jsonReader = new JsonTextReader(streamReader)) - { - return JsonSerializer.Create(new JsonSerializerSettings()).Deserialize(jsonReader, type); - } - } - } - - /// - /// Deserializes from stream. - /// - /// - /// The stream. - /// ``0. - public T DeserializeFromStream(Stream stream) - { - return (T)DeserializeFromStream(stream, typeof(T)); - } - - /// - /// Deserializes from string. - /// - /// - /// The text. - /// ``0. - /// - public T DeserializeFromString(string text) - { - throw new NotImplementedException(); - } - - /// - /// Deserializes from string. - /// - /// The json. - /// The type. - /// System.Object. - /// - public object DeserializeFromString(string json, Type type) - { - throw new NotImplementedException(); - } - - /// - /// Serializes to string. - /// - /// The obj. - /// System.String. - public string SerializeToString(object obj) - { - using (var streamWriter = new StringWriter()) - { - using (var jsonWriter = new JsonTextWriter((streamWriter))) - { - JsonSerializer.Create(new JsonSerializerSettings()).Serialize(jsonWriter, obj); - } - return streamWriter.ToString(); - } - } - - /// - /// Serializes to bytes. - /// - /// The obj. - /// System.Byte[][]. - /// - public byte[] SerializeToBytes(object obj) - { - throw new NotImplementedException(); - } - - /// - /// Serializes to file. - /// - /// The obj. - /// The file. - /// - /// obj - public void SerializeToFile(object obj, string file) - { - throw new NotImplementedException(); - } - - /// - /// Deserializes from file. - /// - /// The type. - /// The file. - /// System.Object. - /// - public object DeserializeFromFile(Type type, string file) - { - throw new NotImplementedException(); - } - - /// - /// Deserializes from file. - /// - /// - /// The file. - /// ``0. - /// - public T DeserializeFromFile(string file) where T : class - { - throw new NotImplementedException(); - } - } -} diff --git a/MediaBrowser.ApiInteraction/Properties/AssemblyInfo.cs b/MediaBrowser.ApiInteraction/Properties/AssemblyInfo.cs deleted file mode 100644 index e4ed8a6ada..0000000000 --- a/MediaBrowser.ApiInteraction/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System.Reflection; -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")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("MediaBrowser.ApiInteraction")] -[assembly: AssemblyCopyright("Copyright © 2012")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("677618f2-de4b-44f4-8dfd-a90176297ee2")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// \ No newline at end of file diff --git a/MediaBrowser.ApiInteraction/SerializationFormats.cs b/MediaBrowser.ApiInteraction/SerializationFormats.cs deleted file mode 100644 index 9bfba7c501..0000000000 --- a/MediaBrowser.ApiInteraction/SerializationFormats.cs +++ /dev/null @@ -1,18 +0,0 @@ - -namespace MediaBrowser.ApiInteraction -{ - /// - /// Enum SerializationFormats - /// - public enum SerializationFormats - { - /// - /// The json - /// - Json, - /// - /// The protobuf - /// - Protobuf - } -} diff --git a/MediaBrowser.ApiInteraction/packages.config b/MediaBrowser.ApiInteraction/packages.config deleted file mode 100644 index b82a8b0dde..0000000000 --- a/MediaBrowser.ApiInteraction/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/MediaBrowser.Common.Implementations/MediaBrowser.Common.Implementations.csproj b/MediaBrowser.Common.Implementations/MediaBrowser.Common.Implementations.csproj index 4adff8380f..831b111ec7 100644 --- a/MediaBrowser.Common.Implementations/MediaBrowser.Common.Implementations.csproj +++ b/MediaBrowser.Common.Implementations/MediaBrowser.Common.Implementations.csproj @@ -149,20 +149,48 @@ - - - - - - - - - - - - - - + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + diff --git a/MediaBrowser.Common.Implementations/swagger-ui/index.html b/MediaBrowser.Common.Implementations/swagger-ui/index.html index 5d2a8d88da..0b2b02b10e 100644 --- a/MediaBrowser.Common.Implementations/swagger-ui/index.html +++ b/MediaBrowser.Common.Implementations/swagger-ui/index.html @@ -42,7 +42,7 @@