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.

75 lines
2.3 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import base64
  4. import re
  5. import xml.etree.ElementTree
  6. import zlib
  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. {
  14. 'url': 'http://vimple.ru/c0f6b1687dcd4000a97ebe70068039cf',
  15. 'md5': '2e750a330ed211d3fd41821c6ad9a279',
  16. 'info_dict': {
  17. 'id': 'c0f6b1687dcd4000a97ebe70068039cf',
  18. 'ext': 'mp4',
  19. 'title': 'Sunset',
  20. 'duration': 20,
  21. 'thumbnail': 're:https?://.*?\.jpg',
  22. },
  23. },
  24. ]
  25. def _real_extract(self, url):
  26. mobj = re.match(self._VALID_URL, url)
  27. video_id = mobj.group('id')
  28. iframe_url = 'http://player.vimple.ru/iframe/%s' % video_id
  29. iframe = self._download_webpage(
  30. iframe_url, video_id,
  31. note='Downloading iframe', errnote='unable to fetch iframe')
  32. player_url = self._html_search_regex(
  33. r'"(http://player.vimple.ru/flash/.+?)"', iframe, 'player url')
  34. player = self._request_webpage(
  35. player_url, video_id, note='Downloading swf player').read()
  36. player = zlib.decompress(player[8:])
  37. xml_pieces = re.findall(b'([a-zA-Z0-9 =+/]{500})', player)
  38. xml_pieces = [piece[1:-1] for piece in xml_pieces]
  39. xml_data = b''.join(xml_pieces)
  40. xml_data = base64.b64decode(xml_data)
  41. xml_data = xml.etree.ElementTree.fromstring(xml_data)
  42. video = xml_data.find('Video')
  43. quality = video.get('quality')
  44. q_tag = video.find(quality.capitalize())
  45. formats = [
  46. {
  47. 'url': q_tag.get('url'),
  48. 'tbr': int(q_tag.get('bitrate')),
  49. 'filesize': int(q_tag.get('filesize')),
  50. 'format_id': quality,
  51. },
  52. ]
  53. return {
  54. 'id': video_id,
  55. 'title': video.find('Title').text,
  56. 'formats': formats,
  57. 'thumbnail': video.find('Poster').get('url'),
  58. 'duration': int_or_none(video.get('duration')),
  59. 'webpage_url': video.find('Share').get('videoPageUrl'),
  60. }