fan.py 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import re
  2. import base64
  3. import requests
  4. import hashlib
  5. import configparser
  6. headers = {'User-Agent': 'okhttp/3.15'}
  7. def get_fan_conf():
  8. config = configparser.ConfigParser()
  9. config.read("config.ini")
  10. url = 'http://饭太硬.com/tv'
  11. response = requests.get(url, headers=headers)
  12. match = re.search(r'[A-Za-z0]{8}\*\*(.*)', response.text)
  13. if not match:
  14. return
  15. result = match.group(1)
  16. m = hashlib.md5()
  17. m.update(result.encode('utf-8'))
  18. md5 = m.hexdigest()
  19. try:
  20. old_md5 = config.get("md5", "conf")
  21. if md5 == old_md5:
  22. print("No update needed")
  23. return
  24. except:
  25. pass
  26. content = base64.b64decode(result).decode('utf-8')
  27. url = re.search(r'spider"\:"(.*);md5;', content).group(1)
  28. content = content.replace(url, './JAR/fan.txt')
  29. content = diy_conf(content)
  30. with open('xo.json', 'w', newline='', encoding='utf-8') as f:
  31. f.write(content)
  32. # 本地包
  33. local_content = local_conf(content)
  34. with open('a.json', 'w', newline='', encoding='utf-8') as f:
  35. f.write(local_content)
  36. # Update conf.md5
  37. config.set("md5", "conf", md5)
  38. with open("config.ini", "w") as f:
  39. config.write(f)
  40. jmd5 = re.search(r';md5;(\w+)"', content).group(1)
  41. current_md5 = config.get("md5", "jar").strip()
  42. if jmd5 != current_md5:
  43. # Update jar.md5
  44. config.set("md5", "jar", jmd5)
  45. with open("config.ini", "w") as f:
  46. config.write(f)
  47. response = requests.get(url)
  48. with open("./JAR/fan.txt", "wb") as f:
  49. f.write(response.content)
  50. def diy_conf(content):
  51. #content = content.replace('https://fanty.run.goorm.site/ext/js/drpy2.min.js', './JS/lib/drpy2.min.js')
  52. #content = content.replace('公众号【神秘的哥哥们】', '豆瓣')
  53. pattern = r'{"key":"Bili"(.)*\n{"key":"Biliych"(.)*\n'
  54. replacement = ''
  55. content = re.sub(pattern, replacement, content)
  56. pattern = r'{"key":"Nbys"(.|\n)*(?={"key":"cc")'
  57. replacement = ''
  58. content = re.sub(pattern, replacement, content)
  59. return content
  60. def local_conf(content):
  61. pattern = r'{"key":"88js"(.|\n)*(?={"key":"米搜")'
  62. replacement = r'{"key":"百度","name":"百度┃采集","type":1,"api":"https://api.apibdzy.com/api.php/provide/vod?ac=list","searchable":1,"filterable":0},\n{"key":"量子","name":"量子┃采集","type":0,"api":"https://cj.lziapi.com/api.php/provide/vod/at/xml/","searchable":1,"changeable":1},\n{"key":"非凡","name":"非凡┃采集","type":0,"api":"http://cj.ffzyapi.com/api.php/provide/vod/at/xml/","searchable":1,"changeable":1},\n{"key":"暴風","name":"暴風┃采集","type":1,"api":"https://bfzyapi.com/api.php/provide/vod/?ac=list","searchable":1,"changeable":1},\n{"key":"索尼","name":"索尼┃采集","type":1,"api":"https://suoniapi.com/api.php/provide/vod","searchable":1,"changeable":1},\n{"key":"快帆","name":"快帆┃采集","type":1,"api":"https://api.kuaifan.tv/api.php/provide/vod","searchable":1,"changeable":1},\n'
  63. content = re.sub(pattern, replacement, content)
  64. return content
  65. if __name__ == '__main__':
  66. get_fan_conf()