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.5 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .adobepass import AdobePassIE
  4. from .uplynk import UplynkPreplayIE
  5. from ..compat import compat_str
  6. from ..utils import (
  7. HEADRequest,
  8. int_or_none,
  9. parse_age_limit,
  10. parse_duration,
  11. try_get,
  12. unified_timestamp,
  13. update_url_query,
  14. )
  15. class FOXIE(AdobePassIE):
  16. _VALID_URL = r'https?://(?:www\.)?fox\.com/watch/(?P<id>[\da-fA-F]+)'
  17. _TESTS = [{
  18. # clip
  19. 'url': 'https://www.fox.com/watch/4b765a60490325103ea69888fb2bd4e8/',
  20. 'md5': 'ebd296fcc41dd4b19f8115d8461a3165',
  21. 'info_dict': {
  22. 'id': '4b765a60490325103ea69888fb2bd4e8',
  23. 'ext': 'mp4',
  24. 'title': 'Aftermath: Bruce Wayne Develops Into The Dark Knight',
  25. 'description': 'md5:549cd9c70d413adb32ce2a779b53b486',
  26. 'duration': 102,
  27. 'timestamp': 1504291893,
  28. 'upload_date': '20170901',
  29. 'creator': 'FOX',
  30. 'series': 'Gotham',
  31. },
  32. 'params': {
  33. 'skip_download': True,
  34. },
  35. }, {
  36. # episode, geo-restricted
  37. 'url': 'https://www.fox.com/watch/087036ca7f33c8eb79b08152b4dd75c1/',
  38. 'only_matching': True,
  39. }, {
  40. # episode, geo-restricted, tv provided required
  41. 'url': 'https://www.fox.com/watch/30056b295fb57f7452aeeb4920bc3024/',
  42. 'only_matching': True,
  43. }]
  44. def _real_extract(self, url):
  45. video_id = self._match_id(url)
  46. video = self._download_json(
  47. 'https://api.fox.com/fbc-content/v1_4/video/%s' % video_id,
  48. video_id, headers={
  49. 'apikey': 'abdcbed02c124d393b39e818a4312055',
  50. 'Content-Type': 'application/json',
  51. 'Referer': url,
  52. })
  53. title = video['name']
  54. release_url = video['videoRelease']['url']
  55. description = video.get('description')
  56. duration = int_or_none(video.get('durationInSeconds')) or int_or_none(
  57. video.get('duration')) or parse_duration(video.get('duration'))
  58. timestamp = unified_timestamp(video.get('datePublished'))
  59. rating = video.get('contentRating')
  60. age_limit = parse_age_limit(rating)
  61. data = try_get(
  62. video, lambda x: x['trackingData']['properties'], dict) or {}
  63. creator = data.get('brand') or data.get('network') or video.get('network')
  64. series = video.get('seriesName') or data.get(
  65. 'seriesName') or data.get('show')
  66. season_number = int_or_none(video.get('seasonNumber'))
  67. episode = video.get('name')
  68. episode_number = int_or_none(video.get('episodeNumber'))
  69. release_year = int_or_none(video.get('releaseYear'))
  70. if data.get('authRequired'):
  71. resource = self._get_mvpd_resource(
  72. 'fbc-fox', title, video.get('guid'), rating)
  73. release_url = update_url_query(
  74. release_url, {
  75. 'auth': self._extract_mvpd_auth(
  76. url, video_id, 'fbc-fox', resource)
  77. })
  78. subtitles = {}
  79. for doc_rel in video.get('documentReleases', []):
  80. rel_url = doc_rel.get('url')
  81. if not url or doc_rel.get('format') != 'SCC':
  82. continue
  83. subtitles['en'] = [{
  84. 'url': rel_url,
  85. 'ext': 'scc',
  86. }]
  87. break
  88. info = {
  89. 'id': video_id,
  90. 'title': title,
  91. 'description': description,
  92. 'duration': duration,
  93. 'timestamp': timestamp,
  94. 'age_limit': age_limit,
  95. 'creator': creator,
  96. 'series': series,
  97. 'season_number': season_number,
  98. 'episode': episode,
  99. 'episode_number': episode_number,
  100. 'release_year': release_year,
  101. 'subtitles': subtitles,
  102. }
  103. urlh = self._request_webpage(HEADRequest(release_url), video_id)
  104. video_url = compat_str(urlh.geturl())
  105. if UplynkPreplayIE.suitable(video_url):
  106. info.update({
  107. '_type': 'url_transparent',
  108. 'url': video_url,
  109. 'ie_key': UplynkPreplayIE.ie_key(),
  110. })
  111. else:
  112. m3u8_url = self._download_json(release_url, video_id)['playURL']
  113. formats = self._extract_m3u8_formats(
  114. m3u8_url, video_id, 'mp4',
  115. entry_protocol='m3u8_native', m3u8_id='hls')
  116. self._sort_formats(formats)
  117. info['formats'] = formats
  118. return info