Walkero0

Untitled

Dec 17th, 2019
536
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.02 KB | None | 0 0
  1. '''
  2. Copyright 2015 ohyou
  3.  
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7.  
  8. http://www.apache.org/licenses/LICENSE-2.0
  9.  
  10. Unless required by applicable law or agreed to in writing, software
  11. distributed under the License is distributed on an "AS IS" BASIS,
  12. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. See the License for the specific language governing permissions and
  14. limitations under the License.
  15. '''
  16.  
  17. import requests
  18. import subprocess
  19. import json
  20. import sys
  21. import multiprocessing
  22. import time
  23. import random
  24.  
  25. channel_url = "mixer.com/"
  26. processes = []
  27.  
  28.  
  29. def get_channel():
  30. # Reading the channel name - passed as an argument to this script
  31. if len(sys.argv) >= 2:
  32. global channel_url
  33. channel_url += sys.argv[1]
  34. else:
  35. print "An error has occurred while trying to read arguments. Did you specify the channel?"
  36. sys.exit(1)
  37.  
  38.  
  39. def get_proxies():
  40. # Reading the list of proxies
  41. try:
  42. lines = [line.rstrip("\n") for line in open("proxylist.txt")]
  43. except IOError as e:
  44. print "An error has occurred while trying to read the list of proxies: %s" % e.strerror
  45. sys.exit(1)
  46.  
  47. return lines
  48.  
  49.  
  50. def get_url():
  51. # Getting the json with all data regarding the stream
  52. try:
  53. response = subprocess.Popen(
  54. ["streamlink", "--http-header", "Client-ID=ewvlchtxgqq88ru9gmfp1gmyt6h2b93",
  55. channel_url, "--json"], stdout=subprocess.PIPE).communicate()[0]
  56. except subprocess.CalledProcessError:
  57. print "An error has occurred while trying to get the stream data. Is the channel online? Is the channel name correct?"
  58. sys.exit(1)
  59. except OSError:
  60. print "An error has occurred while trying to use livestreamer package. Is it installed? Do you have Python in your PATH variable?"
  61.  
  62. # Decoding the url to the worst quality of the stream
  63. try:
  64. url = json.loads(response)['streams']['audio_only']['url']
  65. except:
  66. try:
  67. url = json.loads(response)['streams']['worst']['url']
  68. except (ValueError, KeyError):
  69. print "An error has occurred while trying to get the stream data. Is the channel online? Is the channel name correct?"
  70. sys.exit(1)
  71.  
  72. return url
  73.  
  74.  
  75. def open_url(url, proxy):
  76. # Sending HEAD requests
  77. while True:
  78. try:
  79. with requests.Session() as s:
  80. response = s.head(url, proxies=proxy)
  81. print "Sent HEAD request with %s" % proxy["http"]
  82. time.sleep(20)
  83. except requests.exceptions.Timeout:
  84. print " Timeout error for %s" % proxy["http"]
  85. except requests.exceptions.ConnectionError:
  86. print " Connection error for %s" % proxy["http"]
  87.  
  88.  
  89. def prepare_processes():
  90. global processes
  91. proxies = get_proxies()
  92. n = 0
  93.  
  94. if len(proxies) < 1:
  95. print "An error has occurred while preparing the process: Not enough proxy servers. Need at least 1 to function."
  96. sys.exit(1)
  97.  
  98. for proxy in proxies:
  99. # Preparing the process and giving it its own proxy
  100. processes.append(
  101. multiprocessing.Process(
  102. target=open_url, kwargs={
  103. "url": get_url(), "proxy": {
  104. "http": proxy}}))
  105.  
  106. print '.',
  107.  
  108. print ''
  109.  
  110. if __name__ == "__main__":
  111. print "Obtaining the channel..."
  112. get_channel()
  113. print "Obtained the channel"
  114. print "Preparing the processes..."
  115. prepare_processes()
  116. print "Prepared the processes"
  117. print "Booting up the processes..."
  118.  
  119. # Timer multiplier
  120. n = 8
  121.  
  122. # Starting up the processes
  123. for process in processes:
  124. time.sleep(random.randint(1, 5) * n)
  125. process.daemon = True
  126. process.start()
  127. if n > 1:
  128. n -= 1
  129.  
  130. # Running infinitely
  131. while True:
  132. time.sleep(1)
Advertisement
Add Comment
Please, Sign In to add comment