mangomolo.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import base64
  2. import urllib.parse
  3. from .common import InfoExtractor
  4. from ..utils import classproperty, int_or_none
  5. class MangomoloBaseIE(InfoExtractor):
  6. _BASE_REGEX = r'(?:https?:)?//(?:admin\.mangomolo\.com/analytics/index\.php/customers/embed/|player\.mangomolo\.com/v1/)'
  7. _SLUG = None
  8. @classproperty
  9. def _VALID_URL(cls):
  10. return f'{cls._BASE_REGEX}{cls._SLUG}'
  11. @classproperty
  12. def _EMBED_REGEX(cls):
  13. return [rf'<iframe[^>]+src=(["\'])(?P<url>{cls._VALID_URL}.+?)\1']
  14. def _extract_from_webpage(self, url, webpage):
  15. for res in super()._extract_from_webpage(url, webpage):
  16. yield {
  17. **res,
  18. '_type': 'url_transparent',
  19. 'id': self._search_regex(self._SLUG, res['url'], 'id', group='id'),
  20. 'uploader': self._search_regex(r'^(?:https?://)?([^/]*)/.*', url, 'video uploader'),
  21. }
  22. def _get_real_id(self, page_id):
  23. return page_id
  24. def _real_extract(self, url):
  25. page_id = self._get_real_id(self._match_id(url))
  26. webpage = self._download_webpage(
  27. 'https://player.mangomolo.com/v1/{}?{}'.format(self._TYPE, url.split('?')[1]), page_id)
  28. hidden_inputs = self._hidden_inputs(webpage)
  29. m3u8_entry_protocol = 'm3u8' if self._IS_LIVE else 'm3u8_native'
  30. format_url = self._html_search_regex(
  31. [
  32. r'(?:file|src)\s*:\s*"(https?://[^"]+?/playlist\.m3u8)',
  33. r'<a[^>]+href="(rtsp://[^"]+)"',
  34. ], webpage, 'format url')
  35. formats = self._extract_wowza_formats(
  36. format_url, page_id, m3u8_entry_protocol, ['smil'])
  37. return {
  38. 'id': page_id,
  39. 'title': page_id,
  40. 'uploader_id': hidden_inputs.get('userid'),
  41. 'duration': int_or_none(hidden_inputs.get('duration')),
  42. 'is_live': self._IS_LIVE,
  43. 'formats': formats,
  44. }
  45. class MangomoloVideoIE(MangomoloBaseIE):
  46. _TYPE = 'video'
  47. IE_NAME = 'mangomolo:' + _TYPE
  48. _SLUG = r'video\?.*?\bid=(?P<id>\d+)'
  49. _IS_LIVE = False
  50. class MangomoloLiveIE(MangomoloBaseIE):
  51. _TYPE = 'live'
  52. IE_NAME = 'mangomolo:' + _TYPE
  53. _SLUG = r'(?:live|index)\?.*?\bchannelid=(?P<id>(?:[A-Za-z0-9+/=]|%2B|%2F|%3D)+)'
  54. _IS_LIVE = True
  55. def _get_real_id(self, page_id):
  56. return base64.b64decode(urllib.parse.unquote(page_id)).decode()