mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-20 21:43:33 -07:00
Properly using Xem now
This commit is contained in:
parent
4b5d20cefe
commit
c9c967fa1d
15 changed files with 438 additions and 1 deletions
66
NzbDrone.Core/Providers/XemCommunicationProvider.cs
Normal file
66
NzbDrone.Core/Providers/XemCommunicationProvider.cs
Normal file
|
@ -0,0 +1,66 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NLog;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Ninject;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Model.Xem;
|
||||
|
||||
namespace NzbDrone.Core.Providers
|
||||
{
|
||||
public class XemCommunicationProvider
|
||||
{
|
||||
private readonly HttpProvider _httpProvider;
|
||||
|
||||
private static readonly Logger _logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
private const string XEM_BASE_URL = "http://thexem.de/map/";
|
||||
|
||||
[Inject]
|
||||
public XemCommunicationProvider(HttpProvider httpProvider)
|
||||
{
|
||||
_httpProvider = httpProvider;
|
||||
}
|
||||
|
||||
public XemCommunicationProvider()
|
||||
{
|
||||
}
|
||||
|
||||
public virtual List<Int32> GetXemSeriesIds(string origin = "tvdb")
|
||||
{
|
||||
_logger.Trace("Fetching Series IDs from: {0}", origin);
|
||||
var url = String.Format("{0}allNames?origin={1}", XEM_BASE_URL, origin);
|
||||
var response =_httpProvider.DownloadString(url);
|
||||
|
||||
CheckForFailureResult(response);
|
||||
|
||||
var result = JsonConvert.DeserializeObject<Dictionary<int, List<String>>>(JObject.Parse(response).SelectToken("data").ToString());
|
||||
|
||||
return result.Keys.ToList();
|
||||
}
|
||||
|
||||
public virtual List<XemSceneTvdbMapping> GetSceneTvdbMappings(int id)
|
||||
{
|
||||
_logger.Trace("Fetching Mappings for: {0}", id);
|
||||
var url = String.Format("{0}all?id={1}&origin=tvdb", XEM_BASE_URL, id);
|
||||
var response = _httpProvider.DownloadString(url);
|
||||
|
||||
CheckForFailureResult(response);
|
||||
|
||||
var result = JsonConvert.DeserializeObject<List<XemSceneTvdbMapping>>(JObject.Parse(response).SelectToken("data").ToString());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public virtual void CheckForFailureResult(string response)
|
||||
{
|
||||
var result = JsonConvert.DeserializeObject<XemResult<dynamic>>(response);
|
||||
|
||||
if (result != null && result.Result.Equals("failure", StringComparison.InvariantCultureIgnoreCase))
|
||||
throw new Exception("Error response received from Xem: " + result.Message);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue