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.

188 lines
7.2 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. import time
  5. import hashlib
  6. import json
  7. from .adobepass import AdobePassIE
  8. from .common import InfoExtractor
  9. from ..compat import compat_HTTPError
  10. from ..utils import (
  11. int_or_none,
  12. parse_age_limit,
  13. str_or_none,
  14. parse_duration,
  15. ExtractorError,
  16. extract_attributes,
  17. )
  18. class ViceBaseIE(AdobePassIE):
  19. def _extract_preplay_video(self, url, webpage):
  20. watch_hub_data = extract_attributes(self._search_regex(
  21. r'(?s)(<watch-hub\s*.+?</watch-hub>)', webpage, 'watch hub'))
  22. video_id = watch_hub_data['vms-id']
  23. title = watch_hub_data['video-title']
  24. query = {}
  25. is_locked = watch_hub_data.get('video-locked') == '1'
  26. if is_locked:
  27. resource = self._get_mvpd_resource(
  28. 'VICELAND', title, video_id,
  29. watch_hub_data.get('video-rating'))
  30. query['tvetoken'] = self._extract_mvpd_auth(url, video_id, 'VICELAND', resource)
  31. # signature generation algorithm is reverse engineered from signatureGenerator in
  32. # webpack:///../shared/~/vice-player/dist/js/vice-player.js in
  33. # https://www.viceland.com/assets/common/js/web.vendor.bundle.js
  34. exp = int(time.time()) + 14400
  35. query.update({
  36. 'exp': exp,
  37. 'sign': hashlib.sha512(('%s:GET:%d' % (video_id, exp)).encode()).hexdigest(),
  38. })
  39. try:
  40. host = 'www.viceland' if is_locked else self._PREPLAY_HOST
  41. preplay = self._download_json('https://%s.com/en_us/preplay/%s' % (host, video_id), video_id, query=query)
  42. except ExtractorError as e:
  43. if isinstance(e.cause, compat_HTTPError) and e.cause.code == 400:
  44. error = json.loads(e.cause.read().decode())
  45. raise ExtractorError('%s said: %s' % (self.IE_NAME, error['details']), expected=True)
  46. raise
  47. video_data = preplay['video']
  48. base = video_data['base']
  49. uplynk_preplay_url = preplay['preplayURL']
  50. episode = video_data.get('episode', {})
  51. channel = video_data.get('channel', {})
  52. subtitles = {}
  53. cc_url = preplay.get('ccURL')
  54. if cc_url:
  55. subtitles['en'] = [{
  56. 'url': cc_url,
  57. }]
  58. return {
  59. '_type': 'url_transparent',
  60. 'url': uplynk_preplay_url,
  61. 'id': video_id,
  62. 'title': title,
  63. 'description': base.get('body'),
  64. 'thumbnail': watch_hub_data.get('cover-image') or watch_hub_data.get('thumbnail'),
  65. 'duration': parse_duration(video_data.get('video_duration') or watch_hub_data.get('video-duration')),
  66. 'timestamp': int_or_none(video_data.get('created_at')),
  67. 'age_limit': parse_age_limit(video_data.get('video_rating')),
  68. 'series': video_data.get('show_title') or watch_hub_data.get('show-title'),
  69. 'episode_number': int_or_none(episode.get('episode_number') or watch_hub_data.get('episode')),
  70. 'episode_id': str_or_none(episode.get('id') or video_data.get('episode_id')),
  71. 'season_number': int_or_none(watch_hub_data.get('season')),
  72. 'season_id': str_or_none(episode.get('season_id')),
  73. 'uploader': channel.get('base', {}).get('title') or watch_hub_data.get('channel-title'),
  74. 'uploader_id': str_or_none(channel.get('id')),
  75. 'subtitles': subtitles,
  76. 'ie_key': 'UplynkPreplay',
  77. }
  78. class ViceIE(ViceBaseIE):
  79. _VALID_URL = r'https?://(?:.+?\.)?vice\.com/(?:[^/]+/)?videos?/(?P<id>[^/?#&]+)'
  80. _TESTS = [{
  81. 'url': 'http://www.vice.com/video/cowboy-capitalists-part-1',
  82. 'md5': 'e9d77741f9e42ba583e683cd170660f7',
  83. 'info_dict': {
  84. 'id': '43cW1mYzpia9IlestBjVpd23Yu3afAfp',
  85. 'ext': 'flv',
  86. 'title': 'VICE_COWBOYCAPITALISTS_PART01_v1_VICE_WM_1080p.mov',
  87. 'duration': 725.983,
  88. },
  89. 'add_ie': ['Ooyala'],
  90. }, {
  91. 'url': 'http://www.vice.com/video/how-to-hack-a-car',
  92. 'md5': 'a7ecf64ee4fa19b916c16f4b56184ae2',
  93. 'info_dict': {
  94. 'id': '3jstaBeXgAs',
  95. 'ext': 'mp4',
  96. 'title': 'How to Hack a Car: Phreaked Out (Episode 2)',
  97. 'description': 'md5:ee95453f7ff495db8efe14ae8bf56f30',
  98. 'uploader_id': 'MotherboardTV',
  99. 'uploader': 'Motherboard',
  100. 'upload_date': '20140529',
  101. },
  102. 'add_ie': ['Youtube'],
  103. }, {
  104. 'url': 'https://video.vice.com/en_us/video/the-signal-from-tolva/5816510690b70e6c5fd39a56',
  105. 'md5': '',
  106. 'info_dict': {
  107. 'id': '5816510690b70e6c5fd39a56',
  108. 'ext': 'mp4',
  109. 'uploader': 'Waypoint',
  110. 'title': 'The Signal From Tölva',
  111. 'uploader_id': '57f7d621e05ca860fa9ccaf9',
  112. 'timestamp': 1477941983938,
  113. },
  114. 'params': {
  115. # m3u8 download
  116. 'skip_download': True,
  117. },
  118. 'add_ie': ['UplynkPreplay'],
  119. }, {
  120. 'url': 'https://news.vice.com/video/experimenting-on-animals-inside-the-monkey-lab',
  121. 'only_matching': True,
  122. }, {
  123. 'url': 'http://www.vice.com/ru/video/big-night-out-ibiza-clive-martin-229',
  124. 'only_matching': True,
  125. }, {
  126. 'url': 'https://munchies.vice.com/en/videos/watch-the-trailer-for-our-new-series-the-pizza-show',
  127. 'only_matching': True,
  128. }]
  129. _PREPLAY_HOST = 'video.vice'
  130. def _real_extract(self, url):
  131. video_id = self._match_id(url)
  132. webpage, urlh = self._download_webpage_handle(url, video_id)
  133. embed_code = self._search_regex(
  134. r'embedCode=([^&\'"]+)', webpage,
  135. 'ooyala embed code', default=None)
  136. if embed_code:
  137. return self.url_result('ooyala:%s' % embed_code, 'Ooyala')
  138. youtube_id = self._search_regex(
  139. r'data-youtube-id="([^"]+)"', webpage, 'youtube id', default=None)
  140. if youtube_id:
  141. return self.url_result(youtube_id, 'Youtube')
  142. return self._extract_preplay_video(urlh.geturl(), webpage)
  143. class ViceShowIE(InfoExtractor):
  144. _VALID_URL = r'https?://(?:.+?\.)?vice\.com/(?:[^/]+/)?show/(?P<id>[^/?#&]+)'
  145. _TEST = {
  146. 'url': 'https://munchies.vice.com/en/show/fuck-thats-delicious-2',
  147. 'info_dict': {
  148. 'id': 'fuck-thats-delicious-2',
  149. 'title': "Fuck, That's Delicious",
  150. 'description': 'Follow the culinary adventures of rapper Action Bronson during his ongoing world tour.',
  151. },
  152. 'playlist_count': 17,
  153. }
  154. def _real_extract(self, url):
  155. show_id = self._match_id(url)
  156. webpage = self._download_webpage(url, show_id)
  157. entries = [
  158. self.url_result(video_url, ViceIE.ie_key())
  159. for video_url, _ in re.findall(
  160. r'<h2[^>]+class="article-title"[^>]+data-id="\d+"[^>]*>\s*<a[^>]+href="(%s.*?)"'
  161. % ViceIE._VALID_URL, webpage)]
  162. title = self._search_regex(
  163. r'<title>(.+?)</title>', webpage, 'title', default=None)
  164. if title:
  165. title = re.sub(r'(.+)\s*\|\s*.+$', r'\1', title).strip()
  166. description = self._html_search_meta('description', webpage, 'description')
  167. return self.playlist_result(entries, show_id, title, description)