You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
913 B
33 lines
913 B
using System.Text.RegularExpressions;
|
|
|
|
namespace NzbDrone.Common.Http
|
|
{
|
|
public static class UserAgentParser
|
|
{
|
|
private static readonly Regex AppSourceRegex = new Regex(@"(?<agent>[a-z0-9]*)\/.*(?:\(.*\))?",
|
|
RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
|
|
|
public static string SimplifyUserAgent(string userAgent)
|
|
{
|
|
if (userAgent == null || userAgent.StartsWith("Mozilla/5.0"))
|
|
{
|
|
return null;
|
|
}
|
|
|
|
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";
|
|
}
|
|
}
|
|
}
|