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

ksetresolver.py 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # -*- coding: UTF-8 -*-
  2. #/*
  3. # * Copyright (C) 2013 mx3L
  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, util, decimal, random, base64, urllib
  23. __name__ = 'kset'
  24. def supports(url):
  25. return not _regex(url) == None
  26. def gen_random_decimal(i, d):
  27. return decimal.Decimal('%d.%d' % (random.randint(0, i), random.randint(0, d)))
  28. # returns the steam url
  29. def resolve(url):
  30. m = _regex(url)
  31. if m:
  32. id = int(m.group('id'))
  33. headers = {
  34. "Referer":"http://st.kset.kz/pl/pl.swf"
  35. }
  36. params = {
  37. 'id':id,
  38. 'ref':'http://kset.kz/video_frame.php?id=%d' % id,
  39. 'r':gen_random_decimal(0, 99999999999999)
  40. }
  41. quality = "480p"
  42. data = util.request("http://kset.kz/v.php?" + urllib.urlencode(params), headers=headers)
  43. item = util.json.loads(base64.decodestring(data))
  44. return [{'quality':quality, 'url':item[u'file']}]
  45. def _regex(url):
  46. m = re.search('http://kset\.kz/video_frame\.php\?id=(?P<id>[0-9]+)', url, re.IGNORECASE | re.DOTALL)
  47. return m