mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2025-04-24 13:57:11 -04:00
Cleanup UA Parser
This commit is contained in:
parent
1c97f2b1f4
commit
c694d1ef44
2 changed files with 17 additions and 28 deletions
|
@ -1,13 +1,17 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NzbDrone.Common.Http
|
||||
{
|
||||
public static class UserAgentParser
|
||||
{
|
||||
private static readonly Regex AppSourceRegex = new Regex(@"(?<agent>.*)\/.*(\(.*\))?",
|
||||
RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
||||
|
||||
public static string SimplifyUserAgent(string userAgent)
|
||||
{
|
||||
if (userAgent == null || userAgent.StartsWith("Mozilla/5.0"))
|
||||
|
@ -17,5 +21,17 @@ namespace NzbDrone.Common.Http
|
|||
|
||||
return userAgent;
|
||||
}
|
||||
|
||||
public static string ParseSource(string userAgent)
|
||||
{
|
||||
var match = AppSourceRegex.Match(SimplifyUserAgent(userAgent) ?? string.Empty);
|
||||
|
||||
if (match.Groups["agent"].Success)
|
||||
{
|
||||
return match.Groups["agent"].Value;
|
||||
}
|
||||
|
||||
return "Other";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace NzbDrone.Core.Parser
|
||||
{
|
||||
public static class UserAgentParser
|
||||
{
|
||||
private static readonly List<string> UserAgentWhiteList = new List<string> { "Radarr", "Sonarr", "Readarr", "Lidarr", "Prowlarr" };
|
||||
|
||||
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)
|
||||
{
|
||||
if (UserAgentWhiteList.Contains(match.Groups["agent"].Value))
|
||||
{
|
||||
return match.Groups["agent"].Value;
|
||||
}
|
||||
}
|
||||
|
||||
return "Other";
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue