added support for offset when queries seasons in newznab,

pull/3113/head
kay.one 11 years ago
parent a00587dbd4
commit 227e13d858

@ -24,7 +24,7 @@ namespace NzbDrone.Common
{
private readonly Logger _logger;
public const string CONTENT_LENGHT_HEADER = "Content-Length";
public const string CONTENT_LENGTH_HEADER = "Content-Length";
private readonly string _userAgent;

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace NzbDrone.Common
{
public static class IEnumerableExtensions
{
public static IEnumerable<TSource> DistinctBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
{
var knownKeys = new HashSet<TKey>();
return source.Where(element => knownKeys.Add(keySelector(element)));
}
}
}

@ -89,6 +89,7 @@
<Compile Include="EnvironmentInfo\RuntimeInfo.cs" />
<Compile Include="EnvironmentInfo\OsInfo.cs" />
<Compile Include="Exceptions\NzbDroneException.cs" />
<Compile Include="IEnumerableExtensions.cs" />
<Compile Include="Instrumentation\GlobalExceptionHandlers.cs" />
<Compile Include="Instrumentation\ExceptronTarget.cs" />
<Compile Include="PathEqualityComparer.cs" />

@ -48,7 +48,7 @@ namespace NzbDrone.Core.Test.MediaCoverTests
public void should_return_false_if_file_exists_but_diffrent_size()
{
GivenExistingFileSize(100);
_headers.Add(HttpProvider.CONTENT_LENGHT_HEADER, "200");
_headers.Add(HttpProvider.CONTENT_LENGTH_HEADER, "200");
Subject.AlreadyExists("http://url", "c:\\file.exe").Should().BeFalse();
}
@ -58,7 +58,7 @@ namespace NzbDrone.Core.Test.MediaCoverTests
public void should_return_ture_if_file_exists_and_same_size()
{
GivenExistingFileSize(100);
_headers.Add(HttpProvider.CONTENT_LENGHT_HEADER, "100");
_headers.Add(HttpProvider.CONTENT_LENGTH_HEADER, "100");
Subject.AlreadyExists("http://url", "c:\\file.exe").Should().BeTrue();
}

@ -22,5 +22,16 @@ namespace NzbDrone.Core.DecisionEngine
RemoteEpisode = episode;
Rejections = rejections.ToList();
}
public override string ToString()
{
if (Approved)
{
return "[OK] " + RemoteEpisode;
}
return "[Rejected " + Rejections.Count() + "]" + RemoteEpisode;
}
}
}

@ -1,19 +0,0 @@
namespace NzbDrone.Core.IndexerSearch.Definitions
{
public class PartialSeasonSearchCriteria : SeasonSearchCriteria
{
public int Prefix { get; set; }
public PartialSeasonSearchCriteria(SeasonSearchCriteria seasonSearch, int prefix)
{
Prefix = prefix;
SceneTitle = seasonSearch.SceneTitle;
SeasonNumber = seasonSearch.SeasonNumber;
}
public override string ToString()
{
return string.Format("[{0} : S{1:00}E{2:0}*]", SceneTitle, SeasonNumber, Prefix);
}
}
}

@ -19,6 +19,6 @@ namespace NzbDrone.Core.Indexers
IEnumerable<string> GetEpisodeSearchUrls(string seriesTitle, int tvRageId, int seasonNumber, int episodeNumber);
IEnumerable<string> GetDailyEpisodeSearchUrls(string seriesTitle, int tvRageId, DateTime date);
IEnumerable<string> GetSeasonSearchUrls(string seriesTitle, int tvRageId, int seasonNumber);
IEnumerable<string> GetSeasonSearchUrls(string seriesTitle, int tvRageId, int seasonNumber, int offset);
}
}

