2011-11-13 21:51:15 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ServiceModel.Syndication;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
using Ninject;
|
2012-02-11 01:48:20 +01:00
|
|
|
|
using NzbDrone.Common;
|
2011-11-13 21:51:15 +01:00
|
|
|
|
using NzbDrone.Core.Model;
|
|
|
|
|
using NzbDrone.Core.Providers.Core;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Providers.Indexer
|
|
|
|
|
{
|
|
|
|
|
public class Newznab : IndexerBase
|
|
|
|
|
{
|
|
|
|
|
private readonly NewznabProvider _newznabProvider;
|
|
|
|
|
|
|
|
|
|
[Inject]
|
|
|
|
|
public Newznab(HttpProvider httpProvider, ConfigProvider configProvider, NewznabProvider newznabProvider)
|
|
|
|
|
: base(httpProvider, configProvider)
|
2011-11-29 07:49:38 +01:00
|
|
|
|
{
|
|
|
|
|
_newznabProvider = newznabProvider;
|
|
|
|
|
}
|
2011-11-13 21:51:15 +01:00
|
|
|
|
|
|
|
|
|
protected override string[] Urls
|
|
|
|
|
{
|
|
|
|
|
get { return GetUrls(); }
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-01 02:37:36 +01:00
|
|
|
|
public override bool IsConfigured
|
|
|
|
|
{
|
|
|
|
|
get { return true; }
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-29 07:49:38 +01:00
|
|
|
|
protected override IList<string> GetEpisodeSearchUrls(string seriesTitle, int seasonNumber, int episodeNumber)
|
2011-11-13 21:51:15 +01:00
|
|
|
|
{
|
2011-11-29 07:49:38 +01:00
|
|
|
|
var searchUrls = new List<string>();
|
2011-11-13 21:51:15 +01:00
|
|
|
|
|
2011-11-29 07:49:38 +01:00
|
|
|
|
foreach (var url in Urls)
|
|
|
|
|
{
|
|
|
|
|
searchUrls.Add(String.Format("{0}&limit=100&q={1}&season{2}&ep{3}", url, seriesTitle, seasonNumber, episodeNumber));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return searchUrls;
|
2011-11-13 21:51:15 +01:00
|
|
|
|
}
|
|
|
|
|
|
2011-11-29 07:49:38 +01:00
|
|
|
|
protected override IList<string> GetDailyEpisodeSearchUrls(string seriesTitle, DateTime date)
|
2011-11-13 21:51:15 +01:00
|
|
|
|
{
|
2011-11-29 07:49:38 +01:00
|
|
|
|
var searchUrls = new List<string>();
|
2011-11-13 21:51:15 +01:00
|
|
|
|
|
|
|
|
|
foreach (var url in Urls)
|
|
|
|
|
{
|
2011-11-29 07:49:38 +01:00
|
|
|
|
searchUrls.Add(String.Format("{0}&limit=100&q={1}+{2:yyyy MM dd}", url, seriesTitle, date));
|
2011-11-13 21:51:15 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return searchUrls;
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-29 07:49:38 +01:00
|
|
|
|
protected override IList<string> GetSeasonSearchUrls(string seriesTitle, int seasonNumber)
|
|
|
|
|
{
|
|
|
|
|
return new List<string>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override IList<string> GetPartialSeasonSearchUrls(string seriesTitle, int seasonNumber, int episodeWildcard)
|
|
|
|
|
{
|
|
|
|
|
return new List<string>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string Name
|
|
|
|
|
{
|
|
|
|
|
get { return "Newznab"; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override string NzbDownloadUrl(SyndicationItem item)
|
|
|
|
|
{
|
2012-02-27 21:36:04 +01:00
|
|
|
|
return item.Links[0].Uri.ToString();
|
2011-11-29 07:49:38 +01:00
|
|
|
|
}
|
2012-05-02 21:02:39 +02:00
|
|
|
|
|
|
|
|
|
protected override string NzbInfoUrl(SyndicationItem item)
|
|
|
|
|
{
|
2012-05-03 00:42:21 +02:00
|
|
|
|
return item.Id;
|
2012-05-02 21:02:39 +02:00
|
|
|
|
}
|
2011-11-29 07:49:38 +01:00
|
|
|
|
|
2011-11-13 21:51:15 +01:00
|
|
|
|
protected override EpisodeParseResult CustomParser(SyndicationItem item, EpisodeParseResult currentResult)
|
|
|
|
|
{
|
|
|
|
|
if (currentResult != null)
|
|
|
|
|
{
|
2012-02-27 21:36:04 +01:00
|
|
|
|
if (item.Links.Count > 1)
|
|
|
|
|
currentResult.Size = item.Links[1].Length;
|
2011-11-13 21:51:15 +01:00
|
|
|
|
}
|
2012-02-18 22:18:00 +01:00
|
|
|
|
|
2011-11-13 21:51:15 +01:00
|
|
|
|
return currentResult;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string[] GetUrls()
|
|
|
|
|
{
|
|
|
|
|
var urls = new List<string>();
|
2012-02-27 21:36:04 +01:00
|
|
|
|
var newznabIndexers = _newznabProvider.Enabled();
|
2011-11-13 21:51:15 +01:00
|
|
|
|
|
2012-02-27 21:36:04 +01:00
|
|
|
|
foreach (var newznabDefinition in newznabIndexers)
|
2011-11-13 21:51:15 +01:00
|
|
|
|
{
|
|
|
|
|
if (!String.IsNullOrWhiteSpace(newznabDefinition.ApiKey))
|
|
|
|
|
urls.Add(String.Format("{0}/api?t=tvsearch&cat=5030,5040&apikey={1}", newznabDefinition.Url,
|
|
|
|
|
newznabDefinition.ApiKey));
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
urls.Add(String.Format("{0}/api?t=tvsearch&cat=5030,5040", newznabDefinition.Url));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return urls.ToArray();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|