Jackett/src/Jackett/Indexers/IPTorrents.cs

190 lines
7.5 KiB
C#
Raw Normal View History

2015-04-16 01:16:16 +00:00
using CsQuery;
2015-07-19 00:27:41 +00:00
using Jackett.Models;
2015-07-19 17:18:54 +00:00
using Jackett.Services;
2015-07-19 00:27:41 +00:00
using Jackett.Utils;
using Jackett.Utils.Clients;
2015-04-16 01:16:16 +00:00
using Newtonsoft.Json.Linq;
2015-07-19 00:27:41 +00:00
using NLog;
2015-04-16 01:16:16 +00:00
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
2015-05-05 04:25:28 +00:00
using System.Globalization;
2015-04-16 01:16:16 +00:00
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
2015-04-18 22:08:36 +00:00
using System.Web;
using Jackett.Models.IndexerConfig;
2015-04-16 01:16:16 +00:00
namespace Jackett.Indexers
{
2015-07-19 17:18:54 +00:00
public class IPTorrents : BaseIndexer, IIndexer
2015-05-04 04:12:14 +00:00
{
private string BrowseUrl { get { return SiteLink + "t"; } }
new ConfigurationDataBasicLogin configData
{
get { return (ConfigurationDataBasicLogin)base.configData; }
set { base.configData = value; }
}
2015-08-07 19:09:13 +00:00
public IPTorrents(IIndexerManagerService i, IWebClient wc, Logger l, IProtectionService ps)
: base(name: "IPTorrents",
description: "Always a step ahead.",
link: "https://iptorrents.com/",
2015-08-11 18:48:25 +00:00
caps: TorznabUtil.CreateDefaultTorznabTVCaps(),
manager: i,
client: wc,
logger: l,
2015-08-07 19:09:13 +00:00
p: ps,
configData: new ConfigurationDataBasicLogin())
2015-05-04 04:12:14 +00:00
{
AddCategoryMapping(72, TorznabCatType.Movies);
AddCategoryMapping(77, TorznabCatType.MoviesSD);
AddCategoryMapping(89, TorznabCatType.MoviesSD);
AddCategoryMapping(90, TorznabCatType.MoviesSD);
AddCategoryMapping(96, TorznabCatType.MoviesSD);
AddCategoryMapping(6, TorznabCatType.MoviesSD);
AddCategoryMapping(48, TorznabCatType.MoviesHD);
AddCategoryMapping(54, TorznabCatType.Movies);
AddCategoryMapping(62, TorznabCatType.MoviesSD);
AddCategoryMapping(38, TorznabCatType.MoviesForeign);
AddCategoryMapping(68, TorznabCatType.Movies);
AddCategoryMapping(20, TorznabCatType.MoviesHD);
AddCategoryMapping(7, TorznabCatType.MoviesSD);
AddCategoryMapping(73, TorznabCatType.TV);
AddCategoryMapping(26, TorznabCatType.TVSD);
AddCategoryMapping(55, TorznabCatType.TVSD);
AddCategoryMapping(78, TorznabCatType.TVSD);
AddCategoryMapping(23, TorznabCatType.TVHD);
AddCategoryMapping(24, TorznabCatType.TVSD);
AddCategoryMapping(25, TorznabCatType.TVSD);
AddCategoryMapping(66, TorznabCatType.TVSD);
AddCategoryMapping(82, TorznabCatType.TVSD);
AddCategoryMapping(65, TorznabCatType.TV);
AddCategoryMapping(83, TorznabCatType.TV);
AddCategoryMapping(79, TorznabCatType.TVSD);
AddCategoryMapping(22, TorznabCatType.TVHD);
AddCategoryMapping(79, TorznabCatType.TVSD);
AddCategoryMapping(4, TorznabCatType.TVSD);
AddCategoryMapping(5, TorznabCatType.TVHD);
AddCategoryMapping(75, TorznabCatType.Audio);
AddCategoryMapping(73, TorznabCatType.Audio);
AddCategoryMapping(80, TorznabCatType.AudioLossless);
AddCategoryMapping(93, TorznabCatType.Audio);
AddCategoryMapping(60, TorznabCatType.Anime);
AddCategoryMapping(1, TorznabCatType.Apps);
AddCategoryMapping(64, TorznabCatType.AudioBooks);
AddCategoryMapping(35, TorznabCatType.Books);
AddCategoryMapping(94, TorznabCatType.Comic);
2015-05-04 04:12:14 +00:00
}
2015-05-04 04:12:14 +00:00
public async Task ApplyConfiguration(JToken configJson)
{
configData.LoadValuesFromJson(configJson);
2015-05-04 04:12:14 +00:00
var pairs = new Dictionary<string, string> {
{ "username", configData.Username.Value },
{ "password", configData.Password.Value }
};
var request = new Utils.Clients.WebRequest()
{
Url = SiteLink,
Type = RequestType.POST,
Referer = SiteLink,
PostData = pairs
};
var response = await webclient.GetString(request);
var firstCallCookies = response.Cookies;
2015-07-28 19:22:23 +00:00
// Redirect to ? then to /t
await FollowIfRedirect(response, request.Url, null, firstCallCookies);
await ConfigureIfOK(firstCallCookies, response.Content.Contains("/my.php"), () =>
{
CQ dom = response.Content;
2015-05-04 04:12:14 +00:00
var messageEl = dom["body > div"].First();
var errorMessage = messageEl.Text().Trim();
throw new ExceptionWithConfigData(errorMessage, configData);
});
2015-05-04 04:12:14 +00:00
}
public async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuery query)
2015-05-04 04:12:14 +00:00
{
2015-07-19 17:18:54 +00:00
var releases = new List<ReleaseInfo>();
var searchString = query.SanitizedSearchTerm + " " + query.GetEpisodeSearchString();
var searchUrl = BrowseUrl;
var queryCollection = new NameValueCollection();
if (!string.IsNullOrWhiteSpace(searchString))
{
queryCollection.Add("q", searchString);
}
foreach (var cat in MapTorznabCapsToTrackers(query))
{
queryCollection.Add(cat, string.Empty);
}
if (queryCollection.Count > 0)
{
2015-07-30 20:09:38 +00:00
searchUrl += "?" + queryCollection.GetQueryString();
}
var response = await RequestStringWithCookiesAndRetry(searchUrl, null, BrowseUrl);
2015-05-04 04:12:14 +00:00
var results = response.Content;
try
{
CQ dom = results;
2015-05-04 04:12:14 +00:00
var rows = dom["table.torrents > tbody > tr"];
foreach (var row in rows.Skip(1))
2015-05-04 04:12:14 +00:00
{
var release = new ReleaseInfo();
var qRow = row.Cq();
var qTitleLink = qRow.Find("a.t_title").First();
release.Title = qTitleLink.Text().Trim();
2015-07-26 10:27:50 +00:00
2015-07-26 10:27:55 +00:00
// If we search an get no results, we still get a table just with no info.
2015-07-26 10:27:50 +00:00
if (string.IsNullOrWhiteSpace(release.Title))
{
break;
}
release.Description = release.Title;
2015-07-26 14:22:20 +00:00
release.Guid = new Uri(SiteLink + qTitleLink.Attr("href").Substring(1));
release.Comments = release.Guid;
var descString = qRow.Find(".t_ctime").Text();
var dateString = descString.Split('|').Last().Trim();
dateString = dateString.Split(new string[] { " by " }, StringSplitOptions.None)[0];
release.PublishDate = DateTimeUtil.FromTimeAgo(dateString);
var qLink = row.ChildElements.ElementAt(3).Cq().Children("a");
2015-07-19 17:18:54 +00:00
release.Link = new Uri(SiteLink + qLink.Attr("href"));
var sizeStr = row.ChildElements.ElementAt(5).Cq().Text();
release.Size = ReleaseInfo.GetBytes(sizeStr);
release.Seeders = ParseUtil.CoerceInt(qRow.Find(".t_seeders").Text().Trim());
release.Peers = ParseUtil.CoerceInt(qRow.Find(".t_leechers").Text().Trim()) + release.Seeders;
var cat = row.Cq().Find("td:eq(0) a").First().Attr("href").Substring(1);
release.Category = MapTrackerCatToNewznab(cat);
releases.Add(release);
2015-05-04 04:12:14 +00:00
}
}
catch (Exception ex)
{
2015-07-19 17:18:54 +00:00
OnParseError(results, ex);
2015-05-04 04:12:14 +00:00
}
return releases;
2015-05-04 04:12:14 +00:00
}
}
2015-04-16 01:16:16 +00:00
}