PageRenderTime 48ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/Parsers/Downloads/Engines/Torrent/TorrentDay.cs

https://bitbucket.org/RoliSoft/rs-tv-show-tracker
C# | 188 lines | 116 code | 16 blank | 56 comment | 4 complexity | 49ee9f648469dcac3e2c97c21db7c194 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 NUnit.Framework;
  6. using Newtonsoft.Json.Linq;
  7. /// <summary>
  8. /// Provides support for scraping TorrentDay.
  9. /// </summary>
  10. [TestFixture]
  11. public class TorrentDay : DownloadSearchEngine
  12. {
  13. /// <summary>
  14. /// Gets the name of the site.
  15. /// </summary>
  16. /// <value>The name.</value>
  17. public override string Name
  18. {
  19. get
  20. {
  21. return "TorrentDay";
  22. }
  23. }
  24. /// <summary>
  25. /// Gets the URL of the site.
  26. /// </summary>
  27. /// <value>The site location.</value>
  28. public override string Site
  29. {
  30. get
  31. {
  32. return "http://www.torrentday.com/";
  33. }
  34. }
  35. /// <summary>
  36. /// Gets the name of the plugin's developer.
  37. /// </summary>
  38. /// <value>The name of the plugin's developer.</value>
  39. public override string Developer
  40. {
  41. get
  42. {
  43. return "RoliSoft";
  44. }
  45. }
  46. /// <summary>
  47. /// Gets the version number of the plugin.
  48. /// </summary>
  49. /// <value>The version number of the plugin.</value>
  50. public override Version Version
  51. {
  52. get
  53. {
  54. return Utils.DateTimeToVersion("2012-12-30 10:44 PM");
  55. }
  56. }
  57. /// <summary>
  58. /// Gets a value indicating whether the site requires authentication.
  59. /// </summary>
  60. /// <value><c>true</c> if requires authentication; otherwise, <c>false</c>.</value>
  61. public override bool Private
  62. {
  63. get
  64. {
  65. return true;
  66. }
  67. }
  68. /// <summary>
  69. /// Gets the names of the required cookies for the authentication.
  70. /// </summary>
  71. /// <value>The required cookies for authentication.</value>
  72. public override string[] RequiredCookies
  73. {
  74. get
  75. {
  76. return new[] { "uid", "pass" };
  77. }
  78. }
  79. /// <summary>
  80. /// Gets a value indicating whether this search engine can login using a username and password.
  81. /// </summary>
  82. /// <value>
  83. /// <c>true</c> if this search engine can login; otherwise, <c>false</c>.
  84. /// </value>
  85. public override bool CanLogin
  86. {
  87. get
  88. {
  89. return true;
  90. }
  91. }
  92. /// <summary>
  93. /// Gets the URL to the login page.
  94. /// </summary>
  95. /// <value>The URL to the login page.</value>
  96. public override string LoginURL
  97. {
  98. get
  99. {
  100. return Site + "torrents/";
  101. }
  102. }
  103. /// <summary>
  104. /// Gets the input fields of the login form.
  105. /// </summary>
  106. /// <value>The input fields of the login form.</value>
  107. public override Dictionary<string, object> LoginFields
  108. {
  109. get
  110. {
  111. return new Dictionary<string, object>
  112. {
  113. { "username", LoginFieldTypes.UserName },
  114. { "password", LoginFieldTypes.Password },
  115. };
  116. }
  117. }
  118. /// <summary>
  119. /// Gets the type of the link.
  120. /// </summary>
  121. /// <value>The type of the link.</value>
  122. public override Types Type
  123. {
  124. get
  125. {
  126. return Types.Torrent;
  127. }
  128. }
  129. /// <summary>
  130. /// Searches for download links on the service.
  131. /// </summary>
  132. /// <param name="query">The name of the release to search for.</param>
  133. /// <returns>List of found download links.</returns>
  134. public override IEnumerable<Link> Search(string query)
  135. {
  136. var json = Utils.GetJSON(Site + "V3/API/API.php", "/browse.php?&search=" + Utils.EncodeURL(query) + "&cata=yes&jxt=8&jxw=b", Cookies, request: req => req.Referer = Site + "browse.php");
  137. try
  138. {
  139. if ((int)json["er"] != 0 || json["Fs"][0]["Cn"]["torrents"].Count == 0)
  140. {
  141. yield break;
  142. }
  143. }
  144. catch
  145. {
  146. yield break;
  147. }
  148. foreach (JContainer item in json["Fs"][0]["Cn"]["torrents"])
  149. {
  150. yield return new Link(this)
  151. {
  152. Release = (string)item["name"],
  153. InfoURL = Site + "details.php?id=" + (int)item["id"],
  154. FileURL = Site + "download.php/" + (int)item["id"] + "/" + (string)item["fname"],
  155. Size = (string)item["size"],
  156. Quality = FileNames.Parser.ParseQuality((string)item["name"]),
  157. Infos = Link.SeedLeechFormat.FormatWith((int)item["seed"], (int)item["leech"])
  158. };
  159. }
  160. }
  161. /// <summary>
  162. /// Authenticates with the site and returns the cookies.
  163. /// </summary>
  164. /// <param name="username">The username.</param>
  165. /// <param name="password">The password.</param>
  166. /// <returns>Cookies on success, <c>string.Empty</c> on failure.</returns>
  167. public override string Login(string username, string password)
  168. {
  169. return GazelleTrackerLogin(username, password);
  170. }
  171. }
  172. }