wat.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. ExtractorError,
  4. int_or_none,
  5. try_get,
  6. unified_strdate,
  7. )
  8. class WatIE(InfoExtractor):
  9. _VALID_URL = r'(?:wat:|https?://(?:www\.)?wat\.tv/video/.*-)(?P<id>[0-9a-z]+)'
  10. IE_NAME = 'wat.tv'
  11. _TESTS = [
  12. {
  13. 'url': 'http://www.wat.tv/video/soupe-figues-l-orange-aux-epices-6z1uz_2hvf7_.html',
  14. 'info_dict': {
  15. 'id': '11713067',
  16. 'ext': 'mp4',
  17. 'title': 'Soupe de figues à l\'orange et aux épices',
  18. 'description': 'Retrouvez l\'émission "Petits plats en équilibre", diffusée le 18 août 2014.',
  19. 'upload_date': '20140819',
  20. 'duration': 120,
  21. },
  22. 'params': {
  23. # m3u8 download
  24. 'skip_download': True,
  25. },
  26. 'expected_warnings': ['HTTP Error 404'],
  27. 'skip': 'This content is no longer available',
  28. },
  29. {
  30. 'url': 'http://www.wat.tv/video/gregory-lemarchal-voix-ange-6z1v7_6ygkj_.html',
  31. 'md5': 'b16574df2c3cd1a36ca0098f2a791925',
  32. 'info_dict': {
  33. 'id': '11713075',
  34. 'ext': 'mp4',
  35. 'title': 'Grégory Lemarchal, une voix d\'ange depuis 10 ans (1/3)',
  36. 'upload_date': '20140816',
  37. },
  38. 'expected_warnings': ["Ce contenu n'est pas disponible pour l'instant."],
  39. 'skip': 'This content is no longer available',
  40. },
  41. {
  42. 'url': 'wat:14010600',
  43. 'info_dict': {
  44. 'id': '14010600',
  45. 'title': 'Burger Quiz - S03 EP21 avec Eye Haidara, Anne Depétrini, Jonathan Zaccaï et Pio Marmaï',
  46. 'thumbnail': 'https://photos.tf1.fr/1280/720/burger-quiz-11-9adb79-0@1x.jpg',
  47. 'upload_date': '20230819',
  48. 'duration': 2312,
  49. 'ext': 'mp4',
  50. },
  51. 'params': {'skip_download': 'm3u8'},
  52. },
  53. ]
  54. _GEO_BYPASS = False
  55. def _real_extract(self, url):
  56. video_id = self._match_id(url)
  57. video_id = video_id if video_id.isdigit() and len(video_id) > 6 else str(int(video_id, 36))
  58. # 'contentv4' is used in the website, but it also returns the related
  59. # videos, we don't need them
  60. # video_data = self._download_json(
  61. # 'http://www.wat.tv/interface/contentv4s/' + video_id, video_id)
  62. video_data = self._download_json(
  63. 'https://mediainfo.tf1.fr/mediainfocombo/' + video_id,
  64. video_id, query={'pver': '5010000'})
  65. video_info = video_data['media']
  66. error_desc = video_info.get('error_desc')
  67. if error_desc:
  68. if video_info.get('error_code') == 'GEOBLOCKED':
  69. self.raise_geo_restricted(error_desc, video_info.get('geoList'))
  70. raise ExtractorError(error_desc, expected=True)
  71. title = video_info['title']
  72. formats = []
  73. subtitles = {}
  74. def extract_formats(manifest_urls):
  75. for f, f_url in manifest_urls.items():
  76. if not f_url:
  77. continue
  78. if f in ('dash', 'mpd'):
  79. fmts, subs = self._extract_mpd_formats_and_subtitles(
  80. f_url.replace('://das-q1.tf1.fr/', '://das-q1-ssl.tf1.fr/'),
  81. video_id, mpd_id='dash', fatal=False)
  82. elif f == 'hls':
  83. fmts, subs = self._extract_m3u8_formats_and_subtitles(
  84. f_url, video_id, 'mp4',
  85. 'm3u8_native', m3u8_id='hls', fatal=False)
  86. else:
  87. continue
  88. formats.extend(fmts)
  89. self._merge_subtitles(subs, target=subtitles)
  90. delivery = video_data.get('delivery') or {}
  91. extract_formats({delivery.get('format'): delivery.get('url')})
  92. if not formats:
  93. if delivery.get('drm'):
  94. self.report_drm(video_id)
  95. manifest_urls = self._download_json(
  96. 'http://www.wat.tv/get/webhtml/' + video_id, video_id, fatal=False)
  97. if manifest_urls:
  98. extract_formats(manifest_urls)
  99. return {
  100. 'id': video_id,
  101. 'title': title,
  102. 'thumbnail': video_info.get('preview'),
  103. 'upload_date': unified_strdate(try_get(
  104. video_data, lambda x: x['mediametrie']['chapters'][0]['estatS4'])),
  105. 'duration': int_or_none(video_info.get('duration')),
  106. 'formats': formats,
  107. 'subtitles': subtitles,
  108. }