vimple.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re, zlib, base64
  4. import xml.etree.ElementTree
  5. from .common import InfoExtractor
  6. class VimpleIE(InfoExtractor):
  7. IE_DESC = 'Vimple.ru'
  8. _VALID_URL = r'https?://player.vimple.ru/iframe/(?P<id>[a-f0-9]+)'
  9. _TESTS = [
  10. {
  11. # Quality: Large, from iframe
  12. 'url': 'http://player.vimple.ru/iframe/b132bdfd71b546d3972f9ab9a25f201c',
  13. 'info_dict': {
  14. 'id': 'b132bdfd71b546d3972f9ab9a25f201c',
  15. 'title': 'great-escape-minecraft.flv',
  16. 'ext':'mp4',
  17. 'duration': 352,
  18. 'webpage_url': 'http://vimple.ru/b132bdfd71b546d3972f9ab9a25f201c',
  19. },
  20. }
  21. ]
  22. #http://jsunpack-n.googlecode.com/svn-history/r63/trunk/swf.py
  23. def _real_extract(self, url):
  24. mobj = re.match(self._VALID_URL, url)
  25. video_id = mobj.group('id')
  26. iframe_url = 'http://player.vimple.ru/iframe/%s' % video_id
  27. iframe = self._download_webpage(iframe_url, video_id, note='Downloading iframe', errnote='unable to fetch iframe')
  28. player_url = self._html_search_regex(r'"(http://player.vimple.ru/flash/.+?)"', iframe, 'player url')
  29. player = self._request_webpage(player_url, video_id, note='Downloading swf player').read()
  30. #http://stackoverflow.com/a/6804758
  31. #http://stackoverflow.com/a/12073686
  32. player = zlib.decompress(player[8:])
  33. xml_pieces = re.findall(b'([a-zA-Z0-9 =+/]{500})', player)
  34. xml_pieces = [piece[1:-1] for piece in xml_pieces]
  35. xml_data = b''.join(xml_pieces)
  36. xml_data = base64.b64decode(xml_data)
  37. xml_data = xml.etree.ElementTree.fromstring(xml_data)
  38. video = xml_data.find('Video')
  39. quality = video.get('quality')
  40. q_tag = video.find(quality.capitalize())
  41. formats = [
  42. {
  43. 'url': q_tag.get('url'),
  44. 'tbr': int(q_tag.get('bitrate')),
  45. 'filesize': int(q_tag.get('filesize')),
  46. 'format_id': quality,
  47. },
  48. ]
  49. return {
  50. 'id': video_id,
  51. 'title': video.find('Title').text,
  52. 'formats': formats,
  53. 'thumbnail': video.find('Poster').get('url'),
  54. 'duration': int(video.get('duration')),
  55. 'webpage_url': video.find('Share').get('videoPageUrl'),
  56. }