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.

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