2020-02-09 02:35:16 +00:00
using System ;
2017-10-29 06:50:47 +00:00
using System.Collections.Generic ;
2020-05-03 23:35:52 +00:00
using System.Diagnostics.CodeAnalysis ;
2017-10-29 06:50:47 +00:00
using System.Linq ;
using System.Text ;
using System.Threading.Tasks ;
2018-03-10 08:05:56 +00:00
using Jackett.Common.Helpers ;
using Jackett.Common.Models ;
using Jackett.Common.Models.IndexerConfig ;
using Jackett.Common.Services.Interfaces ;
using Jackett.Common.Utils ;
using Jackett.Common.Utils.Clients ;
2018-01-30 13:11:10 +00:00
using Newtonsoft.Json ;
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 TorrentDay : BaseWebIndexer
2017-04-15 08:45:10 +00:00
{
2020-02-25 16:08:03 +00:00
private string SearchUrl = > SiteLink + "t.json" ;
2017-10-29 06:50:47 +00:00
2020-02-29 19:22:29 +00:00
public override string [ ] AlternativeSiteLinks { get ; protected set ; } = {
2020-07-06 19:40:13 +00:00
"https://tday.love/" ,
"https://torrentday.cool/" ,
2017-04-15 08:45:10 +00:00
"https://secure.torrentday.com/" ,
"https://classic.torrentday.com/" ,
"https://www.torrentday.com/" ,
2020-07-06 19:40:13 +00:00
"https://torrentday.it/" ,
2019-01-15 12:06:05 +00:00
"https://td.findnemo.net/" ,
"https://td.getcrazy.me/" ,
"https://td.venom.global/" ,
2020-07-06 19:40:13 +00:00
"https://td.workisboring.net/"
2020-05-15 21:06:58 +00:00
} ;
public override string [ ] LegacySiteLinks { get ; protected set ; } = {
"https://torrentday.com/" ,
"https://tdonline.org/" , // redirect to https://www.torrentday.com/
"https://torrentday.eu/" , // redirect to https://www.torrentday.com/
"https://td-update.com/" , // redirect to https://www.torrentday.com/
"https://www.torrentday.me/" ,
"https://www.torrentday.ru/" ,
2020-07-06 19:40:13 +00:00
"https://www.td.af/"
2017-04-15 08:45:10 +00:00
} ;
2020-06-09 19:25:19 +00:00
private new ConfigurationDataCookie configData = > ( ConfigurationDataCookie ) base . configData ;
2017-04-15 08:45:10 +00:00
2017-11-05 09:42:03 +00:00
public TorrentDay ( IIndexerConfigurationService configService , WebClient wc , Logger l , IProtectionService ps )
2020-05-11 19:59:28 +00:00
: base ( id : "torrentday" ,
name : "TorrentDay" ,
2020-04-04 20:34:38 +00:00
description : "TorrentDay (TD) is a Private site for TV / MOVIES / GENERAL" ,
2020-07-06 19:40:13 +00:00
link : "https://tday.love/" ,
2020-04-04 20:34:38 +00:00
caps : new TorznabCapabilities
{
2020-04-09 19:48:59 +00:00
SupportsImdbMovieSearch = true
// SupportsImdbTVSearch = true (supported by the site but disabled due to #8107)
2020-04-04 20:34:38 +00:00
} ,
configService : configService ,
client : wc ,
logger : l ,
p : ps ,
2020-06-09 19:25:19 +00:00
configData : new ConfigurationDataCookie (
2020-04-04 20:34:38 +00:00
"Make sure you get the cookies from the same torrent day domain as configured above." ) )
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" ;
2020-04-04 20:34:38 +00:00
wc . EmulateBrowser = false ;
2017-04-15 08:45:10 +00:00
2018-01-30 13:11:10 +00:00
AddCategoryMapping ( 29 , TorznabCatType . TVAnime , "Anime" ) ;
AddCategoryMapping ( 28 , TorznabCatType . PC , "Appz/Packs" ) ;
AddCategoryMapping ( 42 , TorznabCatType . AudioAudiobook , "Audio Books" ) ;
AddCategoryMapping ( 20 , TorznabCatType . Books , "Books" ) ;
AddCategoryMapping ( 30 , TorznabCatType . TVDocumentary , "Documentary" ) ;
AddCategoryMapping ( 47 , TorznabCatType . Other , "Fonts" ) ;
AddCategoryMapping ( 43 , TorznabCatType . PCMac , "Mac" ) ;
2018-07-14 04:45:40 +00:00
AddCategoryMapping ( 96 , TorznabCatType . MoviesUHD , "Movie/4K" ) ;
2018-01-30 13:11:10 +00:00
AddCategoryMapping ( 25 , TorznabCatType . MoviesSD , "Movies/480p" ) ;
AddCategoryMapping ( 11 , TorznabCatType . MoviesBluRay , "Movies/Bluray" ) ;
AddCategoryMapping ( 5 , TorznabCatType . MoviesBluRay , "Movies/Bluray-Full" ) ;
AddCategoryMapping ( 3 , TorznabCatType . MoviesDVD , "Movies/DVD-R" ) ;
AddCategoryMapping ( 21 , TorznabCatType . MoviesSD , "Movies/MP4" ) ;
AddCategoryMapping ( 22 , TorznabCatType . MoviesForeign , "Movies/Non-English" ) ;
AddCategoryMapping ( 13 , TorznabCatType . Movies , "Movies/Packs" ) ;
AddCategoryMapping ( 44 , TorznabCatType . MoviesSD , "Movies/SD/x264" ) ;
2018-07-14 04:45:40 +00:00
AddCategoryMapping ( 48 , TorznabCatType . Movies , "Movies/x265" ) ;
2018-01-30 13:11:10 +00:00
AddCategoryMapping ( 1 , TorznabCatType . MoviesSD , "Movies/XviD" ) ;
2019-10-14 05:42:03 +00:00
AddCategoryMapping ( 17 , TorznabCatType . AudioMP3 , "Music/Audio" ) ;
2018-01-30 13:11:10 +00:00
AddCategoryMapping ( 23 , TorznabCatType . AudioForeign , "Music/Non-English" ) ;
AddCategoryMapping ( 41 , TorznabCatType . Audio , "Music/Packs" ) ;
AddCategoryMapping ( 16 , TorznabCatType . AudioVideo , "Music/Video" ) ;
2018-02-10 04:21:23 +00:00
AddCategoryMapping ( 27 , TorznabCatType . Audio , "Music/Flac" ) ;
2020-02-09 02:35:16 +00:00
2018-01-30 13:11:10 +00:00
AddCategoryMapping ( 45 , TorznabCatType . AudioOther , "Podcast" ) ;
AddCategoryMapping ( 4 , TorznabCatType . PCGames , "PC/Games" ) ;
AddCategoryMapping ( 18 , TorznabCatType . ConsolePS3 , "PS3" ) ;
AddCategoryMapping ( 8 , TorznabCatType . ConsolePSP , "PSP" ) ;
AddCategoryMapping ( 10 , TorznabCatType . ConsoleWii , "Wii" ) ;
AddCategoryMapping ( 9 , TorznabCatType . ConsoleXbox360 , "Xbox-360" ) ;
AddCategoryMapping ( 24 , TorznabCatType . TVSD , "TV/480p" ) ;
AddCategoryMapping ( 32 , TorznabCatType . TVHD , "TV/Bluray" ) ;
AddCategoryMapping ( 31 , TorznabCatType . TVSD , "TV/DVD-R" ) ;
AddCategoryMapping ( 33 , TorznabCatType . TVSD , "TV/DVD-Rip" ) ;
AddCategoryMapping ( 46 , TorznabCatType . TVSD , "TV/Mobile" ) ;
AddCategoryMapping ( 14 , TorznabCatType . TV , "TV/Packs" ) ;
AddCategoryMapping ( 26 , TorznabCatType . TVSD , "TV/SD/x264" ) ;
AddCategoryMapping ( 7 , TorznabCatType . TVHD , "TV/x264" ) ;
AddCategoryMapping ( 34 , TorznabCatType . TVUHD , "TV/x265" ) ;
AddCategoryMapping ( 2 , TorznabCatType . TVSD , "TV/XviD" ) ;
AddCategoryMapping ( 6 , TorznabCatType . XXX , "XXX/Movies" ) ;
AddCategoryMapping ( 15 , TorznabCatType . XXXPacks , "XXX/Packs" ) ;
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 ) ;
2020-06-09 19:25:19 +00:00
CookieHeader = configData . Cookie . Value ;
try
2017-04-15 08:45:10 +00:00
{
2020-06-09 19:25:19 +00:00
var results = await PerformQuery ( new TorznabQuery ( ) ) ;
if ( ! results . Any ( ) )
throw new Exception ( "Found 0 results in the tracker" ) ;
2017-04-15 08:45:10 +00:00
2020-06-09 19:25:19 +00:00
IsConfigured = true ;
SaveConfig ( ) ;
return IndexerConfigurationStatus . Completed ;
}
catch ( Exception e )
2017-04-15 08:45:10 +00:00
{
2020-06-09 19:25:19 +00:00
IsConfigured = false ;
throw new Exception ( "Your cookie did not work: " + e . Message ) ;
}
2017-04-15 08:45:10 +00:00
}
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
{
var releases = new List < ReleaseInfo > ( ) ;
2018-01-30 13:11:10 +00:00
var cats = MapTorznabCapsToTrackers ( query ) ;
if ( cats . Count = = 0 )
cats = GetAllTrackerCategories ( ) ;
var catStr = string . Join ( ";" , cats ) ;
2020-04-04 20:34:38 +00:00
var searchUrl = SearchUrl + "?" + catStr ;
2018-01-30 13:11:10 +00:00
2020-04-04 20:34:38 +00:00
if ( query . IsImdbQuery )
searchUrl + = ";q=" + query . ImdbID ;
2017-04-15 08:45:10 +00:00
else
2020-04-04 20:34:38 +00:00
searchUrl + = ";q=" + WebUtilityHelpers . UrlEncode ( query . GetQueryString ( ) , Encoding ) ;
2017-04-15 08:45:10 +00:00
2020-04-04 20:34:38 +00:00
var results = await RequestStringWithCookiesAndRetry ( searchUrl ) ;
2017-04-15 08:45:10 +00:00
// Check for being logged out
if ( results . IsRedirect )
if ( results . RedirectingTo . Contains ( "login.php" ) )
2020-06-09 19:25:19 +00:00
throw new Exception ( "The user is not logged in. It is possible that the cookie has expired or you made a mistake when copying it. Please check the settings." ) ;
2017-04-15 08:45:10 +00:00
else
2020-06-09 19:25:19 +00:00
throw new Exception ( $"Got a redirect to {results.RedirectingTo}, please adjust your the alternative link" ) ;
2017-04-15 08:45:10 +00:00
try
{
2020-04-04 20:34:38 +00:00
var rows = JsonConvert . DeserializeObject < dynamic > ( results . Content ) ;
2018-01-30 13:11:10 +00:00
2020-04-04 20:34:38 +00:00
foreach ( var row in rows )
2017-04-15 08:45:10 +00:00
{
2020-04-04 20:34:38 +00:00
var title = ( string ) row . name ;
2020-03-27 20:23:10 +00:00
if ( ( ! query . IsImdbQuery | | ! TorznabCaps . SupportsImdbMovieSearch ) & & ! query . MatchQueryStringAND ( title ) )
2017-04-15 08:45:10 +00:00
continue ;
2020-04-04 20:34:38 +00:00
var torrentId = ( long ) row . t ;
var comments = new Uri ( SiteLink + "details.php?id=" + torrentId ) ;
var seeders = ( int ) row . seeders ;
var imdbId = ( string ) row [ "imdb-id" ] ;
var downloadMultiplier = ( double? ) row [ "download-multiplier" ] ? ? 1 ;
var link = new Uri ( SiteLink + "download.php/" + torrentId + "/" + torrentId + ".torrent" ) ;
var publishDate = DateTimeUtil . UnixTimestampToDateTime ( ( long ) row . ctime ) . ToLocalTime ( ) ;
2020-03-26 22:15:28 +00:00
var imdb = ParseUtil . GetImdbID ( imdbId ) ;
2020-04-04 20:34:38 +00:00
2020-03-26 22:15:28 +00:00
var release = new ReleaseInfo
{
2020-03-27 20:23:10 +00:00
Title = title ,
2020-03-26 22:15:28 +00:00
Comments = comments ,
Guid = comments ,
Link = link ,
PublishDate = publishDate ,
2020-04-04 20:34:38 +00:00
Category = MapTrackerCatToNewznab ( row . c . ToString ( ) ) ,
Size = ( long ) row . size ,
Files = ( long ) row . files ,
Grabs = ( long ) row . completed ,
2020-03-26 22:15:28 +00:00
Seeders = seeders ,
2020-04-04 20:34:38 +00:00
Peers = seeders + ( int ) row . leechers ,
2020-03-26 22:15:28 +00:00
Imdb = imdb ,
2020-04-04 20:34:38 +00:00
DownloadVolumeFactor = downloadMultiplier ,
UploadVolumeFactor = 1 ,
MinimumRatio = 1 ,
MinimumSeedTime = 172800 // 48 hours
2020-03-26 22:15:28 +00:00
} ;
2020-04-04 20:34:38 +00:00
2017-04-15 08:45:10 +00:00
releases . Add ( release ) ;
}
}
catch ( Exception ex )
{
OnParseError ( results . Content , ex ) ;
}
return releases ;
}
}
}