io.github.mngsk.devicedetector.device.TelevisionDeviceParser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of device-detector Show documentation
Show all versions of device-detector Show documentation
The Universal Device Detection library that parses User Agents and detects devices (desktop, tablet, mobile, tv, cars, console, etc.), clients (browsers, feed readers, media players, PIMs, ...), operating systems, brands and models.
package io.github.mngsk.devicedetector.device;
import java.util.Optional;
import java.util.regex.Pattern;
import com.fasterxml.jackson.databind.ObjectMapper;
public class TelevisionDeviceParser extends AbstractDeviceParser {
private Pattern hbbtvPattern = Pattern.compile(
"(?:^|[^A-Z0-9\\-_]|[^A-Z0-9\\-]_|sprd-)(?:HbbTV/([1-9]{1}(?:\\.[0-9]{1}){1,2}))",
Pattern.CASE_INSENSITIVE);
public TelevisionDeviceParser() {
super("regexes/device/televisions.yml");
}
public TelevisionDeviceParser(ObjectMapper objectMapper) {
super("regexes/device/televisions.yml", objectMapper);
}
@Override
public Optional parse(String userAgent) {
if (!this.hbbtvPattern.matcher(userAgent).find()) {
return Optional.empty();
}
return Optional.of(
super.parse(userAgent).orElse(new Device("tv", null, null)));
}
}