maariv.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. int_or_none,
  4. parse_resolution,
  5. unified_timestamp,
  6. url_or_none,
  7. )
  8. from ..utils.traversal import traverse_obj
  9. class MaarivIE(InfoExtractor):
  10. IE_NAME = 'maariv.co.il'
  11. _VALID_URL = r'https?://player\.maariv\.co\.il/public/player\.html\?(?:[^#]+&)?media=(?P<id>\d+)'
  12. _EMBED_REGEX = [rf'<iframe[^>]+\bsrc=[\'"](?P<url>{_VALID_URL})']
  13. _TESTS = [{
  14. 'url': 'https://player.maariv.co.il/public/player.html?player=maariv-desktop&media=3611585',
  15. 'info_dict': {
  16. 'id': '3611585',
  17. 'duration': 75,
  18. 'ext': 'mp4',
  19. 'upload_date': '20231009',
  20. 'title': 'מבצע חרבות ברזל',
  21. 'timestamp': 1696851301,
  22. },
  23. }]
  24. _WEBPAGE_TESTS = [{
  25. 'url': 'https://www.maariv.co.il/news/law/Article-1044008',
  26. 'info_dict': {
  27. 'id': '3611585',
  28. 'duration': 75,
  29. 'ext': 'mp4',
  30. 'upload_date': '20231009',
  31. 'title': 'מבצע חרבות ברזל',
  32. 'timestamp': 1696851301,
  33. },
  34. }]
  35. def _real_extract(self, url):
  36. video_id = self._match_id(url)
  37. data = self._download_json(
  38. f'https://dal.walla.co.il/media/{video_id}?origin=player.maariv.co.il', video_id)['data']
  39. formats = []
  40. if hls_url := traverse_obj(data, ('video', 'url', {url_or_none})):
  41. formats.extend(self._extract_m3u8_formats(hls_url, video_id, m3u8_id='hls', fatal=False))
  42. for http_format in traverse_obj(data, ('video', 'stream_urls', ..., 'stream_url', {url_or_none})):
  43. formats.append({
  44. 'url': http_format,
  45. 'format_id': 'http',
  46. **parse_resolution(http_format),
  47. })
  48. return {
  49. 'id': video_id,
  50. **traverse_obj(data, {
  51. 'title': 'title',
  52. 'duration': ('video', 'duration', {int_or_none}),
  53. 'timestamp': ('upload_date', {unified_timestamp}),
  54. }),
  55. 'formats': formats,
  56. }