2020-02-09 02:35:16 +00:00
|
|
|
using System;
|
2017-10-29 06:50:47 +00:00
|
|
|
using System.Collections.Generic;
|
2020-05-03 23:35:52 +00:00
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2017-10-29 06:50:47 +00:00
|
|
|
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
|
|
|
{
|
2020-05-03 23:35:52 +00:00
|
|
|
[ExcludeFromCodeCoverage]
|
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)
|
2020-05-11 19:59:28 +00:00
|
|
|
: base(id: "shazbat",
|
|
|
|
name: "Shazbat",
|
2020-03-04 19:00:06 +00:00
|
|
|
description: "Modern indexer",
|
|
|
|
link: "https://www.shazbat.tv/",
|
2020-03-11 04:58:45 +00:00
|
|
|
caps: new TorznabCapabilities(
|
|
|
|
TorznabCatType.TV,
|
|
|
|
TorznabCatType.TVHD,
|
|
|
|
TorznabCatType.TVSD),
|
2020-03-04 19:00:06 +00:00
|
|
|
configService: configService,
|
|
|
|
client: c,
|
|
|
|
logger: l,
|
|
|
|
p: ps,
|
|
|
|
configData: new ConfigurationDataBasicLoginWithRSS())
|
2017-04-15 08:45:10 +00:00
|
|
|
{
|
|
|
|
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);
|
2020-03-04 19:00:06 +00:00
|
|
|
var pairs = new Dictionary<string, string>
|
|
|
|
{
|
|
|
|
{"referer", "login"},
|
|
|
|
{"query", ""},
|
|
|
|
{"tv_login", configData.Username.Value},
|
|
|
|
{"tv_password", configData.Password.Value},
|
|
|
|
{"email", ""}
|
2017-04-15 08:45:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Get cookie
|
|
|
|
var result = await RequestLoginAndFollowRedirect(LoginUrl, pairs, null, true, null, LoginUrl);
|
2020-06-09 17:36:57 +00:00
|
|
|
await ConfigureIfOK(result.Cookies, result.ContentString?.Contains("glyphicon-log-out") == true,
|
2020-03-04 19:00:06 +00:00
|
|
|
() => throw new ExceptionWithConfigData("The username and password entered do not match.", configData));
|
2020-09-21 06:02:53 +00:00
|
|
|
var rssProfile = await RequestStringWithCookiesAndRetry(RSSProfile);
|
2020-02-29 23:27:09 +00:00
|
|
|
var parser = new HtmlParser();
|
2020-06-09 17:36:57 +00:00
|
|
|
var rssDom = parser.ParseDocument(rssProfile.ContentString);
|
2020-02-29 23:27:09 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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();
|
2020-06-10 21:22:29 +00:00
|
|
|
WebResult results = null;
|
2017-04-15 08:45:10 +00:00
|
|
|
var searchUrls = new List<string>();
|
|
|
|
if (!string.IsNullOrWhiteSpace(query.SanitizedSearchTerm))
|
|
|
|
{
|
2020-03-11 04:58:45 +00:00
|
|
|
var pairs = new Dictionary<string, string>
|
|
|
|
{
|
|
|
|
{"search", query.SanitizedSearchTerm}
|
|
|
|
};
|
2020-09-21 06:02:53 +00:00
|
|
|
results = await PostDataWithCookiesAndRetry(SearchUrl, pairs, null, TorrentsUrl);
|
2017-04-15 08:45:10 +00:00
|
|
|
results = await ReloginIfNecessary(results);
|
2020-02-29 23:27:09 +00:00
|
|
|
var parser = new HtmlParser();
|
2020-06-09 17:36:57 +00:00
|
|
|
var dom = parser.ParseDocument(results.ContentString);
|
2020-02-29 23:27:09 +00:00
|
|
|
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)
|
|
|
|
{
|
2020-09-21 06:02:53 +00:00
|
|
|
results = await RequestStringWithCookies(searchUrl);
|
2017-04-15 08:45:10 +00:00
|
|
|
results = await ReloginIfNecessary(results);
|
2020-02-29 23:27:09 +00:00
|
|
|
var parser = new HtmlParser();
|
2020-06-09 17:36:57 +00:00
|
|
|
var dom = parser.ParseDocument(results.ContentString);
|
2020-02-29 23:27:09 +00:00
|
|
|
var rows = dom.QuerySelectorAll(
|
|
|
|
string.IsNullOrWhiteSpace(queryString) ? "#torrent-table tr" : "table tr");
|
|
|
|
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))
|
|
|
|
{
|
2020-03-26 22:15:28 +00:00
|
|
|
// TODO switch to initializer
|
2017-04-15 08:45:10 +00:00
|
|
|
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();
|
2020-03-04 19:00:06 +00:00
|
|
|
if ((query.ImdbID == null || !TorznabCaps.SupportsImdbMovieSearch) &&
|
|
|
|
!query.MatchQueryStringAND(release.Title))
|
2017-04-15 08:45:10 +00:00
|
|
|
continue;
|
2020-03-04 19:00:06 +00:00
|
|
|
var bannerStyle = row.QuerySelector("div[style^=\"cursor: pointer; background-image:url\"]")
|
|
|
|
?.GetAttribute("style");
|
|
|
|
if (!string.IsNullOrEmpty(bannerStyle))
|
2017-04-15 08:45:10 +00:00
|
|
|
{
|
2020-03-04 19:00:06 +00:00
|
|
|
var bannerImg = Regex.Match(bannerStyle, @"url\('(.*?)'\);").Groups[1].Value;
|
2017-04-15 08:45:10 +00:00
|
|
|
release.BannerUrl = new Uri(SiteLink + bannerImg);
|
|
|
|
}
|
|
|
|
|
2020-03-11 04:58:45 +00:00
|
|
|
var qLink = row.QuerySelector("td:nth-of-type(5) a");
|
2020-02-29 23:27:09 +00:00
|
|
|
release.Link = new Uri(SiteLink + qLink.GetAttribute("href"));
|
2017-04-15 08:45:10 +00:00
|
|
|
release.Guid = release.Link;
|
2020-03-11 04:58:45 +00:00
|
|
|
var qLinkComm = row.QuerySelector("td:nth-of-type(5) a.internal");
|
2020-02-29 23:27:09 +00:00
|
|
|
release.Comments = new Uri(SiteLink + qLinkComm.GetAttribute("href"));
|
2020-03-04 19:00:06 +00:00
|
|
|
var dateString = row.QuerySelector(".datetime")?.GetAttribute("data-timestamp");
|
2017-04-15 08:45:10 +00:00
|
|
|
if (dateString != null)
|
2020-03-04 19:00:06 +00:00
|
|
|
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;
|
2020-03-04 19:00:06 +00:00
|
|
|
release.Size = ParseUtil.CoerceLong(
|
|
|
|
Regex.Match(infoString, "\\((\\d+)\\)").Value.Replace("(", "").Replace(")", ""));
|
2017-04-15 08:45:10 +00:00
|
|
|
var infosplit = infoString.Replace("/", string.Empty).Split(":".ToCharArray());
|
|
|
|
release.Seeders = ParseUtil.CoerceInt(infosplit[1]);
|
|
|
|
release.Peers = release.Seeders + ParseUtil.CoerceInt(infosplit[2]);
|
2020-03-04 19:00:06 +00:00
|
|
|
release.DownloadVolumeFactor = globalFreeleech ? 0 : 1;
|
2017-04-15 08:45:10 +00:00
|
|
|
release.UploadVolumeFactor = 1;
|
2020-03-04 19:00:06 +00:00
|
|
|
release.MinimumRatio = 1;
|
|
|
|
release.MinimumSeedTime = 172800; // 48 hours
|
2017-04-15 08:45:10 +00:00
|
|
|
|
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)
|
|
|
|
{
|
2020-06-09 17:36:57 +00:00
|
|
|
OnParseError(results.ContentString, ex);
|
2017-04-15 08:45:10 +00:00
|
|
|
}
|
|
|
|
foreach (var release in releases)
|
2020-03-04 19:00:06 +00:00
|
|
|
release.Category = release.Title.Contains("1080p") || release.Title.Contains("720p")
|
2020-04-07 16:17:17 +00:00
|
|
|
? new List<int> { TorznabCatType.TVHD.ID }
|
|
|
|
: new List<int> { TorznabCatType.TVSD.ID };
|
2017-04-15 08:45:10 +00:00
|
|
|
return releases;
|
|
|
|
}
|
2020-03-11 04:58:45 +00:00
|
|
|
|
2020-06-10 21:22:29 +00:00
|
|
|
private async Task<WebResult> ReloginIfNecessary(WebResult response)
|
2020-03-11 04:58:45 +00:00
|
|
|
{
|
2020-06-09 17:36:57 +00:00
|
|
|
if (response.ContentString.Contains("onclick=\"document.location='logout'\""))
|
2020-03-11 04:58:45 +00:00
|
|
|
return response;
|
|
|
|
|
|
|
|
await ApplyConfiguration(null);
|
|
|
|
response.Request.Cookies = CookieHeader;
|
2020-09-21 06:02:53 +00:00
|
|
|
return await webclient.GetString(response.Request);
|
2020-03-11 04:58:45 +00:00
|
|
|
}
|
2017-04-15 08:45:10 +00:00
|
|
|
}
|
|
|
|
}
|