2015-04-13 06:25:21 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2015-04-21 00:27:58 +00:00
|
|
|
|
using System.Globalization;
|
2015-04-16 06:04:28 +00:00
|
|
|
|
using System.IO;
|
2015-04-13 06:25:21 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
2015-04-21 00:27:58 +00:00
|
|
|
|
using System.Threading;
|
2015-04-13 06:25:21 +00:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Xml;
|
|
|
|
|
using System.Xml.Linq;
|
|
|
|
|
|
2015-07-19 00:27:41 +00:00
|
|
|
|
namespace Jackett.Models
|
2015-04-13 06:25:21 +00:00
|
|
|
|
{
|
|
|
|
|
public class ResultPage
|
|
|
|
|
{
|
|
|
|
|
static XNamespace atomNs = "http://www.w3.org/2005/Atom";
|
|
|
|
|
static XNamespace torznabNs = "http://torznab.com/schemas/2015/feed";
|
|
|
|
|
|
|
|
|
|
public ChannelInfo ChannelInfo { get; private set; }
|
2017-08-08 15:02:16 +00:00
|
|
|
|
public IEnumerable<ReleaseInfo> Releases { get; set; }
|
2015-04-13 06:25:21 +00:00
|
|
|
|
|
|
|
|
|
public ResultPage(ChannelInfo channelInfo)
|
|
|
|
|
{
|
|
|
|
|
ChannelInfo = channelInfo;
|
|
|
|
|
Releases = new List<ReleaseInfo>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string xmlDateFormat(DateTime dt)
|
|
|
|
|
{
|
2015-04-21 00:27:58 +00:00
|
|
|
|
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
|
2015-04-13 06:25:21 +00:00
|
|
|
|
//Sat, 14 Mar 2015 17:10:42 -0400
|
|
|
|
|
var f = string.Format(@"{0:ddd, dd MMM yyyy HH:mm:ss }{1}", dt, string.Format("{0:zzz}", dt).Replace(":", ""));
|
|
|
|
|
return f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
XElement getTorznabElement(string name, object value)
|
|
|
|
|
{
|
2015-04-17 02:57:01 +00:00
|
|
|
|
return value == null ? null : new XElement(torznabNs + "attr", new XAttribute("name", name), new XAttribute("value", value));
|
2015-04-13 06:25:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string ToXml(Uri selfAtom)
|
|
|
|
|
{
|
2015-04-16 06:04:28 +00:00
|
|
|
|
var xdoc = new XDocument(
|
2015-04-13 06:25:21 +00:00
|
|
|
|
new XDeclaration("1.0", "UTF-8", null),
|
|
|
|
|
new XElement("rss",
|
|
|
|
|
new XAttribute("version", "1.0"),
|
|
|
|
|
new XAttribute(XNamespace.Xmlns + "atom", atomNs.NamespaceName),
|
|
|
|
|
new XAttribute(XNamespace.Xmlns + "torznab", torznabNs.NamespaceName),
|
|
|
|
|
new XElement("channel",
|
|
|
|
|
new XElement(atomNs + "link",
|
|
|
|
|
new XAttribute("href", selfAtom.ToString()),
|
|
|
|
|
new XAttribute("rel", "self"),
|
|
|
|
|
new XAttribute("type", "application/rss+xml")
|
|
|
|
|
),
|
|
|
|
|
new XElement("title", ChannelInfo.Title),
|
|
|
|
|
new XElement("description", ChannelInfo.Description),
|
|
|
|
|
new XElement("link", ChannelInfo.Link),
|
|
|
|
|
new XElement("lanuage", ChannelInfo.Language),
|
|
|
|
|
new XElement("category", ChannelInfo.Category),
|
|
|
|
|
new XElement("image",
|
|
|
|
|
new XElement("url", ChannelInfo.ImageUrl.ToString()),
|
|
|
|
|
new XElement("title", ChannelInfo.ImageTitle),
|
|
|
|
|
new XElement("link", ChannelInfo.ImageLink.ToString()),
|
|
|
|
|
new XElement("description", ChannelInfo.ImageDescription)
|
2015-04-16 06:04:28 +00:00
|
|
|
|
),
|
|
|
|
|
from r in Releases
|
|
|
|
|
select new XElement("item",
|
|
|
|
|
new XElement("title", r.Title),
|
|
|
|
|
new XElement("guid", r.Guid),
|
2015-05-05 04:25:28 +00:00
|
|
|
|
r.Comments == null ? null : new XElement("comments", r.Comments.ToString()),
|
2017-11-07 16:14:10 +00:00
|
|
|
|
r.PublishDate == DateTime.MinValue ? new XElement("pubDate", xmlDateFormat(DateTime.Now)) : new XElement("pubDate", xmlDateFormat(r.PublishDate)),
|
2015-05-05 04:25:28 +00:00
|
|
|
|
r.Size == null ? null : new XElement("size", r.Size),
|
2016-10-25 16:40:46 +00:00
|
|
|
|
r.Files == null ? null : new XElement("files", r.Files),
|
|
|
|
|
r.Grabs == null ? null : new XElement("grabs", r.Grabs),
|
2015-04-16 06:04:28 +00:00
|
|
|
|
new XElement("description", r.Description),
|
2015-04-25 19:37:03 +00:00
|
|
|
|
new XElement("link", r.Link ?? r.MagnetUri),
|
2017-02-21 12:07:54 +00:00
|
|
|
|
r.Category == null ? null : from c in r.Category select new XElement("category", c),
|
2015-04-16 06:04:28 +00:00
|
|
|
|
new XElement(
|
|
|
|
|
"enclosure",
|
2015-04-25 19:37:03 +00:00
|
|
|
|
new XAttribute("url", r.Link ?? r.MagnetUri),
|
2015-05-05 04:25:28 +00:00
|
|
|
|
r.Size == null ? null : new XAttribute("length", r.Size),
|
2015-04-19 20:21:22 +00:00
|
|
|
|
new XAttribute("type", "application/x-bittorrent")
|
2015-04-16 06:04:28 +00:00
|
|
|
|
),
|
2017-09-19 15:32:30 +00:00
|
|
|
|
r.Category == null ? null : from c in r.Category select getTorznabElement("category", c),
|
2015-04-25 19:37:03 +00:00
|
|
|
|
getTorznabElement("magneturl", r.MagnetUri),
|
2015-04-16 06:04:28 +00:00
|
|
|
|
getTorznabElement("rageid", r.RageID),
|
2015-09-30 20:21:43 +00:00
|
|
|
|
getTorznabElement("thetvdb", r.TVDBId),
|
2015-08-23 15:15:41 +00:00
|
|
|
|
getTorznabElement("imdb", r.Imdb),
|
2015-04-16 06:04:28 +00:00
|
|
|
|
getTorznabElement("seeders", r.Seeders),
|
|
|
|
|
getTorznabElement("peers", r.Peers),
|
|
|
|
|
getTorznabElement("infohash", r.InfoHash),
|
|
|
|
|
getTorznabElement("minimumratio", r.MinimumRatio),
|
2016-10-25 16:40:46 +00:00
|
|
|
|
getTorznabElement("minimumseedtime", r.MinimumSeedTime),
|
2017-08-08 15:02:16 +00:00
|
|
|
|
getTorznabElement("downloadvolumefactor", r.DownloadVolumeFactor),
|
|
|
|
|
getTorznabElement("uploadvolumefactor", r.UploadVolumeFactor)
|
2015-04-16 06:04:28 +00:00
|
|
|
|
)
|
2015-04-13 06:25:21 +00:00
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
2015-04-16 06:04:28 +00:00
|
|
|
|
return xdoc.Declaration.ToString() + Environment.NewLine + xdoc.ToString();
|
2015-04-13 06:25:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|