2020-02-09 02:35:16 +00:00
using System ;
2017-10-29 06:50:47 +00:00
using System.Collections.Generic ;
using System.Collections.Specialized ;
2020-05-03 23:35:52 +00:00
using System.Diagnostics.CodeAnalysis ;
2017-10-29 06:50:47 +00:00
using System.Globalization ;
using System.Linq ;
using System.Text ;
using System.Threading.Tasks ;
2020-02-29 19:20:15 +00:00
using AngleSharp.Dom ;
using AngleSharp.Html.Parser ;
2018-03-10 08:05:56 +00:00
using Jackett.Common.Models ;
using Jackett.Common.Models.IndexerConfig ;
using Jackett.Common.Services.Interfaces ;
using Jackett.Common.Utils ;
using Jackett.Common.Utils.Clients ;
2017-04-15 08:45:10 +00:00
using Newtonsoft.Json.Linq ;
using NLog ;
2018-03-10 08:05:56 +00:00
namespace Jackett.Common.Indexers
2017-04-15 08:45:10 +00:00
{
2020-05-03 23:35:52 +00:00
[ExcludeFromCodeCoverage]
2017-07-10 20:58:44 +00:00
public class PirateTheNet : BaseWebIndexer
2017-04-15 08:45:10 +00:00
{
2020-02-25 16:08:03 +00:00
private string SearchUrl = > SiteLink + "torrentsutils.php" ;
private string LoginUrl = > SiteLink + "takelogin.php" ;
private string CaptchaUrl = > SiteLink + "simpleCaptcha.php?numImages=1" ;
2017-04-15 08:45:10 +00:00
2017-10-29 06:50:47 +00:00
private new ConfigurationDataBasicLoginWithRSSAndDisplay configData
2017-04-15 08:45:10 +00:00
{
2020-02-25 16:08:03 +00:00
get = > ( ConfigurationDataBasicLoginWithRSSAndDisplay ) base . configData ;
set = > base . configData = value ;
2017-04-15 08:45:10 +00:00
}
2020-12-11 22:14:21 +00:00
public PirateTheNet ( IIndexerConfigurationService configService , WebClient w , Logger l ,
IProtectionService ps , ICacheService cs )
2020-05-11 19:59:28 +00:00
: base ( id : "piratethenet" ,
name : "PirateTheNet" ,
description : "A movie tracker" ,
link : "http://piratethenet.org/" ,
caps : new TorznabCapabilities
{
2020-10-18 20:47:36 +00:00
MovieSearchParams = new List < MovieSearchParam >
{
MovieSearchParam . Q , MovieSearchParam . ImdbId
}
2020-05-11 19:59:28 +00:00
} ,
configService : configService ,
client : w ,
logger : l ,
p : ps ,
2020-12-11 22:14:21 +00:00
cacheService : cs ,
2020-11-28 18:36:35 +00:00
configData : new ConfigurationDataBasicLoginWithRSSAndDisplay ( "Only the results from the first search result page are shown, adjust your profile settings to show the maximum." ) )
2017-04-15 08:45:10 +00:00
{
2017-11-05 09:42:03 +00:00
Encoding = Encoding . UTF8 ;
2017-04-15 08:45:10 +00:00
Language = "en-us" ;
Type = "private" ;
2017-10-25 16:19:13 +00:00
AddCategoryMapping ( "1080P" , TorznabCatType . MoviesHD , "1080P" ) ;
2020-03-08 11:45:10 +00:00
AddCategoryMapping ( "2160P" , TorznabCatType . MoviesHD , "2160P" ) ;
2017-10-25 16:19:13 +00:00
AddCategoryMapping ( "720P" , TorznabCatType . MoviesHD , "720P" ) ;
AddCategoryMapping ( "BDRip" , TorznabCatType . MoviesSD , "BDRip" ) ;
AddCategoryMapping ( "BluRay" , TorznabCatType . MoviesBluRay , "BluRay" ) ;
AddCategoryMapping ( "BRRip" , TorznabCatType . MoviesSD , "BRRip" ) ;
AddCategoryMapping ( "DVDR" , TorznabCatType . MoviesDVD , "DVDR" ) ;
AddCategoryMapping ( "DVDRip" , TorznabCatType . MoviesSD , "DVDRip" ) ;
2020-03-08 11:45:10 +00:00
AddCategoryMapping ( "FLAC" , TorznabCatType . AudioLossless , "FLAC OST" ) ;
AddCategoryMapping ( "MP3" , TorznabCatType . AudioMP3 , "MP3 OST" ) ;
2017-10-25 16:19:13 +00:00
AddCategoryMapping ( "MP4" , TorznabCatType . MoviesOther , "MP4" ) ;
AddCategoryMapping ( "Packs" , TorznabCatType . MoviesOther , "Packs" ) ;
2020-03-08 11:45:10 +00:00
AddCategoryMapping ( "R5" , TorznabCatType . MoviesDVD , "R5 / SCR" ) ;
2017-10-25 16:19:13 +00:00
AddCategoryMapping ( "Remux" , TorznabCatType . MoviesOther , "Remux" ) ;
AddCategoryMapping ( "TVRip" , TorznabCatType . MoviesOther , "TVRip" ) ;
AddCategoryMapping ( "WebRip" , TorznabCatType . MoviesWEBDL , "WebRip" ) ;
2017-04-15 08:45:10 +00:00
}
2017-06-28 05:31:38 +00:00
public override async Task < IndexerConfigurationStatus > ApplyConfiguration ( JToken configJson )
2017-04-15 08:45:10 +00:00
{
LoadValuesFromJson ( configJson ) ;
2017-11-13 15:54:44 +00:00
CookieHeader = "" ; // clear old cookies
2017-04-15 08:45:10 +00:00
2020-09-21 16:39:47 +00:00
var result1 = await RequestWithCookiesAsync ( CaptchaUrl ) ;
2020-06-09 17:36:57 +00:00
var json1 = JObject . Parse ( result1 . ContentString ) ;
2017-04-15 08:45:10 +00:00
var captchaSelection = json1 [ "images" ] [ 0 ] [ "hash" ] ;
var pairs = new Dictionary < string , string > {
{ "username" , configData . Username . Value } ,
{ "password" , configData . Password . Value } ,
{ "captchaSelection" , ( string ) captchaSelection }
} ;
var result2 = await RequestLoginAndFollowRedirect ( LoginUrl , pairs , result1 . Cookies , true , null , null , true ) ;
2020-06-09 17:36:57 +00:00
await ConfigureIfOK ( result2 . Cookies , result2 . ContentString . Contains ( "logout.php" ) , ( ) = >
2020-03-08 11:45:10 +00:00
throw new ExceptionWithConfigData ( "Login Failed" , configData ) ) ;
2017-04-15 08:45:10 +00:00
return IndexerConfigurationStatus . RequiresTesting ;
}
2017-07-03 05:15:47 +00:00
protected override async Task < IEnumerable < ReleaseInfo > > PerformQuery ( TorznabQuery query )
2017-04-15 08:45:10 +00:00
{
2020-02-10 22:16:19 +00:00
var releases = new List < ReleaseInfo > ( ) ;
2017-04-15 08:45:10 +00:00
2020-03-08 11:45:10 +00:00
var qc = new NameValueCollection
2017-04-15 08:45:10 +00:00
{
2020-03-08 11:45:10 +00:00
{ "action" , "torrentstable" } ,
{ "viewtype" , "0" } ,
{ "visiblecategories" , "Action,Adventure,Animation,Biography,Comedy,Crime,Documentary,Drama,Family,Fantasy,History,Horror,Kids,Music,Mystery,Packs,Romance,Sci-Fi,Short,Sports,Thriller,War,Western" } ,
{ "page" , "1" } ,
{ "visibility" , "showall" } ,
{ "compression" , "showall" } ,
{ "sort" , "added" } ,
{ "order" , "DESC" } ,
{ "titleonly" , "true" } ,
{ "packs" , "showall" } ,
{ "bookmarks" , "showall" } ,
{ "subscriptions" , "showall" } ,
{ "skw" , "showall" }
} ;
if ( ! string . IsNullOrWhiteSpace ( query . ImdbID ) )
qc . Add ( "advancedsearchparameters" , $"[imdb={query.ImdbID}]" ) ;
else if ( ! string . IsNullOrWhiteSpace ( query . GetQueryString ( ) ) )
2017-04-15 08:45:10 +00:00
// search keywords use OR by default and it seems like there's no way to change it, expect unwanted results
2020-03-08 11:45:10 +00:00
qc . Add ( "searchstring" , query . GetQueryString ( ) ) ;
2017-04-15 08:45:10 +00:00
var cats = MapTorznabCapsToTrackers ( query ) ;
2020-03-08 11:45:10 +00:00
qc . Add ( "hiddenqualities" , string . Join ( "," , cats ) ) ;
2017-04-15 08:45:10 +00:00
2020-03-08 11:45:10 +00:00
var searchUrl = SearchUrl + "?" + qc . GetQueryString ( ) ;
2017-04-15 08:45:10 +00:00
2020-06-11 15:09:27 +00:00
var results = await RequestWithCookiesAndRetryAsync ( searchUrl ) ;
2017-11-13 10:18:41 +00:00
if ( results . IsRedirect )
{
// re-login
await ApplyConfiguration ( null ) ;
2020-06-11 15:09:27 +00:00
results = await RequestWithCookiesAndRetryAsync ( searchUrl ) ;
2017-11-13 10:18:41 +00:00
}
2017-04-15 08:45:10 +00:00
try
{
2020-02-29 19:20:15 +00:00
var parser = new HtmlParser ( ) ;
2020-06-09 17:36:57 +00:00
var dom = parser . ParseDocument ( results . ContentString ) ;
2020-02-29 19:20:15 +00:00
var rows = dom . QuerySelectorAll ( "table.main > tbody > tr" ) ;
2017-04-15 08:45:10 +00:00
foreach ( var row in rows . Skip ( 1 ) )
{
2020-02-29 19:20:15 +00:00
var qDetailsLink = row . QuerySelector ( "td:nth-of-type(2) > a:nth-of-type(1)" ) ; // link to the movie, not the actual torrent
2020-03-08 11:45:10 +00:00
var qCatIcon = row . QuerySelector ( "td:nth-of-type(1) > a > img" ) ;
var catStr = qCatIcon ! = null ?
qCatIcon . GetAttribute ( "src" ) . Split ( '/' ) . Last ( ) . Split ( '.' ) . First ( ) :
"packs" ;
2020-02-29 19:20:15 +00:00
var qSeeders = row . QuerySelector ( "td:nth-of-type(9)" ) ;
var qLeechers = row . QuerySelector ( "td:nth-of-type(10)" ) ;
var qDownloadLink = row . QuerySelector ( "td > a:has(img[alt=\"Download Torrent\"])" ) ;
var qPudDate = row . QuerySelector ( "td:nth-of-type(6) > nobr" ) ;
var qSize = row . QuerySelector ( "td:nth-of-type(7)" ) ;
2020-03-26 22:15:28 +00:00
var link = new Uri ( SiteLink + qDownloadLink . GetAttribute ( "href" ) . Substring ( 1 ) ) ;
2017-04-15 08:45:10 +00:00
var dateStr = qPudDate . Text ( ) . Trim ( ) ;
DateTime pubDateUtc ;
if ( dateStr . StartsWith ( "Today " ) )
2020-04-07 16:17:17 +00:00
pubDateUtc = DateTime . SpecifyKind ( DateTime . UtcNow . Date , DateTimeKind . Unspecified ) + DateTime . ParseExact ( dateStr . Split ( new [ ] { ' ' } , 2 ) [ 1 ] , "hh:mm tt" , CultureInfo . InvariantCulture ) . TimeOfDay ;
2017-04-15 08:45:10 +00:00
else if ( dateStr . StartsWith ( "Yesterday " ) )
pubDateUtc = DateTime . SpecifyKind ( DateTime . UtcNow . Date , DateTimeKind . Unspecified ) +
2020-04-07 16:17:17 +00:00
DateTime . ParseExact ( dateStr . Split ( new [ ] { ' ' } , 2 ) [ 1 ] , "hh:mm tt" , CultureInfo . InvariantCulture ) . TimeOfDay - TimeSpan . FromDays ( 1 ) ;
2017-04-15 08:45:10 +00:00
else
pubDateUtc = DateTime . SpecifyKind ( DateTime . ParseExact ( dateStr , "MMM d yyyy hh:mm tt" , CultureInfo . InvariantCulture ) , DateTimeKind . Unspecified ) ;
var sizeStr = qSize . Text ( ) ;
2020-03-26 22:15:28 +00:00
var seeders = ParseUtil . CoerceInt ( qSeeders . Text ( ) ) ;
var files = ParseUtil . CoerceInt ( row . QuerySelector ( "td:nth-child(4)" ) . TextContent ) ;
var grabs = ParseUtil . CoerceInt ( row . QuerySelector ( "td:nth-child(8)" ) . TextContent ) ;
2020-11-08 02:11:27 +00:00
var details = new Uri ( SiteLink + qDetailsLink . GetAttribute ( "href" ) ) ;
2020-03-26 22:15:28 +00:00
var size = ReleaseInfo . GetBytes ( sizeStr ) ;
var leechers = ParseUtil . CoerceInt ( qLeechers . Text ( ) ) ;
var title = qDetailsLink . GetAttribute ( "alt" ) ;
var release = new ReleaseInfo
{
MinimumRatio = 1 ,
MinimumSeedTime = 72 * 60 * 60 ,
Title = title ,
Category = MapTrackerCatToNewznab ( catStr ) ,
Link = link ,
2020-11-08 02:11:27 +00:00
Details = details ,
2020-03-26 22:15:28 +00:00
Guid = link ,
PublishDate = pubDateUtc . ToLocalTime ( ) ,
Size = size ,
Seeders = seeders ,
Peers = leechers + seeders ,
Files = files ,
Grabs = grabs ,
DownloadVolumeFactor = 0 , // ratioless
UploadVolumeFactor = 1
} ;
2017-04-15 08:45:10 +00:00
releases . Add ( release ) ;
}
}
catch ( Exception ex )
{
2020-06-09 17:36:57 +00:00
OnParseError ( results . ContentString , ex ) ;
2017-04-15 08:45:10 +00:00
}
return releases ;
}
}
}