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.

107 lines
4.2 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import time
  4. import hashlib
  5. import json
  6. from .adobepass import AdobePassIE
  7. from ..compat import compat_HTTPError
  8. from ..utils import (
  9. int_or_none,
  10. parse_age_limit,
  11. str_or_none,
  12. parse_duration,
  13. ExtractorError,
  14. extract_attributes,
  15. )
  16. class VicelandIE(AdobePassIE):
  17. _VALID_URL = r'https?://(?:www\.)?viceland\.com/[^/]+/video/[^/]+/(?P<id>[a-f0-9]+)'
  18. _TEST = {
  19. 'url': 'https://www.viceland.com/en_us/video/cyberwar-trailer/57608447973ee7705f6fbd4e',
  20. 'info_dict': {
  21. 'id': '57608447973ee7705f6fbd4e',
  22. 'ext': 'mp4',
  23. 'title': 'CYBERWAR (Trailer)',
  24. 'description': 'Tapping into the geopolitics of hacking and surveillance, Ben Makuch travels the world to meet with hackers, government officials, and dissidents to investigate the ecosystem of cyberwarfare.',
  25. 'age_limit': 14,
  26. 'timestamp': 1466008539,
  27. 'upload_date': '20160615',
  28. 'uploader_id': '11',
  29. 'uploader': 'Viceland',
  30. },
  31. 'params': {
  32. # m3u8 download
  33. 'skip_download': True,
  34. },
  35. 'add_ie': ['UplynkPreplay'],
  36. }
  37. def _real_extract(self, url):
  38. video_id = self._match_id(url)
  39. webpage = self._download_webpage(url, video_id)
  40. watch_hub_data = extract_attributes(self._search_regex(
  41. r'(?s)(<watch-hub\s*.+?</watch-hub>)', webpage, 'watch hub'))
  42. video_id = watch_hub_data['vms-id']
  43. title = watch_hub_data['video-title']
  44. query = {}
  45. if watch_hub_data.get('video-locked') == '1':
  46. resource = self._get_mvpd_resource(
  47. 'VICELAND', title, video_id,
  48. watch_hub_data.get('video-rating'))
  49. query['tvetoken'] = self._extract_mvpd_auth(url, video_id, 'VICELAND', resource)
  50. # signature generation algorithm is reverse engineered from signatureGenerator in
  51. # webpack:///../shared/~/vice-player/dist/js/vice-player.js in
  52. # https://www.viceland.com/assets/common/js/web.vendor.bundle.js
  53. exp = int(time.time()) + 14400
  54. query.update({
  55. 'exp': exp,
  56. 'sign': hashlib.sha512(('%s:GET:%d' % (video_id, exp)).encode()).hexdigest(),
  57. })
  58. try:
  59. preplay = self._download_json('https://www.viceland.com/en_us/preplay/%s' % video_id, video_id, query=query)
  60. except ExtractorError as e:
  61. if isinstance(e.cause, compat_HTTPError) and e.cause.code == 400:
  62. error = json.loads(e.cause.read().decode())
  63. raise ExtractorError('%s said: %s' % (self.IE_NAME, error['details']), expected=True)
  64. raise
  65. video_data = preplay['video']
  66. base = video_data['base']
  67. uplynk_preplay_url = preplay['preplayURL']
  68. episode = video_data.get('episode', {})
  69. channel = video_data.get('channel', {})
  70. subtitles = {}
  71. cc_url = preplay.get('ccURL')
  72. if cc_url:
  73. subtitles['en'] = [{
  74. 'url': cc_url,
  75. }]
  76. return {
  77. '_type': 'url_transparent',
  78. 'url': uplynk_preplay_url,
  79. 'id': video_id,
  80. 'title': title,
  81. 'description': base.get('body'),
  82. 'thumbnail': watch_hub_data.get('cover-image') or watch_hub_data.get('thumbnail'),
  83. 'duration': parse_duration(video_data.get('video_duration') or watch_hub_data.get('video-duration')),
  84. 'timestamp': int_or_none(video_data.get('created_at')),
  85. 'age_limit': parse_age_limit(video_data.get('video_rating')),
  86. 'series': video_data.get('show_title') or watch_hub_data.get('show-title'),
  87. 'episode_number': int_or_none(episode.get('episode_number') or watch_hub_data.get('episode')),
  88. 'episode_id': str_or_none(episode.get('id') or video_data.get('episode_id')),
  89. 'season_number': int_or_none(watch_hub_data.get('season')),
  90. 'season_id': str_or_none(episode.get('season_id')),
  91. 'uploader': channel.get('base', {}).get('title') or watch_hub_data.get('channel-title'),
  92. 'uploader_id': str_or_none(channel.get('id')),
  93. 'subtitles': subtitles,
  94. 'ie_key': 'UplynkPreplay',
  95. }