mangomolo.py 2.4 KB

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