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.

66 lines
1.9 KiB

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