Parse and Store App from UA for Nab Requests Stats

This commit is contained in:
Qstick 2020-12-29 23:06:41 -05:00
parent c6ec632dd2
commit 8f0c872873
6 changed files with 27 additions and 0 deletions

View file

@ -92,6 +92,7 @@ public void Handle(IndexerQueryEvent message)
history.Data.Add("ElapsedTime", message.Time.ToString());
history.Data.Add("Query", message.Query.SearchTerm ?? string.Empty);
history.Data.Add("Categories", string.Join(",", message.Query.Categories) ?? string.Empty);
history.Data.Add("Source", message.Query.Source ?? string.Empty);
history.Data.Add("Successful", message.Successful.ToString());
history.Data.Add("QueryResults", message.Results.HasValue ? message.Results.ToString() : null);

View file

@ -19,5 +19,6 @@ public abstract class SearchCriteriaBase
public string SearchType { get; set; }
public int? Limit { get; set; }
public int? Offset { get; set; }
public string Source { get; set; }
}
}

View file

@ -26,5 +26,6 @@ public class NewznabRequest
public string author { get; set; }
public string title { get; set; }
public string configured { get; set; }
public string source { get; set; }
}
}

View file

@ -121,6 +121,7 @@ private TSpec Get<TSpec>(NewznabRequest query, List<int> indexerIds, bool intera
spec.SearchType = query.t;
spec.Limit = query.limit;
spec.Offset = query.offset;
spec.Source = query.source;
spec.IndexerIds = indexerIds;

View file

@ -0,0 +1,21 @@
using System.Text.RegularExpressions;
namespace NzbDrone.Core.Parser
{
public static class UserAgentParser
{
private static readonly Regex AppSourceRegex = new Regex(@"(?<agent>.*)\/.*\(.*\)",
RegexOptions.IgnoreCase | RegexOptions.Compiled);
public static string ParseSource(string userAgent)
{
var match = AppSourceRegex.Match(userAgent);
if (match.Groups["agent"].Success)
{
return match.Groups["agent"].Value;
}
return "Other";
}
}
}

View file

@ -4,6 +4,7 @@
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.IndexerSearch;
using NzbDrone.Core.Parser;
using Prowlarr.Http.REST;
namespace Prowlarr.Api.V1.Indexers
@ -41,6 +42,7 @@ protected override void Validate(IndexerDefinition definition, bool includeWarni
private object GetNewznabResponse(NewznabRequest request)
{
var requestType = request.t;
request.source = UserAgentParser.ParseSource(Request.Headers.UserAgent);
if (requestType.IsNullOrWhiteSpace())
{