diff --git a/README.md b/README.md index 0ede6041e..993cdd4e0 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,7 @@ Developer note: The software implements the [Torznab](https://github.com/Sonarr/ * Ghost City * GODS * Gormogon + * Hardbay * HD4Free * HD-Space * HD-Torrents diff --git a/src/Jackett/Indexers/Hardbay.cs b/src/Jackett/Indexers/Hardbay.cs new file mode 100644 index 000000000..bce8fbfcf --- /dev/null +++ b/src/Jackett/Indexers/Hardbay.cs @@ -0,0 +1,146 @@ +using Jackett.Models; +using Jackett.Services; +using Jackett.Utils; +using Jackett.Utils.Clients; +using Newtonsoft.Json.Linq; +using NLog; +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; +using Jackett.Models.IndexerConfig; +using System.Collections.Specialized; +using Newtonsoft.Json; +using System.Globalization; + +namespace Jackett.Indexers +{ + public class Hardbay : BaseIndexer, IIndexer + { + private string SearchUrl { get { return SiteLink + "api/v1/torrents"; } } + private string LoginUrl { get { return SiteLink + "api/v1/auth"; } } + + new ConfigurationDataBasicLogin configData + { + get { return (ConfigurationDataBasicLogin)base.configData; } + set { base.configData = value; } + } + + public Hardbay(IIndexerManagerService i, Logger l, IWebClient w, IProtectionService ps) + : base(name: "Hardbay", + description: null, + link: "https://hardbay.club/", + caps: new TorznabCapabilities(), + manager: i, + client: w, + logger: l, + p: ps, + configData: new ConfigurationDataBasicLogin()) + { + Encoding = Encoding.GetEncoding("UTF-8"); + Language = "en-us"; + + AddCategoryMapping(1, TorznabCatType.Audio); + AddCategoryMapping(2, TorznabCatType.AudioLossless); + } + + public async Task ApplyConfiguration(JToken configJson) + { + LoadValuesFromJson(configJson); + var queryCollection = new NameValueCollection(); + + queryCollection.Add("username", configData.Username.Value); + queryCollection.Add("password", configData.Password.Value); + + var loginUrl = LoginUrl + "?" + queryCollection.GetQueryString(); + var loginResult = await RequestStringWithCookies(loginUrl, null, SiteLink); + + await ConfigureIfOK(loginResult.Cookies, loginResult.Content.Contains("\"user\""), () => + { + throw new ExceptionWithConfigData(loginResult.Content, configData); + }); + return IndexerConfigurationStatus.RequiresTesting; + } + + public async Task> PerformQuery(TorznabQuery query) + { + List releases = new List(); + var queryCollection = new NameValueCollection(); + var searchString = query.GetQueryString(); + var searchUrl = SearchUrl; + + queryCollection.Add("extendedSearch", "false"); + queryCollection.Add("hideOld", "false"); + queryCollection.Add("index", "0"); + queryCollection.Add("limit", "100"); + queryCollection.Add("order", "desc"); + queryCollection.Add("page", "search"); + queryCollection.Add("searchText", searchString); + queryCollection.Add("sort", "d"); + + /*foreach (var cat in MapTorznabCapsToTrackers(query)) + queryCollection.Add("categories[]", cat); + */ + + searchUrl += "?" + queryCollection.GetQueryString(); + var results = await RequestStringWithCookies(searchUrl, null, SiteLink); + + try + { + //var json = JArray.Parse(results.Content); + dynamic json = JsonConvert.DeserializeObject(results.Content); + foreach (var row in json) + { + var release = new ReleaseInfo(); + var descriptions = new List(); + var tags = new List(); + + release.MinimumRatio = 0.5; + release.MinimumSeedTime = 0; + release.Title = row.name; + release.Category = TorznabCatType.Audio.ID; + release.Size = row.size; + release.Seeders = row.seeders; + release.Peers = row.leechers + release.Seeders; + release.PublishDate = DateTime.ParseExact(row.added.ToString() + " +01:00", "yyyy-MM-dd HH:mm:ss zzz", CultureInfo.InvariantCulture); + release.Files = row.numfiles; + release.Grabs = row.times_completed; + + release.Comments = new Uri(SiteLink + "torrent/" + row.id.ToString() + "/"); + release.Link = new Uri(SiteLink + "api/v1/torrents/download/" + row.id.ToString()); + + if (row.frileech == 1) + release.DownloadVolumeFactor = 0; + else + release.DownloadVolumeFactor = 0.33; + release.UploadVolumeFactor = 1; + + if ((int)row.p2p == 1) + tags.Add("P2P"); + if ((int)row.pack == 1) + tags.Add("Pack"); + if ((int)row.reqid != 0) + tags.Add("Archive"); + if ((int)row.flac != 0) + { + tags.Add("FLAC"); + release.Category = TorznabCatType.AudioLossless.ID; + } + + if (tags.Count > 0) + descriptions.Add("Tags: " + string.Join(", ", tags)); + + release.Description = string.Join("
\n", descriptions); + + releases.Add(release); + } + } + catch (Exception ex) + { + OnParseError(results.Content, ex); + } + + return releases; + } + } +} \ No newline at end of file diff --git a/src/Jackett/Jackett.csproj b/src/Jackett/Jackett.csproj index f1d20b663..e5382f821 100644 --- a/src/Jackett/Jackett.csproj +++ b/src/Jackett/Jackett.csproj @@ -165,6 +165,7 @@ +