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

vimeoresolver.py 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # -*- coding: UTF-8 -*-
  2. #/*
  3. # * Copyright (C) 2014 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
  23. import urllib
  24. import urllib2
  25. import random
  26. import decimal
  27. import util
  28. __name__='vimeo'
  29. def supports(url):
  30. return not _regex(url) == None
  31. def resolve(url):
  32. m = _regex(url)
  33. if m:
  34. ret = []
  35. data = util.request("http://player.vimeo.com/v2/video/%s/config?type=moogaloop&referrer=&player_url=player.vimeo.com&v=1.0.0&cdn_url=http://a.vimeocdn.com"%m.group('id'))
  36. data = util.json.loads(data)
  37. h264 = data["request"]["files"]["h264"]
  38. for quality in h264.iterkeys():
  39. item = {}
  40. item['title'] = data['video']['title']
  41. item['length'] = data['video']['duration']
  42. item['quality'] = quality == 'hd' and '720p' or '480p'
  43. item['url'] = h264[quality]['url']
  44. ret.append(item)
  45. return ret
  46. def _regex(url):
  47. return re.search('player.vimeo.com/video/(?P<id>\d+)',url,re.IGNORECASE | re.DOTALL)