kuwoMusic.py 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. from base64 import b64encode
  2. import requests
  3. class kwDES:
  4. def __init__(self):
  5. self.key = [121, 108, 122, 115, 120, 107, 119, 109]
  6. def a1(self, iArr, i2, j2):
  7. f8949d = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144,
  8. 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456,
  9. 536870912,
  10. 1073741824, 2147483648, 4294967296, 8589934592, 17179869184, 34359738368, 68719476736, 137438953472,
  11. 274877906944, 549755813888, 1099511627776, 2199023255552, 4398046511104, 8796093022208,
  12. 17592186044416,
  13. 35184372088832, 70368744177664, 140737488355328, 281474976710656, 562949953421312, 1125899906842624,
  14. 2251799813685248, 4503599627370496, 9007199254740992, 18014398509481984, 36028797018963968,
  15. 72057594037927936, 144115188075855872, 288230376151711744, 576460752303423488, 1152921504606846976,
  16. 2305843009213693952, 4611686018427387904, -9223372036854775808]
  17. j3 = 0
  18. for i3 in range(i2):
  19. if iArr[i3] >= 0 and (f8949d[iArr[i3]] & j2) != 0:
  20. j3 |= f8949d[i3]
  21. return j3
  22. def a(self, j2, jArr):
  23. m = [0, 1048577, 3145731]
  24. l = [1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1]
  25. k = [13, 16, 10, 23, 0, 4, -1, -1, 2, 27, 14, 5, 20, 9, -1, -1, 22, 18, 11, 3, 25, 7, -1, -1, 15, 6, 26, 19, 12,
  26. 1,
  27. -1, -1, 40, 51, 30, 36, 46, 54, -1, -1, 29, 39, 50, 44, 32, 47, -1, -1, 43, 48, 38, 55, 33, 52, -1, -1, 45,
  28. 41,
  29. 49, 35, 28, 31, -1, -1]
  30. j = [56, 48, 40, 32, 24, 16, 8, 0, 57, 49, 41, 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18, 10, 2, 59, 51, 43, 35,
  31. 62,
  32. 54, 46, 38, 30, 22, 14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 60, 52, 44, 36, 28, 20, 12, 4, 27, 19, 11, 3]
  33. a2 = self.a1(j, 56, j2)
  34. for i3 in range(16):
  35. a2 = ((a2 & (~m[l[i3]])) >> l[i3]) | ((m[l[i3]] & a2) << (28 - l[i3]))
  36. jArr[i3] = self.a1(k, 64, a2)
  37. def a2(self, jArr, j2):
  38. global v
  39. s = [0] * 2
  40. t = [0] * 8
  41. f8953h = [15, 6, 19, 20, 28, 11, 27, 16, 0, 14, 22, 25, 4, 17, 30, 9, 1, 7, 23, 13, 31, 26, 2, 8, 18, 12, 29, 5,
  42. 21,
  43. 10, 3, 24]
  44. f8950e = [57, 49, 41, 33, 25, 17, 9, 1, 59, 51, 43, 35, 27, 19, 11, 3, 61, 53, 45, 37, 29, 21, 13, 5, 63, 55,
  45. 47,
  46. 39, 31, 23, 15, 7, 56, 48, 40, 32, 24, 16, 8, 0, 58, 50, 42, 34, 26, 18, 10, 2, 60, 52, 44, 36, 28,
  47. 20,
  48. 12, 4, 62, 54, 46, 38, 30, 22, 14, 6]
  49. f8951f = [31, 0, 1, 2, 3, 4, -1, -1, 3, 4, 5, 6, 7, 8, -1, -1, 7, 8, 9, 10, 11, 12, -1, -1, 11, 12, 13, 14, 15,
  50. 16,
  51. -1, -1, 15, 16, 17, 18, 19, 20, -1, -1, 19, 20, 21, 22, 23, 24, -1, -1, 23, 24, 25, 26, 27, 28, -1,
  52. -1,
  53. 27, 28, 29, 30, 31, 30, -1, -1]
  54. f8952g = [[
  55. 14, 4, 3, 15, 2, 13, 5, 3,
  56. 13, 14, 6, 9, 11, 2, 0, 5,
  57. 4, 1, 10, 12, 15, 6, 9, 10,
  58. 1, 8, 12, 7, 8, 11, 7, 0,
  59. 0, 15, 10, 5, 14, 4, 9, 10,
  60. 7, 8, 12, 3, 13, 1, 3, 6,
  61. 15, 12, 6, 11, 2, 9, 5, 0,
  62. 4, 2, 11, 14, 1, 7, 8, 13, ], [
  63. 15, 0, 9, 5, 6, 10, 12, 9,
  64. 8, 7, 2, 12, 3, 13, 5, 2,
  65. 1, 14, 7, 8, 11, 4, 0, 3,
  66. 14, 11, 13, 6, 4, 1, 10, 15,
  67. 3, 13, 12, 11, 15, 3, 6, 0,
  68. 4, 10, 1, 7, 8, 4, 11, 14,
  69. 13, 8, 0, 6, 2, 15, 9, 5,
  70. 7, 1, 10, 12, 14, 2, 5, 9, ], [
  71. 10, 13, 1, 11, 6, 8, 11, 5,
  72. 9, 4, 12, 2, 15, 3, 2, 14,
  73. 0, 6, 13, 1, 3, 15, 4, 10,
  74. 14, 9, 7, 12, 5, 0, 8, 7,
  75. 13, 1, 2, 4, 3, 6, 12, 11,
  76. 0, 13, 5, 14, 6, 8, 15, 2,
  77. 7, 10, 8, 15, 4, 9, 11, 5,
  78. 9, 0, 14, 3, 10, 7, 1, 12, ], [
  79. 7, 10, 1, 15, 0, 12, 11, 5,
  80. 14, 9, 8, 3, 9, 7, 4, 8,
  81. 13, 6, 2, 1, 6, 11, 12, 2,
  82. 3, 0, 5, 14, 10, 13, 15, 4,
  83. 13, 3, 4, 9, 6, 10, 1, 12,
  84. 11, 0, 2, 5, 0, 13, 14, 2,
  85. 8, 15, 7, 4, 15, 1, 10, 7,
  86. 5, 6, 12, 11, 3, 8, 9, 14, ], [
  87. 2, 4, 8, 15, 7, 10, 13, 6,
  88. 4, 1, 3, 12, 11, 7, 14, 0,
  89. 12, 2, 5, 9, 10, 13, 0, 3,
  90. 1, 11, 15, 5, 6, 8, 9, 14,
  91. 14, 11, 5, 6, 4, 1, 3, 10,
  92. 2, 12, 15, 0, 13, 2, 8, 5,
  93. 11, 8, 0, 15, 7, 14, 9, 4,
  94. 12, 7, 10, 9, 1, 13, 6, 3, ], [
  95. 12, 9, 0, 7, 9, 2, 14, 1,
  96. 10, 15, 3, 4, 6, 12, 5, 11,
  97. 1, 14, 13, 0, 2, 8, 7, 13,
  98. 15, 5, 4, 10, 8, 3, 11, 6,
  99. 10, 4, 6, 11, 7, 9, 0, 6,
  100. 4, 2, 13, 1, 9, 15, 3, 8,
  101. 15, 3, 1, 14, 12, 5, 11, 0,
  102. 2, 12, 14, 7, 5, 10, 8, 13, ], [
  103. 4, 1, 3, 10, 15, 12, 5, 0,
  104. 2, 11, 9, 6, 8, 7, 6, 9,
  105. 11, 4, 12, 15, 0, 3, 10, 5,
  106. 14, 13, 7, 8, 13, 14, 1, 2,
  107. 13, 6, 14, 9, 4, 1, 2, 14,
  108. 11, 13, 5, 0, 1, 10, 8, 3,
  109. 0, 11, 3, 5, 9, 4, 15, 2,
  110. 7, 8, 12, 15, 10, 7, 6, 12, ], [
  111. 13, 7, 10, 0, 6, 9, 5, 15,
  112. 8, 4, 3, 10, 11, 14, 12, 5,
  113. 2, 11, 9, 6, 15, 12, 0, 3,
  114. 4, 1, 14, 13, 1, 2, 7, 8,
  115. 1, 2, 12, 15, 10, 4, 0, 3,
  116. 13, 14, 6, 9, 7, 8, 9, 6,
  117. 15, 1, 5, 12, 3, 10, 14, 5,
  118. 8, 7, 11, 0, 4, 13, 2, 11, ],
  119. ]
  120. i = [39, 7, 47, 15, 55, 23, 63, 31, 38, 6, 46, 14, 54, 22, 62, 30, 37, 5, 45, 13, 53, 21, 61, 29, 36, 4, 44, 12,
  121. 52,
  122. 20, 60, 28, 35, 3, 43, 11, 51, 19, 59, 27, 34, 2, 42, 10, 50, 18, 58, 26, 33, 1, 41, 9, 49, 17, 57, 25, 32,
  123. 0,
  124. 40, 8, 48, 16, 56, 24]
  125. p = self.a1(f8950e, 64, j2)
  126. s[0] = int(p & 4294967295)
  127. s[1] = int((p & -4294967296) >> 32)
  128. for i2 in range(16):
  129. r = s[1]
  130. r = self.a1(f8951f, 64, r)
  131. r ^= jArr[i2]
  132. for i3 in range(8):
  133. t[i3] = (255 & (r >> (i3 * 8)))
  134. u = 0
  135. i4 = 7
  136. while 1:
  137. w = i4
  138. if w < 0:
  139. break
  140. u <<= 4
  141. u |= f8952g[w][t[w]]
  142. i4 = w - 1
  143. r = u
  144. r = self.a1(f8953h, 32, r)
  145. q = s[0]
  146. s[0] = s[1]
  147. s[1] = q ^ r
  148. v = s[0]
  149. s[0] = s[1]
  150. s[1] = v
  151. p = ((s[0]) & 4294967295) | (((s[1]) << 32) & -4294967296)
  152. p = self.a1(i, 64, p)
  153. return p
  154. def encrypt(self, msg):
  155. j2 = 0
  156. i4 = 0
  157. i5 = len(msg) // 8
  158. jArr = [0] * 16
  159. jArr2 = [0] * i5
  160. while i4 < 8:
  161. j2 |= (self.key[i4]) << (i4 * 8)
  162. i4 += 1
  163. for i7 in range(i5):
  164. for i8 in range(8):
  165. jArr2[i7] = ((msg[(i7 * 8) + i8]) << (i8 * 8)) | jArr2[i7]
  166. jArr3 = [0] * ((((i5 + 1) * 8) + 1) // 8)
  167. self.a(j2, jArr)
  168. for i9 in range(i5):
  169. jArr3[i9] = self.a2(jArr, jArr2[i9])
  170. i10 = len(msg) % 8
  171. i11 = i5 * 8
  172. i12 = len(msg) - i11
  173. bArr5 = msg[i11:i11 + i12]
  174. j3 = 0
  175. for i13 in range(i10):
  176. j3 |= int((bArr5[i13])) << (i13 * 8)
  177. jArr3[i5] = self.a2(jArr, j3)
  178. bArr3 = [0] * (len(jArr3) * 8)
  179. i14 = 0
  180. i15 = 0
  181. while i14 < len(jArr3):
  182. i16 = i15
  183. for i17 in range(8):
  184. bArr3[i16] = (255 & (jArr3[i14] >> (i17 * 8)))
  185. i16 += 1
  186. i14 += 1
  187. i15 = i16
  188. return b64encode(bytearray(bArr3)).decode()
  189. class KuWo:
  190. def __init__(self, musicurl):
  191. self.url = "http://nmobi.kuwo.cn/mobi.s?f=kuwo&q="
  192. self.rid = musicurl.split("/")[-1]
  193. def start(self):
  194. params = kwDES().encrypt(str("type=convert_url2&br=2000kflac&format=mp3|aac&sig=0&rid=" + self.rid).encode())
  195. res = requests.get(self.url + params).text
  196. print(res)
  197. if __name__ == '__main__':
  198. KuWo().start()