/Parsers/Downloads/Engines/Torrent/TorrentDay.cs
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
- namespace RoliSoft.TVShowTracker.Parsers.Downloads.Engines.Torrent
- {
- using System;
- using System.Collections.Generic;
- using NUnit.Framework;
- using Newtonsoft.Json.Linq;
- /// <summary>
- /// Provides support for scraping TorrentDay.
- /// </summary>
- [TestFixture]
- public class TorrentDay : DownloadSearchEngine
- {
- /// <summary>
- /// Gets the name of the site.
- /// </summary>
- /// <value>The name.</value>
- public override string Name
- {
- get
- {
- return "TorrentDay";
- }
- }
- /// <summary>
- /// Gets the URL of the site.
- /// </summary>
- /// <value>The site location.</value>
- public override string Site
- {
- get
- {
- return "http://www.torrentday.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 10:44 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 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");
- try
- {
- if ((int)json["er"] != 0 || json["Fs"][0]["Cn"]["torrents"].Count == 0)
- {
- yield break;
- }
- }
- catch
- {
- yield break;
- }
- foreach (JContainer item in json["Fs"][0]["Cn"]["torrents"])
- {
- yield return new Link(this)
- {
- Release = (string)item["name"],
- InfoURL = Site + "details.php?id=" + (int)item["id"],
- FileURL = Site + "download.php/" + (int)item["id"] + "/" + (string)item["fname"],
- Size = (string)item["size"],
- Quality = FileNames.Parser.ParseQuality((string)item["name"]),
- Infos = Link.SeedLeechFormat.FormatWith((int)item["seed"], (int)item["leech"])
- };
- }
- }
- /// <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);
- }
- }
- }