Parse and Store App from UA for Nab Requests Stats

pull/6/head
Qstick 4 years ago
parent c6ec632dd2
commit 8f0c872873

@ -92,6 +92,7 @@ namespace NzbDrone.Core.History
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);

@ -19,5 +19,6 @@ namespace NzbDrone.Core.IndexerSearch.Definitions
public string SearchType { get; set; }
public int? Limit { get; set; }
public int? Offset { get; set; }
public string Source { get; set; }
}
}

@ -26,5 +26,6 @@ namespace NzbDrone.Core.IndexerSearch
public string author { get; set; }
public string title { get; set; }
public string configured { get; set; }
public string source { get; set; }
}
}

@ -121,6 +121,7 @@ namespace NzbDrone.Core.IndexerSearch
spec.SearchType = query.t;
spec.Limit = query.limit;
spec.Offset = query.offset;
spec.Source = query.source;
spec.IndexerIds = indexerIds;

@ -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";
}
}
}

@ -4,6 +4,7 @@ using Nancy.ModelBinding;
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 @@ namespace Prowlarr.Api.V1.Indexers
private object GetNewznabResponse(NewznabRequest request)
{
var requestType = request.t;
request.source = UserAgentParser.ParseSource(Request.Headers.UserAgent);
if (requestType.IsNullOrWhiteSpace())
{

Loading…
Cancel
Save