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.

136 lines
5.2 KiB

11 years ago
12 years ago
12 years ago
12 years ago
12 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'http://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. },
  40. ]
  41. def download_video_info(self, real_id):
  42. # 'contentv4' is used in the website, but it also returns the related
  43. # videos, we don't need them
  44. info = self._download_json('http://www.wat.tv/interface/contentv3/' + real_id, real_id)
  45. return info['media']
  46. def _real_extract(self, url):
  47. def real_id_for_chapter(chapter):
  48. return chapter['tc_start'].split('-')[0]
  49. mobj = re.match(self._VALID_URL, url)
  50. short_id = mobj.group('short_id')
  51. display_id = mobj.group('display_id')
  52. webpage = self._download_webpage(url, display_id or short_id)
  53. real_id = self._search_regex(r'xtpage = ".*-(.*?)";', webpage, 'real id')
  54. video_info = self.download_video_info(real_id)
  55. error_desc = video_info.get('error_desc')
  56. if error_desc:
  57. raise ExtractorError(
  58. '%s returned error: %s' % (self.IE_NAME, error_desc), expected=True)
  59. geo_list = video_info.get('geoList')
  60. country = geo_list[0] if geo_list else ''
  61. chapters = video_info['chapters']
  62. first_chapter = chapters[0]
  63. files = video_info['files']
  64. first_file = files[0]
  65. if real_id_for_chapter(first_chapter) != real_id:
  66. self.to_screen('Multipart video detected')
  67. chapter_urls = []
  68. for chapter in chapters:
  69. chapter_id = real_id_for_chapter(chapter)
  70. # Yes, when we this chapter is processed by WatIE,
  71. # it will download the info again
  72. chapter_info = self.download_video_info(chapter_id)
  73. chapter_urls.append(chapter_info['url'])
  74. entries = [self.url_result(chapter_url) for chapter_url in chapter_urls]
  75. return self.playlist_result(entries, real_id, video_info['title'])
  76. upload_date = None
  77. if 'date_diffusion' in first_chapter:
  78. upload_date = unified_strdate(first_chapter['date_diffusion'])
  79. # Otherwise we can continue and extract just one part, we have to use
  80. # the short id for getting the video url
  81. formats = [{
  82. 'url': 'http://wat.tv/get/android5/%s.mp4' % real_id,
  83. 'format_id': 'Mobile',
  84. }]
  85. fmts = [('SD', 'web')]
  86. if first_file.get('hasHD'):
  87. fmts.append(('HD', 'webhd'))
  88. def compute_token(param):
  89. timestamp = '%08x' % int(self._download_webpage(
  90. 'http://www.wat.tv/servertime', real_id,
  91. 'Downloading server time').split('|')[0])
  92. magic = '9b673b13fa4682ed14c3cfa5af5310274b514c4133e9b3a81e6e3aba009l2564'
  93. return '%s/%s' % (hashlib.md5((magic + param + timestamp).encode('ascii')).hexdigest(), timestamp)
  94. for fmt in fmts:
  95. webid = '/%s/%s' % (fmt[1], real_id)
  96. video_url = self._download_webpage(
  97. 'http://www.wat.tv/get%s?token=%s&getURL=1&country=%s' % (webid, compute_token(webid), country),
  98. real_id,
  99. 'Downloding %s video URL' % fmt[0],
  100. 'Failed to download %s video URL' % fmt[0],
  101. False)
  102. if not video_url:
  103. continue
  104. formats.append({
  105. 'url': video_url,
  106. 'ext': 'mp4',
  107. 'format_id': fmt[0],
  108. })
  109. return {
  110. 'id': real_id,
  111. 'display_id': display_id,
  112. 'title': first_chapter['title'],
  113. 'thumbnail': first_chapter['preview'],
  114. 'description': first_chapter['description'],
  115. 'view_count': video_info['views'],
  116. 'upload_date': upload_date,
  117. 'duration': first_file['duration'],
  118. 'formats': formats,
  119. }