import requests, subprocess, json, sys, multiprocessing, time, random

channel_url = "twitch.tv/"
processes = []

def getChannel():
	# Reading the channel name - passed as an argument to this script
	if len(sys.argv) >= 2:
		global channel_url
		channel_url += sys.argv[1]
	else:
		print "An error has occurred while trying to read arguments."
		sys.exit(1)

def getProxies():
	# Reading the list of proxies
	try:
		lines = [line.rstrip("\n") for line in open("proxylist.txt")]
	except IOError as e:
		print "An error has occurred while trying to read the list of proxies: %s" % e.strerror
		sys.exit(1)
		
	return lines

def getUrl():
	# Getting the json with all data regarding the stream
	try:
		response = subprocess.Popen(["livestreamer", channel_url , "-j"], stdout=subprocess.PIPE).communicate()[0]
	except subprocess.CalledProcessError as e:
		print "An error has occurred while trying to get the stream data."
		sys.exit(1)
		
	# Decoding the url to the worst quality of the stream
	try:
		url = json.loads(response)['streams']['worst']['url']
	except (ValueError, KeyError):
		print "An error has occurred while trying to process the response."
		sys.exit(1)
		
	return url

def openUrl(url, proxy):
	while True:
		# Trying to make it look "realistic" by adding a random delay
		time.sleep(random.randint(5, 15))
		
		# Sending the HEAD request using a specific proxy
		try:
			requests.head(url, proxies=proxy)
			print "Sent HEAD request with %s" % proxy["http"]
		except requests.exceptions.Timeout:
			print "  Timeout error for %s" % proxy["http"]
		except requests.exceptions.ConnectionError:
			print "  Connection error for %s" % proxy["http"]
		
def prepareProcesses():
	global processes
	proxies = getProxies()

	if len(proxies) < 1:
		print "An error has occurred while preparing the process: Not enough proxy servers."
		sys.exit(1)
	
	for proxy in proxies:
		# Preparing the process and giving it its own proxy
		processes.append(multiprocessing.Process(target=openUrl, kwargs={"url" : getUrl(), "proxy" : {"http" : proxy}}))
		
if __name__ == "__main__":
	getChannel()
	prepareProcesses()
	
	# Starting up the processes
	for process in processes:
		process.daemon = True
		process.start()
	
	# Running infinitely
	while True:
		time.sleep(1)
@@ -1208,124 +1208,73 @@
 ):%0A%09
-while True:%0A%09%09# Trying to make it look %22realistic%22 by adding a random delay%0A%09%09time.sleep(random.randint(5, 15))%0A%09%09%0A%09
+# Explicitly opening the session%0A%09session = requests.Session()%0A%09%0A
 %09# S
@@ -1280,19 +1280,17 @@
 Sending 
-the
+a
  HEAD re
@@ -1299,30 +1299,50 @@
 est 
-using a specific proxy
+and quit this loop on success%0A%09while True:
 %0A%09%09t
@@ -1348,24 +1348,23 @@
 try:%0A%09%09%09
-requests
+session
 .head(ur
@@ -1426,32 +1426,50 @@
 %25 proxy%5B%22http%22%5D%0A
+%09%09%09time.sleep(30)%0A
 %09%09except request
@@ -2148,16 +2148,51 @@
 cesses:%0A
+%09%09time.sleep(random.randint(1, 5))%0A
 %09%09proces

Add session and rework the timers