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.

64 lines
2.0 KiB

11 years ago
11 years ago
  1. from __future__ import unicode_literals
  2. import json
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import int_or_none
  6. class MporaIE(InfoExtractor):
  7. _VALID_URL = r'^https?://(www\.)?mpora\.(?:com|de)/videos/(?P<id>[^?#/]+)'
  8. IE_NAME = 'MPORA'
  9. _TEST = {
  10. 'url': 'http://mpora.de/videos/AAdo8okx4wiz/embed?locale=de',
  11. 'file': 'AAdo8okx4wiz.mp4',
  12. 'md5': 'a7a228473eedd3be741397cf452932eb',
  13. 'info_dict': {
  14. 'title': 'Katy Curd - Winter in the Forest',
  15. 'duration': 416,
  16. 'uploader': 'Peter Newman Media',
  17. },
  18. }
  19. def _real_extract(self, url):
  20. m = re.match(self._VALID_URL, url)
  21. video_id = m.group('id')
  22. webpage = self._download_webpage(url, video_id)
  23. data_json = self._search_regex(
  24. r"new FM\.Player\('[^']+',\s*(\{.*?)\).player;", webpage, 'json')
  25. data = json.loads(data_json)
  26. uploader = data['info_overlay'].get('username')
  27. duration = data['video']['duration'] // 1000
  28. thumbnail = data['video']['encodings']['sd']['poster']
  29. title = data['info_overlay']['title']
  30. formats = []
  31. for encoding_id, edata in data['video']['encodings'].items():
  32. for src in edata['sources']:
  33. width_str = self._search_regex(
  34. r'_([0-9]+)\.[a-zA-Z0-9]+$', src['src'],
  35. False, default=None)
  36. vcodec = src['type'].partition('/')[2]
  37. formats.append({
  38. 'format_id': encoding_id + '-' + vcodec,
  39. 'url': src['src'],
  40. 'vcodec': vcodec,
  41. 'width': int_or_none(width_str),
  42. })
  43. self._sort_formats(formats)
  44. return {
  45. 'id': video_id,
  46. 'title': title,
  47. 'formats': formats,
  48. 'uploader': uploader,
  49. 'duration': duration,
  50. 'thumbnail': thumbnail,
  51. }