mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-14 10:36:54 -07:00
Merge remote-tracking branch 'upstream/dev'
This commit is contained in:
commit
cd2c9a40e5
283 changed files with 10998 additions and 1985 deletions
|
@ -27,6 +27,7 @@
|
|||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Xml.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
using NLog;
|
||||
|
@ -55,72 +56,46 @@ namespace Ombi.Api
|
|||
public T Execute<T>(IRestRequest request, Uri baseUri) where T : new()
|
||||
{
|
||||
var client = new RestClient { BaseUrl = baseUri };
|
||||
|
||||
var response = client.Execute<T>(request);
|
||||
Log.Trace("Api Content Response:");
|
||||
Log.Trace(response.Content);
|
||||
Log.Trace($"Request made to {response.ResponseUri} with status code {response.StatusCode}. The response was {response.Content}");
|
||||
|
||||
if (response.StatusCode == HttpStatusCode.OK || response.StatusCode == HttpStatusCode.Created)
|
||||
return response.Data;
|
||||
else
|
||||
throw new ApiRequestException($"Got StatusCode={response.StatusCode} for {response.ResponseUri}.");
|
||||
|
||||
if (response.ErrorException != null)
|
||||
{
|
||||
var message = "Error retrieving response. Check inner details for more info.";
|
||||
Log.Error(response.ErrorException);
|
||||
throw new ApiRequestException(message, response.ErrorException);
|
||||
}
|
||||
|
||||
return response.Data;
|
||||
}
|
||||
|
||||
public IRestResponse Execute(IRestRequest request, Uri baseUri)
|
||||
{
|
||||
var client = new RestClient { BaseUrl = baseUri };
|
||||
|
||||
var response = client.Execute(request);
|
||||
|
||||
if (response.ErrorException != null)
|
||||
{
|
||||
Log.Error(response.ErrorException);
|
||||
var message = "Error retrieving response. Check inner details for more info.";
|
||||
throw new ApiRequestException(message, response.ErrorException);
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
public T ExecuteXml<T>(IRestRequest request, Uri baseUri) where T : class
|
||||
{
|
||||
var client = new RestClient { BaseUrl = baseUri };
|
||||
|
||||
var response = client.Execute(request);
|
||||
Log.Trace($"Request made to {response.ResponseUri} with status code {response.StatusCode}. The response was {response.Content}");
|
||||
|
||||
if (response.ErrorException != null)
|
||||
{
|
||||
Log.Error(response.ErrorException);
|
||||
var message = "Error retrieving response. Check inner details for more info.";
|
||||
throw new ApiRequestException(message, response.ErrorException);
|
||||
}
|
||||
if (response.StatusCode == HttpStatusCode.OK || response.StatusCode == HttpStatusCode.Created)
|
||||
return DeserializeXml<T>(response.Content);
|
||||
else
|
||||
throw new ApiRequestException($"Got StatusCode={response.StatusCode} for {response.ResponseUri}.");
|
||||
|
||||
var result = DeserializeXml<T>(response.Content);
|
||||
return result;}
|
||||
}
|
||||
|
||||
public T ExecuteJson<T>(IRestRequest request, Uri baseUri) where T : new()
|
||||
{
|
||||
var client = new RestClient { BaseUrl = baseUri };
|
||||
var response = client.Execute(request);
|
||||
Log.Trace("Api Content Response:");
|
||||
Log.Trace(response.Content);
|
||||
if (response.ErrorException != null)
|
||||
{
|
||||
Log.Error(response.ErrorException);
|
||||
var message = "Error retrieving response. Check inner details for more info.";
|
||||
throw new ApiRequestException(message, response.ErrorException);
|
||||
}
|
||||
Log.Trace($"Request made to {response.ResponseUri} with status code {response.StatusCode}. The response was {response.Content}");
|
||||
|
||||
Log.Trace("Deserialzing Object");
|
||||
var json = JsonConvert.DeserializeObject<T>(response.Content, _settings);
|
||||
Log.Trace("Finished Deserialzing Object");
|
||||
|
||||
return json;
|
||||
if (response.StatusCode == HttpStatusCode.OK || response.StatusCode == HttpStatusCode.Created)
|
||||
return JsonConvert.DeserializeObject<T>(response.Content, _settings);
|
||||
else
|
||||
throw new ApiRequestException($"Got StatusCode={response.StatusCode} for {response.ResponseUri}.");
|
||||
}
|
||||
|
||||
private T DeserializeXml<T>(string input)
|
||||
|
|
81
Ombi.Api/AppveyorApi.cs
Normal file
81
Ombi.Api/AppveyorApi.cs
Normal file
|
@ -0,0 +1,81 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2017 Jamie Rees
|
||||
// File: AppveyorApi.cs
|
||||
// Created By: Jamie Rees
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ************************************************************************/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NLog;
|
||||
using Ombi.Api.Interfaces;
|
||||
using Ombi.Api.Models.Appveyor;
|
||||
using Ombi.Helpers;
|
||||
using RestSharp;
|
||||
|
||||
namespace Ombi.Api
|
||||
{
|
||||
public class AppveyorApi : IAppveyorApi
|
||||
{
|
||||
private const string AppveyorApiUrl = "https://ci.appveyor.com/api";
|
||||
|
||||
private const string Key =
|
||||
"48Ku58C0794nBrXra8IxWav+dc6NqgkRw+PZB3/bQwbt/D0IrnJQkgtjzo0bd6nkooLMKsC8M+Ab7jyBO+ROjY14VRuxffpDopX9r0iG/fjBl6mZVvqkm+VTDNstDtzp";
|
||||
|
||||
|
||||
public AppveyorApi()
|
||||
{
|
||||
Api = new ApiRequest();
|
||||
}
|
||||
private ApiRequest Api { get; set; }
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
//https://ci.appveyor.com/api/projects/tidusjar/requestplex/history?recordsNumber=10&branch=eap
|
||||
public AppveyorProjects GetProjectHistory(string branchName, int records = 10)
|
||||
{
|
||||
var request = new RestRequest
|
||||
{
|
||||
Resource = "projects/tidusjar/requestplex/history?recordsNumber={records}&branch={branch}",
|
||||
Method = Method.GET
|
||||
};
|
||||
|
||||
request.AddUrlSegment("records", records.ToString());
|
||||
request.AddUrlSegment("branch", branchName);
|
||||
AddHeaders(request);
|
||||
|
||||
var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) => Log.Error(exception, "Exception when calling GetProjectHistory for Appveyor, Retrying {0}", timespan), new[] {
|
||||
TimeSpan.FromSeconds (1),
|
||||
});
|
||||
|
||||
var obj = policy.Execute(() => Api.ExecuteJson<AppveyorProjects>(request, new Uri(AppveyorApiUrl)));
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
private void AddHeaders(IRestRequest request)
|
||||
{
|
||||
request.AddHeader("Authorization", $"Bearer {Key}");
|
||||
request.AddHeader("Content-Type", "application/json");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -100,9 +100,9 @@ namespace Ombi.Api
|
|||
|
||||
var obj = RetryHandler.Execute<CouchPotatoStatus>(() => Api.Execute<CouchPotatoStatus>(request, url),
|
||||
(exception, timespan) => Log.Error(exception, "Exception when calling GetStatus for CP, Retrying {0}", timespan), new TimeSpan[] {
|
||||
TimeSpan.FromSeconds (2),
|
||||
TimeSpan.FromSeconds(5),
|
||||
TimeSpan.FromSeconds(10)});
|
||||
TimeSpan.FromSeconds (1),
|
||||
TimeSpan.FromSeconds(2),
|
||||
TimeSpan.FromSeconds(3)});
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
@ -140,9 +140,9 @@ namespace Ombi.Api
|
|||
{
|
||||
var obj = RetryHandler.Execute(() => Api.Execute<CouchPotatoMovies>(request, baseUrl),
|
||||
(exception, timespan) => Log.Error(exception, "Exception when calling GetMovies for CP, Retrying {0}", timespan), new[] {
|
||||
TimeSpan.FromSeconds (5),
|
||||
TimeSpan.FromSeconds(10),
|
||||
TimeSpan.FromSeconds(30)
|
||||
TimeSpan.FromSeconds (1),
|
||||
TimeSpan.FromSeconds(5),
|
||||
TimeSpan.FromSeconds(5)
|
||||
});
|
||||
|
||||
return obj;
|
||||
|
|
314
Ombi.Api/EmbyApi.cs
Normal file
314
Ombi.Api/EmbyApi.cs
Normal file
|
@ -0,0 +1,314 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2017 Jamie Rees
|
||||
// File: EmbyApi.cs
|
||||
// Created By: Jamie Rees
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ************************************************************************/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using Newtonsoft.Json;
|
||||
using NLog;
|
||||
using Ombi.Api.Interfaces;
|
||||
using Ombi.Api.Models.Emby;
|
||||
using Ombi.Helpers;
|
||||
using Polly;
|
||||
using RestSharp;
|
||||
|
||||
namespace Ombi.Api
|
||||
{
|
||||
public class EmbyApi : IEmbyApi
|
||||
{
|
||||
public EmbyApi()
|
||||
{
|
||||
Api = new ApiRequest();
|
||||
}
|
||||
|
||||
private ApiRequest Api { get; }
|
||||
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
/// <summary>
|
||||
/// Returns all users from the Emby Instance
|
||||
/// </summary>
|
||||
/// <param name="baseUri"></param>
|
||||
/// <param name="apiKey"></param>
|
||||
public List<EmbyUser> GetUsers(Uri baseUri, string apiKey)
|
||||
{
|
||||
var request = new RestRequest
|
||||
{
|
||||
Resource = "emby/users",
|
||||
Method = Method.GET
|
||||
};
|
||||
|
||||
AddHeaders(request, apiKey);
|
||||
|
||||
var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) => Log.Error(exception, "Exception when calling GetUsers for Emby, Retrying {0}", timespan), new[] {
|
||||
TimeSpan.FromSeconds (1),
|
||||
});
|
||||
|
||||
var obj = policy.Execute(() => Api.ExecuteJson<List<EmbyUser>>(request, baseUri));
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
public EmbySystemInfo GetSystemInformation(string apiKey, Uri baseUrl)
|
||||
{
|
||||
var request = new RestRequest
|
||||
{
|
||||
Resource = "emby/System/Info",
|
||||
Method = Method.GET
|
||||
};
|
||||
|
||||
AddHeaders(request, apiKey);
|
||||
|
||||
var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) => Log.Error(exception, "Exception when calling GetSystemInformation for Emby, Retrying {0}", timespan), new[] {
|
||||
TimeSpan.FromSeconds (1),
|
||||
TimeSpan.FromSeconds(5)
|
||||
});
|
||||
|
||||
var obj = policy.Execute(() => Api.ExecuteJson<EmbySystemInfo>(request, baseUrl));
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
public EmbyItemContainer<EmbyLibrary> ViewLibrary(string apiKey, string userId, Uri baseUri)
|
||||
{
|
||||
var request = new RestRequest
|
||||
{
|
||||
Resource = "emby/users/{userId}/items",
|
||||
Method = Method.GET
|
||||
};
|
||||
|
||||
request.AddUrlSegment("userId", userId);
|
||||
AddHeaders(request, apiKey);
|
||||
|
||||
var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) => Log.Error(exception, "Exception when calling ViewLibrary for Emby, Retrying {0}", timespan), new[] {
|
||||
TimeSpan.FromSeconds (1),
|
||||
TimeSpan.FromSeconds(5)
|
||||
});
|
||||
|
||||
var obj = policy.Execute(() => Api.ExecuteJson<EmbyItemContainer<EmbyLibrary>>(request, baseUri));
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
public EmbyItemContainer<EmbyMovieItem> GetAllMovies(string apiKey, string userId, Uri baseUri)
|
||||
{
|
||||
return GetAll<EmbyMovieItem>("Movie", apiKey, userId, baseUri);
|
||||
}
|
||||
|
||||
public EmbyItemContainer<EmbyEpisodeItem> GetAllEpisodes(string apiKey, string userId, Uri baseUri)
|
||||
{
|
||||
return GetAll<EmbyEpisodeItem>("Episode", apiKey, userId, baseUri);
|
||||
}
|
||||
|
||||
public EmbyItemContainer<EmbyMovieInformation> GetCollection(string mediaId, string apiKey, string userId, Uri baseUrl)
|
||||
{
|
||||
var request = new RestRequest
|
||||
{
|
||||
Resource = "emby/users/{userId}/items?parentId={mediaId}",
|
||||
Method = Method.GET
|
||||
};
|
||||
|
||||
request.AddUrlSegment("userId", userId);
|
||||
request.AddUrlSegment("mediaId", mediaId);
|
||||
|
||||
AddHeaders(request, apiKey);
|
||||
|
||||
|
||||
var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) => Log.Error(exception, "Exception when calling GetCollections for Emby, Retrying {0}", timespan), new[] {
|
||||
TimeSpan.FromSeconds (1),
|
||||
TimeSpan.FromSeconds(5)
|
||||
});
|
||||
return policy.Execute(() => Api.ExecuteJson<EmbyItemContainer<EmbyMovieInformation>>(request, baseUrl));
|
||||
}
|
||||
|
||||
public EmbyInformation GetInformation(string mediaId, EmbyMediaType type, string apiKey, string userId, Uri baseUri)
|
||||
{
|
||||
var request = new RestRequest
|
||||
{
|
||||
Resource = "emby/users/{userId}/items/{mediaId}",
|
||||
Method = Method.GET
|
||||
};
|
||||
|
||||
request.AddUrlSegment("userId", userId);
|
||||
request.AddUrlSegment("mediaId", mediaId);
|
||||
|
||||
AddHeaders(request, apiKey);
|
||||
|
||||
|
||||
var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) => Log.Error(exception, "Exception when calling GetAll<T>({1}) for Emby, Retrying {0}", timespan, type), new[] {
|
||||
TimeSpan.FromSeconds (1),
|
||||
TimeSpan.FromSeconds(5)
|
||||
});
|
||||
|
||||
IRestResponse response = null;
|
||||
try
|
||||
{
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case EmbyMediaType.Movie:
|
||||
response = policy.Execute(() => Api.Execute(request, baseUri));
|
||||
break;
|
||||
|
||||
case EmbyMediaType.Series:
|
||||
response = policy.Execute(() => Api.Execute(request, baseUri));
|
||||
break;
|
||||
case EmbyMediaType.Music:
|
||||
break;
|
||||
case EmbyMediaType.Episode:
|
||||
response = policy.Execute(() => Api.Execute(request, baseUri));
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(type), type, null);
|
||||
}
|
||||
|
||||
var info = new EmbyInformation();
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case EmbyMediaType.Movie:
|
||||
return new EmbyInformation
|
||||
{
|
||||
MovieInformation = JsonConvert.DeserializeObject<EmbyMovieInformation>(response.Content)
|
||||
};
|
||||
case EmbyMediaType.Series:
|
||||
return new EmbyInformation
|
||||
{
|
||||
SeriesInformation = JsonConvert.DeserializeObject<EmbySeriesInformation>(response.Content)
|
||||
};
|
||||
case EmbyMediaType.Music:
|
||||
break;
|
||||
case EmbyMediaType.Episode:
|
||||
return new EmbyInformation
|
||||
{
|
||||
EpisodeInformation = JsonConvert.DeserializeObject<EmbyEpisodeInformation>(response.Content)
|
||||
};
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(type), type, null);
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error("Could not get the media item's information");
|
||||
Log.Error(e);
|
||||
Log.Debug("ResponseContent");
|
||||
Log.Debug(response?.Content ?? "Empty");
|
||||
Log.Debug("ResponseStatusCode");
|
||||
Log.Debug(response?.StatusCode ?? HttpStatusCode.PreconditionFailed);
|
||||
|
||||
Log.Debug("ResponseError");
|
||||
Log.Debug(response?.ErrorMessage ?? "No Error");
|
||||
Log.Debug("ResponseException");
|
||||
Log.Debug(response?.ErrorException ?? new Exception());
|
||||
|
||||
|
||||
|
||||
throw;
|
||||
}
|
||||
return new EmbyInformation();
|
||||
}
|
||||
|
||||
|
||||
public EmbyItemContainer<EmbySeriesItem> GetAllShows(string apiKey, string userId, Uri baseUri)
|
||||
{
|
||||
return GetAll<EmbySeriesItem>("Series", apiKey, userId, baseUri);
|
||||
}
|
||||
|
||||
public EmbyUser LogIn(string username, string password, string apiKey, Uri baseUri)
|
||||
{
|
||||
var request = new RestRequest
|
||||
{
|
||||
Resource = "emby/users/authenticatebyname",
|
||||
Method = Method.POST
|
||||
};
|
||||
|
||||
var body = new
|
||||
{
|
||||
username,
|
||||
password = StringHasher.GetSha1Hash(password).ToLower(),
|
||||
passwordMd5 = StringHasher.CalcuateMd5Hash(password)
|
||||
};
|
||||
|
||||
request.AddJsonBody(body);
|
||||
|
||||
request.AddHeader("X-Emby-Authorization",
|
||||
$"MediaBrowser Client=\"Ombi\", Device=\"Ombi\", DeviceId=\"{AssemblyHelper.GetProductVersion()}\", Version=\"{AssemblyHelper.GetAssemblyVersion()}\"");
|
||||
AddHeaders(request, apiKey);
|
||||
|
||||
|
||||
var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) => Log.Error(exception, "Exception when calling LogInfor Emby, Retrying {0}", timespan), new[] {
|
||||
TimeSpan.FromSeconds (1)
|
||||
});
|
||||
|
||||
var obj = policy.Execute(() => Api.Execute(request, baseUri));
|
||||
|
||||
if (obj.StatusCode == HttpStatusCode.Unauthorized)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return JsonConvert.DeserializeObject<EmbyUserLogin>(obj.Content)?.User;
|
||||
}
|
||||
|
||||
private EmbyItemContainer<T> GetAll<T>(string type, string apiKey, string userId, Uri baseUri)
|
||||
{
|
||||
var request = new RestRequest
|
||||
{
|
||||
Resource = "emby/users/{userId}/items",
|
||||
Method = Method.GET
|
||||
};
|
||||
|
||||
request.AddUrlSegment("userId", userId);
|
||||
request.AddQueryParameter("Recursive", true.ToString());
|
||||
request.AddQueryParameter("IncludeItemTypes", type);
|
||||
|
||||
AddHeaders(request, apiKey);
|
||||
|
||||
|
||||
var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) => Log.Error(exception, "Exception when calling GetAll<T>({1}) for Emby, Retrying {0}", timespan, type), new[] {
|
||||
TimeSpan.FromSeconds (1),
|
||||
TimeSpan.FromSeconds(5)
|
||||
});
|
||||
|
||||
var obj = policy.Execute(() => Api.ExecuteJson<EmbyItemContainer<T>>(request, baseUri));
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
private static void AddHeaders(IRestRequest req, string apiKey)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(apiKey))
|
||||
{
|
||||
req.AddHeader("X-MediaBrowser-Token", apiKey);
|
||||
}
|
||||
req.AddHeader("Accept", "application/json");
|
||||
req.AddHeader("Content-Type", "application/json");
|
||||
req.AddHeader("Device", "Ombi");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -70,10 +70,15 @@
|
|||
<HintPath>..\packages\TraktApiSharp.0.8.0\lib\portable-net45+netcore45+wpa81\TraktApiSharp.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="WebSocket4Net, Version=0.14.1.0, Culture=neutral, PublicKeyToken=eb4e154b696bf72a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\WebSocket4Net.0.14.1\lib\net45\WebSocket4Net.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ApiRequest.cs" />
|
||||
<Compile Include="AppveyorApi.cs" />
|
||||
<Compile Include="DiscordApi.cs" />
|
||||
<Compile Include="EmbyApi.cs" />
|
||||
<Compile Include="NetflixRouletteApi.cs" />
|
||||
<Compile Include="RadarrApi.cs" />
|
||||
<Compile Include="TraktApi.cs" />
|
||||
|
|
|
@ -62,6 +62,20 @@ namespace Ombi.Api
|
|||
|
||||
return obj;
|
||||
}
|
||||
public List<SonarrRootFolder> GetRootFolders(string apiKey, Uri baseUrl)
|
||||
{
|
||||
var request = new RestRequest { Resource = "/api/rootfolder", Method = Method.GET };
|
||||
|
||||
request.AddHeader("X-Api-Key", apiKey);
|
||||
var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) => Log.Error(exception, "Exception when calling GetRootFolders for Radarr, Retrying {0}", timespan), new TimeSpan[] {
|
||||
TimeSpan.FromSeconds (1),
|
||||
TimeSpan.FromSeconds(2)
|
||||
});
|
||||
|
||||
var obj = policy.Execute(() => Api.ExecuteJson<List<SonarrRootFolder>>(request, baseUrl));
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
public RadarrAddMovie AddMovie(int tmdbId, string title, int year, int qualityId, string rootPath, string apiKey, Uri baseUrl, bool searchNow = false)
|
||||
{
|
||||
|
@ -94,7 +108,6 @@ namespace Ombi.Api
|
|||
request.AddHeader("X-Api-Key", apiKey);
|
||||
request.AddJsonBody(options);
|
||||
|
||||
RadarrAddMovie result;
|
||||
try
|
||||
{
|
||||
var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) => Log.Error(exception, "Exception when calling AddSeries for Sonarr, Retrying {0}", timespan), new TimeSpan[] {
|
||||
|
@ -139,7 +152,7 @@ namespace Ombi.Api
|
|||
}
|
||||
|
||||
|
||||
public List<RadarrMovieResponse> GetMovies(string apiKey, Uri baseUrl)
|
||||
public RadarrMovieContainer GetMovies(string apiKey, Uri baseUrl)
|
||||
{
|
||||
var request = new RestRequest { Resource = "/api/movie", Method = Method.GET };
|
||||
request.AddHeader("X-Api-Key", apiKey);
|
||||
|
@ -152,7 +165,7 @@ namespace Ombi.Api
|
|||
|
||||
var obj = policy.Execute(() => Api.Execute(request, baseUrl));
|
||||
|
||||
return JsonConvert.DeserializeObject<List<RadarrMovieResponse>>(obj.Content);
|
||||
return JsonConvert.DeserializeObject<RadarrMovieContainer>(obj.Content);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -52,9 +52,9 @@ namespace Ombi.Api
|
|||
|
||||
request.AddHeader("X-Api-Key", apiKey);
|
||||
var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) => Log.Error(exception, "Exception when calling GetProfiles for Sonarr, Retrying {0}", timespan), new TimeSpan[] {
|
||||
TimeSpan.FromSeconds (2),
|
||||
TimeSpan.FromSeconds(5),
|
||||
TimeSpan.FromSeconds(10)
|
||||
TimeSpan.FromSeconds (1),
|
||||
TimeSpan.FromSeconds(2),
|
||||
TimeSpan.FromSeconds(5)
|
||||
});
|
||||
|
||||
var obj = policy.Execute(() => Api.ExecuteJson<List<SonarrProfile>>(request, baseUrl));
|
||||
|
@ -68,9 +68,9 @@ namespace Ombi.Api
|
|||
|
||||
request.AddHeader("X-Api-Key", apiKey);
|
||||
var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) => Log.Error(exception, "Exception when calling GetRootFolders for Sonarr, Retrying {0}", timespan), new TimeSpan[] {
|
||||
TimeSpan.FromSeconds (2),
|
||||
TimeSpan.FromSeconds(5),
|
||||
TimeSpan.FromSeconds(10)
|
||||
TimeSpan.FromSeconds (1),
|
||||
TimeSpan.FromSeconds(2),
|
||||
TimeSpan.FromSeconds(5)
|
||||
});
|
||||
|
||||
var obj = policy.Execute(() => Api.ExecuteJson<List<SonarrRootFolder>>(request, baseUrl));
|
||||
|
|
|
@ -37,6 +37,8 @@ using TMDbLib.Objects.General;
|
|||
using TMDbLib.Objects.Movies;
|
||||
using TMDbLib.Objects.Search;
|
||||
using Movie = TMDbLib.Objects.Movies.Movie;
|
||||
using TMDbLib.Objects.People;
|
||||
using System.Linq;
|
||||
|
||||
namespace Ombi.Api
|
||||
{
|
||||
|
@ -69,6 +71,11 @@ namespace Ombi.Api
|
|||
return movies?.Results ?? new List<MovieResult>();
|
||||
}
|
||||
|
||||
private async Task<Movie> GetMovie(int id)
|
||||
{
|
||||
return await Client.GetMovie(id);
|
||||
}
|
||||
|
||||
public TmdbMovieDetails GetMovieInformationWithVideos(int tmdbId)
|
||||
{
|
||||
var request = new RestRequest { Resource = "movie/{movieId}", Method = Method.GET };
|
||||
|
@ -100,5 +107,49 @@ namespace Ombi.Api
|
|||
var movies = await Client.GetMovie(imdbId);
|
||||
return movies ?? new Movie();
|
||||
}
|
||||
|
||||
public async Task<List<Movie>> SearchPerson(string searchTerm)
|
||||
{
|
||||
return await SearchPerson(searchTerm, null);
|
||||
}
|
||||
|
||||
public async Task<List<Movie>> SearchPerson(string searchTerm, Func<int, string, string, Task<bool>> alreadyAvailable)
|
||||
{
|
||||
SearchContainer<SearchPerson> result = await Client.SearchPerson(searchTerm);
|
||||
|
||||
var people = result?.Results ?? new List<SearchPerson>();
|
||||
var person = (people.Count != 0 ? people[0] : null);
|
||||
var movies = new List<Movie>();
|
||||
var counter = 0;
|
||||
try
|
||||
{
|
||||
if (person != null)
|
||||
{
|
||||
var credits = await Client.GetPersonMovieCredits(person.Id);
|
||||
|
||||
// grab results from both cast and crew, prefer items in cast. we can handle directors like this.
|
||||
List<Movie> movieResults = (from MovieRole role in credits.Cast select new Movie() { Id = role.Id, Title = role.Title, ReleaseDate = role.ReleaseDate }).ToList();
|
||||
movieResults.AddRange((from MovieJob job in credits.Crew select new Movie() { Id = job.Id, Title = job.Title, ReleaseDate = job.ReleaseDate }).ToList());
|
||||
|
||||
//only get the first 10 movies and delay a bit between each request so we don't overload the API
|
||||
foreach (var m in movieResults)
|
||||
{
|
||||
if (counter == 10)
|
||||
break;
|
||||
if (alreadyAvailable == null || !(await alreadyAvailable(m.Id, m.Title, m.ReleaseDate.Value.Year.ToString())))
|
||||
{
|
||||
movies.Add(await GetMovie(m.Id));
|
||||
counter++;
|
||||
}
|
||||
await Task.Delay(50);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Log(LogLevel.Error, e);
|
||||
}
|
||||
return movies;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using NLog;
|
||||
using Ombi.Api.Models.Tv;
|
||||
using RestSharp;
|
||||
|
@ -90,21 +91,29 @@ namespace Ombi.Api
|
|||
};
|
||||
request.AddUrlSegment("id", theTvDbId.ToString());
|
||||
request.AddHeader("Content-Type", "application/json");
|
||||
|
||||
var obj = Api.Execute<TvMazeShow>(request, new Uri(Uri));
|
||||
|
||||
var episodes = EpisodeLookup(obj.id).ToList();
|
||||
|
||||
foreach (var e in episodes)
|
||||
try
|
||||
{
|
||||
obj.Season.Add(new TvMazeCustomSeason
|
||||
var result = Api.Execute(request, new Uri(Uri));
|
||||
var obj = JsonConvert.DeserializeObject<TvMazeShow>(result.Content);
|
||||
|
||||
var episodes = EpisodeLookup(obj.id).ToList();
|
||||
|
||||
foreach (var e in episodes)
|
||||
{
|
||||
SeasonNumber = e.season,
|
||||
EpisodeNumber = e.number
|
||||
});
|
||||
obj.Season.Add(new TvMazeCustomSeason
|
||||
{
|
||||
SeasonNumber = e.season,
|
||||
EpisodeNumber = e.number
|
||||
});
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
return obj;
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public List<TvMazeSeasons> GetSeasons(int id)
|
||||
|
|
|
@ -9,4 +9,5 @@
|
|||
<package id="System.Net.Http" version="4.0.0" targetFramework="net45" />
|
||||
<package id="TMDbLib" version="0.9.0.0-alpha" targetFramework="net45" />
|
||||
<package id="TraktApiSharp" version="0.8.0" targetFramework="net45" />
|
||||
<package id="WebSocket4Net" version="0.14.1" targetFramework="net45" />
|
||||
</packages>
|
Loading…
Add table
Add a link
Reference in a new issue