Skip to content

Commit

Permalink
Improve Roku model detection
Browse files Browse the repository at this point in the history
  • Loading branch information
NielsLeenheer committed Jan 4, 2021
1 parent cba3da3 commit 80437c3
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 17 deletions.
102 changes: 85 additions & 17 deletions src/Analyser/Header/Useragent/Device/Television.php
Original file line number Diff line number Diff line change
Expand Up @@ -610,29 +610,97 @@ private function detectSettopboxes($ua)

/* Roku */

if (preg_match('/^Roku\/DVP-(?:[0-9A-Z]+-)?[0-9\.]+ \(([0-9]{2,2})/u', $ua, $match)) {
if (preg_match('/Roku(?:([0-9]+)[A-Z]+)?\/DVP-(?:([0-9]+)[A-Z]+-)?[0-9\.]+/u', $ua, $match)) {
$this->data->os->reset();

$this->data->device->manufacturer = 'Roku';
$this->data->device->type = Constants\DeviceType::TELEVISION;

switch ($match[1]) {
case '02':
$this->data->device->model = '2 XS';
$this->data->device->generic = false;
break;
case '04':
$this->data->device->model = '3';
$this->data->device->generic = false;
break;
case '07':
$this->data->device->model = 'LT';

$models = [
'2000' => 'HD',
'2050' => 'XD',
'2100' => 'XDS',
'2400' => 'LT',
'2450' => 'LT',
'2500' => 'HD',
'2700' => 'LT',
'2710' => '1 SE',
'2720' => '2',
'3000' => '2 HD',
'3050' => '2 XD',
'3100' => '2 XS',
'3400' => 'Streaming Stick, MHL',
'3420' => 'Streaming Stick, MHL',
'3500' => 'Streaming Stick, HDMI',
'3600' => 'Streaming Stick',
'3700' => 'Express',
'3710' => 'Express+',
'3800' => 'Streaming Stick',
'3810' => 'Streaming Stick+',
'3900' => 'Express',
'3910' => 'Express+',
'3920' => 'Premiere',
'3921' => 'Premiere+',
'3930' => 'Express',
'3931' => 'Express+',
'4200' => '3',
'4210' => '2',
'4230' => '3',
'4400' => '4',
'4620' => 'Premiere',
'4630' => 'Premiere+',
'4640' => 'Ultra',
'4660' => 'Ultra',
'4661' => 'Ultra',
'4662' => 'Ultra LT',
'4670' => 'Ultra',
'4800' => 'Ultra',
];

if (!empty($match[1]) || !empty($match[2])) {
$model = !empty($match[1]) ? $match[1] : $match[2];

if (isset($models[$model])) {
$this->data->device->model = $models[$model];
$this->data->device->generic = false;
break;
case '09':
$this->data->device->model = 'Streaming Stick';
}
}

$this->data->device->identified |= Constants\Id::MATCH_UA;
}

if (preg_match('/Roku\/DVP-[0-9\.]+ \(([0-9A-Z]{2,2})[0-9]+\./u', $ua, $match)) {
$this->data->os->reset();

$this->data->device->manufacturer = 'Roku';
$this->data->device->type = Constants\DeviceType::TELEVISION;

$models = [
'02' => '2 XS',
'03' => 'LT',
'04' => '3',
'07' => 'LT',
'09' => 'Streaming Stick',
'29' => 'Ultra',
'30' => [ 'TCL', '4K Roku TV' ],
'51' => 'Express',
'AE' => 'Express',
];

if (!empty($match[1])) {
$model = $match[1];

if (isset($models[$model])) {
if (is_array($models[$model])) {
$this->data->device->manufacturer = $models[$model][0];
$this->data->device->model = $models[$model][1];
}
else {
$this->data->device->model = $models[$model];
}

$this->data->device->generic = false;
break;
}
}

$this->data->device->identified |= Constants\Id::MATCH_UA;
Expand Down
16 changes: 16 additions & 0 deletions tests/data/television/roku.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,19 @@
headers: 'User-Agent: Roku/DVP-5.5 (095.05E02025A)'
result: { device: { type: television, manufacturer: Roku, model: 'Streaming Stick' } }
readable: 'a Roku Streaming Stick'
-
headers: 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36 Roku/DVP-8.10 (468.10E04145A)'
readable: 'a Roku'
result: { browser: { family: { name: Chrome, version: 70 }, type: browser }, engine: { name: Blink }, device: { type: television, manufacturer: Roku } }
-
headers: 'User-Agent: Roku/DVP-9.10 (519.10E04111A)'
readable: 'a Roku Express'
result: { device: { type: television, manufacturer: Roku, model: Express } }
-
headers: 'User-Agent: Roku4640X/DVP-7.70 (297.70E04154A)'
readable: 'a Roku Ultra'
result: { device: { type: television, manufacturer: Roku, model: Ultra } }
-
headers: 'User-Agent: Roku/DVP-9.30 (309.30E04182A)'
readable: 'a TCL 4K Roku TV'
result: { device: { type: television, manufacturer: TCL, model: '4K Roku TV' } }

0 comments on commit 80437c3

Please sign in to comment.