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

mixturevideoresolver.py 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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,resolver
  23. __name__ = 'mixturecloud'
  24. def supports(url):
  25. return not _regex(url) == None
  26. class MyHTTPRedirectHandler(urllib2.HTTPRedirectHandler):
  27. def http_error_302(self, req, fp, code, msg, headers):
  28. self.location = headers.getheader('Location')
  29. return urllib2.HTTPRedirectHandler.http_error_302(self, req, fp, code, msg, headers)
  30. # returns the steam url
  31. def resolve(url):
  32. m = _regex(url)
  33. if m:
  34. defrhandler = urllib2.HTTPRedirectHandler
  35. cookieprocessor = urllib2.HTTPCookieProcessor()
  36. redirecthandler = MyHTTPRedirectHandler()
  37. opener = urllib2.build_opener(redirecthandler, cookieprocessor)
  38. urllib2.install_opener(opener)
  39. req = urllib2.Request(url)
  40. response = urllib2.urlopen(req)
  41. response.close()
  42. urllib2.install_opener(urllib2.build_opener(defrhandler,cookieprocessor))
  43. # mixturevideo uses REDIRECT to 'secret url' ;-)
  44. url = redirecthandler.location
  45. item = resolver.item()
  46. item['surl'] = url
  47. item['name'] = __name__
  48. try:
  49. ishd = re.search('hd\.state=([^\&]+)',url).group(1)
  50. streamer = re.search('streamer=([^$]+)',url).group(1)+'&start=0&'
  51. if ishd == 'true':
  52. item['url'] = streamer + 'hd.file=' +re.search('hd\.file=([^\&]+)',url).group(1)
  53. item['quality'] = 'hd'
  54. else:
  55. item['url'] = streamer + 'file=' +re.search('file=([^\&]+)',url).group(1)
  56. return [item]
  57. except:
  58. traceback.print_exc()
  59. pass
  60. def _regex(url):
  61. return re.search('player\.mixturecloud\.com',url,re.IGNORECASE | re.DOTALL)