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

vkontakteresolver.py 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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
  23. __name__ = 'vkontakte'
  24. def supports(url):
  25. return not _regex(url) == None
  26. def resolve(link):
  27. if not _regex(link) == None:
  28. data = util.request(link)
  29. data = util.substr(data,'div id=\"playerWrap\"','<embed>')
  30. if len(data) > 0:
  31. host = re.search('host=([^\&]+)',data,re.IGNORECASE | re.DOTALL).group(1)
  32. oid = re.search('oid=([^\&]+)',data,re.IGNORECASE | re.DOTALL).group(1)
  33. uid = re.search('uid=([^\&]+)',data,re.IGNORECASE | re.DOTALL).group(1)
  34. vtag = re.search('vtag=([^\&]+)',data,re.IGNORECASE | re.DOTALL).group(1)
  35. hd = re.search('hd_def=([^\&]+)',data,re.IGNORECASE | re.DOTALL).group(1)
  36. max_hd = re.search('hd=([^\&]+)',data,re.IGNORECASE | re.DOTALL).group(1)
  37. no_flv = re.search('no_flv=([^\&]+)',data,re.IGNORECASE | re.DOTALL).group(1)
  38. url = '%su%s/videos/%s' % (host,uid,vtag)
  39. if no_flv != '1':
  40. return [{'name':__name__,'quality':'???','url':url+'.flv','surl':link,'subs':''}]
  41. if no_flv == '1':
  42. res=int(hd)
  43. if max_hd:
  44. res=int(max_hd)
  45. if res < 0:
  46. return [{'name':__name__,'quality':'240p','url':url+'.flv','surl':link,'subs':''}]
  47. resolutions=['240','360','480','720','1080']
  48. ret = []
  49. for index,resolution in enumerate(resolutions):
  50. if index>res:
  51. return ret
  52. ret.append({'name':__name__,'quality':resolution+'p','url':url+'.'+resolution+'.mp4','surl':link,'subs':''})
  53. return ret
  54. def _regex(data):
  55. return re.search('http\://(vkontakte.ru|vk.com)/(.+?)', data, re.IGNORECASE | re.DOTALL)