Skip to content

Commit

Permalink
Added Douyin as an app name (Chinese TikTok), fixes #9.
Browse files Browse the repository at this point in the history
Added `MIUI Browser` to browsers list.
Added tests.
Updated dependencies.
  • Loading branch information
hexydec committed Nov 22, 2024
1 parent 9d9f860 commit c7c94bb
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 39 deletions.
22 changes: 11 additions & 11 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 10 additions & 4 deletions src/mappings/apps.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,10 +361,16 @@ public static function get() : array {
}),

// TikTok
'AppName/' => new props('start', fn(string $value) : array => [
'app' => $value === 'AppName/musical_ly' ? 'TikTok' : \mb_substr($value, 8),
'appname' => \mb_substr($value, 8)
]),
'AppName/' => new props('start', function (string $value) : array {
$map = [
'AppName/musical_ly' => 'TikTok',
'AppName/aweme' => 'Douyin'
];
return [
'app' => $map[$value] ?? \mb_substr($value, 8),
'appname' => \mb_substr($value, 8)
];
}),
'app_version/' => new props('start', fn(string $value) : array => [
'appversion' => \mb_substr($value, 12)
]),
Expand Down
4 changes: 3 additions & 1 deletion src/mappings/browsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public static function get() : array {
'k-meleon' => 'K-Meleon',
'samsungbrowser' => 'Samsung Browser',
'huaweibrowser' => 'Huawei Browser',
'qqbrowser' => 'QQ Browser'
'qqbrowser' => 'QQ Browser',
'miuibrowser' => 'MIUI Browser'
];
$data = ['type' => 'human'];
$browser = \mb_strtolower(\array_shift($parts));
Expand Down Expand Up @@ -130,6 +131,7 @@ public static function get() : array {
'browser' => 'Obigo'
]),
'QQBrowser/' => new props('any', fn (string $value) : array => $fn['browserslash'](\mb_substr($value, \mb_stripos($value, 'QQBrowser/') ?: 0))), // sometimes missing a space from previous declaration, and MQQBrowser for mobile.
'MiuiBrowser/' => new props('any', fn (string $value) : array => $fn['browserslash'](\mb_substr($value, \mb_stripos($value, 'MiuiBrowser/') ?: 0))),
'Lynx/' => new props('start', fn (string $value) : array => [
'browser' => 'Lynx',
'browserversion' => \explode('/', $value, 2)[1] ?? null,
Expand Down
63 changes: 42 additions & 21 deletions tests/appsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,27 +211,6 @@ public function testApps() : void {
'appname' => 'com.google.android.googlequicksearchbox',
'appversion' => '301265987'
],
'Mozilla/5.0 (Linux; Android 10; AOSP on flame Build/QQ3A.200805.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/75.0.3770.156 Mobile Safari/537.36 aweme_140700 JsSdk/1.0 NetType/WIFI Channel/gdt_growth21_yybtp_tengxun AppName/aweme app_version/14.7.0 ByteLocale/zh-Hans-CN Region/CN AppSkin/black AppTheme/dark TTWebView/0751130014013' => [
'string' => 'Mozilla/5.0 (Linux; Android 10; AOSP on flame Build/QQ3A.200805.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/75.0.3770.156 Mobile Safari/537.36 aweme_140700 JsSdk/1.0 NetType/WIFI Channel/gdt_growth21_yybtp_tengxun AppName/aweme app_version/14.7.0 ByteLocale/zh-Hans-CN Region/CN AppSkin/black AppTheme/dark TTWebView/0751130014013',
'type' => 'human',
'category' => 'mobile',
'device' => 'AOSP',
'model' => 'On Flame',
'build' => 'QQ3A.200805.001',
'kernel' => 'Linux',
'platform' => 'Android',
'platformversion' => '10',
'engine' => 'Blink',
'engineversion' => '75.0.3770.156',
'browser' => 'Chrome',
'browserversion' => '75.0.3770.156',
'language' => 'zh-CN',
'app' => 'aweme',
'appname' => 'aweme',
'appversion' => '14.7.0',
'nettype' => 'WIFI',
'darkmode' => true
],
'Mozilla/5.0 (Macintosh; Intel Mac OS X 12_5_0) AppleWebKit/537.36 (KHTML, like Gecko) Teams/1.6.00.364 Chrome/96.0.4664.174 Electron/16.2.8 Safari/537.36' => [
'string' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 12_5_0) AppleWebKit/537.36 (KHTML, like Gecko) Teams/1.6.00.364 Chrome/96.0.4664.174 Electron/16.2.8 Safari/537.36',
'type' => 'human',
Expand Down Expand Up @@ -833,6 +812,48 @@ public function testTikTok() : void {
'appversion' => '27.9.0',
'nettype' => '4G',
'darkmode' => false
],
'Mozilla/5.0 (Linux; Android 10; AOSP on flame Build/QQ3A.200805.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/75.0.3770.156 Mobile Safari/537.36 aweme_140700 JsSdk/1.0 NetType/WIFI Channel/gdt_growth21_yybtp_tengxun AppName/aweme app_version/14.7.0 ByteLocale/zh-Hans-CN Region/CN AppSkin/black AppTheme/dark TTWebView/0751130014013' => [
'string' => 'Mozilla/5.0 (Linux; Android 10; AOSP on flame Build/QQ3A.200805.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/75.0.3770.156 Mobile Safari/537.36 aweme_140700 JsSdk/1.0 NetType/WIFI Channel/gdt_growth21_yybtp_tengxun AppName/aweme app_version/14.7.0 ByteLocale/zh-Hans-CN Region/CN AppSkin/black AppTheme/dark TTWebView/0751130014013',
'type' => 'human',
'category' => 'mobile',
'device' => 'AOSP',
'model' => 'On Flame',
'build' => 'QQ3A.200805.001',
'kernel' => 'Linux',
'platform' => 'Android',
'platformversion' => '10',
'engine' => 'Blink',
'engineversion' => '75.0.3770.156',
'browser' => 'Chrome',
'browserversion' => '75.0.3770.156',
'language' => 'zh-CN',
'app' => 'Douyin',
'appname' => 'aweme',
'appversion' => '14.7.0',
'nettype' => 'WIFI',
'darkmode' => true
],
'Mozilla/5.0 (Linux; Android 14; KB2000 Build/AP2A.240905.003; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/126.0.6478.71 Mobile Safari/537.36 aweme_320000 JsSdk/1.0 NetType/WIFI Channel/doutui_android_1128_81p6qc AppName/aweme app_version/32.0.0 ByteLocale/zh-Hans-CN Region/CN AppSkin/white AppTheme/light BULLET/1 BytedanceWebview/d8a21c6 TTWebView/1261130062414' => [
'string' => 'Mozilla/5.0 (Linux; Android 14; KB2000 Build/AP2A.240905.003; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/126.0.6478.71 Mobile Safari/537.36 aweme_320000 JsSdk/1.0 NetType/WIFI Channel/doutui_android_1128_81p6qc AppName/aweme app_version/32.0.0 ByteLocale/zh-Hans-CN Region/CN AppSkin/white AppTheme/light BULLET/1 BytedanceWebview/d8a21c6 TTWebView/1261130062414',
'type' => 'human',
'category' => 'mobile',
'vendor' => 'OnePlus',
'model' => 'KB2000',
'build' => 'AP2A.240905.003',
'kernel' => 'Linux',
'platform' => 'Android',
'platformversion' => '14',
'engine' => 'Blink',
'engineversion' => '126.0.6478.71',
'browser' => 'Chrome',
'browserversion' => '126.0.6478.71',
'language' => 'zh-CN',
'app' => 'Douyin',
'appname' => 'aweme',
'appversion' => '32.0.0',
'nettype' => 'WIFI',
'darkmode' => false
]
];
foreach ($strings AS $ua => $item) {
Expand Down
33 changes: 33 additions & 0 deletions tests/browsersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,22 @@ public function testUCBrowser() : void {
'type' => 'human',
'category' => 'mobile',
'language' => 'en-US'
],
'Mozilla/5.0 (Linux; U; Android 7.0; zh-CN; SM-G9550 Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/40.0.2214.89 UCBrowser/11.7.0.953 Mobile Safari/537.36' => [
'string' => 'Mozilla/5.0 (Linux; U; Android 7.0; zh-CN; SM-G9550 Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/40.0.2214.89 UCBrowser/11.7.0.953 Mobile Safari/537.36',
'type' => 'human',
'category' => 'mobile',
'vendor' => 'Samsung',
'model' => 'SM-G9550',
'build' => 'NRD90M',
'kernel' => 'Linux',
'platform' => 'Android',
'platformversion' => '7.0',
'engine' => 'Blink',
'engineversion' => '40.0.2214.89',
'browser' => 'UCBrowser',
'browserversion' => '11.7.0.953',
'language' => 'zh-CN'
]
];
foreach ($strings AS $ua => $item) {
Expand Down Expand Up @@ -1904,6 +1920,23 @@ public function testOther() : void {
'appname' => 'Avant Browser',
'appversion' => '1.2.789',
'url' => 'http://www.avantbrowser.com'
],
'Mozilla/5.0 (Linux; U; Android 4.4.4; zh-cn; MI 4LTE Build/KTU84P) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/39.0.0.0 Mobile Safari/537.36 XiaoMi/MiuiBrowser/2.1.1' => [
'string' => 'Mozilla/5.0 (Linux; U; Android 4.4.4; zh-cn; MI 4LTE Build/KTU84P) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/39.0.0.0 Mobile Safari/537.36 XiaoMi/MiuiBrowser/2.1.1',
'type' => 'human',
'category' => 'mobile',
'vendor' => 'Xiaomi',
'device' => 'MI',
'model' => '4LTE',
'build' => 'KTU84P',
'kernel' => 'Linux',
'platform' => 'Android',
'platformversion' => '4.4.4',
'engine' => 'Blink',
'engineversion' => '39.0.0.0',
'browser' => 'MIUI Browser',
'browserversion' => '2.1.1',
'language' => 'zh-CN'
]
];
foreach ($strings AS $ua => $item) {
Expand Down
4 changes: 2 additions & 2 deletions tests/languagesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public function testLanguages() : void {
'platformversion' => '6.0.1',
'engine' => 'Blink',
'engineversion' => '79.0.3945.147',
'browser' => 'Chrome',
'browserversion' => '79.0.3945.147',
'browser' => 'MIUI Browser',
'browserversion' => '12.10.5-go',
'language' => 'en-GB'
],
'com.zhiliaoapp.musically/2022706030 (Linux; U; Android 10; en; TECNO KE5; Build/QP1A.190711.020; Cronet/TTNetVersion:07232c86 2022-12-15 QuicVersion:5f23035d 2022-11-23)' => [
Expand Down

0 comments on commit c7c94bb

Please sign in to comment.