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;
|
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-07-22 23:12:12 +00:00
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
using NLog;
|
|
|
|
|
2018-03-10 08:05:56 +00:00
|
|
|
namespace Jackett.Common.Indexers
|
2017-07-22 23:12:12 +00:00
|
|
|
{
|
2020-05-03 23:35:52 +00:00
|
|
|
[ExcludeFromCodeCoverage]
|
2020-05-11 22:58:10 +00:00
|
|
|
public class YTS : BaseWebIndexer
|
2017-07-22 23:12:12 +00:00
|
|
|
{
|
2020-12-12 09:32:33 +00:00
|
|
|
public override string[] AlternativeSiteLinks { get; protected set; } = {
|
|
|
|
"https://yts.mx/",
|
2021-04-07 21:31:08 +00:00
|
|
|
"https://yts.unblockit.club/",
|
2020-12-20 22:06:24 +00:00
|
|
|
"https://yts.unblockninja.com/"
|
2020-12-12 09:32:33 +00:00
|
|
|
};
|
|
|
|
|
2020-10-19 21:19:10 +00:00
|
|
|
public override string[] LegacySiteLinks { get; protected set; } = {
|
2018-10-09 18:59:47 +00:00
|
|
|
"https://yts.ag/",
|
2019-06-07 19:27:21 +00:00
|
|
|
"https://yts.am/",
|
2020-12-20 22:06:24 +00:00
|
|
|
"https://yts.lt/",
|
2021-01-12 12:58:34 +00:00
|
|
|
"https://yts.unblockit.dev/",
|
2021-02-10 04:23:32 +00:00
|
|
|
"https://yts.root.yt/",
|
2021-03-09 19:49:53 +00:00
|
|
|
"https://yts.unblockit.ltd/",
|
2021-04-07 21:31:08 +00:00
|
|
|
"https://yts.unblockit.buzz/",
|
2021-03-09 19:49:53 +00:00
|
|
|
"https://yts.unblockit.link/"
|
2017-11-29 18:13:52 +00:00
|
|
|
};
|
|
|
|
|
2020-02-25 16:08:03 +00:00
|
|
|
private string ApiEndpoint => SiteLink + "api/v2/list_movies.json";
|
2017-07-22 23:12:12 +00:00
|
|
|
|
2020-12-11 22:14:21 +00:00
|
|
|
public YTS(IIndexerConfigurationService configService, WebClient wc, Logger l, IProtectionService ps,
|
|
|
|
ICacheService cs)
|
2020-05-11 19:59:28 +00:00
|
|
|
: base(id: "yts",
|
|
|
|
name: "YTS",
|
|
|
|
description: "YTS is a Public torrent site specialising in HD movies of small size",
|
|
|
|
link: "https://yts.mx/",
|
|
|
|
caps: new TorznabCapabilities
|
|
|
|
{
|
2020-10-18 17:26:22 +00:00
|
|
|
MovieSearchParams = new List<MovieSearchParam> { MovieSearchParam.Q, MovieSearchParam.ImdbId }
|
2020-05-11 19:59:28 +00:00
|
|
|
},
|
|
|
|
configService: configService,
|
|
|
|
client: wc,
|
|
|
|
logger: l,
|
|
|
|
p: ps,
|
2020-12-11 22:14:21 +00:00
|
|
|
cacheService: cs,
|
2020-05-11 19:59:28 +00:00
|
|
|
configData: new ConfigurationData())
|
2017-07-22 23:12:12 +00:00
|
|
|
{
|
|
|
|
Encoding = Encoding.GetEncoding("windows-1252");
|
|
|
|
Language = "en-us";
|
|
|
|
Type = "public";
|
|
|
|
|
|
|
|
webclient.requestDelay = 2.5; // 0.5 requests per second (2 causes problems)
|
|
|
|
|
2020-01-25 00:38:20 +00:00
|
|
|
// note: the API does not support searching with categories, so these are dummy ones for torznab compatibility
|
2020-04-03 22:37:42 +00:00
|
|
|
// we map these newznab cats with the returned quality value in the releases routine.
|
2020-01-25 00:38:20 +00:00
|
|
|
AddCategoryMapping(45, TorznabCatType.MoviesHD, "Movies/x264/720p");
|
|
|
|
AddCategoryMapping(44, TorznabCatType.MoviesHD, "Movies/x264/1080p");
|
|
|
|
AddCategoryMapping(46, TorznabCatType.MoviesUHD, "Movies/x264/2160p"); // added for #7010
|
2017-07-22 23:12:12 +00:00
|
|
|
AddCategoryMapping(47, TorznabCatType.Movies3D, "Movies/x264/3D");
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<IndexerConfigurationStatus> ApplyConfiguration(JToken configJson)
|
|
|
|
{
|
2020-12-11 23:12:40 +00:00
|
|
|
LoadValuesFromJson(configJson);
|
2017-07-22 23:12:12 +00:00
|
|
|
var releases = await PerformQuery(new TorznabQuery());
|
|
|
|
|
2020-02-25 16:08:03 +00:00
|
|
|
await ConfigureIfOK(string.Empty, releases.Count() > 0,
|
|
|
|
() => throw new Exception("Could not find releases from this URL"));
|
2017-07-22 23:12:12 +00:00
|
|
|
|
|
|
|
return IndexerConfigurationStatus.Completed;
|
|
|
|
}
|
|
|
|
|
2021-02-13 15:07:48 +00:00
|
|
|
protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuery query) => await PerformQueryAsync(query);
|
2017-07-22 23:12:12 +00:00
|
|
|
|
2021-02-13 15:07:48 +00:00
|
|
|
private async Task<IEnumerable<ReleaseInfo>> PerformQueryAsync(TorznabQuery query)
|
|
|
|
{
|
|
|
|
var searchUrl = CreateSearchUrl(query);
|
|
|
|
var response = await RequestWithCookiesAndRetryAsync(searchUrl);
|
|
|
|
var releases = ParseWebResult(response);
|
|
|
|
return releases;
|
|
|
|
}
|
|
|
|
|
|
|
|
private string CreateSearchUrl(TorznabQuery query)
|
2017-07-22 23:12:12 +00:00
|
|
|
{
|
|
|
|
var searchString = query.GetQueryString();
|
2017-10-29 06:50:47 +00:00
|
|
|
|
2020-03-26 22:15:28 +00:00
|
|
|
var queryCollection = new NameValueCollection
|
|
|
|
{
|
|
|
|
// without this the API sometimes returns nothing
|
|
|
|
{ "sort", "date_added" },
|
|
|
|
{ "limit", "50" }
|
|
|
|
};
|
2018-10-15 15:00:19 +00:00
|
|
|
|
2017-07-22 23:12:12 +00:00
|
|
|
if (query.ImdbID != null)
|
|
|
|
{
|
|
|
|
queryCollection.Add("query_term", query.ImdbID);
|
|
|
|
}
|
|
|
|
else if (!string.IsNullOrWhiteSpace(searchString))
|
|
|
|
{
|
|
|
|
searchString = searchString.Replace("'", ""); // ignore ' (e.g. search for america's Next Top Model)
|
|
|
|
queryCollection.Add("query_term", searchString);
|
|
|
|
}
|
|
|
|
|
|
|
|
var searchUrl = ApiEndpoint + "?" + queryCollection.GetQueryString();
|
2021-02-13 15:07:48 +00:00
|
|
|
return searchUrl;
|
|
|
|
}
|
2017-07-22 23:12:12 +00:00
|
|
|
|
2021-02-13 15:07:48 +00:00
|
|
|
private IEnumerable<ReleaseInfo> ParseWebResult(WebResult webResult)
|
|
|
|
{
|
|
|
|
var releases = new List<ReleaseInfo>();
|
|
|
|
var contentString = webResult.ContentString;
|
2017-07-22 23:12:12 +00:00
|
|
|
try
|
|
|
|
{
|
2018-04-01 13:25:35 +00:00
|
|
|
// returned content might start with an html error message, remove it first
|
2021-02-13 15:07:48 +00:00
|
|
|
var jsonStart = contentString.IndexOf('{');
|
|
|
|
var jsonContentStr = contentString.Remove(0, jsonStart);
|
2018-04-01 13:25:35 +00:00
|
|
|
|
|
|
|
var jsonContent = JObject.Parse(jsonContentStr);
|
2017-07-22 23:12:12 +00:00
|
|
|
|
2020-02-10 22:16:19 +00:00
|
|
|
var result = jsonContent.Value<string>("status");
|
2017-07-22 23:12:12 +00:00
|
|
|
if (result != "ok") // query was not successful
|
|
|
|
{
|
2021-02-13 15:07:48 +00:00
|
|
|
return new List<ReleaseInfo>();
|
2017-07-22 23:12:12 +00:00
|
|
|
}
|
|
|
|
|
2021-02-13 15:07:48 +00:00
|
|
|
var dataItems = jsonContent.Value<JToken>("data");
|
|
|
|
var movieCount = dataItems.Value<int>("movie_count");
|
|
|
|
if (movieCount < 1) // no results found in query
|
2017-07-22 23:12:12 +00:00
|
|
|
{
|
2021-02-13 15:07:48 +00:00
|
|
|
return new List<ReleaseInfo>();
|
2017-07-22 23:12:12 +00:00
|
|
|
}
|
|
|
|
|
2021-02-13 15:07:48 +00:00
|
|
|
var movies = dataItems.Value<JToken>("movies");
|
2018-10-15 15:00:19 +00:00
|
|
|
if (movies == null)
|
2021-02-13 15:07:48 +00:00
|
|
|
{
|
|
|
|
return new List<ReleaseInfo>();
|
|
|
|
}
|
2018-10-15 15:00:19 +00:00
|
|
|
|
2021-02-13 15:07:48 +00:00
|
|
|
foreach (var movie in movies)
|
2017-07-22 23:12:12 +00:00
|
|
|
{
|
2021-02-13 15:07:48 +00:00
|
|
|
var torrents = movie.Value<JArray>("torrents");
|
2018-01-30 13:37:39 +00:00
|
|
|
if (torrents == null)
|
|
|
|
continue;
|
2021-02-13 15:07:48 +00:00
|
|
|
foreach (var torrent in torrents)
|
2017-07-22 23:12:12 +00:00
|
|
|
{
|
2021-02-13 15:07:48 +00:00
|
|
|
var release = ParseJsonIntoReleaseInfo(movie, torrent);
|
|
|
|
if (release == null)
|
|
|
|
continue;
|
2020-01-25 00:38:20 +00:00
|
|
|
releases.Add(release);
|
2017-07-22 23:12:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
2021-02-13 15:07:48 +00:00
|
|
|
OnParseError(contentString, ex);
|
2017-07-22 23:12:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return releases;
|
|
|
|
}
|
2021-02-13 15:07:48 +00:00
|
|
|
|
|
|
|
private ReleaseInfo ParseJsonIntoReleaseInfo(JToken movie, JToken torrent)
|
|
|
|
{
|
|
|
|
//TODO change to initializer
|
|
|
|
var release = new ReleaseInfo();
|
|
|
|
|
|
|
|
// append type: BRRip or WEBRip, resolves #3558 via #4577
|
|
|
|
var type = torrent.Value<string>("type");
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case "web":
|
|
|
|
type = "WEBRip";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
type = "BRRip";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
var quality = torrent.Value<string>("quality");
|
|
|
|
var title = movie.Value<string>("title").Replace(":", "").Replace(' ', '.');
|
|
|
|
var year = movie.Value<int>("year");
|
|
|
|
release.Title = $"{title}.{year}.{quality}.{type}-YTS";
|
|
|
|
|
|
|
|
var imdb = movie.Value<string>("imdb_code");
|
|
|
|
release.Imdb = ParseUtil.GetImdbID(imdb);
|
|
|
|
|
|
|
|
release.InfoHash = torrent.Value<string>("hash"); // magnet link is auto generated from infohash
|
|
|
|
|
|
|
|
// ex: 2015-08-16 21:25:08 +0000
|
|
|
|
var dateStr = torrent.Value<string>("date_uploaded");
|
|
|
|
var dateTime = DateTime.ParseExact(dateStr, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
|
|
|
|
release.PublishDate = DateTime.SpecifyKind(dateTime, DateTimeKind.Utc).ToLocalTime();
|
|
|
|
|
|
|
|
release.Link = new Uri(torrent.Value<string>("url"));
|
|
|
|
release.Seeders = torrent.Value<int>("seeds");
|
|
|
|
release.Peers = torrent.Value<int>("peers") + release.Seeders;
|
|
|
|
release.Size = torrent.Value<long>("size_bytes");
|
|
|
|
release.DownloadVolumeFactor = 0;
|
|
|
|
release.UploadVolumeFactor = 1;
|
|
|
|
|
|
|
|
release.Details = new Uri(movie.Value<string>("url"));
|
|
|
|
release.Poster = new Uri(movie.Value<string>("large_cover_image"));
|
|
|
|
release.Guid = release.Link;
|
|
|
|
|
|
|
|
// map the quality to a newznab category for torznab compatibility (for Radarr, etc)
|
|
|
|
switch (quality)
|
|
|
|
{
|
|
|
|
case "720p":
|
|
|
|
release.Category = MapTrackerCatToNewznab("45");
|
|
|
|
break;
|
|
|
|
case "1080p":
|
|
|
|
release.Category = MapTrackerCatToNewznab("44");
|
|
|
|
break;
|
|
|
|
case "2160p":
|
|
|
|
release.Category = MapTrackerCatToNewznab("46");
|
|
|
|
break;
|
|
|
|
case "3D":
|
|
|
|
release.Category = MapTrackerCatToNewznab("47");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
release.Category = MapTrackerCatToNewznab("45");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return release;
|
|
|
|
}
|
2017-07-22 23:12:12 +00:00
|
|
|
}
|
2017-10-03 10:47:02 +00:00
|
|
|
}
|