fox.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. # import json
  4. # import uuid
  5. from .adobepass import AdobePassIE
  6. from ..utils import (
  7. int_or_none,
  8. parse_age_limit,
  9. parse_duration,
  10. try_get,
  11. unified_timestamp,
  12. update_url_query,
  13. )
  14. class FOXIE(AdobePassIE):
  15. _VALID_URL = r'https?://(?:www\.)?(?:fox\.com|nationalgeographic\.com/tv)/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. 'url': 'https://www.nationalgeographic.com/tv/watch/f690e05ebbe23ab79747becd0cc223d1/',
  44. 'only_matching': True,
  45. }]
  46. # _access_token = None
  47. # def _call_api(self, path, video_id, data=None):
  48. # headers = {
  49. # 'X-Api-Key': '238bb0a0c2aba67922c48709ce0c06fd',
  50. # }
  51. # if self._access_token:
  52. # headers['Authorization'] = 'Bearer ' + self._access_token
  53. # return self._download_json(
  54. # 'https://api2.fox.com/v2.0/' + path, video_id, data=data, headers=headers)
  55. # def _real_initialize(self):
  56. # self._access_token = self._call_api(
  57. # 'login', None, json.dumps({
  58. # 'deviceId': compat_str(uuid.uuid4()),
  59. # }).encode())['accessToken']
  60. def _real_extract(self, url):
  61. video_id = self._match_id(url)
  62. video = self._download_json(
  63. 'https://api.fox.com/fbc-content/v1_5/video/%s' % video_id,
  64. video_id, headers={
  65. 'apikey': 'abdcbed02c124d393b39e818a4312055',
  66. 'Content-Type': 'application/json',
  67. 'Referer': url,
  68. })
  69. # video = self._call_api('vodplayer/' + video_id, video_id)
  70. title = video['name']
  71. release_url = video['videoRelease']['url']
  72. # release_url = video['url']
  73. data = try_get(
  74. video, lambda x: x['trackingData']['properties'], dict) or {}
  75. rating = video.get('contentRating')
  76. if data.get('authRequired'):
  77. resource = self._get_mvpd_resource(
  78. 'fbc-fox', title, video.get('guid'), rating)
  79. release_url = update_url_query(
  80. release_url, {
  81. 'auth': self._extract_mvpd_auth(
  82. url, video_id, 'fbc-fox', resource)
  83. })
  84. m3u8_url = self._download_json(release_url, video_id)['playURL']
  85. formats = self._extract_m3u8_formats(
  86. m3u8_url, video_id, 'mp4',
  87. entry_protocol='m3u8_native', m3u8_id='hls')
  88. self._sort_formats(formats)
  89. duration = int_or_none(video.get('durationInSeconds')) or int_or_none(
  90. video.get('duration')) or parse_duration(video.get('duration'))
  91. timestamp = unified_timestamp(video.get('datePublished'))
  92. creator = data.get('brand') or data.get('network') or video.get('network')
  93. series = video.get('seriesName') or data.get(
  94. 'seriesName') or data.get('show')
  95. subtitles = {}
  96. for doc_rel in video.get('documentReleases', []):
  97. rel_url = doc_rel.get('url')
  98. if not url or doc_rel.get('format') != 'SCC':
  99. continue
  100. subtitles['en'] = [{
  101. 'url': rel_url,
  102. 'ext': 'scc',
  103. }]
  104. break
  105. return {
  106. 'id': video_id,
  107. 'title': title,
  108. 'formats': formats,
  109. 'description': video.get('description'),
  110. 'duration': duration,
  111. 'timestamp': timestamp,
  112. 'age_limit': parse_age_limit(rating),
  113. 'creator': creator,
  114. 'series': series,
  115. 'season_number': int_or_none(video.get('seasonNumber')),
  116. 'episode': video.get('name'),
  117. 'episode_number': int_or_none(video.get('episodeNumber')),
  118. 'release_year': int_or_none(video.get('releaseYear')),
  119. 'subtitles': subtitles,
  120. }