Change package name, more fb/insta detection
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
module github.com/mileusna/useragent
|
||||
module github.com/swaven/useragent
|
||||
|
||||
go 1.14
|
||||
|
||||
@@ -57,7 +57,8 @@ const (
|
||||
Applebot = "Applebot"
|
||||
Bingbot = "Bingbot"
|
||||
|
||||
FacebookApp = "Facebook App"
|
||||
FacebookApp = "Facebook App"
|
||||
InstagramApp = "Instagram App"
|
||||
)
|
||||
|
||||
// Parse user agent string returning UserAgent struct
|
||||
@@ -250,6 +251,14 @@ func Parse(userAgent string) UserAgent {
|
||||
|
||||
case tokens.exists("FBAN"):
|
||||
ua.Name = FacebookApp
|
||||
ua.Version = tokens.get("FBAN")
|
||||
case tokens.exists("FB_IAB"):
|
||||
ua.Name = FacebookApp
|
||||
ua.Version = tokens.get("FBAV")
|
||||
|
||||
case tokens.startsWith("Instagram"):
|
||||
ua.Name = InstagramApp
|
||||
ua.Version = tokens.findInstagramVersion()
|
||||
|
||||
case tokens.get("HuaweiBrowser") != "":
|
||||
ua.Name = "Huawei Browser"
|
||||
@@ -484,6 +493,29 @@ func (p properties) findMacOSVersion() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (p properties) startsWith(value string) bool {
|
||||
for _, prop := range p.list {
|
||||
if strings.HasPrefix(prop.Key, value) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (p properties) findInstagramVersion() string {
|
||||
for _, token := range p.list {
|
||||
if strings.HasPrefix(token.Key, "Instagram") {
|
||||
if ver := findVersion(token.Value); ver != "" {
|
||||
return ver
|
||||
} else if ver = findVersion(token.Key); ver != "" {
|
||||
return ver
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// findBestMatch from the rest of the bunch
|
||||
// in first cycle only return key with version value
|
||||
// if withVerValue is false, do another cycle and return any token
|
||||
|
||||
+5
-1
@@ -5,7 +5,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
ua "github.com/mileusna/useragent"
|
||||
ua "github.com/swaven/useragent"
|
||||
)
|
||||
|
||||
var testTable = [][]string{
|
||||
@@ -93,6 +93,10 @@ var testTable = [][]string{
|
||||
|
||||
//FB App
|
||||
{"Mozilla/5.0 (iPhone; CPU iPhone OS 15_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/19E258 [FBAN/FBIOS;FBDV/iPhone8,2;FBMD/iPhone;FBSN/iOS;FBSV/15.4.1;FBSS/3;FBID/phone;FBLC/fr_FR;FBOP/5]", ua.FacebookApp, "FBIOS", "mobile", ua.IOS},
|
||||
{"Mozilla/5.0 (Linux; Android 13; SM-T220 Build/TP1A.220624.014; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/109.0.5414.117 Safari/537.36 [FB_IAB/FB4A;FBAV/400.0.0.37.76;]", ua.FacebookApp, "400.0.0.37.76", "mobile", ua.Android},
|
||||
|
||||
//Instagram
|
||||
{"Mozilla/5.0 (iPhone; CPU iPhone OS 16_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 Instagram 270.0.0.13.83 (iPhone13,2; iOS 16_3; es_ES; es-ES; scale=3.00; 1170x2532; 445843881) NW/1", ua.InstagramApp, "270.0.0.13.83", "mobile", ua.IOS},
|
||||
|
||||
// other
|
||||
{"Mozilla/5.0 (X11; CrOS x86_64 14150.74.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.114 Safari/537.36", ua.Chrome, "94.0.4606.114", "desktop", ua.ChromeOS},
|
||||
|
||||
Reference in New Issue
Block a user