wat.py 4.1 KB

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