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.

114 lines
3.8 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. )
  14. class FOXIE(AdobePassIE):
  15. _VALID_URL = r'https?://(?:www\.)?fox\.com/watch/(?P<id>[\da-fA-F]+)'
  16. _TESTS = [{
  17. # clip
  18. 'url': 'https://www.fox.com/watch/4b765a60490325103ea69888fb2bd4e8/',
  19. 'md5': 'ebd296fcc41dd4b19f8115d8461a3165',
  20. 'info_dict': {
  21. 'id': '4b765a60490325103ea69888fb2bd4e8',
  22. 'ext': 'mp4',
  23. 'title': 'Aftermath: Bruce Wayne Develops Into The Dark Knight',
  24. 'description': 'md5:549cd9c70d413adb32ce2a779b53b486',
  25. 'duration': 102,
  26. 'timestamp': 1504291893,
  27. 'upload_date': '20170901',
  28. 'creator': 'FOX',
  29. 'series': 'Gotham',
  30. },
  31. 'params': {
  32. 'skip_download': True,
  33. },
  34. }, {
  35. # episode, geo-restricted
  36. 'url': 'https://www.fox.com/watch/087036ca7f33c8eb79b08152b4dd75c1/',
  37. 'only_matching': True,
  38. }, {
  39. # episode, geo-restricted, tv provided required
  40. 'url': 'https://www.fox.com/watch/30056b295fb57f7452aeeb4920bc3024/',
  41. 'only_matching': True,
  42. }]
  43. def _real_extract(self, url):
  44. video_id = self._match_id(url)
  45. video = self._download_json(
  46. 'https://api.fox.com/fbc-content/v1_4/video/%s' % video_id,
  47. video_id, headers={
  48. 'apikey': 'abdcbed02c124d393b39e818a4312055',
  49. 'Content-Type': 'application/json',
  50. 'Referer': url,
  51. })
  52. title = video['name']
  53. release_url = video['videoRelease']['url']
  54. description = video.get('description')
  55. duration = int_or_none(video.get('durationInSeconds')) or int_or_none(
  56. video.get('duration')) or parse_duration(video.get('duration'))
  57. timestamp = unified_timestamp(video.get('datePublished'))
  58. age_limit = parse_age_limit(video.get('contentRating'))
  59. data = try_get(
  60. video, lambda x: x['trackingData']['properties'], dict) or {}
  61. creator = data.get('brand') or data.get('network') or video.get('network')
  62. series = video.get('seriesName') or data.get(
  63. 'seriesName') or data.get('show')
  64. season_number = int_or_none(video.get('seasonNumber'))
  65. episode = video.get('name')
  66. episode_number = int_or_none(video.get('episodeNumber'))
  67. release_year = int_or_none(video.get('releaseYear'))
  68. if data.get('authRequired'):
  69. # TODO: AP
  70. pass
  71. info = {
  72. 'id': video_id,
  73. 'title': title,
  74. 'description': description,
  75. 'duration': duration,
  76. 'timestamp': timestamp,
  77. 'age_limit': age_limit,
  78. 'creator': creator,
  79. 'series': series,
  80. 'season_number': season_number,
  81. 'episode': episode,
  82. 'episode_number': episode_number,
  83. 'release_year': release_year,
  84. }
  85. urlh = self._request_webpage(HEADRequest(release_url), video_id)
  86. video_url = compat_str(urlh.geturl())
  87. if UplynkPreplayIE.suitable(video_url):
  88. info.update({
  89. '_type': 'url_transparent',
  90. 'url': video_url,
  91. 'ie_key': UplynkPreplayIE.ie_key(),
  92. })
  93. else:
  94. m3u8_url = self._download_json(release_url, video_id)['playURL']
  95. formats = self._extract_m3u8_formats(
  96. m3u8_url, video_id, 'mp4',
  97. entry_protocol='m3u8_native', m3u8_id='hls')
  98. self._sort_formats(formats)
  99. info['formats'] = formats
  100. return info