2014-05-13 20:57:46 +03:00
|
|
|
using System;
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
using System.Xml.Linq;
|
|
|
|
using NzbDrone.Core.Parser.Model;
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Indexers
|
|
|
|
{
|
|
|
|
public class TorrentRssParser : RssParser
|
|
|
|
{
|
|
|
|
// Parse various seeder/leecher/peers formats in the description element to determine number of seeders.
|
|
|
|
public Boolean ParseSeedersInDescription { get; set; }
|
|
|
|
|
|
|
|
public TorrentRssParser()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override ReleaseInfo CreateNewReleaseInfo()
|
|
|
|
{
|
|
|
|
return new TorrentInfo();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override ReleaseInfo ProcessItem(XElement item, ReleaseInfo releaseInfo)
|
|
|
|
{
|
|
|
|
var result = base.ProcessItem(item, releaseInfo) as TorrentInfo;
|
|
|
|
|
|
|
|
result.InfoHash = GetInfoHash(item);
|
|
|
|
result.MagnetUrl = GetMagnetUrl(item);
|
2014-12-20 03:21:03 +02:00
|
|
|
result.Seeders = GetSeeders(item);
|
2014-05-13 20:57:46 +03:00
|
|
|
result.Peers = GetPeers(item);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected virtual String GetInfoHash(XElement item)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected virtual String GetMagnetUrl(XElement item)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected virtual Int32? GetSeeders(XElement item)
|
|
|
|
{
|
|
|
|
if (ParseSeedersInDescription)
|
|
|
|
{
|
2014-12-21 21:02:02 +02:00
|
|
|
var matchSeeders = ParseSeedersRegex.Match(item.Element("description").Value);
|
2014-05-13 20:57:46 +03:00
|
|
|
|
2014-12-21 21:02:02 +02:00
|
|
|
if (matchSeeders.Success)
|
2014-05-13 20:57:46 +03:00
|
|
|
{
|
2014-12-21 21:02:02 +02:00
|
|
|
return Int32.Parse(matchSeeders.Groups["value"].Value);
|
|
|
|
}
|
|
|
|
|
|
|
|
var matchPeers = ParsePeersRegex.Match(item.Element("description").Value);
|
|
|
|
var matchLeechers = ParseLeechersRegex.Match(item.Element("description").Value);
|
|
|
|
|
|
|
|
if (matchPeers.Success && matchLeechers.Success)
|
|
|
|
{
|
|
|
|
return Int32.Parse(matchPeers.Groups["value"].Value) - Int32.Parse(matchLeechers.Groups["value"].Value);
|
2014-05-13 20:57:46 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected virtual Int32? GetPeers(XElement item)
|
|
|
|
{
|
|
|
|
if (ParseSeedersInDescription)
|
|
|
|
{
|
2014-12-21 21:02:02 +02:00
|
|
|
var matchPeers = ParsePeersRegex.Match(item.Element("description").Value);
|
|
|
|
|
|
|
|
if (matchPeers.Success)
|
|
|
|
{
|
|
|
|
return Int32.Parse(matchPeers.Groups["value"].Value);
|
|
|
|
}
|
|
|
|
|
|
|
|
var matchSeeders = ParseSeedersRegex.Match(item.Element("description").Value);
|
|
|
|
var matchLeechers = ParseLeechersRegex.Match(item.Element("description").Value);
|
2014-05-13 20:57:46 +03:00
|
|
|
|
2014-12-21 21:02:02 +02:00
|
|
|
if (matchSeeders.Success && matchLeechers.Success)
|
2014-05-13 20:57:46 +03:00
|
|
|
{
|
2014-12-21 21:02:02 +02:00
|
|
|
return Int32.Parse(matchSeeders.Groups["value"].Value) + Int32.Parse(matchLeechers.Groups["value"].Value);
|
2014-05-13 20:57:46 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static readonly Regex ParseSeedersRegex = new Regex(@"(Seeder)s?:\s+(?<value>\d+)|(?<value>\d+)\s+(seeder)s?", RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
2014-12-21 21:02:02 +02:00
|
|
|
private static readonly Regex ParseLeechersRegex = new Regex(@"(Leecher)s?:\s+(?<value>\d+)|(?<value>\d+)\s+(leecher)s?", RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
|
|
|
private static readonly Regex ParsePeersRegex = new Regex(@"(Peer)s?:\s+(?<value>\d+)|(?<value>\d+)\s+(peer)s?", RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
2014-05-13 20:57:46 +03:00
|
|
|
}
|
|
|
|
}
|