2020-02-09 02:35:16 +00:00
using System ;
2016-09-22 10:27:35 +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 19:03:13 +00:00
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-22 10:27:35 +00:00
{
2017-07-10 20:58:44 +00:00
public class myAmity : BaseWebIndexer
2016-09-22 10:27:35 +00:00
{
2020-02-25 16:08:03 +00:00
private string LoginUrl = > SiteLink + "account-login.php" ;
private string BrowseUrl = > SiteLink + "torrents-search.php" ;
2016-09-22 10:27:35 +00:00
2017-10-29 06:21:18 +00:00
private new ConfigurationDataBasicLoginWithRSSAndDisplay configData
2016-09-22 10:27:35 +00:00
{
2020-02-25 16:08:03 +00:00
get = > ( ConfigurationDataBasicLoginWithRSSAndDisplay ) base . configData ;
set = > base . configData = value ;
2016-09-22 10:27:35 +00:00
}
2017-11-05 09:42:03 +00:00
public myAmity ( IIndexerConfigurationService configService , WebClient wc , Logger l , IProtectionService ps )
2016-09-22 10:27:35 +00:00
: base ( name : "myAmity" ,
description : "A German general tracker." ,
link : "https://ttv2.myamity.info/" ,
caps : TorznabUtil . CreateDefaultTorznabTVCaps ( ) ,
2017-07-10 20:58:44 +00:00
configService : configService ,
2016-09-22 10:27:35 +00:00
client : wc ,
logger : l ,
p : ps ,
configData : new ConfigurationDataBasicLoginWithRSSAndDisplay ( ) )
{
2017-11-05 09:42:03 +00:00
Encoding = Encoding . UTF8 ;
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 ( 20 , TorznabCatType . PC ) ; // Apps - PC
AddCategoryMapping ( 24 , TorznabCatType . AudioAudiobook ) ; // Audio - Hoerbuch/-spiel
AddCategoryMapping ( 22 , TorznabCatType . Audio ) ; // Audio - Musik
AddCategoryMapping ( 52 , TorznabCatType . Movies3D ) ; // Filme - 3D
AddCategoryMapping ( 51 , TorznabCatType . MoviesBluRay ) ; // Filme - BluRay Complete
2020-02-09 02:35:16 +00:00
AddCategoryMapping ( 1 , TorznabCatType . MoviesDVD ) ; // Filme - DVD
2020-02-06 03:38:43 +00:00
AddCategoryMapping ( 56 , TorznabCatType . MoviesUHD ) ; // Filme - UHD/4K
2017-04-15 08:45:10 +00:00
AddCategoryMapping ( 54 , TorznabCatType . MoviesHD ) ; // Filme - HD/1080p
2020-02-09 02:35:16 +00:00
AddCategoryMapping ( 3 , TorznabCatType . MoviesHD ) ; // Filme - HD/720p
2017-04-15 08:45:10 +00:00
AddCategoryMapping ( 48 , TorznabCatType . XXX ) ; // Filme - Heimatfilme.XXX
AddCategoryMapping ( 50 , TorznabCatType . Movies ) ; // Filme - x264/H.264
2020-02-09 02:35:16 +00:00
AddCategoryMapping ( 2 , TorznabCatType . MoviesSD ) ; // Filme - XViD
2017-04-15 08:45:10 +00:00
AddCategoryMapping ( 11 , TorznabCatType . Console ) ; // Games - Konsolen
AddCategoryMapping ( 10 , TorznabCatType . PCGames ) ; // Games - PC
AddCategoryMapping ( 53 , TorznabCatType . Other ) ; // International - Complete
AddCategoryMapping ( 36 , TorznabCatType . Books ) ; // Sonstige - E-Books
AddCategoryMapping ( 38 , TorznabCatType . Other ) ; // Sonstige - Handy
2020-02-06 03:38:43 +00:00
AddCategoryMapping ( 59 , TorznabCatType . TVAnime ) ; // Sonstige - Anime
2020-02-09 02:35:16 +00:00
AddCategoryMapping ( 7 , TorznabCatType . TVDocumentary ) ; // TV/HDTV - Dokus
AddCategoryMapping ( 8 , TorznabCatType . TV ) ; // TV/HDTV - Serien
2020-02-06 03:38:43 +00:00
AddCategoryMapping ( 57 , TorznabCatType . TVSport ) ; // Sport - Allgemein
2016-09-22 10:27:35 +00:00
}
2017-06-28 05:31:38 +00:00
public override async Task < IndexerConfigurationStatus > ApplyConfiguration ( JToken configJson )
2016-09-22 10:27:35 +00:00
{
2017-01-02 20:39:28 +00:00
LoadValuesFromJson ( configJson ) ;
2016-09-22 10:27:35 +00:00
var pairs = new Dictionary < string , string >
{
{ "username" , configData . Username . Value } ,
{ "password" , configData . Password . Value }
} ;
2017-04-15 08:45:10 +00:00
var result = await RequestLoginAndFollowRedirect ( LoginUrl , pairs , null , true , null , LoginUrl , true ) ;
await ConfigureIfOK ( result . Cookies , result . Content ! = null & & result . Cookies . Contains ( "pass=" ) & & ! result . Cookies . Contains ( "deleted" ) , ( ) = >
{
2020-02-29 19:03:13 +00:00
var parser = new HtmlParser ( ) ;
var dom = parser . ParseDocument ( result . Content ) ;
var errorMessage = dom . QuerySelector ( "div.myFrame-content" ) . InnerHtml ;
2017-04-15 08:45:10 +00:00
throw new ExceptionWithConfigData ( errorMessage , configData ) ;
2016-09-22 10:27:35 +00:00
} ) ;
return IndexerConfigurationStatus . RequiresTesting ;
}
2017-07-03 05:15:47 +00:00
protected override async Task < IEnumerable < ReleaseInfo > > PerformQuery ( TorznabQuery query )
2016-09-22 10:27:35 +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-22 10:27:35 +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 ( "incldead" , "1" ) ;
queryCollection . Add ( "freeleech" , "0" ) ;
queryCollection . Add ( "inclexternal" , "0" ) ;
queryCollection . Add ( "lang" , "0" ) ;
if ( ! string . IsNullOrWhiteSpace ( searchString ) )
{
queryCollection . Add ( "search" , searchString ) ;
}
foreach ( var cat in MapTorznabCapsToTrackers ( query ) )
{
queryCollection . Add ( "c" + cat , "1" ) ;
}
2016-09-22 10:27:35 +00:00
searchUrl + = "?" + queryCollection . GetQueryString ( ) ;
2016-12-06 13:56:47 +00:00
var response = await RequestStringWithCookies ( searchUrl ) ;
2017-08-22 17:15:29 +00:00
if ( response . IsRedirect | | response . Cookies ! = null & & response . Cookies . Contains ( "pass=deleted;" ) )
2017-04-15 08:45:10 +00:00
{
// re-login
await ApplyConfiguration ( null ) ;
response = await RequestStringWithCookies ( searchUrl ) ;
2017-02-03 12:05:24 +00:00
}
2016-12-06 13:56:47 +00:00
var results = response . Content ;
2016-09-22 10:27:35 +00:00
try
{
2020-02-29 19:03:13 +00:00
var parser = new HtmlParser ( ) ;
var dom = parser . ParseDocument ( results ) ;
var rows = dom . QuerySelectorAll ( "table.ttable_headinner > tbody > tr.t-row" ) ;
2016-09-22 10:27:35 +00:00
foreach ( var row in rows )
{
var release = new ReleaseInfo ( ) ;
2017-04-15 08:45:10 +00:00
release . MinimumRatio = 1 ;
2016-09-22 10:27:35 +00:00
release . MinimumSeedTime = 90 * 60 ;
2020-03-02 07:40:09 +00:00
var qDetailsLink = row . QuerySelector ( "a[href^=\"torrents-details.php?id=\"]" ) ;
2020-02-29 19:03:13 +00:00
var qDetailsTitle = row . QuerySelector ( "td:has(a[href^=\"torrents-details.php?id=\"]) b" ) ; // #7100
release . Title = qDetailsTitle . TextContent ;
2017-04-15 08:45:10 +00:00
if ( ! query . MatchQueryStringAND ( release . Title ) )
continue ;
2020-03-02 07:40:09 +00:00
var qCatLink = row . QuerySelector ( "a[href^=\"torrents.php?cat=\"]" ) ;
var qDLLink = row . QuerySelector ( "a[href^=\"download.php\"]" ) ;
2020-02-29 19:03:13 +00:00
var qSeeders = row . QuerySelector ( "td:nth-of-type(7)" ) ;
var qLeechers = row . QuerySelector ( "td:nth-of-type(8)" ) ;
var qDateStr = row . QuerySelector ( "td:nth-of-type(10)" ) ;
var qSize = row . QuerySelector ( "td:nth-of-type(5)" ) ;
2017-04-15 08:45:10 +00:00
2020-02-29 19:03:13 +00:00
var catStr = qCatLink . GetAttribute ( "href" ) . Split ( '=' ) [ 1 ] ;
2017-04-15 08:45:10 +00:00
release . Category = MapTrackerCatToNewznab ( catStr ) ;
2020-02-29 19:03:13 +00:00
release . Link = new Uri ( SiteLink + qDLLink . GetAttribute ( "href" ) ) ;
release . Comments = new Uri ( SiteLink + qDetailsLink . GetAttribute ( "href" ) ) ;
2017-04-15 08:45:10 +00:00
release . Guid = release . Link ;
2020-02-29 19:03:13 +00:00
var sizeStr = qSize . TextContent ;
2017-04-15 08:45:10 +00:00
release . Size = ReleaseInfo . GetBytes ( sizeStr ) ;
2020-02-29 19:03:13 +00:00
release . Seeders = ParseUtil . CoerceInt ( qSeeders . TextContent ) ;
release . Peers = ParseUtil . CoerceInt ( qLeechers . TextContent ) + release . Seeders ;
2016-09-22 10:27:35 +00:00
2020-02-29 19:03:13 +00:00
var dateStr = qDateStr . TextContent . Trim ( ) ;
2020-02-10 22:16:19 +00:00
var dateGerman = DateTime . SpecifyKind ( DateTime . ParseExact ( dateStr , "dd.MM.yy HH:mm:ss" , CultureInfo . InvariantCulture ) , DateTimeKind . Unspecified ) ;
2017-04-15 08:45:10 +00:00
2020-02-10 22:16:19 +00:00
var pubDateUtc = TimeZoneInfo . ConvertTimeToUtc ( dateGerman , germanyTz ) ;
2016-09-22 10:27:35 +00:00
release . PublishDate = pubDateUtc . ToLocalTime ( ) ;
2020-02-29 19:03:13 +00:00
var grabs = row . QuerySelector ( "td:nth-child(6)" ) . TextContent ;
2016-10-27 07:35:31 +00:00
release . Grabs = ParseUtil . CoerceInt ( grabs ) ;
2020-02-29 19:03:13 +00:00
if ( row . QuerySelector ( "img[src=\"images/free.gif\"]" ) ! = null )
2017-04-15 08:45:10 +00:00
release . DownloadVolumeFactor = 0 ;
2016-10-27 07:35:31 +00:00
else
release . DownloadVolumeFactor = 1 ;
release . UploadVolumeFactor = 1 ;
2016-09-22 10:27:35 +00:00
releases . Add ( release ) ;
}
}
catch ( Exception ex )
{
OnParseError ( results , ex ) ;
}
return releases ;
}
}
}