PageRenderTime 72ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/Parsers/Downloads/Engines/Torrent/IPTorrents.cs

https://bitbucket.org/RoliSoft/rs-tv-show-tracker
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
  1. namespace RoliSoft.TVShowTracker.Parsers.Downloads.Engines.Torrent
  2. {
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Security.Authentication;
  6. using HtmlAgilityPack;
  7. using NUnit.Framework;
  8. /// <summary>
  9. /// Provides support for scraping IPTorrents.
  10. /// </summary>
  11. [TestFixture]
  12. public class IPTorrents : DownloadSearchEngine
  13. {
  14. /// <summary>
  15. /// Gets the name of the site.
  16. /// </summary>
  17. /// <value>The name.</value>
  18. public override string Name
  19. {
  20. get
  21. {
  22. return "IPTorrents";
  23. }
  24. }
  25. /// <summary>
  26. /// Gets the URL of the site.
  27. /// </summary>
  28. /// <value>The site location.</value>
  29. public override string Site
  30. {
  31. get
  32. {
  33. return "http://on.iptorrents.com/";
  34. }
  35. }
  36. /// <summary>
  37. /// Gets the name of the plugin's developer.
  38. /// </summary>
  39. /// <value>The name of the plugin's developer.</value>
  40. public override string Developer
  41. {
  42. get
  43. {
  44. return "RoliSoft";
  45. }
  46. }
  47. /// <summary>
  48. /// Gets the version number of the plugin.
  49. /// </summary>
  50. /// <value>The version number of the plugin.</value>
  51. public override Version Version
  52. {
  53. get
  54. {
  55. return Utils.DateTimeToVersion("2012-12-30 1:04 PM");
  56. }
  57. }
  58. /// <summary>
  59. /// Gets a value indicating whether the site requires authentication.
  60. /// </summary>
  61. /// <value><c>true</c> if requires authentication; otherwise, <c>false</c>.</value>
  62. public override bool Private
  63. {
  64. get
  65. {
  66. return true;
  67. }
  68. }
  69. /// <summary>
  70. /// Gets the names of the required cookies for the authentication.
  71. /// </summary>
  72. /// <value>The required cookies for authentication.</value>
  73. public override string[] RequiredCookies
  74. {
  75. get
  76. {
  77. return new[] { "uid", "pass" };
  78. }
  79. }
  80. /// <summary>
  81. /// Gets a value indicating whether this search engine can login using a username and password.
  82. /// </summary>
  83. /// <value>
  84. /// <c>true</c> if this search engine can login; otherwise, <c>false</c>.
  85. /// </value>
  86. public override bool CanLogin
  87. {
  88. get
  89. {
  90. return true;
  91. }
  92. }
  93. /// <summary>
  94. /// Gets the URL to the login page.
  95. /// </summary>
  96. /// <value>The URL to the login page.</value>
  97. public override string LoginURL
  98. {
  99. get
  100. {
  101. return Site + "torrents/";
  102. }
  103. }
  104. /// <summary>
  105. /// Gets the input fields of the login form.
  106. /// </summary>
  107. /// <value>The input fields of the login form.</value>
  108. public override Dictionary<string, object> LoginFields
  109. {
  110. get
  111. {
  112. return new Dictionary<string, object>
  113. {
  114. { "username", LoginFieldTypes.UserName },
  115. { "password", LoginFieldTypes.Password },
  116. };
  117. }
  118. }
  119. /// <summary>
  120. /// Gets the type of the link.
  121. /// </summary>
  122. /// <value>The type of the link.</value>
  123. public override Types Type
  124. {
  125. get
  126. {
  127. return Types.Torrent;
  128. }
  129. }
  130. /// <summary>
  131. /// Searches for download links on the service.
  132. /// </summary>
  133. /// <param name="query">The name of the release to search for.</param>
  134. /// <returns>List of found download links.</returns>
  135. public override IEnumerable<Link> Search(string query)
  136. {
  137. var html = Utils.GetHTML(Site + "torrents/?title_only=1&q=" + Utils.EncodeURL(query), cookies: Cookies);
  138. if (GazelleTrackerLoginRequired(html.DocumentNode))
  139. {
  140. throw new InvalidCredentialException();
  141. }
  142. var links = html.DocumentNode.SelectNodes("//a[@class='t_title']");
  143. if (links == null)
  144. {
  145. yield break;
  146. }
  147. foreach (var node in links)
  148. {
  149. var link = new Link(this);
  150. link.Release = HtmlEntity.DeEntitize(node.InnerText).Trim();
  151. link.InfoURL = Site.TrimEnd('/') + node.GetAttributeValue("href");
  152. link.FileURL = Site.TrimEnd('/') + node.GetNodeAttributeValue("../../td[4]/a", "href");
  153. link.Size = node.GetTextValue("../../td[6]").Trim();
  154. link.Quality = FileNames.Parser.ParseQuality(link.Release);
  155. link.Infos = Link.SeedLeechFormat.FormatWith(node.GetTextValue("../../td[8]").Trim(), node.GetTextValue("../../td[9]").Trim())
  156. + (node.GetHtmlValue("../span[@class='t_tag_free_leech']") != null ? ", Free" : string.Empty);
  157. yield return link;
  158. }
  159. }
  160. /// <summary>
  161. /// Authenticates with the site and returns the cookies.
  162. /// </summary>
  163. /// <param name="username">The username.</param>
  164. /// <param name="password">The password.</param>
  165. /// <returns>Cookies on success, <c>string.Empty</c> on failure.</returns>
  166. public override string Login(string username, string password)
  167. {
  168. return GazelleTrackerLogin(username, password);
  169. }
  170. }
  171. }