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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # -*- coding: UTF-8 -*-
  2. # /*
  3. # * Copyright (C) 2015 Lubomir Kucera
  4. # *
  5. # *
  6. # * This Program is free software; you can redistribute it and/or modify
  7. # * it under the terms of the GNU General Public License as published by
  8. # * the Free Software Foundation; either version 2, or (at your option)
  9. # * any later version.
  10. # *
  11. # * This Program is distributed in the hope that it will be useful,
  12. # * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # * GNU General Public License for more details.
  15. # *
  16. # * You should have received a copy of the GNU General Public License
  17. # * along with this program; see the file COPYING. If not, write to
  18. # * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  19. # * http://www.gnu.org/copyleft/gpl.html
  20. # *
  21. # */
  22. import re
  23. import util
  24. import urllib2
  25. from aadecode import AADecoder
  26. __author__ = 'Jose Riha/Lubomir Kucera'
  27. __name__ = 'openload'
  28. def supports(url):
  29. return re.search(r'openload\.\w+/embed/.+', url) is not None
  30. # uses code fragments from https://github.com/LordVenom/venom-xbmc-addons
  31. def resolve(url):
  32. input = util.request(url)
  33. c = re.search('>welikekodi_ya_rly = ([0-9- ]+);<', input).group(1)
  34. cc = str(eval(c))
  35. vid = '[' + cc + ']'
  36. def base10toN(num, n):
  37. """Change a to a base-n number.
  38. Up to base-36 is supported without special notation."""
  39. new_num_string = ''
  40. current = num
  41. while current != 0:
  42. remainder = current % n
  43. if 36 > remainder > 9:
  44. remainder_string = chr(remainder + 87)
  45. elif remainder >= 36:
  46. remainder_string = '(' + str(remainder) + ')'
  47. else:
  48. remainder_string = str(remainder)
  49. new_num_string = remainder_string + new_num_string
  50. current = current / n
  51. return new_num_string
  52. sPattern = '<script type="text\/javascript">(.........+?)<\/script>'
  53. aResult = re.findall(sPattern, input, flags=re.M )
  54. string2=[]
  55. for aEntry in aResult:
  56. s = AADecoder(aEntry).decode()
  57. string2.append(s)
  58. for string3 in string2:
  59. if isinstance (string3,bool):
  60. continue
  61. if ('toString' in string3) and (vid in string3):
  62. base = int(re.findall('toString\(a\+([0-9]+)\)',string3)[0])
  63. table = re.findall('(\([0-9][^)]+\))',string3)
  64. for str1 in table:
  65. val = re.findall('([0-9]+),([0-9]+)',str1)
  66. base2 = base + int(val[0][0])
  67. str2 = base10toN(int(val[0][1]), base2)
  68. string3 = string3.replace(str1, str2)
  69. #clean up
  70. string3 = string3.replace('+', '')
  71. string3 = string3.replace('"', '')
  72. string3 = string3.replace('', '')
  73. #a hack for not having to recode everything
  74. url = re.findall('(http[^<>}]+)',string3)[0]
  75. string = 'src="' + url + '?mime=true"'
  76. string=string.replace('src="','').replace('"','')
  77. return [{'url': string}]