mirror of
https://github.com/Jackett/Jackett.git
synced 2025-09-17 17:34:09 +02:00
Initial commit
This commit is contained in:
88
src/Jackett/ResultPage.cs
Normal file
88
src/Jackett/ResultPage.cs
Normal file
@@ -0,0 +1,88 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Jackett
|
||||
{
|
||||
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; }
|
||||
public List<ReleaseInfo> Releases { get; private set; }
|
||||
|
||||
public ResultPage(ChannelInfo channelInfo)
|
||||
{
|
||||
ChannelInfo = channelInfo;
|
||||
Releases = new List<ReleaseInfo>();
|
||||
}
|
||||
|
||||
string xmlDateFormat(DateTime dt)
|
||||
{
|
||||
//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)
|
||||
{
|
||||
return value == null ? null : new XElement(torznabNs + "attr", new XAttribute(name, "rageid"), new XAttribute("value", value));
|
||||
}
|
||||
|
||||
public string ToXml(Uri selfAtom)
|
||||
{
|
||||
var doc = new XDocument(
|
||||
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)
|
||||
)
|
||||
),
|
||||
|
||||
from r in Releases
|
||||
select new XElement("item",
|
||||
new XElement("title", r.Title),
|
||||
new XElement("guid", r.Guid),
|
||||
new XElement("link", r.Link),
|
||||
new XElement("comments", r.Comments.ToString()),
|
||||
new XElement("pubDate", xmlDateFormat(r.PublishDate)),
|
||||
new XElement("category", r.Category),
|
||||
new XElement("size", r.Size),
|
||||
new XElement("description", r.Description),
|
||||
new XElement("enclosure", new XAttribute("url", r.Link), new XAttribute("length", r.Size), new XAttribute("type", "application/x-bittorrent")),
|
||||
getTorznabElement("rageid", r.RageID),
|
||||
getTorznabElement("seeders", r.Seeders),
|
||||
getTorznabElement("peers", r.Peers),
|
||||
getTorznabElement("infohash", r.InfoHash),
|
||||
getTorznabElement("minimumratio", r.MinimumRatio),
|
||||
getTorznabElement("minimumseedtime", r.MinimumSeedTime)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
return doc.ToString();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user