scenehd: passkey login and code clean up. resolves #7034 (#8571)

This commit is contained in:
Diego Heras
2020-05-09 23:35:43 +02:00
committed by GitHub
parent 6f903fa360
commit 4262c5de6f

View File

@@ -19,33 +19,31 @@ namespace Jackett.Common.Indexers
[ExcludeFromCodeCoverage] [ExcludeFromCodeCoverage]
public class SceneHD : BaseWebIndexer public class SceneHD : BaseWebIndexer
{ {
private string SearchUrl => SiteLink + "browse.php"; private string SearchUrl => SiteLink + "browse.php?";
private string CommentsUrl => SiteLink + "details.php?";
private string DownloadUrl => SiteLink + "download.php?";
private new ConfigurationDataCookie configData private new ConfigurationDataPasskey configData => (ConfigurationDataPasskey)base.configData;
{
get => (ConfigurationDataCookie)base.configData;
set => base.configData = value;
}
public SceneHD(IIndexerConfigurationService configService, WebClient c, Logger l, IProtectionService ps) public SceneHD(IIndexerConfigurationService configService, WebClient c, Logger l, IProtectionService ps)
: base(name: "SceneHD", : base("SceneHD",
description: "SceneHD is Private site for HD TV / MOVIES", description: "SceneHD is Private site for HD TV / MOVIES",
link: "https://scenehd.org/", link: "https://scenehd.org/",
configService: configService, configService: configService,
caps: new TorznabCapabilities caps: new TorznabCapabilities
{ {
SupportsImdbMovieSearch = true SupportsImdbMovieSearch = true
}, },
client: c, client: c,
logger: l, logger: l,
p: ps, p: ps,
configData: new ConfigurationDataCookie()) configData: new ConfigurationDataPasskey("You can find the Passkey if you generate a RSS " +
"feed link. It's the last parameter in the URL."))
{ {
Encoding = Encoding.UTF8; Encoding = Encoding.UTF8;
Language = "en-us"; Language = "en-us";
Type = "private"; Type = "private";
webclient.EmulateBrowser = false;
webclient.AddTrustedCertificate(new Uri(SiteLink).Host, "D948487DD52462F2D1E62B990D608051E3DE5AA6"); webclient.AddTrustedCertificate(new Uri(SiteLink).Host, "D948487DD52462F2D1E62B990D608051E3DE5AA6");
AddCategoryMapping(2, TorznabCatType.MoviesUHD, "Movie/2160"); AddCategoryMapping(2, TorznabCatType.MoviesUHD, "Movie/2160");
@@ -66,101 +64,67 @@ namespace Jackett.Common.Indexers
{ {
LoadValuesFromJson(configJson); LoadValuesFromJson(configJson);
// TODO: implement captcha if (configData.Passkey.Value.Length != 32)
CookieHeader = configData.Cookie.Value; throw new Exception("Invalid Passkey configured. Expected length: 32");
try
{
var results = await PerformQuery(new TorznabQuery());
if (results.Count() == 0)
{
throw new Exception("Found 0 results in the tracker");
}
IsConfigured = true; var releases = await PerformQuery(new TorznabQuery());
SaveConfig(); await ConfigureIfOK(string.Empty, releases.Any(),
return IndexerConfigurationStatus.Completed; () => throw new Exception("Could not find releases from this URL."));
}
catch (Exception e) return IndexerConfigurationStatus.Completed;
{
IsConfigured = false;
throw new Exception("Your cookie did not work: " + e.Message);
}
} }
protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuery query) protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuery query)
{ {
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);
TimeZoneInfo.AdjustmentRule[] adjustments = { adjustment };
var Tz = TimeZoneInfo.CreateCustomTimeZone("custom", new TimeSpan(1, 0, 0), "custom", "custom", "custom", adjustments);
var releases = new List<ReleaseInfo>(); var releases = new List<ReleaseInfo>();
var passkey = configData.Passkey.Value;
var qParams = new NameValueCollection var qc = new NameValueCollection
{ {
{ "api", "" } { "api", "" },
{ "passkey", passkey },
{ "search", query.IsImdbQuery ? query.ImdbID : query.GetQueryString() }
}; };
if (query.ImdbIDShort != null)
qParams.Add("imdb", query.ImdbIDShort);
else
qParams.Add("search", query.SearchTerm);
foreach (var cat in MapTorznabCapsToTrackers(query)) foreach (var cat in MapTorznabCapsToTrackers(query))
{ qc.Add("categories[" + cat + "]", "1");
qParams.Add("categories[" + cat + "]", "1");
}
var urlSearch = SearchUrl; var searchUrl = SearchUrl + qc.GetQueryString();
urlSearch += "?" + qParams.GetQueryString(); var response = await RequestStringWithCookiesAndRetry(searchUrl);
var response = await RequestStringWithCookiesAndRetry(urlSearch); if (response.Content?.Contains("User not found or passkey not set") == true)
if (response.IsRedirect) throw new Exception("The passkey is invalid. Check the indexer configuration.");
throw new Exception("not logged in");
try try
{ {
var jsonContent = JArray.Parse(response.Content); var jsonContent = JArray.Parse(response.Content);
var sitelink = new Uri(SiteLink);
foreach (var item in jsonContent) foreach (var item in jsonContent)
{ {
//TODO convert to initializer
var release = new ReleaseInfo();
var id = item.Value<long>("id"); var id = item.Value<long>("id");
release.Title = item.Value<string>("name"); var comments = new Uri(CommentsUrl + "id=" + id);
var link = new Uri(DownloadUrl + "id=" + id + "&passkey=" + passkey);
var publishDate = DateTime.ParseExact(item.Value<string>("added"), "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
var dlVolumeFactor = item.Value<int>("is_freeleech") == 1 ? 0 : 1;
var imdbid = item.Value<string>("imdbid"); var release = new ReleaseInfo
if (!string.IsNullOrEmpty(imdbid)) {
release.Imdb = long.Parse(imdbid); Title = item.Value<string>("name"),
Link = link,
var category = item.Value<string>("category"); Comments = comments,
release.Category = MapTrackerCatToNewznab(category); Guid = comments,
Category = MapTrackerCatToNewznab(item.Value<string>("category")),
release.Link = new Uri(sitelink, "/download.php?id=" + id); PublishDate = publishDate,
release.Comments = new Uri(sitelink, "/details.php?id=" + id); Size = item.Value<long>("size"),
release.Guid = release.Comments; Grabs = item.Value<long>("times_completed"),
Files = item.Value<long>("numfiles"),
var dateStr = item.Value<string>("added"); Seeders = item.Value<int>("seeders"),
var dateTime = DateTime.SpecifyKind(DateTime.ParseExact(dateStr, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture), DateTimeKind.Unspecified); Peers = item.Value<int>("leechers") + item.Value<int>("seeders"),
var pubDateUtc = TimeZoneInfo.ConvertTimeToUtc(dateTime, Tz); Imdb = ParseUtil.GetImdbID(item.Value<string>("imdbid")),
release.PublishDate = pubDateUtc; MinimumRatio = 1,
MinimumSeedTime = 0,
release.Grabs = item.Value<long>("times_completed"); DownloadVolumeFactor = dlVolumeFactor,
release.Files = item.Value<long>("numfiles"); UploadVolumeFactor = 1
release.Seeders = item.Value<int>("seeders"); };
release.Peers = item.Value<int>("leechers") + release.Seeders;
var size = item.Value<string>("size");
release.Size = ReleaseInfo.GetBytes(size);
var is_freeleech = item.Value<int>("is_freeleech");
if (is_freeleech == 1)
release.DownloadVolumeFactor = 0;
else
release.DownloadVolumeFactor = 1;
release.UploadVolumeFactor = 1;
releases.Add(release); releases.Add(release);
} }