@ -36,6 +36,6 @@ namespace NzbDrone.Core.Indexers
public abstract IEnumerable<string> RecentFeed { get; }
public abstract IEnumerable<string> GetEpisodeSearchUrls(string seriesTitle, int tvRageId, int seasonNumber, int episodeNumber);
public abstract IEnumerable<string> GetDailyEpisodeSearchUrls(string seriesTitle, int tvRageId, DateTime date);
public abstract IEnumerable<string> GetSeasonSearchUrls(string seriesTitle, int tvRageId, int seasonNumber);
public abstract IEnumerable<string> GetSeasonSearchUrls(string seriesTitle, int tvRageId, int seasonNumber, int offset);
}
}

@ -5,6 +5,7 @@ using NLog;
using NzbDrone.Common;
using NzbDrone.Core.IndexerSearch.Definitions;
using NzbDrone.Core.Parser.Model;
using System.Linq;
namespace NzbDrone.Core.Indexers
{
@ -14,7 +15,6 @@ namespace NzbDrone.Core.Indexers
IList<ReportInfo> Fetch(IIndexer indexer, SeasonSearchCriteria searchCriteria);
IList<ReportInfo> Fetch(IIndexer indexer, SingleEpisodeSearchCriteria searchCriteria);
IList<ReportInfo> Fetch(IIndexer indexer, PartialSeasonSearchCriteria searchCriteria);
IList<ReportInfo> Fetch(IIndexer indexer, DailyEpisodeSearchCriteria searchCriteria);
}
@ -46,39 +46,46 @@ namespace NzbDrone.Core.Indexers
{
_logger.Debug("Searching for {0}", searchCriteria);
var searchUrls = indexer.GetSeasonSearchUrls(searchCriteria.QueryTitle, searchCriteria.SeriesTvRageId, searchCriteria.SeasonNumber);
var result = Fetch(indexer, searchUrls);
var result = Fetch(indexer, searchCriteria, 0).DistinctBy(c => c.NzbUrl).ToList();
_logger.Info("Finished searching {0} on {1}. Found {2}", indexer.Name, searchCriteria, result.Count);
return result;
}
public IList<ReportInfo> Fetch(IIndexer indexer, SingleEpisodeSearchCriteria searchCriteria)
private IList<ReportInfo> Fetch(IIndexer indexer, SeasonSearchCriteria searchCriteria, int offset)
{
_logger.Debug("Searching for {0}", searchCriteria);
_logger.Debug("Searching for {0} offset: {1}", searchCriteria, offset);
var searchUrls = indexer.GetEpisodeSearchUrls(searchCriteria.QueryTitle, searchCriteria.SeriesTvRageId, searchCriteria.SeasonNumber, searchCriteria.EpisodeNumber);
var searchUrls = indexer.GetSeasonSearchUrls(searchCriteria.QueryTitle, searchCriteria.SeriesTvRageId, searchCriteria.SeasonNumber, offset);
var result = Fetch(indexer, searchUrls);
_logger.Info("Finished searching {0} on {1}. Found {2}", indexer.Name, searchCriteria, result.Count);
return result;
_logger.Info("{0} offset {1}. Found {2}", indexer.Name, searchCriteria, result.Count);
if (result.Count > 90)
{
result.AddRange(Fetch(indexer, searchCriteria, offset + 90));
}
return result;
}
public IList<ReportInfo> Fetch(IIndexer indexer, PartialSeasonSearchCriteria searchCriteria)
public IList<ReportInfo> Fetch(IIndexer indexer, SingleEpisodeSearchCriteria searchCriteria)
{
_logger.Debug("Searching for {0}", searchCriteria);
var searchUrls = indexer.GetSeasonSearchUrls(searchCriteria.QueryTitle, searchCriteria.SeriesTvRageId, searchCriteria.SeasonNumber);
var searchUrls = indexer.GetEpisodeSearchUrls(searchCriteria.QueryTitle, searchCriteria.SeriesTvRageId, searchCriteria.SeasonNumber, searchCriteria.EpisodeNumber);
var result = Fetch(indexer, searchUrls);
_logger.Info("Finished searching {0} on {1}. Found {2}", indexer.Name, searchCriteria, result.Count);
return result;
}
public IList<ReportInfo> Fetch(IIndexer indexer, DailyEpisodeSearchCriteria searchCriteria)
{
_logger.Debug("Searching for {0}", searchCriteria);

@ -104,16 +104,17 @@ namespace NzbDrone.Core.Indexers.Newznab
return RecentFeed.Select(url => String.Format("{0}&limit=100&q={1}&season={2:yyyy}&ep={2:MM/dd}", url, NewsnabifyTitle(seriesTitle), date)).ToList();
}
public override IEnumerable<string> GetSeasonSearchUrls(string seriesTitle, int tvRageId, int seasonNumber)
public override IEnumerable<string> GetSeasonSearchUrls(string seriesTitle, int tvRageId, int seasonNumber, int offset)
{
if (tvRageId > 0)
{
return RecentFeed.Select(url => String.Format("{0}&limit=100&rid={1}&season={2}", url, tvRageId, seasonNumber));
return RecentFeed.Select(url => String.Format("{0}&limit=100&rid={1}&season={2}&offset={3}", url, tvRageId, seasonNumber, offset));
}
return RecentFeed.Select(url => String.Format("{0}&limit=100&q={1}&season={2}", url, NewsnabifyTitle(seriesTitle), seasonNumber));
return RecentFeed.Select(url => String.Format("{0}&limit=100&q={1}&season={2}&offset={3}", url, NewsnabifyTitle(seriesTitle), seasonNumber, offset));
}
public override string Name
{
get

@ -47,7 +47,7 @@ namespace NzbDrone.Core.Indexers.NzbClub
return searchUrls;
}
public override IEnumerable<string> GetSeasonSearchUrls(string seriesTitle, int tvRageId, int seasonNumber)
public override IEnumerable<string> GetSeasonSearchUrls(string seriesTitle, int tvRageId, int seasonNumber, int offset)
{
var searchUrls = new List<string>();

@ -52,7 +52,7 @@ namespace NzbDrone.Core.Indexers.Omgwtfnzbs
return searchUrls;
}
public override IEnumerable<string> GetSeasonSearchUrls(string seriesTitle, int tvRageId, int seasonNumber)
public override IEnumerable<string> GetSeasonSearchUrls(string seriesTitle, int tvRageId, int seasonNumber, int offset)
{
var searchUrls = new List<String>();

@ -28,7 +28,7 @@ namespace NzbDrone.Core.Indexers.Wombles
return new List<string>();
}
public override IEnumerable<string> GetSeasonSearchUrls(string seriesTitle, int tvRageId, int seasonNumber)
public override IEnumerable<string> GetSeasonSearchUrls(string seriesTitle, int tvRageId, int seasonNumber, int offset)
{
return new List<string>();
}

@ -33,7 +33,7 @@ namespace NzbDrone.Core.MediaCover
string sizeString;
if (headers.TryGetValue(HttpProvider.CONTENT_LENGHT_HEADER, out sizeString))
if (headers.TryGetValue(HttpProvider.CONTENT_LENGTH_HEADER, out sizeString))
{
int size;
int.TryParse(sizeString, out size);

@ -249,7 +249,6 @@
<Compile Include="Helpers\SortHelper.cs" />
<Compile Include="History\HistoryRepository.cs" />
<Compile Include="IndexerSearch\Definitions\DailyEpisodeSearchCriteria.cs" />
<Compile Include="IndexerSearch\Definitions\PartialSeasonSearchCriteria.cs" />
<Compile Include="IndexerSearch\Definitions\SearchCriteriaBase.cs" />
<Compile Include="IndexerSearch\Definitions\SeasonSearchCriteria.cs" />
<Compile Include="IndexerSearch\Definitions\SingleEpisodeSearchCriteria.cs" />

Loading…
Cancel
Save