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.

62 lines
2.0 KiB

10 years ago
10 years ago
10 years ago
  1. from __future__ import unicode_literals
  2. from .common import InfoExtractor
  3. from ..utils import int_or_none
  4. class MporaIE(InfoExtractor):
  5. _VALID_URL = r'https?://(?:www\.)?mpora\.(?:com|de)/videos/(?P<id>[^?#/]+)'
  6. IE_NAME = 'MPORA'
  7. _TEST = {
  8. 'url': 'http://mpora.de/videos/AAdo8okx4wiz/embed?locale=de',
  9. 'md5': 'a7a228473eedd3be741397cf452932eb',
  10. 'info_dict': {
  11. 'id': 'AAdo8okx4wiz',
  12. 'ext': 'mp4',
  13. 'title': 'Katy Curd - Winter in the Forest',
  14. 'duration': 416,
  15. 'uploader': 'Peter Newman Media',
  16. },
  17. }
  18. def _real_extract(self, url):
  19. video_id = self._match_id(url)
  20. webpage = self._download_webpage(url, video_id)
  21. data_json = self._search_regex(
  22. [r"new FM\.Player\('[^']+',\s*(\{.*?)\).player;",
  23. r"new\s+FM\.Kaltura\.Player\('[^']+'\s*,\s*({.+?})\);"],
  24. webpage, 'json')
  25. data = self._parse_json(data_json, video_id)
  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. }