malltv.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. clean_html,
  4. dict_get,
  5. float_or_none,
  6. int_or_none,
  7. merge_dicts,
  8. parse_duration,
  9. try_get,
  10. )
  11. class MallTVIE(InfoExtractor):
  12. _VALID_URL = r'https?://(?:(?:www|sk)\.)?mall\.tv/(?:[^/]+/)*(?P<id>[^/?#&]+)'
  13. _TESTS = [{
  14. 'url': 'https://www.mall.tv/18-miliard-pro-neziskovky-opravdu-jsou-sportovci-nebo-clovek-v-tisni-pijavice',
  15. 'md5': 'cd69ce29176f6533b65bff69ed9a5f2a',
  16. 'info_dict': {
  17. 'id': 't0zzt0',
  18. 'display_id': '18-miliard-pro-neziskovky-opravdu-jsou-sportovci-nebo-clovek-v-tisni-pijavice',
  19. 'ext': 'mp4',
  20. 'title': '18 miliard pro neziskovky. Opravdu jsou sportovci nebo Člověk v tísni pijavice?',
  21. 'description': 'md5:db7d5744a4bd4043d9d98324aa72ab35',
  22. 'duration': 216,
  23. 'timestamp': 1538870400,
  24. 'upload_date': '20181007',
  25. 'view_count': int,
  26. 'comment_count': int,
  27. 'thumbnail': 'https://cdn.vpplayer.tech/agmipnzv/encode/vjsnigfq/thumbnails/retina.jpg',
  28. 'average_rating': 9.060869565217391,
  29. 'dislike_count': int,
  30. 'like_count': int,
  31. }
  32. }, {
  33. 'url': 'https://www.mall.tv/kdo-to-plati/18-miliard-pro-neziskovky-opravdu-jsou-sportovci-nebo-clovek-v-tisni-pijavice',
  34. 'only_matching': True,
  35. }, {
  36. 'url': 'https://sk.mall.tv/gejmhaus/reklamacia-nehreje-vyrobnik-tepla-alebo-spekacka',
  37. 'only_matching': True,
  38. }, {
  39. 'url': 'https://www.mall.tv/zivoty-slavnych/nadeje-vychodu-i-zapadu-jak-michail-gorbacov-zmenil-politickou-mapu-sveta-a-ziskal-za-to-nobelovu-cenu-miru',
  40. 'info_dict': {
  41. 'id': 'yx010y',
  42. 'ext': 'mp4',
  43. 'dislike_count': int,
  44. 'description': 'md5:aee02bee5a8d072c6a8207b91d1905a9',
  45. 'thumbnail': 'https://cdn.vpplayer.tech/agmipnzv/encode/vjsnjdeu/thumbnails/retina.jpg',
  46. 'comment_count': int,
  47. 'display_id': 'md5:0ec2afa94d2e2b7091c019cef2a43a9b',
  48. 'like_count': int,
  49. 'duration': 752,
  50. 'timestamp': 1646956800,
  51. 'title': 'md5:fe79385daaf16d74c12c1ec4a26687af',
  52. 'view_count': int,
  53. 'upload_date': '20220311',
  54. 'average_rating': 9.685714285714285,
  55. }
  56. }]
  57. def _real_extract(self, url):
  58. display_id = self._match_id(url)
  59. webpage = self._download_webpage(
  60. url, display_id, headers=self.geo_verification_headers())
  61. video = self._parse_json(self._search_regex(
  62. r'videoObject\s*=\s*JSON\.parse\(JSON\.stringify\(({.+?})\)\);',
  63. webpage, 'video object'), display_id)
  64. video_id = self._search_regex(
  65. r'<input\s*id\s*=\s*player-id-name\s*[^>]+value\s*=\s*(\w+)', webpage, 'video id')
  66. formats = self._extract_m3u8_formats(
  67. video['VideoSource'], video_id, 'mp4', 'm3u8_native')
  68. subtitles = {}
  69. for s in (video.get('Subtitles') or {}):
  70. s_url = s.get('Url')
  71. if not s_url:
  72. continue
  73. subtitles.setdefault(s.get('Language') or 'cz', []).append({
  74. 'url': s_url,
  75. })
  76. entity_counts = video.get('EntityCounts') or {}
  77. def get_count(k):
  78. v = entity_counts.get(k + 's') or {}
  79. return int_or_none(dict_get(v, ('Count', 'StrCount')))
  80. info = self._search_json_ld(webpage, video_id, default={})
  81. return merge_dicts({
  82. 'id': str(video_id),
  83. 'display_id': display_id,
  84. 'title': video.get('Title'),
  85. 'description': clean_html(video.get('Description')),
  86. 'thumbnail': video.get('ThumbnailUrl'),
  87. 'formats': formats,
  88. 'subtitles': subtitles,
  89. 'duration': int_or_none(video.get('DurationSeconds')) or parse_duration(video.get('Duration')),
  90. 'view_count': get_count('View'),
  91. 'like_count': get_count('Like'),
  92. 'dislike_count': get_count('Dislike'),
  93. 'average_rating': float_or_none(try_get(video, lambda x: x['EntityRating']['AvarageRate'])),
  94. 'comment_count': get_count('Comment'),
  95. }, info)