/Parsers/Downloads/Engines/Torrent/IPTorrents.cs
C# | 191 lines | 115 code | 20 blank | 56 comment | 4 complexity | fd5eeee483824fe640dd979b7a65974a MD5 | raw file
Possible License(s): Apache-2.0, LGPL-3.0, LGPL-2.0, CC-BY-SA-3.0, JSON, MIT
- namespace RoliSoft.TVShowTracker.Parsers.Downloads.Engines.Torrent
- {
- using System;
- using System.Collections.Generic;
- using System.Security.Authentication;
- using HtmlAgilityPack;
- using NUnit.Framework;
- /// <summary>
- /// Provides support for scraping IPTorrents.
- /// </summary>
- [TestFixture]
- public class IPTorrents : DownloadSearchEngine
- {
- /// <summary>
- /// Gets the name of the site.
- /// </summary>
- /// <value>The name.</value>
- public override string Name
- {
- get
- {
- return "IPTorrents";
- }
- }
- /// <summary>
- /// Gets the URL of the site.
- /// </summary>
- /// <value>The site location.</value>
- public override string Site
- {
- get
- {
- return "http://on.iptorrents.com/";
- }
- }
- /// <summary>
- /// Gets the name of the plugin's developer.
- /// </summary>
- /// <value>The name of the plugin's developer.</value>
- public override string Developer
- {
- get
- {
- return "RoliSoft";
- }
- }
- /// <summary>
- /// Gets the version number of the plugin.
- /// </summary>
- /// <value>The version number of the plugin.</value>
- public override Version Version
- {
- get
- {
- return Utils.DateTimeToVersion("2012-12-30 1:04 PM");
- }
- }
- /// <summary>
- /// Gets a value indicating whether the site requires authentication.
- /// </summary>
- /// <value><c>true</c> if requires authentication; otherwise, <c>false</c>.</value>
- public override bool Private
- {
- get
- {
- return true;
- }
- }
- /// <summary>
- /// Gets the names of the required cookies for the authentication.
- /// </summary>
- /// <value>The required cookies for authentication.</value>
- public override string[] RequiredCookies
- {
- get
- {
- return new[] { "uid", "pass" };
- }
- }
- /// <summary>
- /// Gets a value indicating whether this search engine can login using a username and password.
- /// </summary>
- /// <value>
- /// <c>true</c> if this search engine can login; otherwise, <c>false</c>.
- /// </value>
- public override bool CanLogin
- {
- get
- {
- return true;
- }
- }
- /// <summary>
- /// Gets the URL to the login page.
- /// </summary>
- /// <value>The URL to the login page.</value>
- public override string LoginURL
- {
- get
- {
- return Site + "torrents/";
- }
- }
- /// <summary>
- /// Gets the input fields of the login form.
- /// </summary>
- /// <value>The input fields of the login form.</value>
- public override Dictionary<string, object> LoginFields
- {
- get
- {
- return new Dictionary<string, object>
- {
- { "username", LoginFieldTypes.UserName },
- { "password", LoginFieldTypes.Password },
- };
- }
- }
- /// <summary>
- /// Gets the type of the link.
- /// </summary>
- /// <value>The type of the link.</value>
- public override Types Type
- {
- get
- {
- return Types.Torrent;
- }
- }
- /// <summary>
- /// Searches for download links on the service.
- /// </summary>
- /// <param name="query">The name of the release to search for.</param>
- /// <returns>List of found download links.</returns>
- public override IEnumerable<Link> Search(string query)
- {
- var html = Utils.GetHTML(Site + "torrents/?title_only=1&q=" + Utils.EncodeURL(query), cookies: Cookies);
- if (GazelleTrackerLoginRequired(html.DocumentNode))
- {
- throw new InvalidCredentialException();
- }
- var links = html.DocumentNode.SelectNodes("//a[@class='t_title']");
- if (links == null)
- {
- yield break;
- }
- foreach (var node in links)
- {
- var link = new Link(this);
- link.Release = HtmlEntity.DeEntitize(node.InnerText).Trim();
- link.InfoURL = Site.TrimEnd('/') + node.GetAttributeValue("href");
- link.FileURL = Site.TrimEnd('/') + node.GetNodeAttributeValue("../../td[4]/a", "href");
- link.Size = node.GetTextValue("../../td[6]").Trim();
- link.Quality = FileNames.Parser.ParseQuality(link.Release);
- link.Infos = Link.SeedLeechFormat.FormatWith(node.GetTextValue("../../td[8]").Trim(), node.GetTextValue("../../td[9]").Trim())
- + (node.GetHtmlValue("../span[@class='t_tag_free_leech']") != null ? ", Free" : string.Empty);
- yield return link;
- }
- }
- /// <summary>
- /// Authenticates with the site and returns the cookies.
- /// </summary>
- /// <param name="username">The username.</param>
- /// <param name="password">The password.</param>
- /// <returns>Cookies on success, <c>string.Empty</c> on failure.</returns>
- public override string Login(string username, string password)
- {
- return GazelleTrackerLogin(username, password);
- }
- }
- }