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.

139 lines
5.3 KiB

11 years ago
12 years ago
12 years ago
12 years ago
12 years ago
10 years ago
11 years ago
11 years ago
12 years ago
12 years ago
12 years ago
11 years ago
11 years ago
11 years ago
11 years ago
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. import hashlib
  5. from .common import InfoExtractor
  6. from ..utils import (
  7. ExtractorError,
  8. unified_strdate,
  9. )
  10. class WatIE(InfoExtractor):
  11. _VALID_URL = r'(?:wat:(?P<real_id>\d{8})|https?://www\.wat\.tv/video/(?P<display_id>.*)-(?P<short_id>.*?)_.*?\.html)'
  12. IE_NAME = 'wat.tv'
  13. _TESTS = [
  14. {
  15. 'url': 'http://www.wat.tv/video/soupe-figues-l-orange-aux-epices-6z1uz_2hvf7_.html',
  16. 'md5': 'ce70e9223945ed26a8056d413ca55dc9',
  17. 'info_dict': {
  18. 'id': '11713067',
  19. 'display_id': 'soupe-figues-l-orange-aux-epices',
  20. 'ext': 'mp4',
  21. 'title': 'Soupe de figues à l\'orange et aux épices',
  22. 'description': 'Retrouvez l\'émission "Petits plats en équilibre", diffusée le 18 août 2014.',
  23. 'upload_date': '20140819',
  24. 'duration': 120,
  25. },
  26. },
  27. {
  28. 'url': 'http://www.wat.tv/video/gregory-lemarchal-voix-ange-6z1v7_6ygkj_.html',
  29. 'md5': 'fbc84e4378165278e743956d9c1bf16b',
  30. 'info_dict': {
  31. 'id': '11713075',
  32. 'display_id': 'gregory-lemarchal-voix-ange',
  33. 'ext': 'mp4',
  34. 'title': 'Grégory Lemarchal, une voix d\'ange depuis 10 ans (1/3)',
  35. 'description': 'md5:b7a849cf16a2b733d9cd10c52906dee3',
  36. 'upload_date': '20140816',
  37. 'duration': 2910,
  38. },
  39. 'skip': "Ce contenu n'est pas disponible pour l'instant.",
  40. },
  41. ]
  42. def download_video_info(self, real_id):
  43. # 'contentv4' is used in the website, but it also returns the related
  44. # videos, we don't need them
  45. info = self._download_json('http://www.wat.tv/interface/contentv3/' + real_id, real_id)
  46. return info['media']
  47. def _real_extract(self, url):
  48. def real_id_for_chapter(chapter):
  49. return chapter['tc_start'].split('-')[0]
  50. mobj = re.match(self._VALID_URL, url)
  51. display_id = mobj.group('display_id')
  52. real_id = mobj.group('real_id')
  53. if not real_id:
  54. short_id = mobj.group('short_id')
  55. webpage = self._download_webpage(url, display_id or short_id)
  56. real_id = self._search_regex(r'xtpage = ".*-(.*?)";', webpage, 'real id')
  57. video_info = self.download_video_info(real_id)
  58. error_desc = video_info.get('error_desc')
  59. if error_desc:
  60. raise ExtractorError(
  61. '%s returned error: %s' % (self.IE_NAME, error_desc), expected=True)
  62. geo_list = video_info.get('geoList')
  63. country = geo_list[0] if geo_list else ''
  64. chapters = video_info['chapters']
  65. first_chapter = chapters[0]
  66. files = video_info['files']
  67. first_file = files[0]
  68. if real_id_for_chapter(first_chapter) != real_id:
  69. self.to_screen('Multipart video detected')
  70. chapter_urls = []
  71. for chapter in chapters:
  72. chapter_id = real_id_for_chapter(chapter)
  73. # Yes, when we this chapter is processed by WatIE,
  74. # it will download the info again
  75. chapter_info = self.download_video_info(chapter_id)
  76. chapter_urls.append(chapter_info['url'])
  77. entries = [self.url_result(chapter_url) for chapter_url in chapter_urls]
  78. return self.playlist_result(entries, real_id, video_info['title'])
  79. upload_date = None
  80. if 'date_diffusion' in first_chapter:
  81. upload_date = unified_strdate(first_chapter['date_diffusion'])
  82. # Otherwise we can continue and extract just one part, we have to use
  83. # the short id for getting the video url
  84. formats = [{
  85. 'url': 'http://wat.tv/get/android5/%s.mp4' % real_id,
  86. 'format_id': 'Mobile',
  87. }]
  88. fmts = [('SD', 'web')]
  89. if first_file.get('hasHD'):
  90. fmts.append(('HD', 'webhd'))
  91. def compute_token(param):
  92. timestamp = '%08x' % int(self._download_webpage(
  93. 'http://www.wat.tv/servertime', real_id,
  94. 'Downloading server time').split('|')[0])
  95. magic = '9b673b13fa4682ed14c3cfa5af5310274b514c4133e9b3a81e6e3aba009l2564'
  96. return '%s/%s' % (hashlib.md5((magic + param + timestamp).encode('ascii')).hexdigest(), timestamp)
  97. for fmt in fmts:
  98. webid = '/%s/%s' % (fmt[1], real_id)
  99. video_url = self._download_webpage(
  100. 'http://www.wat.tv/get%s?token=%s&getURL=1&country=%s' % (webid, compute_token(webid), country),
  101. real_id,
  102. 'Downloading %s video URL' % fmt[0],
  103. 'Failed to download %s video URL' % fmt[0],
  104. False)
  105. if not video_url:
  106. continue
  107. formats.append({
  108. 'url': video_url,
  109. 'ext': 'mp4',
  110. 'format_id': fmt[0],
  111. })
  112. return {
  113. 'id': real_id,
  114. 'display_id': display_id,
  115. 'title': first_chapter['title'],
  116. 'thumbnail': first_chapter['preview'],
  117. 'description': first_chapter['description'],
  118. 'view_count': video_info['views'],
  119. 'upload_date': upload_date,
  120. 'duration': first_file['duration'],
  121. 'formats': formats,
  122. }