2018-04-01 18:21:24 +00:00
|
|
|
using System;
|
2018-03-14 20:41:36 +00:00
|
|
|
using System.Collections.Generic;
|
2015-05-24 22:47:48 +00:00
|
|
|
using System.Linq;
|
2019-12-29 01:26:07 +00:00
|
|
|
using NzbDrone.Common.Extensions;
|
2015-04-14 04:30:02 +00:00
|
|
|
using NzbDrone.Common.Http;
|
|
|
|
using NzbDrone.Common.Serializer;
|
2015-05-24 22:47:48 +00:00
|
|
|
using NzbDrone.Core.IndexerSearch.Definitions;
|
2015-04-14 04:30:02 +00:00
|
|
|
|
|
|
|
namespace NzbDrone.Core.Indexers.HDBits
|
|
|
|
{
|
2015-05-24 22:47:48 +00:00
|
|
|
public class HDBitsRequestGenerator : IIndexerRequestGenerator
|
2015-04-14 04:30:02 +00:00
|
|
|
{
|
2015-05-24 22:47:48 +00:00
|
|
|
public HDBitsSettings Settings { get; set; }
|
2015-04-14 04:30:02 +00:00
|
|
|
|
2015-10-09 18:56:40 +00:00
|
|
|
public virtual IndexerPageableRequestChain GetRecentRequests()
|
2015-04-14 04:30:02 +00:00
|
|
|
{
|
2015-10-09 18:56:40 +00:00
|
|
|
var pageableRequests = new IndexerPageableRequestChain();
|
2015-04-14 04:30:02 +00:00
|
|
|
pageableRequests.Add(GetRequest(new TorrentQuery()));
|
|
|
|
return pageableRequests;
|
|
|
|
}
|
|
|
|
|
2017-01-28 21:46:54 +00:00
|
|
|
public virtual IndexerPageableRequestChain GetSearchRequests(MovieSearchCriteria searchCriteria)
|
2015-04-14 04:30:02 +00:00
|
|
|
{
|
2017-01-09 17:28:08 +00:00
|
|
|
var pageableRequests = new IndexerPageableRequestChain();
|
2019-12-29 01:26:07 +00:00
|
|
|
var query = new TorrentQuery();
|
2017-01-28 21:46:54 +00:00
|
|
|
|
2019-12-29 01:26:07 +00:00
|
|
|
if (TryAddSearchParameters(query, searchCriteria))
|
2017-01-28 21:46:54 +00:00
|
|
|
{
|
|
|
|
pageableRequests.Add(GetRequest(query));
|
|
|
|
}
|
|
|
|
|
2017-01-09 17:28:08 +00:00
|
|
|
return pageableRequests;
|
2015-04-14 04:30:02 +00:00
|
|
|
}
|
|
|
|
|
2017-01-28 21:46:54 +00:00
|
|
|
private bool TryAddSearchParameters(TorrentQuery query, SearchCriteriaBase searchCriteria)
|
|
|
|
{
|
2019-12-29 01:26:07 +00:00
|
|
|
if (searchCriteria.Movie.ImdbId.IsNullOrWhiteSpace())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-01-28 21:46:54 +00:00
|
|
|
var imdbId = int.Parse(searchCriteria.Movie.ImdbId.Substring(2));
|
|
|
|
|
|
|
|
if (imdbId != 0)
|
|
|
|
{
|
|
|
|
query.ImdbInfo = query.ImdbInfo ?? new ImdbInfo();
|
|
|
|
query.ImdbInfo.Id = imdbId;
|
|
|
|
return true;
|
|
|
|
}
|
2019-12-22 22:08:53 +00:00
|
|
|
|
2017-01-28 21:46:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
2019-12-22 21:24:11 +00:00
|
|
|
|
2018-04-01 18:21:24 +00:00
|
|
|
public Func<IDictionary<string, string>> GetCookies { get; set; }
|
|
|
|
public Action<IDictionary<string, string>, DateTime?> CookiesUpdater { get; set; }
|
2017-01-28 21:46:54 +00:00
|
|
|
|
2015-04-14 04:30:02 +00:00
|
|
|
private IEnumerable<IndexerRequest> GetRequest(TorrentQuery query)
|
|
|
|
{
|
2016-02-28 15:41:22 +00:00
|
|
|
var request = new HttpRequestBuilder(Settings.BaseUrl)
|
|
|
|
.Resource("/api/torrents")
|
|
|
|
.Build();
|
2015-04-14 04:30:02 +00:00
|
|
|
|
|
|
|
request.Method = HttpMethod.POST;
|
|
|
|
const string appJson = "application/json";
|
|
|
|
request.Headers.Accept = appJson;
|
|
|
|
request.Headers.ContentType = appJson;
|
|
|
|
|
|
|
|
query.Username = Settings.Username;
|
|
|
|
query.Passkey = Settings.ApiKey;
|
|
|
|
|
2017-05-29 15:56:16 +00:00
|
|
|
query.Category = Settings.Categories.ToArray();
|
|
|
|
query.Codec = Settings.Codecs.ToArray();
|
|
|
|
query.Medium = Settings.Mediums.ToArray();
|
|
|
|
|
2016-02-28 15:41:22 +00:00
|
|
|
request.SetContent(query.ToJson());
|
2015-04-14 04:30:02 +00:00
|
|
|
|
|
|
|
yield return new IndexerRequest(request);
|
|
|
|
}
|
|
|
|
}
|
2018-03-14 20:41:36 +00:00
|
|
|
}
|