-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdevicetype.go
160 lines (151 loc) · 2.03 KB
/
devicetype.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package uaparser
// Device Type id's.
const (
PC = iota + 2 // 2
PHONE // 3
TABLET // 4
CONSOLE // 5
SETTOPBOX // 6
)
var DeviceTypes = map[int64]string{
UNKNOWN: "Unknown",
PC: "PC",
PHONE: "Phone",
TABLET: "Tablet",
CONSOLE: "Console",
SETTOPBOX: "Set top box",
}
var deviceTypes = []pattern{
// Set-top box
{
SETTOPBOX,
[]string{"media center pc"},
[]string{},
nil,
},
{
SETTOPBOX,
[]string{"googletv"},
[]string{},
nil,
},
{
SETTOPBOX,
[]string{"smart-tv"},
[]string{},
nil,
},
// Console
{
CONSOLE,
[]string{"playstation"},
[]string{},
nil,
},
{
CONSOLE,
[]string{"xbox"},
[]string{},
nil,
},
{
CONSOLE,
[]string{"nintendo"},
[]string{},
nil,
},
// When we don't know anything else we just mark all Opera Mini devices as phones.
{
PHONE,
[]string{"opera mini"},
[]string{},
nil,
},
// PC
{
PC,
[]string{"windows"},
[]string{"windows phone"},
nil,
},
{
PC,
[]string{"mac os x"},
[]string{"iphone", "ipad", "ipod"},
nil,
},
{
PC,
[]string{"linux"},
[]string{"android"},
nil,
},
{
PC,
[]string{"cros"},
[]string{},
nil,
},
// Phone
{
PHONE,
[]string{"iphone"},
[]string{"ipad"}, // Firefox for iPad contains both.
nil,
},
{
PHONE,
[]string{"windows phone"},
[]string{},
nil,
},
{
PHONE,
[]string{"android", "mobile"},
[]string{},
nil,
},
{
PHONE,
[]string{"blackberry"},
[]string{"playbook"},
nil,
},
// Tablet
{
TABLET,
[]string{"ipad"},
[]string{},
nil,
},
{
TABLET,
[]string{"android"},
[]string{"mobile", "cros"},
nil,
},
{
TABLET,
[]string{"rim Tablet"},
[]string{},
nil,
},
{
TABLET,
[]string{"tablet pc"},
[]string{},
nil,
},
{
TABLET,
[]string{"blackberry", "playbook"},
[]string{},
nil,
},
}
// DeviceType will return the device type.
// Returns 1 when nothing matched.
func DeviceType(userAgent string) int64 {
id, _, _ := find(deviceTypes, userAgent)
return id
}