Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions device_detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ var desktopOsArray = []string{
`Chrome OS`,
}

var(
var (
chrMobReg = regexp.MustCompile(fixUserAgentRegEx(`Chrome/[\.0-9]* Mobile`), regexp.IgnoreCase)
chrTabReg = regexp.MustCompile(fixUserAgentRegEx(`Chrome/[\.0-9]* (?!Mobile)`), regexp.IgnoreCase)
opaTabReg = regexp.MustCompile(fixUserAgentRegEx(`Opera Tablet`), regexp.IgnoreCase)
opaTvReg = regexp.MustCompile(fixUserAgentRegEx(`Opera TV Store`), regexp.IgnoreCase)
opaTvReg = regexp.MustCompile(fixUserAgentRegEx(`Opera TV Store`), regexp.IgnoreCase)
)

func fixUserAgentRegEx(regex string) string {
Expand Down Expand Up @@ -90,7 +90,6 @@ func NewDeviceDetector(dir string) (*DeviceDetector, error) {
NewBot(filepath.Join(dir, FixtureFileBot)),
}


return d, nil
}

Expand Down Expand Up @@ -184,7 +183,7 @@ func (d *DeviceDetector) parseInfo(info *DeviceInfo) {
// If it is present the device should be a smartphone, otherwise it's a tablet
// See https://developer.chrome.com/multidevice/user-agent#chrome_for_android_user_agent
if deviceType == DEVICE_TYPE_INVALID && osFamily == `Android` {
if browserName,ok:=client.GetBrowserFamily(cmr.ShortName); ok&&browserName== `Chrome` {
if browserName, ok := client.GetBrowserFamily(cmr.ShortName); ok && browserName == `Chrome` {
if ok, _ := chrMobReg.MatchString(ua); ok {
deviceType = DEVICE_TYPE_SMARTPHONE
} else if ok, _ = chrTabReg.MatchString(ua); ok {
Expand Down Expand Up @@ -268,4 +267,3 @@ func (d *DeviceDetector) Parse(ua string) *DeviceInfo {

return info
}

6 changes: 3 additions & 3 deletions device_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ var (
type DeviceInfo struct {
userAgent string
device.DeviceMatchResult
client *client.ClientMatchResult
os *OsMatchResult
bot *BotMatchResult
client *client.ClientMatchResult
os *OsMatchResult
bot *BotMatchResult
}

func (d *DeviceInfo) GetDeviceType() int {
Expand Down
2 changes: 1 addition & 1 deletion device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,4 @@ func TestRegThread(t *testing.T) {
}
}
wg.Wait()
}
}
7 changes: 5 additions & 2 deletions parser/device/hbbtv.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ func init() {
}

func NewHbbTv(fileName string) *HbbTv {
h := &HbbTv{}
h := &HbbTv{
hbbTvRegx: Regular{
Regex: `HbbTV/([1-9]{1}(?:.[0-9]{1}){1,2})`,
},
}
if err := h.Load(fileName); err != nil {
h.hbbTvRegx.Regex = `HbbTV/([1-9]{1}(?:.[0-9]{1}){1,2})`
return nil
}
return h
Expand Down