You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
2.8 KiB

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