2020-02-09 02:35:16 +00:00
|
|
|
using System;
|
2017-10-29 06:50:47 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Text;
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
using System.Threading.Tasks;
|
2020-02-29 23:27:09 +00:00
|
|
|
using AngleSharp.Html.Parser;
|
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-04-15 08:45:10 +00:00
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
using NLog;
|
|
|
|
|
2018-03-10 08:05:56 +00:00
|
|
|
namespace Jackett.Common.Indexers
|
2017-04-15 08:45:10 +00:00
|
|
|
{
|
2017-07-10 20:58:44 +00:00
|
|
|
public class Shazbat : BaseWebIndexer
|
2017-04-15 08:45:10 +00:00
|
|
|
{
|
2020-02-25 16:08:03 +00:00
|
|
|
private string LoginUrl => SiteLink + "login";
|
|
|
|
private string SearchUrl => SiteLink + "search";
|
|
|
|
private string TorrentsUrl => SiteLink + "torrents";
|
|
|
|
private string ShowUrl => SiteLink + "show?id=";
|
|
|
|
private string RSSProfile => SiteLink + "rss_feeds";
|
2017-04-15 08:45:10 +00:00
|
|
|
|
2017-10-29 06:50:47 +00:00
|
|
|
private new ConfigurationDataBasicLoginWithRSS configData
|
2017-04-15 08:45:10 +00:00
|
|
|
{
|
2020-02-25 16:08:03 +00:00
|
|
|
get => (ConfigurationDataBasicLoginWithRSS)base.configData;
|
|
|
|
set => base.configData = value;
|
2017-04-15 08:45:10 +00:00
|
|
|
}
|
|
|
|
|
2017-11-05 09:42:03 +00:00
|
|
|
public Shazbat(IIndexerConfigurationService configService, WebClient c, Logger l, IProtectionService ps)
|
2017-04-15 08:45:10 +00:00
|
|
|
: base(name: "Shazbat",
|
|
|
|
description: "Modern indexer",
|
|
|
|
link: "https://www.shazbat.tv/",
|
|
|
|
caps: new TorznabCapabilities(TorznabCatType.TV,
|
|
|
|
TorznabCatType.TVHD,
|
|
|
|
TorznabCatType.TVSD),
|
2017-07-10 20:58:44 +00:00
|
|
|
configService: configService,
|
2017-04-15 08:45:10 +00:00
|
|
|
client: c,
|
|
|
|
logger: l,
|
|
|
|
p: ps,
|
|
|
|
configData: new ConfigurationDataBasicLoginWithRSS())
|
|
|
|
{
|
|
|
|
Encoding = Encoding.UTF8;
|
|
|
|
Language = "en-us";
|
|
|
|
Type = "private";
|
|
|
|
}
|
|
|
|
|
2017-06-28 05:31:38 +00:00
|
|
|
public override async Task<IndexerConfigurationStatus> ApplyConfiguration(JToken configJson)
|
2017-04-15 08:45:10 +00:00
|
|
|
{
|
|
|
|
LoadValuesFromJson(configJson);
|
|
|
|
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);
|
2020-02-25 16:08:03 +00:00
|
|
|
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));
|
2017-04-15 08:45:10 +00:00
|
|
|
|
|
|
|
var rssProfile = await RequestStringWithCookiesAndRetry(RSSProfile);
|
2020-02-29 23:27:09 +00:00
|
|
|
var parser = new HtmlParser();
|
|
|
|
var rssDom = parser.ParseDocument(rssProfile.Content);
|
|
|
|
configData.RSSKey.Value = rssDom.QuerySelector(".col-sm-9:nth-of-type(1)").TextContent.Trim();
|
2017-04-15 08:45:10 +00:00
|
|
|
if (string.IsNullOrWhiteSpace(configData.RSSKey.Value))
|
|
|
|
{
|
|
|
|
throw new ExceptionWithConfigData("Failed to find RSS key.", configData);
|
|
|
|
}
|
|
|
|
|
|
|
|
SaveConfig();
|
|
|
|
return IndexerConfigurationStatus.RequiresTesting;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected async Task<WebClientStringResult> ReloginIfNecessary(WebClientStringResult response)
|
|
|
|
{
|
|
|
|
if (!response.Content.Contains("onclick=\"document.location='logout'\""))
|
|
|
|
{
|
|
|
|
await ApplyConfiguration(null);
|
|
|
|
response.Request.Cookies = CookieHeader;
|
|
|
|
return await webclient.GetString(response.Request);
|
|
|
|
}
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
2017-07-03 05:15:47 +00:00
|
|
|
protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuery query)
|
2017-04-15 08:45:10 +00:00
|
|
|
{
|
|
|
|
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);
|
2020-02-29 23:27:09 +00:00
|
|
|
var parser = new HtmlParser();
|
|
|
|
var dom = parser.ParseDocument(results.Content);
|
|
|
|
var shows = dom.QuerySelectorAll("div.show[data-id]");
|
2017-04-15 08:45:10 +00:00
|
|
|
foreach (var show in shows)
|
|
|
|
{
|
|
|
|
var showUrl = ShowUrl + show.GetAttribute("data-id");
|
|
|
|
searchUrls.Add(showUrl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
searchUrls.Add(TorrentsUrl);
|
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
foreach (var searchUrl in searchUrls)
|
|
|
|
{
|
|
|
|
results = await RequestStringWithCookies(searchUrl);
|
|
|
|
results = await ReloginIfNecessary(results);
|
|
|
|
|
2020-02-29 23:27:09 +00:00
|
|
|
var parser = new HtmlParser();
|
|
|
|
var dom = parser.ParseDocument(results.Content);
|
|
|
|
var rows = dom.QuerySelectorAll(
|
|
|
|
string.IsNullOrWhiteSpace(queryString) ? "#torrent-table tr" : "table tr");
|
2017-04-15 08:45:10 +00:00
|
|
|
|
2020-02-29 23:27:09 +00:00
|
|
|
var globalFreeleech =
|
|
|
|
dom.QuerySelector("span:contains(\"Freeleech until:\"):has(span.datetime)") != null;
|
2017-04-15 08:45:10 +00:00
|
|
|
|
|
|
|
foreach (var row in rows.Skip(1))
|
|
|
|
{
|
|
|
|
var release = new ReleaseInfo();
|
2020-02-29 23:27:09 +00:00
|
|
|
var titleRow = row.QuerySelector("td:nth-of-type(3)");
|
|
|
|
foreach (var child in titleRow.Children)
|
|
|
|
child.Remove();
|
|
|
|
release.Title = titleRow.TextContent.Trim();
|
2019-05-11 03:27:25 +00:00
|
|
|
if ((query.ImdbID == null || !TorznabCaps.SupportsImdbMovieSearch) && !query.MatchQueryStringAND(release.Title))
|
2017-04-15 08:45:10 +00:00
|
|
|
continue;
|
|
|
|
|
2020-02-29 23:27:09 +00:00
|
|
|
var qBanner = row.QuerySelector("div[style^=\"cursor: pointer; background-image:url\"]");
|
|
|
|
var qBannerStyle = qBanner.GetAttribute("style");
|
2017-04-15 08:45:10 +00:00
|
|
|
if (!string.IsNullOrEmpty(qBannerStyle))
|
|
|
|
{
|
|
|
|
var bannerImg = Regex.Match(qBannerStyle, @"url\('(.*?)'\);").Groups[1].Value;
|
|
|
|
release.BannerUrl = new Uri(SiteLink + bannerImg);
|
|
|
|
}
|
|
|
|
|
2020-02-29 23:27:09 +00:00
|
|
|
var qLink = row.QuerySelector("td:nth-of-type(5) a:nth-of-type(1)");
|
|
|
|
release.Link = new Uri(SiteLink + qLink.GetAttribute("href"));
|
2017-04-15 08:45:10 +00:00
|
|
|
release.Guid = release.Link;
|
2020-02-29 23:27:09 +00:00
|
|
|
var qLinkComm = row.QuerySelector("td:nth-of-type(5) a:nth-of-type(2)");
|
|
|
|
release.Comments = new Uri(SiteLink + qLinkComm.GetAttribute("href"));
|
2017-04-15 08:45:10 +00:00
|
|
|
|
2020-02-29 23:27:09 +00:00
|
|
|
var dateString = row.QuerySelector(".datetime").GetAttribute("data-timestamp");
|
2017-04-15 08:45:10 +00:00
|
|
|
if (dateString != null)
|
|
|
|
release.PublishDate = DateTimeUtil.UnixTimestampToDateTime(ParseUtil.CoerceDouble(dateString)).ToLocalTime();
|
2020-02-29 23:27:09 +00:00
|
|
|
var infoString = row.QuerySelector("td:nth-of-type(4)").TextContent;
|
2017-04-15 08:45:10 +00:00
|
|
|
|
|
|
|
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.UploadVolumeFactor = 1;
|
|
|
|
|
2020-02-29 23:27:09 +00:00
|
|
|
// var tags = row.QuerySelector(".label-tag").TextContent; These don't see to parse - bad tags?
|
2017-04-15 08:45:10 +00:00
|
|
|
|
|
|
|
releases.Add(release);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
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 };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return releases;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|