2020-02-09 02:35:16 +00:00
using System ;
2016-09-20 16:41:39 +00:00
using System.Collections.Generic ;
2017-04-15 08:45:10 +00:00
using System.Collections.Specialized ;
2017-10-29 06:21:18 +00:00
using System.Globalization ;
2017-04-15 08:45:10 +00:00
using System.Text ;
2017-10-29 06:21:18 +00:00
using System.Threading.Tasks ;
2020-02-29 23:07:18 +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-10-29 06:21:18 +00:00
using Newtonsoft.Json.Linq ;
using NLog ;
2017-04-15 08:45:10 +00:00
2018-03-10 08:05:56 +00:00
namespace Jackett.Common.Indexers
2016-09-20 16:41:39 +00:00
{
2017-07-10 20:58:44 +00:00
public class NewRealWorld : BaseWebIndexer
2016-09-20 16:41:39 +00:00
{
2020-02-25 16:08:03 +00:00
private string LoginUrl = > SiteLink + "login.php" ;
private string BrowseUrl = > SiteLink + "browse.php" ;
2016-09-20 16:41:39 +00:00
2017-10-29 06:21:18 +00:00
private new ConfigurationDataBasicLoginWithRSSAndDisplay configData
2016-09-20 16:41:39 +00:00
{
2020-02-25 16:08:03 +00:00
get = > ( ConfigurationDataBasicLoginWithRSSAndDisplay ) base . configData ;
set = > base . configData = value ;
2016-09-20 16:41:39 +00:00
}
2017-11-05 09:42:03 +00:00
public NewRealWorld ( IIndexerConfigurationService configService , WebClient wc , Logger l , IProtectionService ps )
2016-09-20 16:41:39 +00:00
: base ( name : "New Real World" ,
description : "A German general tracker." ,
2017-08-17 16:53:38 +00:00
link : "https://nrw-tracker.eu/" ,
2016-09-20 16:41:39 +00:00
caps : TorznabUtil . CreateDefaultTorznabTVCaps ( ) ,
2017-07-10 20:58:44 +00:00
configService : configService ,
2016-09-20 16:41:39 +00:00
client : wc ,
logger : l ,
p : ps ,
configData : new ConfigurationDataBasicLoginWithRSSAndDisplay ( ) )
{
2016-12-06 13:56:47 +00:00
Encoding = Encoding . GetEncoding ( "iso-8859-1" ) ;
2016-12-09 17:20:58 +00:00
Language = "de-de" ;
2017-01-27 15:57:32 +00:00
Type = "private" ;
2016-12-06 13:56:47 +00:00
2017-04-15 08:45:10 +00:00
AddCategoryMapping ( 39 , TorznabCatType . TVAnime ) ; // Anime: HD|1080p
AddCategoryMapping ( 38 , TorznabCatType . TVAnime ) ; // Anime: HD|720p
2020-02-09 02:35:16 +00:00
AddCategoryMapping ( 1 , TorznabCatType . TVAnime ) ; // Anime: SD
AddCategoryMapping ( 7 , TorznabCatType . PCPhoneOther ) ; // Appz: Handy-PDA
2017-04-15 08:45:10 +00:00
AddCategoryMapping ( 36 , TorznabCatType . PCMac ) ; // Appz: Mac
AddCategoryMapping ( 18 , TorznabCatType . PC ) ; // Appz: Sonstiges
AddCategoryMapping ( 17 , TorznabCatType . PC ) ; // Appz: Win
AddCategoryMapping ( 15 , TorznabCatType . Audio ) ; // Audio: DVD-R
AddCategoryMapping ( 49 , TorznabCatType . AudioLossless ) ; // Audio: Flac
AddCategoryMapping ( 30 , TorznabCatType . AudioAudiobook ) ; // Audio: Hörspiele
AddCategoryMapping ( 14 , TorznabCatType . AudioMP3 ) ; // Audio: MP3
AddCategoryMapping ( 22 , TorznabCatType . AudioVideo ) ; // Audio: Videoclip
AddCategoryMapping ( 19 , TorznabCatType . Other ) ; // Diverses: Sonstiges
AddCategoryMapping ( 43 , TorznabCatType . TVDocumentary ) ; // Dokus: HD
2020-02-09 02:35:16 +00:00
AddCategoryMapping ( 2 , TorznabCatType . TVDocumentary ) ; // Dokus: SD
AddCategoryMapping ( 3 , TorznabCatType . Books ) ; // Ebooks: Bücher
2017-04-15 08:45:10 +00:00
AddCategoryMapping ( 52 , TorznabCatType . BooksComics ) ; // Ebooks: Comics
AddCategoryMapping ( 53 , TorznabCatType . BooksMagazines ) ; // Ebooks: Magazine
AddCategoryMapping ( 55 , TorznabCatType . BooksOther ) ; // Ebooks: XXX
AddCategoryMapping ( 54 , TorznabCatType . BooksOther ) ; // Ebooks: Zeitungen
AddCategoryMapping ( 47 , TorznabCatType . PCPhoneOther ) ; // Games: Andere
AddCategoryMapping ( 32 , TorznabCatType . PCMac ) ; // Games: Mac
AddCategoryMapping ( 41 , TorznabCatType . ConsoleNDS ) ; // Games: NDS/3DS
2020-02-09 02:35:16 +00:00
AddCategoryMapping ( 4 , TorznabCatType . PCGames ) ; // Games: PC
AddCategoryMapping ( 5 , TorznabCatType . ConsolePS3 ) ; // Games: PS2
AddCategoryMapping ( 9 , TorznabCatType . ConsolePS3 ) ; // Games: PS3
AddCategoryMapping ( 6 , TorznabCatType . ConsolePSP ) ; // Games: PSP
2017-04-15 08:45:10 +00:00
AddCategoryMapping ( 28 , TorznabCatType . ConsoleWii ) ; // Games: Wii
AddCategoryMapping ( 31 , TorznabCatType . ConsoleXbox ) ; // Games: XboX
AddCategoryMapping ( 51 , TorznabCatType . Movies3D ) ; // Movies: 3D
AddCategoryMapping ( 37 , TorznabCatType . MoviesBluRay ) ; // Movies: BluRay
AddCategoryMapping ( 25 , TorznabCatType . MoviesHD ) ; // Movies: HD|1080p
AddCategoryMapping ( 29 , TorznabCatType . MoviesHD ) ; // Movies: HD|720p
AddCategoryMapping ( 11 , TorznabCatType . MoviesDVD ) ; // Movies: SD|DVD-R
2020-02-09 02:35:16 +00:00
AddCategoryMapping ( 8 , TorznabCatType . MoviesSD ) ; // Movies: SD|x264
2017-04-15 08:45:10 +00:00
AddCategoryMapping ( 13 , TorznabCatType . MoviesSD ) ; // Movies: SD|XviD
AddCategoryMapping ( 40 , TorznabCatType . MoviesForeign ) ; // Movies: US Movies
AddCategoryMapping ( 33 , TorznabCatType . TV ) ; // Serien: DVD-R
AddCategoryMapping ( 34 , TorznabCatType . TVHD ) ; // Serien: HD
AddCategoryMapping ( 56 , TorznabCatType . TVHD ) ; // Serien: Packs|HD
AddCategoryMapping ( 44 , TorznabCatType . TVSD ) ; // Serien: Packs|SD
AddCategoryMapping ( 16 , TorznabCatType . TVSD ) ; // Serien: SD
AddCategoryMapping ( 10 , TorznabCatType . TVOTHER ) ; // Serien: TV/Shows
AddCategoryMapping ( 21 , TorznabCatType . TVFOREIGN ) ; // Serien: US TV
AddCategoryMapping ( 24 , TorznabCatType . TVSport ) ; // Sport: Diverses
AddCategoryMapping ( 23 , TorznabCatType . TVSport ) ; // Sport: Wrestling
AddCategoryMapping ( 57 , TorznabCatType . Movies ) ; // Tracker - Crew: pmHD
AddCategoryMapping ( 58 , TorznabCatType . MoviesHD ) ; // Ultra-HD: 4K
AddCategoryMapping ( 46 , TorznabCatType . XXXOther ) ; // XXX: Diverses
AddCategoryMapping ( 50 , TorznabCatType . XXX ) ; // XXX: HD
AddCategoryMapping ( 45 , TorznabCatType . XXXPacks ) ; // XXX: Packs
2016-09-20 16:41:39 +00:00
AddCategoryMapping ( 27 , TorznabCatType . XXX ) ; // XXX: SD
}
2017-06-28 05:31:38 +00:00
public override async Task < IndexerConfigurationStatus > ApplyConfiguration ( JToken configJson )
2016-09-20 16:41:39 +00:00
{
2017-01-02 20:39:28 +00:00
LoadValuesFromJson ( configJson ) ;
2016-09-20 16:41:39 +00:00
var pairs = new Dictionary < string , string >
{
{ "username" , configData . Username . Value } ,
{ "password" , configData . Password . Value } ,
{ "submit" , "Log+in!" }
} ;
var result = await RequestLoginAndFollowRedirect ( LoginUrl , pairs , null , true , null , LoginUrl , true ) ;
await ConfigureIfOK ( result . Cookies , result . Content ! = null & & result . Content . Contains ( "logout.php" ) , ( ) = >
{
2020-02-29 23:07:18 +00:00
var parser = new HtmlParser ( ) ;
var dom = parser . ParseDocument ( result . Content ) ;
var errorMessage = dom . QuerySelector ( "table.tableinborder" ) . InnerHtml ;
2016-09-20 16:41:39 +00:00
throw new ExceptionWithConfigData ( errorMessage , configData ) ;
} ) ;
return IndexerConfigurationStatus . RequiresTesting ;
}
2017-07-03 05:15:47 +00:00
protected override async Task < IEnumerable < ReleaseInfo > > PerformQuery ( TorznabQuery query )
2016-09-20 16:41:39 +00:00
{
2020-02-10 22:16:19 +00:00
var startTransition = TimeZoneInfo . TransitionTime . CreateFloatingDateRule ( new DateTime ( 1 , 1 , 1 , 3 , 0 , 0 ) , 3 , 5 , DayOfWeek . Sunday ) ;
var endTransition = TimeZoneInfo . TransitionTime . CreateFloatingDateRule ( new DateTime ( 1 , 1 , 1 , 4 , 0 , 0 ) , 10 , 5 , DayOfWeek . Sunday ) ;
var delta = new TimeSpan ( 1 , 0 , 0 ) ;
var adjustment = TimeZoneInfo . AdjustmentRule . CreateAdjustmentRule ( new DateTime ( 1999 , 10 , 1 ) , DateTime . MaxValue . Date , delta , startTransition , endTransition ) ;
2017-04-15 08:45:10 +00:00
TimeZoneInfo . AdjustmentRule [ ] adjustments = { adjustment } ;
2020-02-10 22:16:19 +00:00
var germanyTz = TimeZoneInfo . CreateCustomTimeZone ( "W. Europe Standard Time" , new TimeSpan ( 1 , 0 , 0 ) , "(GMT+01:00) W. Europe Standard Time" , "W. Europe Standard Time" , "W. Europe DST Time" , adjustments ) ;
2016-09-20 16:41:39 +00:00
var releases = new List < ReleaseInfo > ( ) ;
2017-10-29 06:21:18 +00:00
2017-04-15 08:45:10 +00:00
var searchString = query . GetQueryString ( ) ;
var searchUrl = BrowseUrl ;
2020-03-26 22:15:28 +00:00
var queryCollection = new NameValueCollection
{
{ "showsearch" , "1" } ,
{ "incldead" , "1" } ,
{ "orderby" , "added" } ,
{ "sort" , "desc" } ,
{ "cat" , MapTorznabCapsToTrackers ( query ) . FirstIfSingleOrDefault ( "0" ) }
} ;
2017-04-15 08:45:10 +00:00
if ( ! string . IsNullOrWhiteSpace ( searchString ) )
{
queryCollection . Add ( "search" , searchString ) ;
}
2016-09-20 16:41:39 +00:00
searchUrl + = "?" + queryCollection . GetQueryString ( ) ;
2016-12-06 13:56:47 +00:00
var response = await RequestStringWithCookies ( searchUrl ) ;
2017-08-17 16:53:38 +00:00
if ( response . IsRedirect )
{
// re-login
await ApplyConfiguration ( null ) ;
response = await RequestStringWithCookies ( searchUrl ) ;
}
2016-09-20 16:41:39 +00:00
try
{
2020-02-29 23:07:18 +00:00
var parser = new HtmlParser ( ) ;
var dom = parser . ParseDocument ( response . Content ) ;
var rows = dom . QuerySelectorAll ( "table.testtable> tbody > tr:has(td.tableb)" ) ;
2016-09-20 16:41:39 +00:00
foreach ( var row in rows )
{
2020-02-29 23:07:18 +00:00
var qDetailsLink = row . QuerySelector ( "a[href^=details.php?id=]" ) ;
2020-03-26 22:15:28 +00:00
var title = qDetailsLink . TextContent ;
if ( ! query . MatchQueryStringAND ( title ) )
2017-04-15 08:45:10 +00:00
continue ;
2020-03-02 07:54:41 +00:00
var qCatLink = row . QuerySelector ( "a[href^=\"browse.php?cat=\"]" ) ;
2020-02-29 23:07:18 +00:00
var qSeeders = row . QuerySelector ( "td > table.testtable2 > tbody > tr > td > strong:nth-of-type(4)" ) ;
var qLeechers = row . QuerySelector ( "td > table.testtable2 > tbody > tr > td > strong:nth-of-type(5)" ) ;
var qDateStr = row . QuerySelector ( "td > table.testtable2 > tbody > tr > td:nth-of-type(8)" ) ;
var qSize = row . QuerySelector ( "td > table.testtable2 > tbody > tr > td > strong:nth-of-type(2)" ) ;
2020-03-02 07:54:41 +00:00
var qDownloadLink = row . QuerySelector ( "a[href*=\"download\"]" ) ;
2017-04-15 08:45:10 +00:00
2020-02-29 23:07:18 +00:00
var catStr = qCatLink . GetAttribute ( "href" ) . Split ( '=' ) [ 1 ] ;
2017-04-15 08:45:10 +00:00
2020-02-29 23:07:18 +00:00
var dlLink = qDownloadLink . GetAttribute ( "href" ) ;
2017-10-29 06:21:18 +00:00
if ( dlLink . Contains ( "javascript" ) ) // depending on the user agent the DL link is a javascript call
2017-04-15 08:45:10 +00:00
{
var dlLinkParts = dlLink . Split ( new char [ ] { '\'' , ',' } ) ;
dlLink = SiteLink + "download/" + dlLinkParts [ 3 ] + "/" + dlLinkParts [ 5 ] ;
}
2020-03-26 22:15:28 +00:00
var link = new Uri ( dlLink ) ;
var seeders = ParseUtil . CoerceInt ( qSeeders . Text ( ) ) ;
2020-02-29 23:07:18 +00:00
var dateStr = qDateStr . TextContent . Replace ( ' \ xA0 ' , ' ' ) ;
2016-09-20 16:41:39 +00:00
var dateGerman = DateTime . SpecifyKind ( DateTime . ParseExact ( dateStr , "dd.MM.yyyy HH:mm:ss" , CultureInfo . InvariantCulture ) , DateTimeKind . Unspecified ) ;
2020-02-10 22:16:19 +00:00
var pubDateUtc = TimeZoneInfo . ConvertTimeToUtc ( dateGerman , germanyTz ) ;
2020-03-26 22:15:28 +00:00
var files = ParseUtil . CoerceInt ( row . QuerySelector ( "td:contains(Datei) > strong ~ strong" ) . TextContent ) ;
var comments = new Uri ( SiteLink + qDetailsLink . GetAttribute ( "href" ) ) ;
var leechers = ParseUtil . CoerceInt ( qLeechers . Text ( ) ) ;
var size = ReleaseInfo . GetBytes ( qSize . TextContent . Replace ( "." , "" ) . Replace ( "," , "." ) ) ;
var downloadVolumeFactor = row . QuerySelector ( "img[title=\"OnlyUpload\"]" ) ! = null ? 0 : 1 ;
var release = new ReleaseInfo
{
MinimumRatio = 0.75 ,
MinimumSeedTime = 0 ,
Title = title ,
Category = MapTrackerCatToNewznab ( catStr ) ,
Link = link ,
Comments = comments ,
Guid = link ,
Size = size ,
Seeders = seeders ,
Peers = leechers + seeders ,
PublishDate = pubDateUtc ,
Files = files ,
DownloadVolumeFactor = downloadVolumeFactor ,
UploadVolumeFactor = 1
} ;
2016-09-20 16:41:39 +00:00
releases . Add ( release ) ;
}
}
catch ( Exception ex )
{
2020-02-29 23:07:18 +00:00
OnParseError ( response . Content , ex ) ;
2016-09-20 16:41:39 +00:00
}
return releases ;
}
}
}