mirror of
https://github.com/Jackett/Jackett
synced 2025-03-06 19:58:38 +00:00
iptorrents: add support for tvsearch by imdbid (#13997)
This commit is contained in:
parent
4791401843
commit
49ec063ee7
1 changed files with 45 additions and 39 deletions
|
@ -4,6 +4,7 @@ using System.Collections.Specialized;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using AngleSharp.Html.Parser;
|
using AngleSharp.Html.Parser;
|
||||||
using Jackett.Common.Models;
|
using Jackett.Common.Models;
|
||||||
|
@ -74,7 +75,8 @@ namespace Jackett.Common.Indexers
|
||||||
BookSearchParams = new List<BookSearchParam>
|
BookSearchParams = new List<BookSearchParam>
|
||||||
{
|
{
|
||||||
BookSearchParam.Q
|
BookSearchParam.Q
|
||||||
}
|
},
|
||||||
|
TvSearchImdbAvailable = true
|
||||||
},
|
},
|
||||||
configService: configService,
|
configService: configService,
|
||||||
client: wc,
|
client: wc,
|
||||||
|
@ -87,7 +89,7 @@ namespace Jackett.Common.Indexers
|
||||||
Language = "en-US";
|
Language = "en-US";
|
||||||
Type = "private";
|
Type = "private";
|
||||||
|
|
||||||
var sort = new ConfigurationData.SingleSelectConfigurationItem("Sort requested from site", new Dictionary<string, string>
|
var sort = new SingleSelectConfigurationItem("Sort requested from site", new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{"time", "created"},
|
{"time", "created"},
|
||||||
{"size", "size"},
|
{"size", "size"},
|
||||||
|
@ -199,7 +201,8 @@ namespace Jackett.Common.Indexers
|
||||||
{
|
{
|
||||||
var releases = new List<ReleaseInfo>();
|
var releases = new List<ReleaseInfo>();
|
||||||
|
|
||||||
var ValidList = new List<string>() {
|
var validTagList = new List<string>
|
||||||
|
{
|
||||||
"action",
|
"action",
|
||||||
"adventure",
|
"adventure",
|
||||||
"animation",
|
"animation",
|
||||||
|
@ -228,48 +231,45 @@ namespace Jackett.Common.Indexers
|
||||||
"western"
|
"western"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* notes:
|
||||||
/* notes:
|
|
||||||
* IPTorrents can search for genre (tags) using the default title&tags search
|
* IPTorrents can search for genre (tags) using the default title&tags search
|
||||||
* qf=
|
* qf=
|
||||||
* "" = Title and Tags
|
* "" = Title and Tags
|
||||||
* ti = Title
|
* ti = Title
|
||||||
* ta = Tags
|
* ta = Tags
|
||||||
* all = Title, Tags & Description
|
* all = Title, Tags & Description
|
||||||
* adv = Advanced
|
* adv = Advanced
|
||||||
*
|
*
|
||||||
* But only movies and tv have tags.
|
* But only movies and tv have tags.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
var headers = new Dictionary<string, string>();
|
||||||
|
if (!string.IsNullOrEmpty(configData.UserAgent.Value))
|
||||||
|
headers.Add("User-Agent", configData.UserAgent.Value);
|
||||||
|
|
||||||
var qc = new NameValueCollection();
|
var qc = new NameValueCollection();
|
||||||
|
|
||||||
|
|
||||||
Dictionary<string, string> headers = null;
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(configData.UserAgent.Value))
|
|
||||||
{
|
|
||||||
headers = new Dictionary<string, string>
|
|
||||||
{
|
|
||||||
{ "User-Agent", configData.UserAgent.Value }
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (query.IsImdbQuery)
|
|
||||||
qc.Add("q", query.ImdbID);
|
|
||||||
else
|
|
||||||
if (query.IsGenreQuery)
|
|
||||||
qc.Add("q", query.GetQueryString() + " " + query.Genre);
|
|
||||||
else
|
|
||||||
if (!string.IsNullOrWhiteSpace(query.GetQueryString()))
|
|
||||||
qc.Add("q", query.GetQueryString());
|
|
||||||
|
|
||||||
foreach (var cat in MapTorznabCapsToTrackers(query))
|
foreach (var cat in MapTorznabCapsToTrackers(query))
|
||||||
qc.Add(cat, string.Empty);
|
qc.Set(cat, string.Empty);
|
||||||
|
|
||||||
if (((BoolConfigurationItem)configData.GetDynamic("freeleech")).Value)
|
if (((BoolConfigurationItem)configData.GetDynamic("freeleech")).Value)
|
||||||
qc.Add("free", "on");
|
qc.Set("free", "on");
|
||||||
|
|
||||||
qc.Add("o", ((SingleSelectConfigurationItem)configData.GetDynamic("sort")).Value);
|
var searchQuery = new List<string>();
|
||||||
|
|
||||||
|
// IPT uses sphinx, which supports boolean operators and grouping
|
||||||
|
if (query.IsImdbQuery)
|
||||||
|
searchQuery.Add($"+({query.ImdbID})");
|
||||||
|
else if (query.IsGenreQuery)
|
||||||
|
searchQuery.Add($"+({query.Genre})");
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(query.GetQueryString()))
|
||||||
|
searchQuery.Add($"+({query.GetQueryString()})");
|
||||||
|
|
||||||
|
if (searchQuery.Any())
|
||||||
|
qc.Set("q", $"{string.Join(" ", searchQuery)}");
|
||||||
|
|
||||||
|
qc.Set("o", ((SingleSelectConfigurationItem)configData.GetDynamic("sort")).Value);
|
||||||
|
|
||||||
var searchUrl = SearchUrl + "?" + qc.GetQueryString();
|
var searchUrl = SearchUrl + "?" + qc.GetQueryString();
|
||||||
var response = await RequestWithCookiesAndRetryAsync(searchUrl, referer: SearchUrl, headers: headers);
|
var response = await RequestWithCookiesAndRetryAsync(searchUrl, referer: SearchUrl, headers: headers);
|
||||||
|
@ -281,20 +281,21 @@ namespace Jackett.Common.Indexers
|
||||||
if (string.IsNullOrWhiteSpace(query.ImdbID) && string.IsNullOrWhiteSpace(query.SearchTerm) && results.Contains("No Torrents Found!"))
|
if (string.IsNullOrWhiteSpace(query.ImdbID) && string.IsNullOrWhiteSpace(query.SearchTerm) && results.Contains("No Torrents Found!"))
|
||||||
throw new Exception("Got No Torrents Found! Make sure your IPTorrents profile config contain proper default category settings.");
|
throw new Exception("Got No Torrents Found! Make sure your IPTorrents profile config contain proper default category settings.");
|
||||||
|
|
||||||
|
char[] delimiters = { ',', ' ', '/', ')', '(', '.', ';', '[', ']', '"', '|', ':' };
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var parser = new HtmlParser();
|
var parser = new HtmlParser();
|
||||||
var doc = parser.ParseDocument(results);
|
var doc = parser.ParseDocument(results);
|
||||||
|
|
||||||
var rows = doc.QuerySelectorAll("table[id='torrents'] > tbody > tr");
|
var rows = doc.QuerySelectorAll("table[id=\"torrents\"] > tbody > tr");
|
||||||
foreach (var row in rows)
|
foreach (var row in rows)
|
||||||
{
|
{
|
||||||
var qTitleLink = row.QuerySelector("a.hv");
|
var qTitleLink = row.QuerySelector("a.hv");
|
||||||
if (qTitleLink == null) // no results
|
if (qTitleLink == null) // no results
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// drop invalid char that seems to have cropped up in some titles. #6582
|
var title = CleanTitle(qTitleLink.TextContent);
|
||||||
var title = qTitleLink.TextContent.Trim().Replace("\u000f", "");
|
|
||||||
var details = new Uri(SiteLink + qTitleLink.GetAttribute("href").TrimStart('/'));
|
var details = new Uri(SiteLink + qTitleLink.GetAttribute("href").TrimStart('/'));
|
||||||
|
|
||||||
var qLink = row.QuerySelector("a[href^=\"/download.php/\"]");
|
var qLink = row.QuerySelector("a[href^=\"/download.php/\"]");
|
||||||
|
@ -305,9 +306,7 @@ namespace Jackett.Common.Indexers
|
||||||
var publishDate = DateTimeUtil.FromTimeAgo(dateSplit.First());
|
var publishDate = DateTimeUtil.FromTimeAgo(dateSplit.First());
|
||||||
var description = descrSplit.Length > 1 ? "Tags: " + descrSplit.First().Trim() : "";
|
var description = descrSplit.Length > 1 ? "Tags: " + descrSplit.First().Trim() : "";
|
||||||
description += dateSplit.Length > 1 ? " Uploaded by: " + dateSplit.Last().Trim() : "";
|
description += dateSplit.Length > 1 ? " Uploaded by: " + dateSplit.Last().Trim() : "";
|
||||||
|
var releaseGenres = validTagList.Intersect(description.ToLower().Split(delimiters, StringSplitOptions.RemoveEmptyEntries)).ToList();
|
||||||
char[] delimiters = { ',', ' ', '/', ')', '(', '.', ';', '[', ']', '"', '|', ':' };
|
|
||||||
var releaseGenres = ValidList.Intersect(description.ToLower().Split(delimiters, System.StringSplitOptions.RemoveEmptyEntries)).ToList();
|
|
||||||
|
|
||||||
var catIcon = row.QuerySelector("td:nth-of-type(1) a");
|
var catIcon = row.QuerySelector("td:nth-of-type(1) a");
|
||||||
if (catIcon == null)
|
if (catIcon == null)
|
||||||
|
@ -340,6 +339,7 @@ namespace Jackett.Common.Indexers
|
||||||
PublishDate = publishDate,
|
PublishDate = publishDate,
|
||||||
Category = cat,
|
Category = cat,
|
||||||
Description = description,
|
Description = description,
|
||||||
|
Genres = releaseGenres,
|
||||||
Size = size,
|
Size = size,
|
||||||
Files = files,
|
Files = files,
|
||||||
Grabs = grabs,
|
Grabs = grabs,
|
||||||
|
@ -350,9 +350,6 @@ namespace Jackett.Common.Indexers
|
||||||
MinimumRatio = 1,
|
MinimumRatio = 1,
|
||||||
MinimumSeedTime = 1209600 // 336 hours
|
MinimumSeedTime = 1209600 // 336 hours
|
||||||
};
|
};
|
||||||
if (release.Genres == null)
|
|
||||||
release.Genres = new List<string>();
|
|
||||||
release.Genres = releaseGenres;
|
|
||||||
|
|
||||||
releases.Add(release);
|
releases.Add(release);
|
||||||
}
|
}
|
||||||
|
@ -364,5 +361,14 @@ namespace Jackett.Common.Indexers
|
||||||
|
|
||||||
return releases;
|
return releases;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string CleanTitle(string title)
|
||||||
|
{
|
||||||
|
// drop invalid chars that seems to have cropped up in some titles. #6582
|
||||||
|
title = Regex.Replace(title, @"[\u0000-\u0008\u000A-\u001F\u0100-\uFFFF]", string.Empty, RegexOptions.Compiled);
|
||||||
|
title = Regex.Replace(title, @"[\(\[\{]REQ(UEST(ED)?)?[\)\]\}]", string.Empty, RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||||
|
|
||||||
|
return title.Trim(' ', '-', ':');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue