2013-02-21 08:07:34 +01:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System;
|
2011-11-13 21:51:15 +01:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ServiceModel.Syndication;
|
|
|
|
|
using System.Text.RegularExpressions;
|
2012-02-11 01:48:20 +01:00
|
|
|
|
using NzbDrone.Common;
|
2013-02-24 07:48:52 +01:00
|
|
|
|
using NzbDrone.Core.Configuration;
|
2011-11-13 21:51:15 +01:00
|
|
|
|
using NzbDrone.Core.Model;
|
2013-02-21 08:07:34 +01:00
|
|
|
|
using NzbDrone.Core.Providers;
|
2011-11-13 21:51:15 +01:00
|
|
|
|
using NzbDrone.Core.Providers.Core;
|
|
|
|
|
|
2013-02-23 05:37:23 +01:00
|
|
|
|
namespace NzbDrone.Core.Indexers
|
2011-11-13 21:51:15 +01:00
|
|
|
|
{
|
|
|
|
|
public class Newznab : IndexerBase
|
|
|
|
|
{
|
2013-02-23 05:51:43 +01:00
|
|
|
|
private readonly INewznabService _newznabProvider;
|
2011-11-13 21:51:15 +01:00
|
|
|
|
|
2013-02-24 07:48:52 +01:00
|
|
|
|
public Newznab(HttpProvider httpProvider, IConfigService configService, INewznabService newznabProvider)
|
|
|
|
|
: base(httpProvider, configService)
|
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)
|
|
|
|
|
{
|
2012-11-15 18:17:47 +01:00
|
|
|
|
searchUrls.Add(String.Format("{0}&limit=100&q={1}&season={2}&ep={3}", url, seriesTitle, seasonNumber, episodeNumber));
|
2011-11-29 07:49:38 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
2013-02-02 21:35:46 +01:00
|
|
|
|
searchUrls.Add(String.Format("{0}&limit=100&q={1}&season={2:yyyy}&ep={2: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)
|
|
|
|
|
{
|
2012-08-22 01:44:17 +02:00
|
|
|
|
var searchUrls = new List<string>();
|
|
|
|
|
|
|
|
|
|
foreach (var url in Urls)
|
|
|
|
|
{
|
2012-11-15 18:17:47 +01:00
|
|
|
|
searchUrls.Add(String.Format("{0}&limit=100&q={1}&season={2}", url, seriesTitle, seasonNumber));
|
2012-08-22 01:44:17 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return searchUrls;
|
2011-11-29 07:49:38 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override IList<string> GetPartialSeasonSearchUrls(string seriesTitle, int seasonNumber, int episodeWildcard)
|
|
|
|
|
{
|
2012-08-22 01:44:17 +02:00
|
|
|
|
var searchUrls = new List<string>();
|
|
|
|
|
|
|
|
|
|
foreach (var url in Urls)
|
|
|
|
|
{
|
|
|
|
|
searchUrls.Add(String.Format("{0}&limit=100&q={1}+S{2:00}E{3}", url, seriesTitle, seasonNumber, episodeWildcard));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return searchUrls;
|
2011-11-29 07:49:38 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
2012-05-08 23:29:24 +02:00
|
|
|
|
|
|
|
|
|
currentResult.Indexer = GetName(item);
|
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))
|
2012-12-20 05:44:16 +01:00
|
|
|
|
urls.Add(String.Format("{0}/api?t=tvsearch&cat=5030,5040,5070,5090&apikey={1}", newznabDefinition.Url,
|
2011-11-13 21:51:15 +01:00
|
|
|
|
newznabDefinition.ApiKey));
|
|
|
|
|
|
|
|
|
|
else
|
2012-12-20 05:44:16 +01:00
|
|
|
|
urls.Add(String.Format("{0}/api?t=tvsearch&cat=5030,5040,5070,5090s", newznabDefinition.Url));
|
2011-11-13 21:51:15 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return urls.ToArray();
|
|
|
|
|
}
|
2012-05-08 23:29:24 +02:00
|
|
|
|
|
|
|
|
|
private string GetName(SyndicationItem item)
|
|
|
|
|
{
|
|
|
|
|
var hostname = item.Links[0].Uri.DnsSafeHost.ToLower();
|
|
|
|
|
return String.Format("{0}_{1}", Name, hostname);
|
|
|
|
|
}
|
2012-09-06 17:37:38 +02:00
|
|
|
|
|
|
|
|
|
public override string GetQueryTitle(string title)
|
|
|
|
|
{
|
|
|
|
|
title = RemoveThe.Replace(title, string.Empty);
|
|
|
|
|
|
|
|
|
|
//remove any repeating whitespace
|
|
|
|
|
var cleanTitle = TitleSearchRegex.Replace(title, "%20");
|
|
|
|
|
|
|
|
|
|
cleanTitle = Regex.Replace(cleanTitle, @"(%20){1,100}", "%20");
|
|
|
|
|
|
|
|
|
|
//Trim %20 from start then then the end
|
|
|
|
|
cleanTitle = Regex.Replace(cleanTitle, "^(%20)", "");
|
|
|
|
|
cleanTitle = Regex.Replace(cleanTitle, "(%20)$", "");
|
|
|
|
|
|
|
|
|
|
return cleanTitle;
|
|
|
|
|
}
|
2011-11-13 21:51:15 +01:00
|
|
|
|
}
|
|
|
|
|
}
|