Get delay

@param  string|null $userAgent - which robot to check for
@param  string $type - in case of non-standard directive
@return int|float
516952
public function getDelay($userAgent = null, $type = 'crawl-delay')
    {
        if ($userAgent !== null) {
            $this->setUserAgent($userAgent);
        }
        switch (mb_strtolower($type)) {
            case 'cache':
            case 'cache-delay':
                // non-standard directive
                $directive = self::DIRECTIVE_CACHE_DELAY;
                break;
            default:
                $directive = self::DIRECTIVE_CRAWL_DELAY;
        }
        if (isset($this->rules[$this->userAgentMatch][$directive])) {
            // return delay for requested directive
            return $this->rules[$this->userAgentMatch][$directive];
        } elseif (isset($this->rules[$this->userAgentMatch][self::DIRECTIVE_CRAWL_DELAY])) {
            $this->log[] = "$directive directive (unofficial): Not found, fallback to " . self::DIRECTIVE_CRAWL_DELAY . ' directive';
            return $this->rules[$this->userAgentMatch][self::DIRECTIVE_CRAWL_DELAY];
        }
        $this->log[] = "$directive directive: Not found";
        return 0;
    }
1139952
public function lookForMatchingUserAgent($userAgent)
    {
        $tolerance = Utils::firstSlash($userAgent);

        return Utils::risMatch($this->userAgents, $userAgent, $tolerance);
    }
947669
public function getBrowser(string $userAgent) : ?FormatterInterface
    {
        $userAgent = strtolower($userAgent);
        $formatter = null;

        foreach ($this->patternHelper->getPatterns($userAgent) as $patterns) {
            $patternToMatch = '/^(?:' . str_replace("\t", ')|(?:', $patterns) . ')$/i';

            if (! preg_match($patternToMatch, $userAgent)) {
                continue;
            }

            // strtok() requires less memory than explode()
            $pattern = strtok($patterns, "\t");

            while (false !== $pattern) {
                $pattern = str_replace('[\d]', '(\d)', $pattern);
                $quotedPattern = '/^' . $pattern . '$/i';
                $matches = [];

                if (preg_match($quotedPattern, $userAgent, $matches)) {
                    // Insert the digits back into the pattern, so that we can search the settings for it
                    if (1 < count($matches)) {
                        array_shift($matches);
                        foreach ($matches as $oneMatch) {
                            $numPos = strpos($pattern, '(\d)');
                            $pattern = substr_replace($pattern, $oneMatch, $numPos, 4);
                        }
                    }

                    // Try to get settings - as digits have been replaced to speed up the pattern search (up to 90 faster),
                    // we won't always find the data in the first step - so check if settings have been found and if not,
                    // search for the next pattern.
                    $settings = $this->dataHelper->getSettings($pattern);

                    if (0 < count($settings)) {
                        $formatter = $this->formatter;
                        $formatter->setData($settings);

                        break 2;
                    }
                }

                $pattern = strtok("\t");
            }
        }

        return $formatter;
    }
488971
public static function getUcAndroidVersion($userAgent, $useDefault = true)
    {
        if (preg_match('/; Adr (\d+\.\d+)\.?/', $userAgent, $matches)) {
            $u2k_an_version = $matches[1];

            if (in_array($u2k_an_version, AndroidHandler::$validAndroidVersions)) {
                return $u2k_an_version;
            }
        }

        return $useDefault ? AndroidHandler::ANDROID_DEFAULT_VERSION : null;
    }
1165187
public function isAllowed($url, $userAgent = null)
    {
        if ($userAgent !== null) {
            $this->setUserAgent($userAgent);
        }
        $url = $this->encode_url($url);
        return $this->checkRules(self::DIRECTIVE_ALLOW, $this->getPath($url), $this->userAgentMatch);
    }
1237839
public function getBits(string $useragent): ?int
    {
        // 32 bits on 64 bit system
        if (preg_match('/i686 on x86_64|i686 \(x86_64\)/i', $useragent)) {
            return 32;
        }

        // 64 bits
        if (preg_match('/x64|win64|x86_64|amd64|ppc64|sparc64|osf1/i', $useragent)) {
            return 64;
        }

        // old deprecated 16 bit windows systems
        if (preg_match('/win3\.1|windows 3\.1/i', $useragent)) {
            return 16;
        }

        // old deprecated 8 bit systems
        if (preg_match('/cp\/m|8-bit/i', $useragent)) {
            return 8;
        }

        return 32;
    }
204655
public function detectVersion(string $useragent): VersionInterface
    {
        $doMatch = preg_match('/ObigoInternetBrowser\/QO?([\d.]+)/', $useragent, $matches);

        if ($doMatch) {
            return (new VersionFactory())->set($matches[1]);
        }

        $doMatch = preg_match('/obigo\-browser\/q([\d.]+)/i', $useragent, $matches);

        if ($doMatch) {
            return (new VersionFactory())->set($matches[1]);
        }

        $doMatch = preg_match('/(?:teleca|obigo)[\-\/]q([\d.]+)/i', $useragent, $matches);

        if ($doMatch) {
            return (new VersionFactory())->set($matches[1]);
        }

        return (new VersionFactory())->set('0');
    }
273019
public function setUserAgent($userAgent = null)
        {
            if (!empty($userAgent)) {
                return $this->userAgent = $userAgent;
            } else {
                $this->userAgent = null;
                foreach($this->getUaHttpHeaders() as $altHeader) {
                    if(!empty($this->httpHeaders[$altHeader])) { // @todo: should use getHttpHeader(), but it would be slow. (Serban)
                        $this->userAgent .= $this->httpHeaders[$altHeader] . " ";
                    }
                }
                return $this->userAgent = (!empty($this->userAgent) ? trim($this->userAgent) : null);
            }
        }
1055128
public static function getInstance($userAgent)
    {
        if (array_key_exists($userAgent, self::$deviceDetectorInstances)) {
            return self::$deviceDetectorInstances[$userAgent];
        }

        $deviceDetector = new DeviceDetector($userAgent);
        $deviceDetector->discardBotInformation();
        $deviceDetector->setCache(new DeviceDetectorCache(86400));
        $deviceDetector->parse();

        self::$deviceDetectorInstances[$userAgent] = $deviceDetector;

        return $deviceDetector;
    }
41824
public function delay(int $delay, AsyncSchedulerInterface $scheduler = null): Observable
    {
        return $this->lift(function () use ($delay, $scheduler) {
            return new DelayOperator($delay, $scheduler ?: Scheduler::getAsync());
        });
    }
806266
protected static function getBrowscapInfo($UserAgent=false)
    {
        // Check if user agent present
        if ($UserAgent === false)
        {
            return false; // No user agent, no search.
        }
        
        // set an own cache directory (otherwise the system temp directory is used)
        \Crossjoin\Browscap\Cache\File::setCacheDirectory(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'cache');
        
        //Large sonst fehlt Browser_Type / Crawler um Bots zu erkennen
        \Crossjoin\Browscap\Browscap::setDatasetType(\Crossjoin\Browscap\Browscap::DATASET_TYPE_LARGE);

        // disable automatic updates 
        $updater = new \Crossjoin\Browscap\Updater\None(); 
        \Crossjoin\Browscap\Browscap::setUpdater($updater);
        
        $browscap = new \Crossjoin\Browscap\Browscap(false); //autoUpdate = false
        $settings = $browscap->getBrowser($UserAgent)->getData();
        
        return $settings;
        /*
            stdClass Object
            (
                [browser_name_regex] => /^Yandex\/1\.01\.001 \(compatible; Win16; .*\)$/
                [browser_name_pattern] => Yandex/1.01.001 (compatible; Win16; *)
                [parent] => Yandex
                [comment] => Yandex
                [browser] => Yandex
                [browser_type] => Bot/Crawler
                [browser_maker] => Yandex
                [crawler] => true
                .....
            stdClass Object
            (
                [browser_name_regex] => /^Googlebot\-Image.*$/
                [browser_name_pattern] => Googlebot-Image*
                [parent] => Googlebot
                [browser] => Googlebot-Image
                [comment] => Googlebot
                [browser_type] => Bot/Crawler
                [browser_maker] => Google Inc
                [crawler] => true
                .....
         */
    }
629866
public static function isSmartTV($userAgent)
    {
        if (self::$isSmartTv !== null) {
            return self::$isSmartTv;
        }
        self::$isSmartTv = false;
        $userAgent       = strtolower($userAgent);
        foreach (self::$smartTVBrowsers as $key) {
            if (strpos($userAgent, $key) !== false) {
                self::$isSmartTv = true;
                break;
            }
        }

        return self::$isSmartTv;
    }
12919
public static function isMobileBrowser($userAgent)
    {
        if (self::$_is_mobile_browser !== null) {
            return self::$_is_mobile_browser;
        }
        self::$_is_mobile_browser = false;
        $userAgent = strtolower($userAgent);
        foreach (self::$mobileBrowsers as $key) {
            if (strpos($userAgent, $key) !== false) {
                self::$_is_mobile_browser = true;
                break;
            }
        }
        return self::$_is_mobile_browser;
    }
942970
public static function isRobot($userAgent)
    {
        self::$isRobot = false;
        $userAgent     = strtolower($userAgent);

        foreach (self::$robots as $key) {
            if (strpos($userAgent, $key) !== false) {
                self::$isRobot = true;
                break;
            }
        }

        return self::$isRobot;
    }
698459
def get_crawl_delay(self, user_agent):
        
        # See is_allowed() comment about the explicit unicode conversion.
        if (PY_MAJOR_VERSION < 3) and (not isinstance(user_agent, unicode)):
            user_agent = user_agent.decode()
    
        for ruleset in self.__rulesets:
            if ruleset.does_user_agent_match(user_agent):
                return ruleset.crawl_delay
                
        return None
386120
public function user_agent($user_agent = NULL)
	{
		if ($user_agent !== NULL)
		{
			\Request::$user_agent = $user_agent;
			return $this;
		}
		return \Request::$user_agent;
	}
834627
public static function toleranceToRisDelimeter($userAgent)
    {
        $tolerance = strpos($userAgent, WurflConstants::RIS_DELIMITER);
        if ($tolerance === false) {
            return false;
        }

        // Push the tolerance to the *end* of the RIS Delimiter
        return $tolerance + strlen(WurflConstants::RIS_DELIMITER);
    }