2017-10-29 06:50:47 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Collections.Specialized;
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
public class Yts : BaseWebIndexer
|
|
|
|
|
{
|
2017-11-29 18:13:52 +00:00
|
|
|
|
public override string[] LegacySiteLinks { get; protected set; } = new string[] {
|
2018-10-09 18:59:47 +00:00
|
|
|
|
"https://yts.ag/",
|
2017-11-29 18:13:52 +00:00
|
|
|
|
};
|
|
|
|
|
|
2017-11-29 18:32:21 +00:00
|
|
|
|
private string ApiEndpoint { get { return SiteLink + "api/v2/list_movies.json"; } }
|
2017-07-22 23:12:12 +00:00
|
|
|
|
|
2017-11-29 18:32:21 +00:00
|
|
|
|
private new ConfigurationData configData
|
2017-07-22 23:12:12 +00:00
|
|
|
|
{
|
2017-11-29 18:32:21 +00:00
|
|
|
|
get { return (ConfigurationData)base.configData; }
|
2017-07-22 23:12:12 +00:00
|
|
|
|
set { base.configData = value; }
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-05 09:42:03 +00:00
|
|
|
|
public Yts(IIndexerConfigurationService configService, WebClient wc, Logger l, IProtectionService ps)
|
2017-07-22 23:12:12 +00:00
|
|
|
|
: base(name: "YTS",
|
2017-10-03 10:47:02 +00:00
|
|
|
|
description: "YTS is a Public torrent site specialising in HD movies of small size",
|
2018-10-09 18:59:47 +00:00
|
|
|
|
link: "https://yts.am/",
|
2017-07-22 23:12:12 +00:00
|
|
|
|
caps: new TorznabCapabilities(),
|
|
|
|
|
configService: configService,
|
|
|
|
|
client: wc,
|
|
|
|
|
logger: l,
|
|
|
|
|
p: ps,
|
2017-11-29 18:32:21 +00:00
|
|
|
|
configData: new ConfigurationData())
|
2017-07-22 23:12:12 +00:00
|
|
|
|
{
|
|
|
|
|
Encoding = Encoding.GetEncoding("windows-1252");
|
|
|
|
|
Language = "en-us";
|
|
|
|
|
Type = "public";
|
|
|
|
|
|
|
|
|
|
TorznabCaps.SupportsImdbSearch = true;
|
|
|
|
|
|
|
|
|
|
webclient.requestDelay = 2.5; // 0.5 requests per second (2 causes problems)
|
|
|
|
|
|
|
|
|
|
AddCategoryMapping(45, TorznabCatType.MoviesHD, "Movies/x264/720");
|
|
|
|
|
AddCategoryMapping(44, TorznabCatType.MoviesHD, "Movies/x264/1080");
|
|
|
|
|
AddCategoryMapping(47, TorznabCatType.Movies3D, "Movies/x264/3D");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override async Task<IndexerConfigurationStatus> ApplyConfiguration(JToken configJson)
|
|
|
|
|
{
|
|
|
|
|
configData.LoadValuesFromJson(configJson);
|
|
|
|
|
var releases = await PerformQuery(new TorznabQuery());
|
|
|
|
|
|
|
|
|
|
await ConfigureIfOK(string.Empty, releases.Count() > 0, () =>
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Could not find releases from this URL");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return IndexerConfigurationStatus.Completed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuery query)
|
|
|
|
|
{
|
|
|
|
|
return await PerformQuery(query, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuery query, int attempts)
|
|
|
|
|
{
|
|
|
|
|
var releases = new List<ReleaseInfo>();
|
|
|
|
|
var searchString = query.GetQueryString();
|
2017-10-29 06:50:47 +00:00
|
|
|
|
|
2017-07-22 23:12:12 +00:00
|
|
|
|
var queryCollection = new NameValueCollection();
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This API does not seem to be working for quality=720p or quality=1080p
|
|
|
|
|
// Only quality=3D seems to return a proper result?
|
|
|
|
|
//var cats = string.Join(";", MapTorznabCapsToTrackers(query));
|
|
|
|
|
//if (!string.IsNullOrEmpty(cats))
|
|
|
|
|
//{
|
|
|
|
|
// if (cats == "45")
|
|
|
|
|
// {
|
|
|
|
|
// queryCollection.Add("quality", "720p");
|
|
|
|
|
// }
|
|
|
|
|
// if (cats == "44")
|
|
|
|
|
// {
|
|
|
|
|
// queryCollection.Add("quality", "1080p");
|
|
|
|
|
// }
|
|
|
|
|
// if (cats == "2050")
|
|
|
|
|
// {
|
|
|
|
|
// queryCollection.Add("quality", "3D");
|
|
|
|
|
// }
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
var searchUrl = ApiEndpoint + "?" + queryCollection.GetQueryString();
|
|
|
|
|
var response = await RequestStringWithCookiesAndRetry(searchUrl, string.Empty);
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2018-04-01 13:25:35 +00:00
|
|
|
|
// returned content might start with an html error message, remove it first
|
|
|
|
|
var jsonStart = response.Content.IndexOf('{');
|
|
|
|
|
var jsonContentStr = response.Content.Remove(0, jsonStart);
|
|
|
|
|
|
|
|
|
|
var jsonContent = JObject.Parse(jsonContentStr);
|
2017-07-22 23:12:12 +00:00
|
|
|
|
|
|
|
|
|
string result = jsonContent.Value<string>("status");
|
|
|
|
|
if (result != "ok") // query was not successful
|
|
|
|
|
{
|
|
|
|
|
return releases.ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var data_items = jsonContent.Value<JToken>("data");
|
|
|
|
|
int movie_count = data_items.Value<int>("movie_count");
|
|
|
|
|
if (movie_count < 1) // no results found in query
|
|
|
|
|
{
|
|
|
|
|
return releases.ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var movie_item in data_items.Value<JToken>("movies"))
|
|
|
|
|
{
|
2018-01-30 13:37:39 +00:00
|
|
|
|
var torrents = movie_item.Value<JArray>("torrents");
|
|
|
|
|
if (torrents == null)
|
|
|
|
|
continue;
|
|
|
|
|
foreach (var torrent_info in torrents)
|
2017-07-22 23:12:12 +00:00
|
|
|
|
{
|
|
|
|
|
var release = new ReleaseInfo();
|
|
|
|
|
|
|
|
|
|
// Append the quality to the title because thats how radarr seems to be determining the quality?
|
2017-11-29 18:32:21 +00:00
|
|
|
|
// All releases are BRRips, see issue #2200
|
|
|
|
|
release.Title = movie_item.Value<string>("title_long") + " " + torrent_info.Value<string>("quality") + " BRRip";
|
2017-07-22 23:12:12 +00:00
|
|
|
|
var imdb = movie_item.Value<string>("imdb_code");
|
|
|
|
|
release.Imdb = ParseUtil.GetImdbID(imdb);
|
|
|
|
|
|
|
|
|
|
// API does not provide magnet link, so, construct it
|
|
|
|
|
string magnet_uri = "magnet:?xt=urn:btih:" + torrent_info.Value<string>("hash") +
|
|
|
|
|
"&dn=" + movie_item.Value<string>("slug") +
|
|
|
|
|
"&tr=udp://open.demonii.com:1337/announce" +
|
|
|
|
|
"&tr=udp://tracker.openbittorrent.com:80" +
|
|
|
|
|
"&tr=udp://tracker.coppersurfer.tk:6969" +
|
|
|
|
|
"&tr=udp://glotorrents.pw:6969/announce" +
|
|
|
|
|
"&tr=udp://tracker.opentrackr.org:1337/announce" +
|
|
|
|
|
"&tr=udp://torrent.gresille.org:80/announce" +
|
|
|
|
|
"&tr=udp://p4p.arenabg.com:1337&tr=udp://tracker.leechers-paradise.org:6969";
|
|
|
|
|
|
|
|
|
|
release.MagnetUri = new Uri(magnet_uri);
|
|
|
|
|
release.InfoHash = torrent_info.Value<string>("hash");
|
|
|
|
|
|
|
|
|
|
// ex: 2015-08-16 21:25:08 +0000
|
|
|
|
|
var dateStr = torrent_info.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();
|
2017-11-29 18:32:21 +00:00
|
|
|
|
release.Link = new Uri(torrent_info.Value<string>("url"));
|
2017-07-22 23:12:12 +00:00
|
|
|
|
release.Seeders = torrent_info.Value<int>("seeds");
|
|
|
|
|
release.Peers = torrent_info.Value<int>("peers") + release.Seeders;
|
|
|
|
|
release.Size = torrent_info.Value<long>("size_bytes");
|
|
|
|
|
release.DownloadVolumeFactor = 0;
|
|
|
|
|
release.UploadVolumeFactor = 1;
|
|
|
|
|
|
2017-11-29 18:32:21 +00:00
|
|
|
|
release.Comments = new Uri(movie_item.Value<string>("url"));
|
|
|
|
|
release.BannerUrl = new Uri(movie_item.Value<string>("large_cover_image"));
|
|
|
|
|
release.Guid = release.Link;
|
2017-07-22 23:12:12 +00:00
|
|
|
|
|
|
|
|
|
// Hack to prevent adding non-specified catogery, since API doesn't seem to be working
|
|
|
|
|
string categories = string.Join(";", MapTorznabCapsToTrackers(query));
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(categories))
|
|
|
|
|
{
|
|
|
|
|
if (categories.Contains("45") || categories.Contains("2040"))
|
|
|
|
|
{
|
|
|
|
|
if (torrent_info.Value<string>("quality") == "720p")
|
|
|
|
|
{
|
|
|
|
|
release.Category = MapTrackerCatToNewznab("45");
|
|
|
|
|
releases.Add(release);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (categories.Contains("44") || categories.Contains("2040"))
|
|
|
|
|
{
|
|
|
|
|
if (torrent_info.Value<string>("quality") == "1080p")
|
|
|
|
|
{
|
|
|
|
|
release.Category = MapTrackerCatToNewznab("44");
|
|
|
|
|
releases.Add(release);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (categories.Contains("47"))
|
|
|
|
|
{
|
|
|
|
|
if (torrent_info.Value<string>("quality") == "3D")
|
|
|
|
|
{
|
|
|
|
|
release.Category = MapTrackerCatToNewznab("47");
|
|
|
|
|
releases.Add(release);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
release.Category = MapTrackerCatToNewznab("45");
|
|
|
|
|
releases.Add(release);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
OnParseError(response.Content, ex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return releases;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-10-03 10:47:02 +00:00
|
|
|
|
}
|