mirror of
https://github.com/Jackett/Jackett.git
synced 2025-09-17 17:34:09 +02:00
Add imdbid validation
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
using AutoMapper;
|
using AutoMapper;
|
||||||
using Jackett.Models;
|
using Jackett.Models;
|
||||||
using Jackett.Services;
|
using Jackett.Services;
|
||||||
|
using Jackett.Utils;
|
||||||
using NLog;
|
using NLog;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@@ -12,7 +13,8 @@ using System.Text;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Web;
|
using System.Web;
|
||||||
using System.Web.Http;
|
using System.Web.Http;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
namespace Jackett.Controllers
|
namespace Jackett.Controllers
|
||||||
{
|
{
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
@@ -32,6 +34,24 @@ namespace Jackett.Controllers
|
|||||||
cacheService = c;
|
cacheService = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public HttpResponseMessage GetErrorXML(int code, string description)
|
||||||
|
{
|
||||||
|
var xdoc = new XDocument(
|
||||||
|
new XDeclaration("1.0", "UTF-8", null),
|
||||||
|
new XElement("error",
|
||||||
|
new XAttribute("code", code.ToString()),
|
||||||
|
new XAttribute("description", description)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
var xml = xdoc.Declaration.ToString() + Environment.NewLine + xdoc.ToString();
|
||||||
|
|
||||||
|
return new HttpResponseMessage()
|
||||||
|
{
|
||||||
|
Content = new StringContent(xml, Encoding.UTF8, "application/xml")
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public async Task<HttpResponseMessage> Call(string indexerID)
|
public async Task<HttpResponseMessage> Call(string indexerID)
|
||||||
{
|
{
|
||||||
@@ -62,6 +82,27 @@ namespace Jackett.Controllers
|
|||||||
{
|
{
|
||||||
logger.Warn(string.Format("Rejected a request to {0} which is unconfigured.", indexer.DisplayName));
|
logger.Warn(string.Format("Rejected a request to {0} which is unconfigured.", indexer.DisplayName));
|
||||||
return Request.CreateResponse(HttpStatusCode.Forbidden, "This indexer is not configured.");
|
return Request.CreateResponse(HttpStatusCode.Forbidden, "This indexer is not configured.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (torznabQuery.ImdbID != null)
|
||||||
|
{
|
||||||
|
if (torznabQuery.QueryType != "movie")
|
||||||
|
{
|
||||||
|
logger.Warn(string.Format("A non movie request with an imdbid was made from {0}.", Request.GetOwinContext().Request.RemoteIpAddress));
|
||||||
|
return GetErrorXML(201, "Incorrect parameter: only movie-search supports the imdbid parameter");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (torznabQuery.SearchTerm != null)
|
||||||
|
{
|
||||||
|
logger.Warn(string.Format("A movie-search request from {0} was made contining q and imdbid.", Request.GetOwinContext().Request.RemoteIpAddress));
|
||||||
|
return GetErrorXML(201, "Incorrect parameter: please specify either imdbid or q");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ParseUtil.GetImdbID(torznabQuery.ImdbID) == null)
|
||||||
|
{
|
||||||
|
logger.Warn(string.Format("A movie-search request from {0} was made with an invalid imdbid.", Request.GetOwinContext().Request.RemoteIpAddress));
|
||||||
|
return GetErrorXML(201, "Incorrect parameter: invalid imdbid format");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var releases = await indexer.PerformQuery(torznabQuery);
|
var releases = await indexer.PerformQuery(torznabQuery);
|
||||||
|
@@ -9,6 +9,7 @@ namespace Jackett.Utils
|
|||||||
new Regex(
|
new Regex(
|
||||||
@"(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x9F\uFEFF\uFFFE\uFFFF]",
|
@"(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x9F\uFEFF\uFFFE\uFFFF]",
|
||||||
RegexOptions.Compiled);
|
RegexOptions.Compiled);
|
||||||
|
private static readonly Regex ImdbId = new Regex(@"^tt(\d{7})$",RegexOptions.Compiled);
|
||||||
|
|
||||||
public static string NormalizeSpace(string s)
|
public static string NormalizeSpace(string s)
|
||||||
{
|
{
|
||||||
@@ -72,5 +73,14 @@ namespace Jackett.Utils
|
|||||||
{
|
{
|
||||||
return long.TryParse(NormalizeNumber(str), NumberStyles.Any, CultureInfo.InvariantCulture, out result);
|
return long.TryParse(NormalizeNumber(str), NumberStyles.Any, CultureInfo.InvariantCulture, out result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int? GetImdbID(string imdbstr)
|
||||||
|
{
|
||||||
|
var match = ImdbId.Match(imdbstr);
|
||||||
|
if (!match.Success)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return CoerceInt(match.Groups[1].Value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user