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 ;
using CsQuery ;
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" ) , ( ) = >
{
CQ dom = result . Content ;
var errorMessage = dom [ "table.tableinborder" ] . Html ( ) ;
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 ;
var queryCollection = new NameValueCollection ( ) ;
queryCollection . Add ( "showsearch" , "1" ) ;
queryCollection . Add ( "incldead" , "1" ) ;
queryCollection . Add ( "orderby" , "added" ) ;
queryCollection . Add ( "sort" , "desc" ) ;
if ( ! string . IsNullOrWhiteSpace ( searchString ) )
{
queryCollection . Add ( "search" , searchString ) ;
}
var cats = MapTorznabCapsToTrackers ( query ) ;
2020-02-10 22:16:19 +00:00
var cat = " 0 ";
2017-04-15 08:45:10 +00:00
if ( cats . Count = = 1 )
{
cat = cats [ 0 ] ;
}
queryCollection . Add ( "cat" , cat ) ;
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-12-06 13:56:47 +00:00
var results = response . Content ;
2016-09-20 16:41:39 +00:00
try
{
CQ dom = results ;
var rows = dom [ "table.testtable> tbody > tr:has(td.tableb)" ] ;
foreach ( var row in rows )
{
var release = new ReleaseInfo ( ) ;
2017-04-15 08:45:10 +00:00
release . MinimumRatio = 0.75 ;
2016-09-20 16:41:39 +00:00
release . MinimumSeedTime = 0 ;
2017-04-15 08:45:10 +00:00
var qRow = row . Cq ( ) ;
var qDetailsLink = qRow . Find ( "a[href^=details.php?id=]" ) . First ( ) ;
release . Title = qDetailsLink . Text ( ) ;
if ( ! query . MatchQueryStringAND ( release . Title ) )
continue ;
var qCatLink = qRow . Find ( "a[href^=browse.php?cat=]" ) . First ( ) ;
2020-02-14 18:08:54 +00:00
var qSeeders = qRow . Find ( "td > table.testtable2 > tbody > tr > td > strong:eq(3)" ) ;
var qLeechers = qRow . Find ( "td > table.testtable2 > tbody > tr > td > strong:eq(4)" ) ;
var qDateStr = qRow . Find ( "td > table.testtable2 > tbody > tr > td:eq(7)" ) ;
var qSize = qRow . Find ( "td > table.testtable2 > tbody > tr > td > strong:eq(1)" ) ;
2017-04-15 08:45:10 +00:00
var qDownloadLink = qRow . Find ( "a[href*=download]" ) . First ( ) ;
var catStr = qCatLink . Attr ( "href" ) . Split ( '=' ) [ 1 ] ;
release . Category = MapTrackerCatToNewznab ( catStr ) ;
var dlLink = qDownloadLink . Attr ( "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 ] ;
}
release . Link = new Uri ( dlLink ) ;
release . Comments = new Uri ( SiteLink + qDetailsLink . Attr ( "href" ) ) ;
release . Guid = release . Link ;
var sizeStr = qSize . Text ( ) ;
release . Size = ReleaseInfo . GetBytes ( sizeStr . Replace ( "." , "" ) . Replace ( "," , "." ) ) ;
release . Seeders = ParseUtil . CoerceInt ( qSeeders . Text ( ) ) ;
2016-09-20 16:41:39 +00:00
release . Peers = ParseUtil . CoerceInt ( qLeechers . Text ( ) ) + release . Seeders ;
var dateStr = qDateStr . Text ( ) . Replace ( ' \ xA0 ' , ' ' ) ;
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 ) ;
2016-09-20 16:41:39 +00:00
release . PublishDate = pubDateUtc ;
2016-10-27 07:35:31 +00:00
var files = qRow . Find ( "td:contains(Datei) > strong ~ strong" ) . Text ( ) ;
release . Files = ParseUtil . CoerceInt ( files ) ;
2017-04-15 08:45:10 +00:00
if ( qRow . Find ( "img[title=\"OnlyUpload\"]" ) . Length > = 1 )
release . DownloadVolumeFactor = 0 ;
2016-10-27 07:35:31 +00:00
else
release . DownloadVolumeFactor = 1 ;
release . UploadVolumeFactor = 1 ;
2016-09-20 16:41:39 +00:00
releases . Add ( release ) ;
}
}
catch ( Exception ex )
{
OnParseError ( results , ex ) ;
}
return releases ;
}
}
}