Jackett/src/Jackett.Common/Models/ResultPage.cs

105 lines
5.1 KiB
C#
Raw Normal View History

2015-04-13 06:25:21 +00:00
using System;
using System.Collections.Generic;
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;
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; }
Feature/new api (#1584) * Introducing API v2 There were multiple inconsistencies in the old API and I have been toying with the idea to replace it. This will suck for everyone who was building on top of the Jackett API, however as it was probably too painful to do so I'd say no one really tried. Now API v2.0 should be much more constistent as it uses DTObjects, and instead of manually constructing a json response it is handled by the ASP.NET web api. It is much more RESTful than it was, proper GET endpoints are introduced, and updating resources are now done via POST - it might be improved by introducing other type of REST methods. I know this sucks as completely breaks backward compatibility, however it'll probably make it easier to maintain and build on top of in the long run. * Use DELETE method to unconfigure an indexer * Remove debugging format from NLog * Fixing an null exception * Properly implementing IExceptionFilter interface * Enable adding public indexers without configuration * Fix missing manual search results * Basic modularization of the JS API * Introduce API versioning * Fix redirects to the dashboard * Cleaning up a little bit * Revamping Torznab and Potato as well * Move preconditions to FilterAttributes and simplify logic * Remove legacy filtering... will move to IResultFilter * Minor adjustment on results interface * Use Interpolated strings in ResultsController * DTO-ify * Remove fallback logic from potato results * DTO everywhere!!! * DTO-ify everything! * I hope this is my last piece of modification to this PR * Remove test variables... * Left out a couple conflicts... It's late
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)
{
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)
{
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()),
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),
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),
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
),
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),
getTorznabElement("thetvdb", r.TVDBId),
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),
getTorznabElement("minimumseedtime", r.MinimumSeedTime),
Feature/new api (#1584) * Introducing API v2 There were multiple inconsistencies in the old API and I have been toying with the idea to replace it. This will suck for everyone who was building on top of the Jackett API, however as it was probably too painful to do so I'd say no one really tried. Now API v2.0 should be much more constistent as it uses DTObjects, and instead of manually constructing a json response it is handled by the ASP.NET web api. It is much more RESTful than it was, proper GET endpoints are introduced, and updating resources are now done via POST - it might be improved by introducing other type of REST methods. I know this sucks as completely breaks backward compatibility, however it'll probably make it easier to maintain and build on top of in the long run. * Use DELETE method to unconfigure an indexer * Remove debugging format from NLog * Fixing an null exception * Properly implementing IExceptionFilter interface * Enable adding public indexers without configuration * Fix missing manual search results * Basic modularization of the JS API * Introduce API versioning * Fix redirects to the dashboard * Cleaning up a little bit * Revamping Torznab and Potato as well * Move preconditions to FilterAttributes and simplify logic * Remove legacy filtering... will move to IResultFilter * Minor adjustment on results interface * Use Interpolated strings in ResultsController * DTO-ify * Remove fallback logic from potato results * DTO everywhere!!! * DTO-ify everything! * I hope this is my last piece of modification to this PR * Remove test variables... * Left out a couple conflicts... It's late
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
}
}
}