店播爬取Python脚本

Xg04.py 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. from random import choice
  2. from time import time
  3. from hashlib import md5
  4. from copy import deepcopy
  5. def hex_string(num):
  6. tmp_string = hex(num)[2:]
  7. if len(tmp_string) < 2:
  8. tmp_string = '0' + tmp_string
  9. return tmp_string
  10. def reverse(num):
  11. tmp_string = hex(num)[2:]
  12. if len(tmp_string) < 2:
  13. tmp_string = '0' + tmp_string
  14. return int(tmp_string[1:] + tmp_string[:1], 16)
  15. def RBIT(num):
  16. result = ''
  17. tmp_string = bin(num)[2:]
  18. while len(tmp_string) < 8:
  19. tmp_string = '0' + tmp_string
  20. for i in range(0, 8):
  21. result = result + tmp_string[7 - i]
  22. return int(result, 2)
  23. class XG:
  24. def __init__(self, debug):
  25. self.length = 0x14
  26. self.debug = debug
  27. # a=choice(range(0, 0xFF))
  28. # b=8 * choice(range(0, 0x1F))
  29. # print(a,b)
  30. # a=231
  31. # b=64
  32. # a=195
  33. # # b=72
  34. # a=23
  35. # b=80
  36. # a=139
  37. # b=160
  38. # a=237
  39. # b=104
  40. # m=[(231,64),(195,72),(23,80),(139,160)]
  41. # c=choice(m)
  42. # a=c[0]
  43. # b=c[1]
  44. a=231
  45. b=64
  46. self.hex_510 = [0x1E, 0x00, 0xE0, a, 0x93, 0x45, 0x01,b ]
  47. def addr_920(self):
  48. tmp = ''
  49. hex_920 = []
  50. for i in range(0x0, 0x100):
  51. hex_920.append(i)
  52. # check_log(hex_920)
  53. for i in range(0, 0x100):
  54. if i == 0:
  55. A = 0
  56. elif tmp:
  57. A = tmp
  58. else:
  59. A = hex_920[i - 1]
  60. B = self.hex_510[i % 0x8]
  61. if A == 0x55:
  62. if i != 1:
  63. if tmp != 0x55:
  64. A = 0
  65. C = A + i + B
  66. while C >= 0x100:
  67. C = C - 0x100
  68. if C < i:
  69. tmp = C
  70. else:
  71. tmp = ''
  72. D = hex_920[C]
  73. hex_920[i] = D
  74. # check_log(hex_920)
  75. return hex_920
  76. def initial(self, debug, hex_920):
  77. tmp_add = []
  78. tmp_hex = deepcopy(hex_920)
  79. for i in range(self.length):
  80. A = debug[i]
  81. if not tmp_add:
  82. B = 0
  83. else:
  84. B = tmp_add[-1]
  85. C = hex_920[i + 1] + B
  86. while C >= 0x100:
  87. C = C - 0x100
  88. tmp_add.append(C)
  89. D = tmp_hex[C]
  90. tmp_hex[i + 1] = D
  91. E = D + D
  92. while E >= 0x100:
  93. E = E - 0x100
  94. F = tmp_hex[E]
  95. G = A ^ F
  96. debug[i] = G
  97. return debug
  98. def calculate(self, debug):
  99. for i in range(self.length):
  100. A = debug[i]
  101. B = reverse(A)
  102. C = debug[(i + 1) % self.length]
  103. D = B ^ C
  104. E = RBIT(D)
  105. F = E ^ self.length
  106. G = ~F
  107. while G < 0:
  108. G += 0x100000000
  109. H = int(hex(G)[-2:], 16)
  110. debug[i] = H
  111. return debug
  112. def main(self):
  113. result = ''
  114. for item in self.calculate(self.initial(self.debug, self.addr_920())):
  115. result = result + hex_string(item)
  116. return '0401{}{}0001{}'.format(hex_string(self.hex_510[7]), hex_string(self.hex_510[3]), result)
  117. def X_Gorgon(url, data, cookie = '', model='utf-8'):
  118. gorgon = []
  119. Khronos = hex(int(time()))[2:]
  120. url_md5 = md5(bytearray(url, 'utf-8')).hexdigest()
  121. for i in range(0, 4):
  122. gorgon.append(int(url_md5[2 * i: 2 * i + 2], 16))
  123. if data:
  124. if model == 'utf-8':
  125. data_md5 = md5(bytearray(data, 'utf-8')).hexdigest()
  126. for i in range(0, 4):
  127. gorgon.append(int(data_md5[2 * i: 2 * i + 2], 16))
  128. elif model == 'octet':
  129. data_md5 = md5(data).hexdigest()
  130. for i in range(0, 4):
  131. gorgon.append(int(data_md5[2 * i: 2 * i + 2], 16))
  132. else:
  133. for i in range(0, 4):
  134. gorgon.append(0x0)
  135. if cookie:
  136. cookie_md5 = md5(bytearray(cookie, 'utf-8')).hexdigest()
  137. for i in range(0, 4):
  138. gorgon.append(int(cookie_md5[2 * i: 2 * i + 2], 16))
  139. else:
  140. for i in range(0, 4):
  141. gorgon.append(0x0)
  142. for i in range(0, 4):
  143. gorgon.append(0x0)
  144. for i in range(0, 4):
  145. gorgon.append(int(Khronos[2 * i: 2 * i + 2], 16))
  146. return {'X-Gorgon': XG(gorgon).main(), 'X-Khronos': str(int(Khronos, 16))}
  147. if __name__ == "__main__":
  148. url = 'os_api=22&device_type=OPPO%20R17%20Pro&ssmix=a&manifest_version_code=110901&dpi=320&uuid=866174816715680&app_name=aweme&version_name=11.9.0&ts=1606715214&cpu_support64=false&storage_type=0&app_type=normal&ac=wifi&host_abi=armeabi-v7a&update_version_code=11909900&channel=lephone_1128_1&_rticket=1606715214501&device_platform=android&iid=3606038575327836&version_code=110900&mac_address=7C%3AB2%3A7D%3A15%3A68%3A46&cdid=f84bf379-019e-44a6-8426-0fd2bc3f8278&openudid=764841d6f5377125&device_id=3579659689950456&resolution=1080*1920&os_version=5.1.1&language=zh&device_brand=OPPO&aid=1128&mcc_mnc=46007'
  149. data = 'promotion_id=3448966412629092080&product_id=3448963960152394964&aweme_id=0&author_id=1626898700712935&meta_param=%7B%22enter_from%22%3A%22live%22%2C%22live_room_id%22%3A%226900732511879039758%22%2C%22entrance_info%22%3A%22%7B%5C%22_param_live_platform%5C%22%3A%5C%22live%5C%22%2C%5C%22action_type%5C%22%3A%5C%22click%5C%22%2C%5C%22anchor_id%5C%22%3A%5C%221626898700712935%5C%22%2C%5C%22carrier_source%5C%22%3A%5C%22homepage_hot%5C%22%2C%5C%22carrier_type%5C%22%3A%5C%22live_list_card%5C%22%2C%5C%22category_name%5C%22%3A%5C%22homepage_hot_temai_video_head%5C%22%2C%5C%22ecom_group_type%5C%22%3A%5C%22live%5C%22%2C%5C%22enter_from%5C%22%3A%5C%22live%5C%22%2C%5C%22enter_from_merge%5C%22%3A%5C%22homepage_hot%5C%22%2C%5C%22enter_method%5C%22%3A%5C%22video_head%5C%22%2C%5C%22follow_status%5C%22%3A%5C%220%5C%22%2C%5C%22group_id%5C%22%3A%5C%226900356917323959567%5C%22%2C%5C%22live_id%5C%22%3A1%2C%5C%22product_activity_type%5C%22%3A%5C%22nonactivity%5C%22%2C%5C%22request_id%5C%22%3A%5C%22202011301345510101980821034009F2B6%5C%22%2C%5C%22room_id%5C%22%3A%5C%226900732511879039758%5C%22%2C%5C%22sdk_version%5C%22%3A%5C%221600%5C%22%2C%5C%22source_method%5C%22%3A%5C%22video_head%5C%22%7D%22%7D&enter_from=live'
  150. cookie = ''
  151. res = X_Gorgon(url, data, cookie)
  152. print(res)