tv-vault: add imdb search and improve season search. #8508 (#8969)

* Add IMDB search
* Improve TV season search
This commit is contained in:
Diego Heras 2020-06-14 13:39:04 +02:00 committed by GitHub
parent 2c4ca6be1f
commit a7d6cafbc6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 54 additions and 49 deletions

View File

@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
@ -22,23 +23,23 @@ namespace Jackett.Common.Indexers
private string LoginUrl => SiteLink + "login.php";
private string BrowseUrl => SiteLink + "torrents.php";
private new ConfigurationDataBasicLoginWithRSSAndDisplay configData
{
get => (ConfigurationDataBasicLoginWithRSSAndDisplay)base.configData;
set => base.configData = value;
}
private new ConfigurationDataBasicLogin configData => (ConfigurationDataBasicLogin)base.configData;
public TVVault(IIndexerConfigurationService configService, WebClient wc, Logger l, IProtectionService ps)
: base(id: "tvvault",
name: "TV-Vault",
description: "A TV tracker for old shows.",
description: "A TV tracker for old shows",
link: "https://tv-vault.me/",
caps: TorznabUtil.CreateDefaultTorznabTVCaps(),
caps: new TorznabCapabilities
{
SupportsImdbMovieSearch = true
// SupportsImdbTVSearch = true (supported by the site but disabled due to #8107)
},
configService: configService,
client: wc,
logger: l,
p: ps,
configData: new ConfigurationDataBasicLoginWithRSSAndDisplay())
configData: new ConfigurationDataBasicLogin())
{
Encoding = Encoding.UTF8;
Language = "en-us";
@ -66,70 +67,65 @@ namespace Jackett.Common.Indexers
return IndexerConfigurationStatus.RequiresTesting;
}
private string StripSearchString(string term)
{
// Search does not support searching with episode numbers so strip it if we have one
// Ww AND filter the result later to archive the proper result
term = Regex.Replace(term, @"[S|E]\d\d", string.Empty);
return term.Trim();
}
protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuery query)
{
var releases = new List<ReleaseInfo>();
var searchString = query.GetQueryString();
var searchUrl = BrowseUrl;
var queryCollection = new NameValueCollection
var qc = new NameValueCollection
{
{ "searchstr", StripSearchString(searchString) },
{ "order_by", "s3" },
{ "order_way", "desc" },
{ "disablegrouping", "1" }
};
searchUrl += "?" + queryCollection.GetQueryString();
if (query.IsImdbQuery)
{
qc.Add("action", "advanced");
qc.Add("imdbid", query.ImdbID);
}
else
qc.Add("searchstr", StripSearchString(query.GetQueryString()));
var searchUrl = BrowseUrl + "?" + qc.GetQueryString();
var results = await RequestStringWithCookies(searchUrl);
try
{
var RowsSelector = "table.torrent_table > tbody > tr.torrent";
var seasonRegEx = new Regex(@$"Season\s+0*{query.Season}[^\d]", RegexOptions.IgnoreCase);
var SearchResultParser = new HtmlParser();
var SearchResultDocument = SearchResultParser.ParseDocument(results.Content);
var Rows = SearchResultDocument.QuerySelectorAll(RowsSelector);
foreach (var Row in Rows)
var parser = new HtmlParser();
var doc = parser.ParseDocument(results.Content);
var rows = doc.QuerySelectorAll("table.torrent_table > tbody > tr.torrent");
foreach (var row in rows)
{
var qDetailsLink = Row.QuerySelector("a[href^=\"torrents.php?id=\"]");
var DescStr = qDetailsLink.NextSibling;
var Files = Row.QuerySelector("td:nth-child(3)");
var Added = Row.QuerySelector("td:nth-child(4)");
var Size = Row.QuerySelector("td:nth-child(5)").FirstChild;
var Grabs = Row.QuerySelector("td:nth-child(6)");
var Seeders = Row.QuerySelector("td:nth-child(7)");
var Leechers = Row.QuerySelector("td:nth-child(8)");
var FreeLeech = Row.QuerySelector("strong.freeleech_normal");
var qDetailsLink = row.QuerySelector("a[href^=\"torrents.php?id=\"]");
var title = qDetailsLink.TextContent;
// if it's a season search, we filter results. the trailing space is to match regex
if (query.Season > 0 && !seasonRegEx.Match($"{title} ").Success)
continue;
var TorrentIdParts = qDetailsLink.GetAttribute("href").Split('=');
var TorrentId = TorrentIdParts[TorrentIdParts.Length - 1];
var DLLink = "torrents.php?action=download&id=" + TorrentId.ToString();
var link = new Uri(SiteLink + DLLink);
var seeders = ParseUtil.CoerceInt(Seeders.TextContent);
var description = DescStr.TextContent.Trim();
var publishDate = DateTimeUtil.FromTimeAgo(Added.TextContent);
var description = qDetailsLink.NextSibling.TextContent.Trim();
title += " " + description;
var comments = new Uri(SiteLink + qDetailsLink.GetAttribute("href"));
var leechers = ParseUtil.CoerceInt(Leechers.TextContent);
var size = ReleaseInfo.GetBytes(Size.TextContent);
var grabs = ParseUtil.CoerceLong(Grabs.TextContent);
var files = ParseUtil.CoerceLong(Files.TextContent);
var torrentId = qDetailsLink.GetAttribute("href").Split('=').Last();
var link = new Uri(SiteLink + "torrents.php?action=download&id=" + torrentId);
var files = ParseUtil.CoerceLong(row.QuerySelector("td:nth-child(3)").TextContent);
var publishDate = DateTimeUtil.FromTimeAgo(row.QuerySelector("td:nth-child(4)").TextContent);
var size = ReleaseInfo.GetBytes(row.QuerySelector("td:nth-child(5)").FirstChild.TextContent);
var grabs = ParseUtil.CoerceLong(row.QuerySelector("td:nth-child(6)").TextContent);
var seeders = ParseUtil.CoerceInt(row.QuerySelector("td:nth-child(7)").TextContent);
var leechers = ParseUtil.CoerceInt(row.QuerySelector("td:nth-child(8)").TextContent);
var dlVolumeFactor = row.QuerySelector("strong.freeleech_normal") != null ? 0 : 1;
var category = new List<int> { TvCategoryParser.ParseTvShowQuality(description) };
var release = new ReleaseInfo
{
MinimumRatio = 1,
MinimumSeedTime = 0,
Description = description,
Title = qDetailsLink.TextContent + " " + description,
Title = title,
PublishDate = publishDate,
Category = category,
Link = link,
@ -140,7 +136,7 @@ namespace Jackett.Common.Indexers
Size = size,
Grabs = grabs,
Files = files,
DownloadVolumeFactor = FreeLeech != null ? 0 : 1,
DownloadVolumeFactor = dlVolumeFactor,
UploadVolumeFactor = 1
};
releases.Add(release);
@ -153,5 +149,14 @@ namespace Jackett.Common.Indexers
return releases;
}
private string StripSearchString(string term)
{
// Search does not support searching with episode numbers so strip it if we have one
// Ww AND filter the result later to archive the proper result
term = Regex.Replace(term, @"[S|E]\d\d", string.Empty);
return term.Trim();
}
}
}