logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

wat.py (4130B)


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