You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

133 lines
4.8 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. clean_html,
  6. extract_attributes,
  7. float_or_none,
  8. int_or_none,
  9. try_get,
  10. )
  11. class EllenTubeBaseIE(InfoExtractor):
  12. def _extract_data_config(self, webpage, video_id):
  13. details = self._search_regex(
  14. r'(<[^>]+\bdata-component=(["\'])[Dd]etails.+?></div>)', webpage,
  15. 'details')
  16. return self._parse_json(
  17. extract_attributes(details)['data-config'], video_id)
  18. def _extract_video(self, data, video_id):
  19. title = data['title']
  20. formats = []
  21. duration = None
  22. for entry in data.get('media'):
  23. if entry.get('id') == 'm3u8':
  24. formats = self._extract_m3u8_formats(
  25. entry['url'], video_id, 'mp4',
  26. entry_protocol='m3u8_native', m3u8_id='hls')
  27. duration = int_or_none(entry.get('duration'))
  28. break
  29. self._sort_formats(formats)
  30. def get_insight(kind):
  31. return int_or_none(try_get(
  32. data, lambda x: x['insight']['%ss' % kind]))
  33. return {
  34. 'extractor_key': EllenTubeIE.ie_key(),
  35. 'id': video_id,
  36. 'title': title,
  37. 'description': data.get('description'),
  38. 'duration': duration,
  39. 'thumbnail': data.get('thumbnail'),
  40. 'timestamp': float_or_none(data.get('publishTime'), scale=1000),
  41. 'view_count': get_insight('view'),
  42. 'like_count': get_insight('like'),
  43. 'formats': formats,
  44. }
  45. class EllenTubeIE(EllenTubeBaseIE):
  46. _VALID_URL = r'''(?x)
  47. (?:
  48. ellentube:|
  49. https://api-prod\.ellentube\.com/ellenapi/api/item/
  50. )
  51. (?P<id>[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12})
  52. '''
  53. _TESTS = [{
  54. 'url': 'https://api-prod.ellentube.com/ellenapi/api/item/0822171c-3829-43bf-b99f-d77358ae75e3',
  55. 'md5': '2fabc277131bddafdd120e0fc0f974c9',
  56. 'info_dict': {
  57. 'id': '0822171c-3829-43bf-b99f-d77358ae75e3',
  58. 'ext': 'mp4',
  59. 'title': 'Ellen Meets Las Vegas Survivors Jesus Campos and Stephen Schuck',
  60. 'description': 'md5:76e3355e2242a78ad9e3858e5616923f',
  61. 'thumbnail': r're:^https?://.+?',
  62. 'duration': 514,
  63. 'timestamp': 1508505120,
  64. 'upload_date': '20171020',
  65. 'view_count': int,
  66. 'like_count': int,
  67. }
  68. }, {
  69. 'url': 'ellentube:734a3353-f697-4e79-9ca9-bfc3002dc1e0',
  70. 'only_matching': True,
  71. }]
  72. def _real_extract(self, url):
  73. video_id = self._match_id(url)
  74. data = self._download_json(
  75. 'https://api-prod.ellentube.com/ellenapi/api/item/%s' % video_id,
  76. video_id)
  77. return self._extract_video(data, video_id)
  78. class EllenTubeVideoIE(EllenTubeBaseIE):
  79. _VALID_URL = r'https?://(?:www\.)?ellentube\.com/video/(?P<id>.+?)\.html'
  80. _TEST = {
  81. 'url': 'https://www.ellentube.com/video/ellen-meets-las-vegas-survivors-jesus-campos-and-stephen-schuck.html',
  82. 'only_matching': True,
  83. }
  84. def _real_extract(self, url):
  85. display_id = self._match_id(url)
  86. webpage = self._download_webpage(url, display_id)
  87. video_id = self._extract_data_config(webpage, display_id)['id']
  88. return self.url_result(
  89. 'ellentube:%s' % video_id, ie=EllenTubeIE.ie_key(),
  90. video_id=video_id)
  91. class EllenTubePlaylistIE(EllenTubeBaseIE):
  92. _VALID_URL = r'https?://(?:www\.)?ellentube\.com/(?:episode|studios)/(?P<id>.+?)\.html'
  93. _TESTS = [{
  94. 'url': 'https://www.ellentube.com/episode/dax-shepard-jordan-fisher-haim.html',
  95. 'info_dict': {
  96. 'id': 'dax-shepard-jordan-fisher-haim',
  97. 'title': "Dax Shepard, 'DWTS' Team Jordan Fisher & Lindsay Arnold, HAIM",
  98. 'description': 'md5:bfc982194dabb3f4e325e43aa6b2e21c',
  99. },
  100. 'playlist_count': 6,
  101. }, {
  102. 'url': 'https://www.ellentube.com/studios/macey-goes-rving0.html',
  103. 'only_matching': True,
  104. }]
  105. def _real_extract(self, url):
  106. display_id = self._match_id(url)
  107. webpage = self._download_webpage(url, display_id)
  108. data = self._extract_data_config(webpage, display_id)['data']
  109. feed = self._download_json(
  110. 'https://api-prod.ellentube.com/ellenapi/api/feed/?%s'
  111. % data['filter'], display_id)
  112. entries = [
  113. self._extract_video(elem, elem['id'])
  114. for elem in feed if elem.get('type') == 'VIDEO' and elem.get('id')]
  115. return self.playlist_result(
  116. entries, display_id, data.get('title'),
  117. clean_html(data.get('description')))