|
|
|
@ -1,111 +1,119 @@
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
using NzbDrone.Common.Extensions;
|
|
|
|
|
using NzbDrone.Common.Http;
|
|
|
|
|
using NzbDrone.Core.IndexerSearch.Definitions;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Indexers.TitansOfTv
|
|
|
|
|
{
|
|
|
|
|
public class TitansOfTvRequestGenerator : IIndexerRequestGenerator
|
|
|
|
|
{
|
|
|
|
|
public int MaxPages { get; set; }
|
|
|
|
|
public int PageSize { get; set; }
|
|
|
|
|
public TitansOfTvSettings Settings { get; set; }
|
|
|
|
|
|
|
|
|
|
public TitansOfTvRequestGenerator()
|
|
|
|
|
{
|
|
|
|
|
MaxPages = 30;
|
|
|
|
|
PageSize = 100;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IList<IEnumerable<IndexerRequest>> GetRecentRequests()
|
|
|
|
|
{
|
|
|
|
|
var pageableRequests = new List<IEnumerable<IndexerRequest>>();
|
|
|
|
|
var innerList = new List<IndexerRequest>();
|
|
|
|
|
var httpRequest = BuildHttpRequest(GetBaseUrl());
|
|
|
|
|
|
|
|
|
|
innerList.Add(new IndexerRequest(httpRequest));
|
|
|
|
|
pageableRequests.Add(innerList);
|
|
|
|
|
pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages));
|
|
|
|
|
|
|
|
|
|
return pageableRequests;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private HttpRequest BuildHttpRequest(string url)
|
|
|
|
|
public IList<IEnumerable<IndexerRequest>> GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria)
|
|
|
|
|
{
|
|
|
|
|
var httpRequest = new HttpRequest(url, HttpAccept.Json);
|
|
|
|
|
httpRequest.Headers["X-Authorization"] = Settings.ApiKey;
|
|
|
|
|
var pageableRequests = new List<IEnumerable<IndexerRequest>>();
|
|
|
|
|
|
|
|
|
|
return httpRequest;
|
|
|
|
|
pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages,
|
|
|
|
|
series_id: searchCriteria.Series.TvdbId,
|
|
|
|
|
episode: string.Format("S{0:00}E{1:00}", searchCriteria.SeasonNumber, searchCriteria.EpisodeNumber)));
|
|
|
|
|
|
|
|
|
|
pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages,
|
|
|
|
|
series_id: searchCriteria.Series.TvdbId,
|
|
|
|
|
season: string.Format("Season {0:00}", searchCriteria.SeasonNumber)));
|
|
|
|
|
|
|
|
|
|
return pageableRequests;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IList<IEnumerable<IndexerRequest>> GetSearchRequests(IndexerSearch.Definitions.SingleEpisodeSearchCriteria searchCriteria)
|
|
|
|
|
public IList<IEnumerable<IndexerRequest>> GetSearchRequests(SeasonSearchCriteria searchCriteria)
|
|
|
|
|
{
|
|
|
|
|
var url = GetBaseUrl() + "&series_id={series}&episode={episode}";
|
|
|
|
|
var requests = new List<IEnumerable<IndexerRequest>>();
|
|
|
|
|
var innerList = new List<IndexerRequest>();
|
|
|
|
|
requests.Add(innerList);
|
|
|
|
|
var pageableRequests = new List<IEnumerable<IndexerRequest>>();
|
|
|
|
|
|
|
|
|
|
var httpRequest = BuildHttpRequest(url);
|
|
|
|
|
var episodeString = String.Format("S{0:00}E{1:00}", searchCriteria.SeasonNumber, searchCriteria.EpisodeNumber);
|
|
|
|
|
httpRequest.AddSegment("series", searchCriteria.Series.TvdbId.ToString(CultureInfo.InvariantCulture));
|
|
|
|
|
httpRequest.AddSegment("episode", episodeString);
|
|
|
|
|
// TODO: Search for all episodes?!?
|
|
|
|
|
|
|
|
|
|
var request = new IndexerRequest(httpRequest);
|
|
|
|
|
innerList.Add(request);
|
|
|
|
|
pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages,
|
|
|
|
|
series_id: searchCriteria.Series.TvdbId,
|
|
|
|
|
season: string.Format("Season {0:00}", searchCriteria.SeasonNumber)));
|
|
|
|
|
|
|
|
|
|
return requests;
|
|
|
|
|
return pageableRequests;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IList<IEnumerable<IndexerRequest>> GetSearchRequests(IndexerSearch.Definitions.SeasonSearchCriteria searchCriteria)
|
|
|
|
|
public IList<IEnumerable<IndexerRequest>> GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria)
|
|
|
|
|
{
|
|
|
|
|
var url = GetBaseUrl() + "&series_id={series}&season={season}";
|
|
|
|
|
var requests = new List<IEnumerable<IndexerRequest>>();
|
|
|
|
|
var innerList = new List<IndexerRequest>();
|
|
|
|
|
requests.Add(innerList);
|
|
|
|
|
|
|
|
|
|
var httpRequest = BuildHttpRequest(url);
|
|
|
|
|
var seasonString = String.Format("Season {0:00}", searchCriteria.SeasonNumber);
|
|
|
|
|
httpRequest.AddSegment("series", searchCriteria.Series.TvdbId.ToString(CultureInfo.InvariantCulture));
|
|
|
|
|
httpRequest.AddSegment("season", seasonString);
|
|
|
|
|
|
|
|
|
|
var request = new IndexerRequest(httpRequest);
|
|
|
|
|
innerList.Add(request);
|
|
|
|
|
|
|
|
|
|
httpRequest = BuildHttpRequest(url);
|
|
|
|
|
seasonString = String.Format("Season {0}", searchCriteria.SeasonNumber);
|
|
|
|
|
httpRequest.AddSegment("series", searchCriteria.Series.TvdbId.ToString(CultureInfo.InvariantCulture));
|
|
|
|
|
httpRequest.AddSegment("season", seasonString);
|
|
|
|
|
var pageableRequests = new List<IEnumerable<IndexerRequest>>();
|
|
|
|
|
|
|
|
|
|
request = new IndexerRequest(httpRequest);
|
|
|
|
|
innerList.Add(request);
|
|
|
|
|
pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages,
|
|
|
|
|
series_id: searchCriteria.Series.TvdbId,
|
|
|
|
|
air_date: searchCriteria.AirDate));
|
|
|
|
|
|
|
|
|
|
return requests;
|
|
|
|
|
return pageableRequests;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IList<IEnumerable<IndexerRequest>> GetSearchRequests(IndexerSearch.Definitions.DailyEpisodeSearchCriteria searchCriteria)
|
|
|
|
|
public IList<IEnumerable<IndexerRequest>> GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria)
|
|
|
|
|
{
|
|
|
|
|
var url = GetBaseUrl() + "&series_id={series}&air_date={air_date}";
|
|
|
|
|
var requests = new List<IEnumerable<IndexerRequest>>();
|
|
|
|
|
var innerList = new List<IndexerRequest>();
|
|
|
|
|
return new List<IEnumerable<IndexerRequest>>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
requests.Add(innerList);
|
|
|
|
|
public IList<IEnumerable<IndexerRequest>> GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria)
|
|
|
|
|
{
|
|
|
|
|
return new List<IEnumerable<IndexerRequest>>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var httpRequest = BuildHttpRequest(url);
|
|
|
|
|
var airDate = searchCriteria.AirDate.ToString("yyyy-MM-dd");
|
|
|
|
|
private IEnumerable<IndexerRequest> GetPagedRequests(int maxPages, int? series_id = null, string episode = null, string season = null, DateTime? air_date = null)
|
|
|
|
|
{
|
|
|
|
|
var pageSize = PageSize;
|
|
|
|
|
|
|
|
|
|
httpRequest.AddSegment("series", searchCriteria.Series.TvdbId.ToString(CultureInfo.InvariantCulture));
|
|
|
|
|
httpRequest.AddSegment("air_date", airDate);
|
|
|
|
|
if (pageSize == 0)
|
|
|
|
|
{
|
|
|
|
|
maxPages = 1;
|
|
|
|
|
pageSize = 100;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var request = new IndexerRequest(httpRequest);
|
|
|
|
|
innerList.Add(request);
|
|
|
|
|
for (var page = 0; page < maxPages; page++)
|
|
|
|
|
{
|
|
|
|
|
var request = new IndexerRequest(string.Format("{0}/torrents?offset={1}&limit={2}", Settings.BaseUrl.TrimEnd('/'), page * pageSize, pageSize), HttpAccept.Json);
|
|
|
|
|
request.HttpRequest.Headers.Add("X-Authorization", Settings.ApiKey);
|
|
|
|
|
|
|
|
|
|
return requests;
|
|
|
|
|
if (series_id.HasValue)
|
|
|
|
|
{
|
|
|
|
|
request.HttpRequest.AddQueryParam("series_id", series_id.Value.ToString(CultureInfo.InvariantCulture));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IList<IEnumerable<IndexerRequest>> GetSearchRequests(IndexerSearch.Definitions.AnimeEpisodeSearchCriteria searchCriteria)
|
|
|
|
|
if (season != null)
|
|
|
|
|
{
|
|
|
|
|
return new List<IEnumerable<IndexerRequest>>();
|
|
|
|
|
request.HttpRequest.AddQueryParam("season", season);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IList<IEnumerable<IndexerRequest>> GetSearchRequests(IndexerSearch.Definitions.SpecialEpisodeSearchCriteria searchCriteria)
|
|
|
|
|
if (episode != null)
|
|
|
|
|
{
|
|
|
|
|
return new List<IEnumerable<IndexerRequest>>();
|
|
|
|
|
request.HttpRequest.AddQueryParam("episode", episode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string GetBaseUrl()
|
|
|
|
|
if (air_date.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return Settings.BaseUrl + "?limit=100";
|
|
|
|
|
request.HttpRequest.AddQueryParam("air_date", air_date.Value.ToString("yyyy-MM-dd"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
yield return request;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|