Fix parse errors with Shazbat (#7493) resolves #7492

This commit is contained in:
garfield69
2020-03-05 08:00:06 +13:00
committed by GitHub
parent 4e8c52e16a
commit d53a0ae4b9

View File

@@ -31,16 +31,16 @@ namespace Jackett.Common.Indexers
public Shazbat(IIndexerConfigurationService configService, WebClient c, Logger l, IProtectionService ps)
: base(name: "Shazbat",
description: "Modern indexer",
link: "https://www.shazbat.tv/",
caps: new TorznabCapabilities(TorznabCatType.TV,
TorznabCatType.TVHD,
TorznabCatType.TVSD),
configService: configService,
client: c,
logger: l,
p: ps,
configData: new ConfigurationDataBasicLoginWithRSS())
description: "Modern indexer",
link: "https://www.shazbat.tv/",
caps: new TorznabCapabilities(TorznabCatType.TV,
TorznabCatType.TVHD,
TorznabCatType.TVSD),
configService: configService,
client: c,
logger: l,
p: ps,
configData: new ConfigurationDataBasicLoginWithRSS())
{
Encoding = Encoding.UTF8;
Language = "en-us";
@@ -50,30 +50,26 @@ namespace Jackett.Common.Indexers
public override async Task<IndexerConfigurationStatus> ApplyConfiguration(JToken configJson)
{
LoadValuesFromJson(configJson);
var pairs = new Dictionary<string, string> {
{ "referer", "login"},
{ "query", ""},
{ "tv_login", configData.Username.Value },
{ "tv_password", configData.Password.Value },
{ "email", "" }
var pairs = new Dictionary<string, string>
{
{"referer", "login"},
{"query", ""},
{"tv_login", configData.Username.Value},
{"tv_password", configData.Password.Value},
{"email", ""}
};
// Get cookie
var firstRequest = await RequestStringWithCookiesAndRetry(LoginUrl);
var result = await RequestLoginAndFollowRedirect(LoginUrl, pairs, null, true, null, LoginUrl);
await ConfigureIfOK(result.Cookies, result.Content != null && result.Content.Contains("glyphicon-log-out"),
() => throw new ExceptionWithConfigData("The username and password entered do not match.", configData));
await ConfigureIfOK(result.Cookies, result.Content?.Contains("glyphicon-log-out") == true,
() => throw new ExceptionWithConfigData("The username and password entered do not match.", configData));
var rssProfile = await RequestStringWithCookiesAndRetry(RSSProfile);
var parser = new HtmlParser();
var rssDom = parser.ParseDocument(rssProfile.Content);
configData.RSSKey.Value = rssDom.QuerySelector(".col-sm-9:nth-of-type(1)").TextContent.Trim();
if (string.IsNullOrWhiteSpace(configData.RSSKey.Value))
{
throw new ExceptionWithConfigData("Failed to find RSS key.", configData);
}
SaveConfig();
return IndexerConfigurationStatus.RequiresTesting;
}
@@ -86,24 +82,21 @@ namespace Jackett.Common.Indexers
response.Request.Cookies = CookieHeader;
return await webclient.GetString(response.Request);
}
return response;
}
protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuery query)
{
var releases = new List<ReleaseInfo>();
var queryString = query.GetQueryString();
var url = TorrentsUrl;
WebClientStringResult results = null;
var searchUrls = new List<string>();
if (!string.IsNullOrWhiteSpace(query.SanitizedSearchTerm))
{
var pairs = new Dictionary<string, string>();
pairs.Add("search", query.SanitizedSearchTerm);
results = await PostDataWithCookiesAndRetry(SearchUrl, pairs, null, TorrentsUrl);
results = await ReloginIfNecessary(results);
var parser = new HtmlParser();
@@ -116,9 +109,7 @@ namespace Jackett.Common.Indexers
}
}
else
{
searchUrls.Add(TorrentsUrl);
}
try
{
@@ -126,15 +117,12 @@ namespace Jackett.Common.Indexers
{
results = await RequestStringWithCookies(searchUrl);
results = await ReloginIfNecessary(results);
var parser = new HtmlParser();
var dom = parser.ParseDocument(results.Content);
var rows = dom.QuerySelectorAll(
string.IsNullOrWhiteSpace(queryString) ? "#torrent-table tr" : "table tr");
var globalFreeleech =
dom.QuerySelector("span:contains(\"Freeleech until:\"):has(span.datetime)") != null;
foreach (var row in rows.Skip(1))
{
var release = new ReleaseInfo();
@@ -142,14 +130,14 @@ namespace Jackett.Common.Indexers
foreach (var child in titleRow.Children)
child.Remove();
release.Title = titleRow.TextContent.Trim();
if ((query.ImdbID == null || !TorznabCaps.SupportsImdbMovieSearch) && !query.MatchQueryStringAND(release.Title))
if ((query.ImdbID == null || !TorznabCaps.SupportsImdbMovieSearch) &&
!query.MatchQueryStringAND(release.Title))
continue;
var qBanner = row.QuerySelector("div[style^=\"cursor: pointer; background-image:url\"]");
var qBannerStyle = qBanner.GetAttribute("style");
if (!string.IsNullOrEmpty(qBannerStyle))
var bannerStyle = row.QuerySelector("div[style^=\"cursor: pointer; background-image:url\"]")
?.GetAttribute("style");
if (!string.IsNullOrEmpty(bannerStyle))
{
var bannerImg = Regex.Match(qBannerStyle, @"url\('(.*?)'\);").Groups[1].Value;
var bannerImg = Regex.Match(bannerStyle, @"url\('(.*?)'\);").Groups[1].Value;
release.BannerUrl = new Uri(SiteLink + bannerImg);
}
@@ -158,27 +146,22 @@ namespace Jackett.Common.Indexers
release.Guid = release.Link;
var qLinkComm = row.QuerySelector("td:nth-of-type(5) a:nth-of-type(2)");
release.Comments = new Uri(SiteLink + qLinkComm.GetAttribute("href"));
var dateString = row.QuerySelector(".datetime").GetAttribute("data-timestamp");
var dateString = row.QuerySelector(".datetime")?.GetAttribute("data-timestamp");
if (dateString != null)
release.PublishDate = DateTimeUtil.UnixTimestampToDateTime(ParseUtil.CoerceDouble(dateString)).ToLocalTime();
release.PublishDate = DateTimeUtil
.UnixTimestampToDateTime(ParseUtil.CoerceDouble(dateString)).ToLocalTime();
var infoString = row.QuerySelector("td:nth-of-type(4)").TextContent;
release.Size = ParseUtil.CoerceLong(Regex.Match(infoString, "\\((\\d+)\\)").Value.Replace("(", "").Replace(")", ""));
release.Size = ParseUtil.CoerceLong(
Regex.Match(infoString, "\\((\\d+)\\)").Value.Replace("(", "").Replace(")", ""));
var infosplit = infoString.Replace("/", string.Empty).Split(":".ToCharArray());
release.Seeders = ParseUtil.CoerceInt(infosplit[1]);
release.Peers = release.Seeders + ParseUtil.CoerceInt(infosplit[2]);
if (globalFreeleech)
release.DownloadVolumeFactor = 0;
else
release.DownloadVolumeFactor = 1;
release.DownloadVolumeFactor = globalFreeleech ? 0 : 1;
release.UploadVolumeFactor = 1;
release.MinimumRatio = 1;
release.MinimumSeedTime = 172800; // 48 hours
// var tags = row.QuerySelector(".label-tag").TextContent; These don't see to parse - bad tags?
releases.Add(release);
}
}
@@ -187,68 +170,10 @@ namespace Jackett.Common.Indexers
{
OnParseError(results.Content, ex);
}
/* else
{
var rssUrl = SiteLink + "rss/recent?passkey=" + configData.RSSKey.Value;
results = await RequestStringWithCookiesAndRetry(rssUrl);
try
{
var doc = XDocument.Parse(results.Content);
foreach (var result in doc.Descendants("item"))
{
var xTitle = result.Element("title").Value;
var xLink = result.Element("link").Value;
var xGUID = result.Element("guid").Value;
var xDesc = result.Element("description").Value;
var xDate = result.Element("pubDate").Value;
var release = new ReleaseInfo();
release.Guid =release.Link = new Uri(xLink);
release.MinimumRatio = 1;
release.Seeders = 1; // We are not supplied with peer info so just mark it as one.
foreach (var element in xDesc.Split(";".ToCharArray()))
{
var split = element.IndexOf(':');
if (split > -1)
{
var key = element.Substring(0, split).Trim();
var value = element.Substring(split+1).Trim();
switch (key)
{
case "Filename":
release.Title = release.Description = value;
break;
}
}
}
//"Thu, 24 Sep 2015 18:07:07 +0000"
release.PublishDate = DateTime.ParseExact(xDate, "ddd, dd MMM yyyy HH:mm:ss +0000", CultureInfo.InvariantCulture);
if (!string.IsNullOrWhiteSpace(release.Title))
{
releases.Add(release);
}
}
}
catch (Exception ex)
{
OnParseError(results.Content, ex);
}*/
foreach (var release in releases)
{
if (release.Title.Contains("1080p") || release.Title.Contains("720p"))
{
release.Category = new List<int> { TorznabCatType.TVHD.ID };
}
else
{
release.Category = new List<int> { TorznabCatType.TVSD.ID };
}
}
release.Category = release.Title.Contains("1080p") || release.Title.Contains("720p")
? new List<int> {TorznabCatType.TVHD.ID}
: new List<int> {TorznabCatType.TVSD.ID};
return releases;
}
}