random proxy

This commit is contained in:
Roy Olav Purser 2021-05-11 14:45:33 +02:00
parent 6771bb774b
commit 647c377f65
Signed by: roypur
GPG Key ID: E14D26A036F21656

View File

@ -1,12 +1,13 @@
#!/usr/bin/env python3
import random
import json
import urllib.parse
import re
import os
import streamlink
import tornado.web
import tornado.routing
import requests
import json
import os
import urllib.parse
import re
providers = {}
providers["nrk"] = "https://tv.nrk.no"
@ -168,8 +169,13 @@ class MainHandler(tornado.web.RequestHandler):
path = path.strip("/")
src = providers[provider] + self.request.path
proxy = None
proxy_list = proxies.get(provider)
proxy_list = None
proxy_list_orig = proxies.get(provider)
if isinstance(proxy_list_orig, list):
proxy_list = proxy_list_orig.copy()
if isinstance(proxy_list, list):
rand = random.SystemRandom()
rand.shuffle(proxy_list)
for proxy_temp in proxy_list:
try:
resp = requests.head(src, allow_redirects=True, proxies=proxy_temp.req)