PageRenderTime 22ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/Parsers/Downloads/Engines/Torrent/BitHUmen.cs

https://bitbucket.org/RoliSoft/rs-tv-show-tracker
C# | 204 lines | 127 code | 21 blank | 56 comment | 4 complexity | 8626e011753b6fbcf01ca3f909607d1c 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 System.Text;
  7. using NUnit.Framework;
  8. /// <summary>
  9. /// Provides support for scraping bitHUmen.
  10. /// </summary>
  11. [TestFixture]
  12. public class BitHUmen : 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 "bitHUmen";
  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://bithumen.be/";
  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-04-17 7:51 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", "rid" };
  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 + "takelogin.php";
  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. { "salted_passhash", string.Empty },
  115. { "username", LoginFieldTypes.UserName },
  116. { "password", LoginFieldTypes.Password },
  117. { "megjegyez", "on" },
  118. {
  119. "vxx",
  120. (Func<string>)(() =>
  121. {
  122. var login = Utils.GetHTML(Site + "login.php?simplelogin=1");
  123. var token = login.DocumentNode.GetNodeAttributeValue("//input[@type='hidden' and @name='vxx']", "value");
  124. return token;
  125. })
  126. },
  127. };
  128. }
  129. }
  130. /// <summary>
  131. /// Gets the type of the link.
  132. /// </summary>
  133. /// <value>The type of the link.</value>
  134. public override Types Type
  135. {
  136. get
  137. {
  138. return Types.Torrent;
  139. }
  140. }
  141. /// <summary>
  142. /// Searches for download links on the service.
  143. /// </summary>
  144. /// <param name="query">The name of the release to search for.</param>
  145. /// <returns>List of found download links.</returns>
  146. public override IEnumerable<Link> Search(string query)
  147. {
  148. var html = Utils.GetHTML(Site + "browse.php?c7=1&c26=1&genre=0&search=" + Utils.EncodeURL(query), cookies: Cookies, encoding: Encoding.GetEncoding("iso-8859-2"));
  149. if (GazelleTrackerLoginRequired(html.DocumentNode))
  150. {
  151. throw new InvalidCredentialException();
  152. }
  153. var links = html.DocumentNode.SelectNodes("//table[@id='torrenttable']/tr/td[2]/a[1]/b");
  154. if (links == null)
  155. {
  156. yield break;
  157. }
  158. var fl = html.DocumentNode.GetHtmlValue("//font[@color='red']/h2[contains(translate(text(), 'FRELCH ', 'frelch'), 'freeleech')]") != null;
  159. foreach (var node in links)
  160. {
  161. var link = new Link(this);
  162. link.Release = node.GetNodeAttributeValue("../", "title") ?? node.InnerText;
  163. link.InfoURL = Site + node.GetNodeAttributeValue("../../a", "href");
  164. link.FileURL = Site + node.GetNodeAttributeValue("../../a[starts-with(@title, 'Let')]", "href");
  165. link.Size = node.GetHtmlValue("../../../td[6]/u").Replace("<br>", " ");
  166. link.Quality = FileNames.Parser.ParseQuality(link.Release);
  167. link.Infos = Link.SeedLeechFormat.FormatWith(node.GetTextValue("../../../td[8]").Trim(), node.GetTextValue("../../../td[9]").Trim().Split('/')[1].Trim())
  168. + (fl ? ", Global Freeleech" : string.Empty);
  169. yield return link;
  170. }
  171. }
  172. /// <summary>
  173. /// Authenticates with the site and returns the cookies.
  174. /// </summary>
  175. /// <param name="username">The username.</param>
  176. /// <param name="password">The password.</param>
  177. /// <returns>Cookies on success, <c>string.Empty</c> on failure.</returns>
  178. public override string Login(string username, string password)
  179. {
  180. return GazelleTrackerLogin(username, password);
  181. }
  182. }
  183. }