Python module (submodule repositary), which provides content (video streams) from various online stream sources to corresponding Enigma2, Kodi, Plex plugins

aadecode.py 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. #-*- coding: utf-8 -*-
  2. #
  3. # author : Djeman
  4. # Updated by Shani-08 (https://github.com/Shani-08/ShaniXBMCWork2)
  5. import re
  6. class AADecoder(object):
  7. def __init__(self, aa_encoded_data):
  8. self.encoded_str = aa_encoded_data.replace('/*´∇`*/','')
  9. self.b = ["(c^_^o)", "(゚Θ゚)", "((o^_^o) - (゚Θ゚))", "(o^_^o)",
  10. "(゚ー゚)", "((゚ー゚) + (゚Θ゚))", "((o^_^o) +(o^_^o))", "((゚ー゚) + (o^_^o))",
  11. "((゚ー゚) + (゚ー゚))", "((゚ー゚) + (゚ー゚) + (゚Θ゚))", "(゚Д゚) .゚ω゚ノ", "(゚Д゚) .゚Θ゚ノ",
  12. "(゚Д゚) ['c']", "(゚Д゚) .゚ー゚ノ", "(゚Д゚) .゚Д゚ノ", "(゚Д゚) [゚Θ゚]"]
  13. def is_aaencoded(self):
  14. idx = self.encoded_str.find("゚ω゚ノ= /`m´)ノ ~┻━┻ //*´∇`*/ ['_']; o=(゚ー゚) =_=3; c=(゚Θ゚) =(゚ー゚)-(゚ー゚); ")
  15. if idx == -1:
  16. return False
  17. if self.encoded_str.find("(゚Д゚)[゚o゚]) (゚Θ゚)) ('_');", idx) == -1:
  18. return False
  19. return True
  20. def base_repr(self, number, base=2, padding=0):
  21. digits = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  22. if base > len(digits):
  23. base = len(digits)
  24. num = abs(number)
  25. res = []
  26. while num:
  27. res.append(digits[num % base])
  28. num //= base
  29. if padding:
  30. res.append('0' * padding)
  31. if number < 0:
  32. res.append('-')
  33. return ''.join(reversed(res or '0'))
  34. def decode_char(self, enc_char, radix):
  35. end_char = "+ "
  36. str_char = ""
  37. while enc_char != '':
  38. found = False
  39. if not found:
  40. for i in range(len(self.b)):
  41. enc_char=enc_char.replace(self.b[i], str(i))
  42. startpos=0
  43. findClose=True
  44. balance=1
  45. result=[]
  46. if enc_char.startswith('('):
  47. l=0
  48. for t in enc_char[1:]:
  49. l+=1
  50. if findClose and t==')':
  51. balance-=1;
  52. if balance==0:
  53. result+=[enc_char[startpos:l+1]]
  54. findClose=False
  55. continue
  56. elif not findClose and t=='(':
  57. startpos=l
  58. findClose=True
  59. balance=1
  60. continue
  61. elif t=='(':
  62. balance+=1
  63. if result is None or len(result)==0:
  64. return ""
  65. else:
  66. for r in result:
  67. value = self.decode_digit(r, radix)
  68. if value == "":
  69. return ""
  70. else:
  71. str_char += value
  72. return str_char
  73. enc_char = enc_char[len(end_char):]
  74. return str_char
  75. def decode_digit(self, enc_int, radix):
  76. rr = '(\(.+?\)\))\+'
  77. rerr=enc_int.split('))+')
  78. v = ''
  79. #new mode
  80. for c in rerr:
  81. if len(c)>0:
  82. if c.strip().endswith('+'):
  83. c=c.strip()[:-1]
  84. startbrackets=len(c)-len(c.replace('(',''))
  85. endbrackets=len(c)-len(c.replace(')',''))
  86. if startbrackets>endbrackets:
  87. c+=')'*startbrackets-endbrackets
  88. c = c.replace('!+[]','1')
  89. c = c.replace('-~','1+')
  90. c = c.replace('[]','0')
  91. v+=str(eval(c))
  92. return v
  93. mode = 0
  94. value = 0
  95. while enc_int != '':
  96. found = False
  97. for i in range(len(self.b)):
  98. if enc_int.find(self.b[i]) == 0:
  99. if mode == 0:
  100. value += i
  101. else:
  102. value -= i
  103. enc_int = enc_int[len(self.b[i]):]
  104. found = True
  105. break
  106. if not found:
  107. return ""
  108. enc_int = re.sub('^\s+|\s+$', '', enc_int)
  109. if enc_int.find("+") == 0:
  110. mode = 0
  111. else:
  112. mode = 1
  113. enc_int = enc_int[1:]
  114. enc_int = re.sub('^\s+|\s+$', '', enc_int)
  115. return self.base_repr(value, radix)
  116. def decode(self):
  117. self.encoded_str = re.sub('^\s+|\s+$', '', self.encoded_str)
  118. # get data
  119. pattern = (r"\(゚Д゚\)\[゚o゚\]\+ (.+?)\(゚Д゚\)\[゚o゚\]\)")
  120. result = re.search(pattern, self.encoded_str, re.DOTALL)
  121. if result is None:
  122. print "AADecoder: data not found"
  123. return False
  124. data = result.group(1)
  125. # hex decode string
  126. begin_char = "(゚Д゚)[゚ε゚]+"
  127. alt_char = "(o゚ー゚o)+ "
  128. out = ''
  129. while data != '':
  130. # Check new char
  131. if data.find(begin_char) != 0:
  132. print "AADecoder: data not found"
  133. return False
  134. data = data[len(begin_char):]
  135. # Find encoded char
  136. enc_char = ""
  137. if data.find(begin_char) == -1:
  138. enc_char = data
  139. data = ""
  140. else:
  141. enc_char = data[:data.find(begin_char)]
  142. data = data[len(enc_char):]
  143. radix = 8
  144. # Detect radix 16 for utf8 char
  145. if enc_char.find(alt_char) == 0:
  146. enc_char = enc_char[len(alt_char):]
  147. radix = 16
  148. str_char = self.decode_char(enc_char, radix)
  149. if str_char == "":
  150. print "no match : "
  151. print data + "\nout = " + out + "\n"
  152. return False
  153. out += chr(int(str_char, radix))
  154. if out == "":
  155. print "no match : " + data
  156. return False
  157. return out