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.

101 lines
3.3 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .adobepass import AdobePassIE
  4. from ..utils import (
  5. int_or_none,
  6. parse_age_limit,
  7. parse_duration,
  8. try_get,
  9. unified_timestamp,
  10. )
  11. class FOXIE(AdobePassIE):
  12. _VALID_URL = r'https?://(?:www\.)?fox\.com/watch/(?P<id>[\da-fA-F]+)'
  13. _TESTS = [{
  14. # clip
  15. 'url': 'https://www.fox.com/watch/4b765a60490325103ea69888fb2bd4e8/',
  16. 'md5': 'ebd296fcc41dd4b19f8115d8461a3165',
  17. 'info_dict': {
  18. 'id': '4b765a60490325103ea69888fb2bd4e8',
  19. 'ext': 'mp4',
  20. 'title': 'Aftermath: Bruce Wayne Develops Into The Dark Knight',
  21. 'description': 'md5:549cd9c70d413adb32ce2a779b53b486',
  22. 'duration': 102,
  23. 'timestamp': 1504291893,
  24. 'upload_date': '20170901',
  25. 'creator': 'FOX',
  26. 'series': 'Gotham',
  27. },
  28. 'params': {
  29. 'skip_download': True,
  30. },
  31. }, {
  32. # episode, geo-restricted
  33. 'url': 'https://www.fox.com/watch/087036ca7f33c8eb79b08152b4dd75c1/',
  34. 'only_matching': True,
  35. }, {
  36. # episode, geo-restricted, tv provided required
  37. 'url': 'https://www.fox.com/watch/30056b295fb57f7452aeeb4920bc3024/',
  38. 'only_matching': True,
  39. }]
  40. def _real_extract(self, url):
  41. video_id = self._match_id(url)
  42. video = self._download_json(
  43. 'https://api.fox.com/fbc-content/v1_4/video/%s' % video_id,
  44. video_id, headers={
  45. 'apikey': 'abdcbed02c124d393b39e818a4312055',
  46. 'Content-Type': 'application/json',
  47. 'Referer': url,
  48. })
  49. title = video['name']
  50. m3u8_url = self._download_json(
  51. video['videoRelease']['url'], video_id)['playURL']
  52. formats = self._extract_m3u8_formats(
  53. m3u8_url, video_id, 'mp4',
  54. entry_protocol='m3u8_native', m3u8_id='hls')
  55. self._sort_formats(formats)
  56. description = video.get('description')
  57. duration = int_or_none(video.get('durationInSeconds')) or int_or_none(
  58. video.get('duration')) or parse_duration(video.get('duration'))
  59. timestamp = unified_timestamp(video.get('datePublished'))
  60. age_limit = parse_age_limit(video.get('contentRating'))
  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. # TODO: AP
  72. pass
  73. return {
  74. 'id': video_id,
  75. 'title': title,
  76. 'description': description,
  77. 'duration': duration,
  78. 'timestamp': timestamp,
  79. 'age_limit': age_limit,
  80. 'creator': creator,
  81. 'series': series,
  82. 'season_number': season_number,
  83. 'episode': episode,
  84. 'episode_number': episode_number,
  85. 'release_year': release_year,
  86. 'formats': formats,
  87. }