huya.py 531 B

123456789101112131415161718192021222324
  1. import requests
  2. import re
  3. from base64 import b64decode
  4. import json
  5. class huya:
  6. def __init__(self, url):
  7. self.url = url
  8. def decodeStream(self, stream):
  9. return b64decode(stream).decode()
  10. def start(self):
  11. res = requests.get(self.url).text
  12. hyplay = re.findall('hyPlayerConfig\s=\s(.*?});', res, re.S)
  13. stream = json.loads(self.decodeStream(eval(hyplay[0])['stream']).replace("amp;", ""))
  14. print(stream)
  15. return stream
  16. if __name__ == '__main__':
  17. huya().start()