2020-03-28 16:24:46 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Collections.Specialized;
|
2020-05-03 23:35:52 +00:00
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2020-03-28 16:24:46 +00:00
|
|
|
using System.Linq;
|
|
|
|
using System.Text;
|
2020-04-24 17:44:24 +00:00
|
|
|
using System.Text.RegularExpressions;
|
2020-03-28 16:24:46 +00:00
|
|
|
using System.Threading.Tasks;
|
|
|
|
using System.Xml.Linq;
|
|
|
|
using Jackett.Common.Models;
|
|
|
|
using Jackett.Common.Models.IndexerConfig;
|
|
|
|
using Jackett.Common.Services.Interfaces;
|
|
|
|
using Jackett.Common.Utils;
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
using NLog;
|
|
|
|
|
|
|
|
namespace Jackett.Common.Indexers
|
|
|
|
{
|
2020-05-03 23:35:52 +00:00
|
|
|
[ExcludeFromCodeCoverage]
|
2020-03-28 16:24:46 +00:00
|
|
|
public class AwesomeHD : BaseWebIndexer
|
|
|
|
{
|
|
|
|
private string SearchUrl => SiteLink + "searchapi.php";
|
|
|
|
private string TorrentUrl => SiteLink + "torrents.php";
|
2020-04-24 17:44:24 +00:00
|
|
|
private readonly Regex _removeYearRegex = new Regex(@" [\(\[]?(19|20)\d{2}[\)\]]?$", RegexOptions.Compiled);
|
2020-03-28 16:24:46 +00:00
|
|
|
private new ConfigurationDataPasskey configData => (ConfigurationDataPasskey)base.configData;
|
|
|
|
|
|
|
|
public AwesomeHD(IIndexerConfigurationService configService, Utils.Clients.WebClient c, Logger l, IProtectionService ps)
|
2020-05-11 19:59:28 +00:00
|
|
|
: base(id: "awesomehd",
|
|
|
|
name: "Awesome-HD",
|
|
|
|
description: "An HD tracker",
|
|
|
|
link: "https://awesome-hd.me/",
|
|
|
|
caps: new TorznabCapabilities
|
|
|
|
{
|
|
|
|
SupportsImdbMovieSearch = true
|
|
|
|
// SupportsImdbTVSearch = true (supported by the site but disabled due to #8107)
|
|
|
|
},
|
|
|
|
configService: configService,
|
|
|
|
client: c,
|
|
|
|
logger: l,
|
|
|
|
p: ps,
|
|
|
|
configData: new ConfigurationDataPasskey("Note: You can find the Passkey in your profile, " +
|
|
|
|
"next to Personal information."))
|
2020-03-28 16:24:46 +00:00
|
|
|
{
|
|
|
|
Encoding = Encoding.UTF8;
|
|
|
|
Language = "en-us";
|
|
|
|
Type = "private";
|
|
|
|
|
|
|
|
AddCategoryMapping(1, TorznabCatType.MoviesHD);
|
|
|
|
AddCategoryMapping(2, TorznabCatType.TVHD);
|
2020-03-31 01:37:07 +00:00
|
|
|
AddCategoryMapping(3, TorznabCatType.Audio);
|
2020-03-28 16:24:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<IndexerConfigurationStatus> ApplyConfiguration(JToken configJson)
|
|
|
|
{
|
|
|
|
LoadValuesFromJson(configJson);
|
|
|
|
|
|
|
|
if (configData.Passkey.Value.Length != 32)
|
|
|
|
throw new Exception("Invalid Passkey configured. Expected length: 32");
|
|
|
|
|
|
|
|
var releases = await PerformQuery(new TorznabQuery());
|
|
|
|
await ConfigureIfOK(string.Empty, releases.Any(),
|
|
|
|
() => throw new Exception("Could not find release from this URL."));
|
|
|
|
|
|
|
|
return IndexerConfigurationStatus.Completed;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuery query)
|
|
|
|
{
|
|
|
|
var releases = new List<ReleaseInfo>();
|
|
|
|
var passkey = configData.Passkey.Value;
|
|
|
|
|
|
|
|
var qc = new NameValueCollection
|
|
|
|
{
|
|
|
|
{"passkey", passkey}
|
|
|
|
};
|
|
|
|
|
2020-03-31 01:37:07 +00:00
|
|
|
if (query.IsImdbQuery)
|
2020-03-28 16:24:46 +00:00
|
|
|
{
|
|
|
|
qc.Add("action", "imdbsearch");
|
|
|
|
qc.Add("imdb", query.ImdbID);
|
|
|
|
}
|
|
|
|
else if (!string.IsNullOrWhiteSpace(query.GetQueryString()))
|
|
|
|
{
|
2020-04-24 17:44:24 +00:00
|
|
|
// not use query.GetQueryString(), because it includes the season
|
|
|
|
var searchTerm = query.SearchTerm;
|
|
|
|
// search for tv series
|
|
|
|
if (query.Season > 0)
|
2020-03-31 01:37:07 +00:00
|
|
|
searchTerm += $": Season {query.Season:D2}";
|
2020-04-24 17:44:24 +00:00
|
|
|
// remove the year, it's not supported in the api
|
|
|
|
searchTerm = _removeYearRegex.Replace(searchTerm, "");
|
2020-03-28 16:24:46 +00:00
|
|
|
qc.Add("action", "titlesearch");
|
2020-03-31 01:37:07 +00:00
|
|
|
qc.Add("title", searchTerm);
|
2020-03-28 16:24:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qc.Add("action", "latestmovies");
|
|
|
|
// the endpoint 'latestmovies' only returns movies, this hack overwrites categories to get movies even if
|
|
|
|
// you are searching for tv series. this allows to configure the tracker in Sonarr
|
2020-04-07 16:17:17 +00:00
|
|
|
query.Categories = new int[] { };
|
2020-03-28 16:24:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var searchUrl = SearchUrl + "?" + qc.GetQueryString();
|
2020-09-21 06:02:53 +00:00
|
|
|
var results = await RequestStringWithCookies(searchUrl);
|
2020-09-21 06:04:26 +00:00
|
|
|
if (string.IsNullOrWhiteSpace(results.Content))
|
2020-03-28 16:24:46 +00:00
|
|
|
throw new Exception("Empty response. Please, check the Passkey.");
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2020-09-21 06:04:26 +00:00
|
|
|
var doc = XDocument.Parse(results.Content);
|
2020-03-28 16:24:46 +00:00
|
|
|
|
|
|
|
var errorMsg = doc.Descendants("error").FirstOrDefault()?.Value;
|
|
|
|
if (errorMsg?.Contains("No Results") == true)
|
|
|
|
return releases; // no results
|
|
|
|
if (errorMsg != null)
|
|
|
|
throw new Exception(errorMsg);
|
|
|
|
|
|
|
|
var authkey = doc.Descendants("authkey").First().Value;
|
|
|
|
var torrents = doc.Descendants("torrent");
|
|
|
|
foreach (var torrent in torrents)
|
|
|
|
{
|
|
|
|
var torrentName = torrent.FirstValue("name").Trim();
|
|
|
|
|
|
|
|
// the field <type> is always Movie, so we have to guess if it's a tv series
|
|
|
|
var isSerie = torrentName.Contains(": Season ");
|
|
|
|
if (isSerie)
|
|
|
|
torrentName = torrentName.Replace(": Season ", " S");
|
|
|
|
|
2020-03-31 01:37:07 +00:00
|
|
|
// we have to guess if it's an audio track too
|
|
|
|
var isAudio = string.IsNullOrWhiteSpace((string)torrent.Element("resolution"));
|
|
|
|
var cat = new List<int>
|
|
|
|
{
|
|
|
|
isSerie ? TorznabCatType.TVHD.ID :
|
|
|
|
isAudio ? TorznabCatType.Audio.ID :
|
|
|
|
TorznabCatType.MoviesHD.ID
|
|
|
|
};
|
|
|
|
|
2020-03-28 16:24:46 +00:00
|
|
|
// if the category is not in the search categories, skip
|
|
|
|
if (query.Categories.Any() && !query.Categories.Intersect(cat).Any())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
var title = new StringBuilder(torrentName);
|
|
|
|
if (!isSerie && torrent.Element("year") != null) // only for movies
|
|
|
|
title.Append($" {torrent.FirstValue("year")}");
|
|
|
|
if (torrent.Element("internal")?.Value == "1")
|
|
|
|
title.Append(" iNTERNAL");
|
|
|
|
if (torrent.Element("resolution") != null)
|
|
|
|
title.Append($" {torrent.FirstValue("resolution")}");
|
|
|
|
if (torrent.Element("media") != null)
|
|
|
|
title.Append($" {torrent.FirstValue("media")}");
|
|
|
|
if (torrent.Element("encoding") != null)
|
|
|
|
title.Append($" {torrent.FirstValue("encoding")}");
|
|
|
|
if (torrent.Element("audioformat") != null)
|
|
|
|
title.Append($" {torrent.FirstValue("audioformat")}");
|
|
|
|
if (torrent.Element("releasegroup") != null)
|
|
|
|
title.Append($"-{torrent.FirstValue("releasegroup")}");
|
|
|
|
|
|
|
|
var torrentId = torrent.FirstValue("id");
|
|
|
|
var groupId = torrent.FirstValue("groupid");
|
|
|
|
var comments = new Uri($"{TorrentUrl}?id={groupId}&torrentid={torrentId}");
|
|
|
|
var link = new Uri($"{TorrentUrl}?action=download&id={torrentId}&authkey={authkey}&torrent_pass={passkey}");
|
|
|
|
|
|
|
|
var publishDate = DateTime.Parse(torrent.FirstValue("time"));
|
|
|
|
var size = long.Parse(torrent.FirstValue("size"));
|
|
|
|
var grabs = int.Parse(torrent.FirstValue("snatched"));
|
|
|
|
var seeders = int.Parse(torrent.FirstValue("seeders"));
|
|
|
|
var peers = seeders + int.Parse(torrent.FirstValue("leechers"));
|
|
|
|
var freeleech = double.Parse(torrent.FirstValue("freeleech"));
|
|
|
|
|
|
|
|
Uri banner = null;
|
2020-03-31 01:37:07 +00:00
|
|
|
string description = null;
|
|
|
|
if (!isAudio) // audio tracks don't have banner either description
|
|
|
|
{
|
|
|
|
// small cover only for movies
|
|
|
|
if (!isSerie && !string.IsNullOrWhiteSpace(torrent.Element("smallcover")?.Value))
|
|
|
|
banner = new Uri(torrent.FirstValue("smallcover"));
|
|
|
|
else if (!string.IsNullOrWhiteSpace(torrent.Element("cover")?.Value))
|
|
|
|
banner = new Uri(torrent.FirstValue("cover"));
|
|
|
|
|
|
|
|
description = torrent.Element("encodestatus") != null ?
|
|
|
|
$"Encode status: {torrent.FirstValue("encodestatus")}" : null;
|
|
|
|
}
|
2020-03-28 16:24:46 +00:00
|
|
|
|
|
|
|
var imdb = ParseUtil.GetImdbID(torrent.Element("imdb")?.Value);
|
|
|
|
|
|
|
|
var release = new ReleaseInfo
|
|
|
|
{
|
|
|
|
Title = title.ToString(),
|
|
|
|
Comments = comments,
|
|
|
|
Link = link,
|
|
|
|
Guid = link,
|
|
|
|
PublishDate = publishDate,
|
|
|
|
Category = cat,
|
|
|
|
BannerUrl = banner,
|
|
|
|
Description = description,
|
|
|
|
Imdb = imdb,
|
|
|
|
Size = size,
|
|
|
|
Grabs = grabs,
|
|
|
|
Seeders = seeders,
|
|
|
|
Peers = peers,
|
|
|
|
MinimumRatio = 1,
|
|
|
|
MinimumSeedTime = 259200, // 72 hours
|
|
|
|
DownloadVolumeFactor = freeleech,
|
|
|
|
UploadVolumeFactor = 1
|
|
|
|
};
|
|
|
|
|
|
|
|
releases.Add(release);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
2020-09-21 06:04:26 +00:00
|
|
|
OnParseError(results.Content, ex);
|
2020-03-28 16:24:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return releases;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|