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.7 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. # 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. 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(
  41. iframe_url, video_id,
  42. note='Downloading iframe', errnote='unable to fetch iframe')
  43. player_url = self._html_search_regex(
  44. r'"(http://player.vimple.ru/flash/.+?)"', iframe, 'player url')
  45. player = self._request_webpage(
  46. player_url, video_id, note='Downloading swf player').read()
  47. player = zlib.decompress(player[8:])
  48. xml_pieces = re.findall(b'([a-zA-Z0-9 =+/]{500})', player)
  49. xml_pieces = [piece[1:-1] for piece in xml_pieces]
  50. xml_data = b''.join(xml_pieces)
  51. xml_data = base64.b64decode(xml_data)
  52. xml_data = xml.etree.ElementTree.fromstring(xml_data)
  53. video = xml_data.find('Video')
  54. quality = video.get('quality')
  55. q_tag = video.find(quality.capitalize())
  56. formats = [
  57. {
  58. 'url': q_tag.get('url'),
  59. 'tbr': int(q_tag.get('bitrate')),
  60. 'filesize': int(q_tag.get('filesize')),
  61. 'format_id': quality,
  62. },
  63. ]
  64. return {
  65. 'id': video_id,
  66. 'title': video.find('Title').text,
  67. 'formats': formats,
  68. 'thumbnail': video.find('Poster').get('url'),
  69. 'duration': int_or_none(video.get('duration')),
  70. 'webpage_url': video.find('Share').get('videoPageUrl'),
  71. }