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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. # -*- coding: UTF-8 -*-
  2. # /*
  3. # * Copyright (C) 2011 Libor Zoubek
  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, urllib2, traceback
  23. __name__ = 'koukni.cz'
  24. def supports(url):
  25. return not _regex(url) == None
  26. # returns the steam url
  27. def url(url):
  28. m = _regex(url)
  29. if not m == None:
  30. iframe = _iframe(url)
  31. if iframe:
  32. return iframe[0]['url']
  33. def resolve(url):
  34. m = _regex(url)
  35. if not m == None:
  36. try:
  37. iframe = _iframe(url)
  38. except:
  39. traceback.print_exc()
  40. return
  41. if iframe:
  42. return iframe
  43. # else:
  44. # return [{'name':__name__,'quality':'720p','url':url,'surl':url}]
  45. def _furl(url):
  46. if url.startswith('http'):
  47. return url
  48. url = url.lstrip('./')
  49. return 'http://www.koukni.cz/' + url
  50. def _iframe(url):
  51. index = url.find('&')
  52. if index > 0:
  53. url = url[:index]
  54. iframe = re.search('(\d+)$', url, re.IGNORECASE | re.DOTALL)
  55. if iframe:
  56. data = util.request(url)
  57. ress = re.search('var api = flowplayer\(\),\s+resolutions = \{([^\}]+)\}', data, re.IGNORECASE | re.DOTALL)
  58. valid_ress = re.compile("<span[^>]*>([^<]+)</span>", re.IGNORECASE | re.DOTALL).findall(data)
  59. subs = re.search('<track.+?src=\"(?P<url>[^\"]+)', data, re.IGNORECASE | re.DOTALL)
  60. if ress:
  61. ret = []
  62. ress = ress.group(1).strip().split(',')
  63. for r in ress:
  64. r = r.replace('"', '').split(':')
  65. res = r[0].strip()
  66. vurl = _furl(r[1].strip())
  67. if res in valid_ress:
  68. v = {'name':__name__, 'url':vurl, 'quality':res, 'surl':url,'subs':''}
  69. if subs:
  70. v['subs'] = _furl(subs.group('url'))
  71. ret.append(v)
  72. if len(ret)>0:
  73. return ret
  74. video = re.search('url\: \'(?P<url>mp4[^\']+)', data, re.IGNORECASE | re.DOTALL)
  75. subs = re.search('captionUrl\: \'(?P<url>[^\']+)', data, re.IGNORECASE | re.DOTALL)
  76. if video:
  77. ret = {'name':__name__, 'quality':'720p', 'surl':url}
  78. ret['url'] = 'rtmp://koukni.cz/mp4 playpath=%s' % video.group('url')
  79. if subs:
  80. ret['subs'] = _furl(subs.group('url'))
  81. return [ret]
  82. def _regex(url):
  83. return re.search('(www\.)?koukni.cz/(.+?)', url, re.IGNORECASE | re.DOTALL)