Skip to content

Commit

Permalink
Detect new brands: Bell, BYJU'S, CX, ELE-GATE, GlocalMe, G-PLUS, I KA…
Browse files Browse the repository at this point in the history
…LL, iHome Life, iFIT, KENWOOD, LongTV, Logitech, Mode Mobile, Motorola Solutions, Okapi, M-KOPA, Realix, Trimble, Veidoo and Detect devices for exist brands (#202)

* feat(sync) Adds detection for Cromite and Mises browsers (matomo-org#7812)
* Adds detection for Cromite
* Adds detection for Mises
---
feat(sync) Improve code for version detection (matomo-org#7804)
---
feat(sync) Improves detection for macOS (matomo-org#7816)
---
feat(sync) Remove DuckDuckGo Privacy Browser from mobile only browsers (matomo-org#7817)
---
feat(sync) Add skip recursive parsing is UA client hints and model name empty (matomo-org#7823)
---
feat(sync) Improves version detection for iOS (matomo-org#7824)
---
feat(sync) Improves detection for Apple devices (matomo-org#7825)
---
feat(sync) Adds detection for various bots (matomo-org#7828)
* Adds detection for Bravebot
* Adds detection for 1001FirmsBot
* Adds detection for Google-CloudVertexBot
* Split bots from Googlebot
---
feat(sync) Improves detection for frozen client hints in Linux (matomo-org#7831)
---
feat(sync) Adds detection for BYJU'S, CX, ELE-GATE, G-PLUS, Humanware, KENWOOD, LongTV, Mode Mobile, M-KOPA, Okapi, RCT, Realix, Trimble brands and improves detection for existing ones (matomo-org#7827)
* Adds detection for KENWOOD brand
* Improves detection for Amazon devices
* Improves detection for Fairphone devices
* Improves detection for FoxxD devices
* Improves detection for Ceibal devices
* Adds detection for G-PLUS brand
* Improves detection for Kalley devices
* Adds detection for Humanware brand
* Improves detection for Tecno Mobile devices
* Improves detection for DGTEC devices
* Improves detection for CellAllure devices
* Adds detection for BYJU'S brand
* Improves detection for Yezz devices
* Adds detection for LongTV brand
* Improves detection for Jio devices
* Improves detection for Senwa brand
* Adds detection for M-KOPA brand
* Improves detection for M3 Mobile devices
* Improves detection for meanIT devices
* Adds detection for Mode Mobile brand
* Add website for Mode Mobile
* Improves detection for Starlight devices
* Adds detection for Trimble brand
* Improves detection for NOGA devices
* Improves detection for Neon IQ devices
* Improves detection for Olax devices
* Adds detection for Okapi brand
* Improves detection for OPPO devices
* Improves detection for OpelMobile devices
* Adds detection for Realix brand
* Improves detection for Zebra devices
* Improves detection for Stylo devices
* Adds detection for ELE-GATE brand
* Improves detection for Logicom devices
* Improves detection for Huawei devices
* Improves detection for Unitech devices
* Improves detection for Everis devices
* Adds detection for CX brand
* Improves detection for Atozee devices
* Improves detection for Xiaomi devices
* Improves detection for ONN devices
* Improves detection for Sky devices
* Improves detection for SPC devices
* Improves detection for Vortex devices
* Adds detection for RCT brand
* Improves detection for Maze Speed devices
* Improves detection for SGIN devices
* Improves detection for Packard Bell devices
* Improves detection for Samsung devices
* Move Everis devices to tablets
---
feat(sync) Improves version detection for Chrome OS (matomo-org#7818)
---
feat(sync) Adds detection for Puffin OS, Puffin Cloud Browser, Puffin Incognito Browser and renames Puffin to Puffin Secure Browser (matomo-org#7819)
---
feat(sync) Improves detection for Chromium based browsers (matomo-org#7798)
* Improves detection for Chromium based browsers
* Fix test for TV-Browser Internet
---
feat(sync) Adds detection for Oh Dear and improves detection for vuhuvBot and Bravebot (matomo-org#7837)
---
feat(sync) Adds detection for Privacy Pioneer Browser, Mojeek and improves detection for various apps and browsers (matomo-org#7839)
* Adds detection for Mojeek
* Improves detection for Telegram
* Improves detection for ZTE Browser
* Improves detection for Via
* Adds detection for Privacy Pioneer Browser
---
feat(sync) Improves detection for Chrome OS (matomo-org#7840)
---
feat(sync) Adds detection for Bell, iHome Life, Logitech, Veidoo brands and improves detection for existing ones (matomo-org#7838)
* Improves detection for Touchmate devices
* Improves detection for Crosscall devices
* Improves detection for Soho Style devices
* Improves detection for Alcatel devices
* Adds detection for Veidoo brand
* Improves detection for Soho Style devices
* Improves detection for X-Mobile devices
* Adds detection for Logitech brand
* Improves detection for Retroid Pocket devices
* Improves detection for zuum devices
* Improves detection for nubia devices
* Improves detection for Kempler & Strauss devices
* Improves detection for Walton devices
* Improves detection for Soho Style devices
* Adds detection for Bell brand
* Adds detection for iHome Life brand
* Improves detection for Aiwa devices
* Improves detection for INSYS devices
* Improves detection for Hisense devices
* Improves detection for unknown tv
* Improves detection for H96 devices

* fix tests

* chore: generate indexes
  • Loading branch information
sanchezzzhak authored Sep 23, 2024
1 parent 28f17cc commit 0d0b41f
Show file tree
Hide file tree
Showing 59 changed files with 6,765 additions and 1,757 deletions.
134 changes: 76 additions & 58 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,39 +58,27 @@ IndexerDevice.init();
IndexerClient.init();

class DeviceDetector {
/**
* @typedef DeviceDetectorOptions
* @param {boolean} skipBotDetection
* @param {number|null} osVersionTruncate
* @param {number|null} clientVersionTruncate
* @param {number|null} maxUserAgentSize
* @param {boolean} deviceIndexes
* @param {boolean} clientIndexes
* @param {boolean} deviceAliasCode
* @param {boolean} deviceInfo
* @param {boolean} deviceTrusted
*/

vendorParserList = {};
osParserList = {};
botParserList = {};
deviceParserList = {};
clientParserList = {};

#skipBotDetection = false;
#deviceIndexes = false;
#clientIndexes = false;
#deviceAliasCode = false;
#deviceTrusted = false;
#deviceInfo = false;
#clientVersionTruncate = null;
#osVersionTruncate = null;
#maxUserAgentSize = null;

/**
* @param {DeviceDetectorOptions} options
**/
constructor(options) {
this.vendorParserList = {};
this.osParserList = {};
this.botParserList = {};
this.deviceParserList = {};
this.clientParserList = {};

this.__skipBotDetection = false;
this.__deviceIndexes = false;
this.__clientIndexes = false;
this.__deviceAliasCode = false;
this.__deviceTrusted = false;
this.__deviceInfo = false;
this.__clientVersionTruncate = null;
this.__osVersionTruncate = null;
this.__maxUserAgentSize = null;

this.init();

this.skipBotDetection = attr(options, 'skipBotDetection', false);
Expand Down Expand Up @@ -129,27 +117,27 @@ class DeviceDetector {
}

set deviceTrusted(check) {
this.__deviceTrusted = check;
this.#deviceTrusted = check;
}

get deviceTrusted() {
return this.__deviceTrusted;
return this.#deviceTrusted;
}

set deviceInfo(stage) {
this.__deviceInfo = stage;
this.#deviceInfo = stage;
}

get deviceInfo() {
return this.__deviceInfo;
return this.#deviceInfo;
}

/**
* Set string size limit for the useragent
* @param {number} size
*/
set maxUserAgentSize(size) {
this.__maxUserAgentSize = size;
this.#maxUserAgentSize = size;
for (let name in this.clientParserList) {
this.clientParserList[name].setMaxUserAgentSize(size);
}
Expand All @@ -166,68 +154,72 @@ class DeviceDetector {
* @returns {null|number}
*/
get maxUserAgentSize() {
return this.__maxUserAgentSize;
return this.#maxUserAgentSize;
}

get skipBotDetection() {
return this.__skipBotDetection;
return this.#skipBotDetection;
}

set skipBotDetection(discard) {
this.__skipBotDetection = discard;
this.#skipBotDetection = discard;
}

/**
* @param {boolean} status - true use indexes, false not use indexes
*/
set deviceIndexes(status) {
this.__deviceIndexes = status;
this.#deviceIndexes = status;
}

/**
* @return {boolean} - true use indexes, false not use indexes
*/
get deviceIndexes() {
return this.__deviceIndexes;
return this.#deviceIndexes;
}

/**
* @param {boolean} status - true use indexes, false not use indexes
* true use indexes, false not use indexes
* @param {boolean} status
*/
set clientIndexes(status) {
this.__clientIndexes = status;
this.#clientIndexes = status;
for (let name in this.clientParserList) {
this.clientParserList[name].clientIndexes = status;
}
}

/**
* @return {boolean} - true use indexes, false not use indexes
* true use indexes, false not use indexes
* @return {boolean}
*/
get clientIndexes() {
return this.__clientIndexes;
return this.#clientIndexes;
}

/**
* @param {boolean} status - true use deviceAliasCode, false not use deviceAliasCode
* true use deviceAliasCode, false not use deviceAliasCode
* @param {boolean} status
*/
set deviceAliasCode(status) {
this.__deviceAliasCode = status;
this.#deviceAliasCode = status;
}

/**
* @return {boolean} - true use deviceAliasCode, false not use deviceAliasCode
* true use deviceAliasCode, false not use deviceAliasCode
* @return {boolean}
*/
get deviceAliasCode() {
return this.__deviceAliasCode;
return this.#deviceAliasCode;
}

/**
* set truncate client version (default null - all)
* @param value
*/
set clientVersionTruncate(value) {
this.__clientVersionTruncate = value;
this.#clientVersionTruncate = value;
for (let name in this.clientParserList) {
this.clientParserList[name].setVersionTruncation(value);
}
Expand All @@ -238,15 +230,15 @@ class DeviceDetector {
* @return int|null
*/
get clientVersionTruncate() {
return this.__clientVersionTruncate;
return this.#clientVersionTruncate;
}

/**
* set truncate os version (default null - all)
* @param value
*/
set osVersionTruncate(value) {
this.__osVersionTruncate = value;
this.#osVersionTruncate = value;
for (let name in this.osParserList) {
this.osParserList[name].setVersionTruncation(value);
}
Expand All @@ -257,7 +249,7 @@ class DeviceDetector {
* @return {null|number}
*/
get osVersionTruncate() {
return this.__osVersionTruncate;
return this.#osVersionTruncate;
}

/**
Expand Down Expand Up @@ -288,7 +280,7 @@ class DeviceDetector {

/**
* get all brands
* @returns {string[]}
* @return {string[]}
*/
getAvailableBrands() {
return this.getParseDevice(DEVICE_PARSER_LIST.MOBILE).getAvailableBrands();
Expand All @@ -297,7 +289,7 @@ class DeviceDetector {
/**
* has device brand
* @param brand
* @returns {boolean}
* @return {boolean}
*/
hasBrand(brand) {
return this.getParseDevice(DEVICE_PARSER_LIST.MOBILE).getCollectionBrands()[brand] !== void 0;
Expand Down Expand Up @@ -592,6 +584,26 @@ class DeviceDetector {
) {
deviceType = DEVICE_TYPE.TABLET;
}
/**
* All devices running Puffin Secure Browser that contain letter 'D' are assumed to be desktops
*/
if (deviceType === '' && helper.hasPuffinDesktopFragment(userAgent)) {
deviceType = DEVICE_TYPE.DESKTOP;
}

/**
* All devices running Puffin Web Browser that contain letter 'P' are assumed to be smartphones
*/
if (deviceType === '' && helper.hasPuffinSmartphoneFragment(userAgent)) {
deviceType = DEVICE_TYPE.SMARTPHONE;
}

/**
* All devices running Puffin Web Browser that contain letter 'T' are assumed to be tablets
*/
if (deviceType === '' && helper.hasPuffinTabletFragment(userAgent)) {
deviceType = DEVICE_TYPE.TABLET;
}

/**
* All devices running Opera TV Store are assumed to be a tv
Expand Down Expand Up @@ -619,10 +631,9 @@ class DeviceDetector {
}

if (
DEVICE_TYPE.DESKTOP !== deviceType &&
userAgent.indexOf('Desktop') !== -1
DEVICE_TYPE.DESKTOP !== deviceType && userAgent.indexOf('Desktop') !== -1
) {
if (helper.hasDesktopFragment(userAgent)) {
if (helper.matchUserAgent('Desktop(?: (x(?:32|64)|WOW64))?;', userAgent)) {
deviceType = DEVICE_TYPE.DESKTOP;
}
}
Expand Down Expand Up @@ -682,15 +693,23 @@ class DeviceDetector {
if (!helper.hasDeviceModelByClientHints(clientHints)) {
return userAgent;
}

const deviceModel = clientHints.device.model;
if (deviceModel && helper.hasUserAgentClientHintsFragment(userAgent)) {

if (deviceModel !== '' && helper.hasUserAgentClientHintsFragment(userAgent)) {
const osHints = attr(clientHints, 'os', {});
const osVersion = attr(osHints, 'version', '');
return userAgent.replace(/(Android 10[.\d]*; K)/,
`Android ${osVersion !== '' ? osVersion: '10'}; ${deviceModel}`
);
}

if (deviceModel !== '' && helper.hasDesktopFragment(userAgent)) {
return userAgent.replace(/(X11; Linux x86_64)/,
`X11; Linux x86_64; ${deviceModel}`
);
}

return userAgent;
}

Expand All @@ -703,7 +722,6 @@ class DeviceDetector {
parseDevice(userAgent, clientHints) {
let ua = this.restoreUserAgentFromClientHints(userAgent, clientHints);
let brandIndexes = [];
let deviceCode = '';

let result = {
id: '',
Expand All @@ -715,7 +733,7 @@ class DeviceDetector {
trusted: null
};

if (!helper.hasDeviceModelByClientHints(clientHints) && helper.hasUserAgentClientHintsFragment(userAgent)) {
if (!helper.hasDeviceModelByClientHints(clientHints) && helper.hasUserAgentClientHintsFragment(ua)) {
return Object.assign({}, result);
}

Expand Down
8 changes: 5 additions & 3 deletions parser/client-abstract-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@ const ParserAbstract = require('./abstract-parser');
const IndexerClient = require('./client/indexer-client');

class ClientAbstractParser extends ParserAbstract {

#clientIndexes = true;

constructor() {
super();
this.collectionLength = 0;
this.type = '';
this.__clientIndexes = true;
}

get clientIndexes() {
return this.__clientIndexes;
return this.#clientIndexes;
}

set clientIndexes(stage) {
this.__clientIndexes = stage;
this.#clientIndexes = stage;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion parser/client/browser-families.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module.exports = {
'K4', 'WK', 'T3', 'K5', 'MU', '9P', 'K6', 'VR', 'N9',
'M9', 'F9', '0P', '0A', 'JR', 'D3', 'TK', 'BP', '2F',
'2M', 'K7', '1N', '8A', 'H7', 'X3', 'T4', 'X4', '5O',
'8C', '3M',
'8C', '3M', '6I', '2P', 'PU', '7I', 'X5',
],
'Firefox': [
'FF', 'BI', 'BF', 'BH', 'BN', 'C0', 'CU', 'EI', 'F1',
Expand Down
5 changes: 3 additions & 2 deletions parser/client/browser-short-mobile.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module.exports = [
'36', 'AH', 'AI', 'BL', 'C1', 'C4', 'CB', 'CW', 'DB',
'3M', 'DT', 'EU', 'EZ', 'FK', 'FM', 'FR', 'FX', 'GH',
'GI', 'GR', 'HA', 'HU', 'IV', 'JB', 'KD', 'M1', 'MF',
'MN', 'MZ', 'NX', 'OC', 'OI', 'OM', 'OZ', 'PU', 'PI',
'MN', 'MZ', 'NX', 'OC', 'OI', 'OM', 'OZ', '2P', 'PI',
'PE', 'QU', 'RE', 'S0', 'S7', 'SA', 'SB', 'SG', 'SK',
'ST', 'SU', 'T1', 'UH', 'UM', 'UT', 'VE', 'VV', 'WI',
'WP', 'YN', 'IO', 'IS', 'HQ', 'RW', 'HI', 'PN', 'BW',
Expand All @@ -22,6 +22,7 @@ module.exports = [
'5A', 'TT', '6P', 'G3', '7P', 'VU', 'F8', 'L4', 'DK',
'DP', 'KL', 'K4', 'N6', 'KU', 'WK', 'M8', 'UP', 'ZT',
'9P', 'N8', 'VR', 'N9', 'M9', 'F9', '0P', '0A', '2F',
'2M', 'K7', '1N', '8A', 'H7', 'X3', 'X4', '5O',
'2M', 'K7', '1N', '8A', 'H7', 'X3', 'X4', '5O', '6I',
'7I', 'X5',

];
5 changes: 4 additions & 1 deletion parser/client/browser-short.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,9 @@ module.exports = {
'PP': 'Oppo Browser',
'P6': 'Opus Browser',
'PR': 'Palm Pre',
'PU': 'Puffin',
'7I': 'Puffin Cloud Browser',
'6I': 'Puffin Incognito Browser',
'PU': 'Puffin Secure Browser',
'2P': 'Puffin Web Browser',
'PW': 'Palm WebPro',
'PA': 'Palmscape',
Expand All @@ -470,6 +472,7 @@ module.exports = {
'BP': 'Privacy Browser',
'PI': 'PrivacyWall',
'P4': 'Privacy Explorer Fast Safe',
'X5': 'Privacy Pioneer Browser',
'P3': 'Private Internet Browser',
'P5': 'Proxy Browser',
'7P': 'Proxyium',
Expand Down
Loading

0 comments on commit 0d0b41f

Please sign in to comment.