Enigma2 plugin to to play various online streams (mostly Latvian).

videozerresolver.py 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. # * Copyright (C) 2011 Libor Zoubek
  2. # *
  3. # *
  4. # * This Program is free software; you can redistribute it and/or modify
  5. # * it under the terms of the GNU General Public License as published by
  6. # * the Free Software Foundation; either version 2, or (at your option)
  7. # * any later version.
  8. # *
  9. # * This Program is distributed in the hope that it will be useful,
  10. # * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # * GNU General Public License for more details.
  13. # *
  14. # * You should have received a copy of the GNU General Public License
  15. # * along with this program; see the file COPYING. If not, write to
  16. # * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  17. # * http://www.gnu.org/copyleft/gpl.html
  18. # *
  19. # */
  20. # thanks to Lynx187 and his fix in https://github.com/t0mm0/xbmc-urlresolver
  21. import re,util,base64
  22. from base64 import b64decode
  23. from binascii import unhexlify
  24. __name__ = 'videozer'
  25. def supports(url):
  26. return not _regex(url) == None
  27. def _regex(url):
  28. return re.search('videozer.com/embed/(?P<id>[_\-\w\d]+)',url,re.IGNORECASE | re.DOTALL)
  29. def resolve(url):
  30. m = _regex(url)
  31. if not m == None:
  32. stream = None
  33. data = util.request('http://www.videozer.com/player_control/settings.php?v=%s&em=TRUE&fv=v1.1.12' % m.group('id'))
  34. json = data.replace('false','False').replace('true','True').replace('null','None')
  35. aData = eval('('+json+')')
  36. max_res = 99999
  37. r = re.finditer('"l".*?:.*?"(.+?)".+?"u".*?:.*?"(.+?)"', json)
  38. chosen_res = 0
  39. stream_url_part1 = False
  40. if r:
  41. for match in r:
  42. res, url = match.groups()
  43. if (res == 'LQ' ): res = 240
  44. elif (res == 'SD') : res = 480
  45. else:
  46. res = 720
  47. if res > chosen_res and res <= max_res:
  48. stream_url_part1 = url.decode('base-64')
  49. chosen_res = res
  50. else:
  51. return
  52. if not stream_url_part1:
  53. return
  54. # Decode the link from the json data settings.
  55. spn_ik = unhexlify(__decrypt(aData["cfg"]["login"]["spen"], aData["cfg"]["login"]["salt"], 950569)).split(';')
  56. spn = spn_ik[0].split('&')
  57. ik = spn_ik[1]
  58. for item in ik.split('&') :
  59. temp = item.split('=')
  60. if temp[0] == 'ik' :
  61. key = __get_key(temp[1])
  62. sLink = ""
  63. for item in spn :
  64. item = item.split('=')
  65. if(int(item[1])==1):
  66. sLink = sLink + item[0]+ '=' + __decrypt(aData["cfg"]["info"]["sece2"], aData["cfg"]["environment"]["rkts"], key) + '&' #decrypt32byte
  67. elif(int(item[1]==2)):
  68. sLink = sLink + item[0]+ '=' + __decrypt(aData["cfg"]["ads"]["g_ads"]["url"],aData["cfg"]["environment"]["rkts"], key) + '&'
  69. elif(int(item[1])==3):
  70. sLink = sLink + item[0]+ '=' + __decrypt(aData["cfg"]["ads"]["g_ads"]["type"],aData["cfg"]["environment"]["rkts"], key,26,25431,56989,93,32589,784152) + '&'
  71. elif(int(item[1])==4):
  72. sLink = sLink + item[0]+ '=' + __decrypt(aData["cfg"]["ads"]["g_ads"]["time"],aData["cfg"]["environment"]["rkts"], key,82,84669,48779,32,65598,115498) + '&'
  73. elif(int(item[1])==5):
  74. sLink = sLink + item[0]+ '=' + __decrypt(aData["cfg"]["login"]["euno"],aData["cfg"]["login"]["pepper"], key,10,12254,95369,39,21544,545555) + '&'
  75. elif(int(item[1])==6):
  76. sLink = sLink + item[0]+ '=' + __decrypt(aData["cfg"]["login"]["sugar"],aData["cfg"]["ads"]["lightbox2"]["time"], key,22,66595,17447,52,66852,400595) + '&'
  77. sLink = sLink + "start=0"
  78. sMediaLink = stream_url_part1 + '&' + sLink
  79. return [{'url':sMediaLink}]
  80. def __decrypt(str, k1, k2, p4 = 11, p5 = 77213, p6 = 81371, p7 = 17, p8 = 92717, p9 = 192811):
  81. tobin = hex2bin(str,len(str)*4)
  82. tobin_lenght = len(tobin)
  83. keys = []
  84. index = 0
  85. while (index < tobin_lenght*3):
  86. k1 = ((int(k1) * p4) + p5) % p6
  87. k2 = ((int(k2) * p7) + p8) % p9
  88. keys.append((int(k1) + int(k2)) % tobin_lenght)
  89. index += 1
  90. index = tobin_lenght*2
  91. while (index >= 0):
  92. val1 = keys[index]
  93. mod = index%tobin_lenght
  94. val2 = tobin[val1]
  95. tobin[val1] = tobin[mod]
  96. tobin[mod] = val2
  97. index -= 1
  98. index = 0
  99. while(index < tobin_lenght):
  100. tobin[index] = int(tobin[index]) ^ int(keys[index+(tobin_lenght*2)]) & 1
  101. index += 1
  102. decrypted = bin2hex(tobin)
  103. return decrypted
  104. def hex2bin(val,fill):
  105. bin_array = []
  106. string = bin(int(val, 16))[2:].zfill(fill)
  107. for value in string:
  108. bin_array.append(value)
  109. return bin_array
  110. def bin2hex(val):
  111. string = str("")
  112. for char in val:
  113. string+=str(char)
  114. return "%x" % int(string, 2)
  115. def bin( x):
  116. '''
  117. bin(number) -> string
  118. Stringifies an int or long in base 2.
  119. '''
  120. if x < 0:
  121. return '-' + bin(-x)
  122. out = []
  123. if x == 0: out.append('0')
  124. while x > 0:
  125. out.append('01'[x & 1])
  126. x >>= 1
  127. pass
  128. try:
  129. return '0b' + ''.join(reversed(out))
  130. except NameError, ne2:
  131. out.reverse()
  132. return '0b' + ''.join(out)
  133. def __get_key(nbr):
  134. if nbr == '1': return 215678
  135. elif nbr == '2': return 516929
  136. elif nbr == '3': return 962043
  137. elif nbr == '4': return 461752
  138. elif nbr == '5': return 141994
  139. else: return False