From 647c377f65b46e408402a77f13a890b0d1ac43a7 Mon Sep 17 00:00:00 2001 From: Roy Olav Purser Date: Tue, 11 May 2021 14:45:33 +0200 Subject: [PATCH] random proxy --- stream.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/stream.py b/stream.py index 60269bc..e25e065 100755 --- a/stream.py +++ b/stream.py @@ -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)