All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.mngsk.devicedetector.device.TelevisionDeviceParser Maven / Gradle / Ivy

Go to download

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.

There is a newer version: 1.0.10
Show newest version
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)));
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy