mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
19 lines
649 B
JavaScript
19 lines
649 B
JavaScript
const UserAgent = require('user-agents');
|
|
|
|
const PROXY_HOSTS = process.env.PROXY_HOSTS && process.env.PROXY_HOSTS.split(',');
|
|
const PROXY_USERNAME = process.env.PROXY_USERNAME;
|
|
const PROXY_PASSWORD = process.env.PROXY_PASSWORD;
|
|
const userAgent = new UserAgent();
|
|
|
|
function getRandomUserAgent() {
|
|
return userAgent.random().toString();
|
|
}
|
|
|
|
function getRandomProxy() {
|
|
if (PROXY_HOSTS && PROXY_HOSTS.length && PROXY_USERNAME && PROXY_PASSWORD) {
|
|
return `http://${PROXY_USERNAME}:${PROXY_PASSWORD}@${PROXY_HOSTS[Math.floor(Math.random() * PROXY_HOSTS.length)]}`;
|
|
}
|
|
return undefined;
|
|
}
|
|
|
|
module.exports = { getRandomUserAgent, getRandomProxy }; |