logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

malltv.py (3298B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. clean_html,
  6. dict_get,
  7. float_or_none,
  8. int_or_none,
  9. merge_dicts,
  10. parse_duration,
  11. try_get,
  12. )
  13. class MallTVIE(InfoExtractor):
  14. _VALID_URL = r'https?://(?:(?:www|sk)\.)?mall\.tv/(?:[^/]+/)*(?P<id>[^/?#&]+)'
  15. _TESTS = [{
  16. 'url': 'https://www.mall.tv/18-miliard-pro-neziskovky-opravdu-jsou-sportovci-nebo-clovek-v-tisni-pijavice',
  17. 'md5': '1c4a37f080e1f3023103a7b43458e518',
  18. 'info_dict': {
  19. 'id': 't0zzt0',
  20. 'display_id': '18-miliard-pro-neziskovky-opravdu-jsou-sportovci-nebo-clovek-v-tisni-pijavice',
  21. 'ext': 'mp4',
  22. 'title': '18 miliard pro neziskovky. Opravdu jsou sportovci nebo Člověk v tísni pijavice?',
  23. 'description': 'md5:db7d5744a4bd4043d9d98324aa72ab35',
  24. 'duration': 216,
  25. 'timestamp': 1538870400,
  26. 'upload_date': '20181007',
  27. 'view_count': int,
  28. }
  29. }, {
  30. 'url': 'https://www.mall.tv/kdo-to-plati/18-miliard-pro-neziskovky-opravdu-jsou-sportovci-nebo-clovek-v-tisni-pijavice',
  31. 'only_matching': True,
  32. }, {
  33. 'url': 'https://sk.mall.tv/gejmhaus/reklamacia-nehreje-vyrobnik-tepla-alebo-spekacka',
  34. 'only_matching': True,
  35. }]
  36. def _real_extract(self, url):
  37. display_id = self._match_id(url)
  38. webpage = self._download_webpage(
  39. url, display_id, headers=self.geo_verification_headers())
  40. video = self._parse_json(self._search_regex(
  41. r'videoObject\s*=\s*JSON\.parse\(JSON\.stringify\(({.+?})\)\);',
  42. webpage, 'video object'), display_id)
  43. video_source = video['VideoSource']
  44. video_id = self._search_regex(
  45. r'/([\da-z]+)/index\b', video_source, 'video id')
  46. formats = self._extract_m3u8_formats(
  47. video_source + '.m3u8', video_id, 'mp4', 'm3u8_native')
  48. self._sort_formats(formats)
  49. subtitles = {}
  50. for s in (video.get('Subtitles') or {}):
  51. s_url = s.get('Url')
  52. if not s_url:
  53. continue
  54. subtitles.setdefault(s.get('Language') or 'cz', []).append({
  55. 'url': s_url,
  56. })
  57. entity_counts = video.get('EntityCounts') or {}
  58. def get_count(k):
  59. v = entity_counts.get(k + 's') or {}
  60. return int_or_none(dict_get(v, ('Count', 'StrCount')))
  61. info = self._search_json_ld(webpage, video_id, default={})
  62. return merge_dicts({
  63. 'id': video_id,
  64. 'display_id': display_id,
  65. 'title': video.get('Title'),
  66. 'description': clean_html(video.get('Description')),
  67. 'thumbnail': video.get('ThumbnailUrl'),
  68. 'formats': formats,
  69. 'subtitles': subtitles,
  70. 'duration': int_or_none(video.get('DurationSeconds')) or parse_duration(video.get('Duration')),
  71. 'view_count': get_count('View'),
  72. 'like_count': get_count('Like'),
  73. 'dislike_count': get_count('Dislike'),
  74. 'average_rating': float_or_none(try_get(video, lambda x: x['EntityRating']['AvarageRate'])),
  75. 'comment_count': get_count('Comment'),
  76. }, info)