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.

116 lines
4.3 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
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 time
  5. import hashlib
  6. from .common import InfoExtractor
  7. from ..utils import (
  8. ExtractorError,
  9. unified_strdate,
  10. )
  11. class WatIE(InfoExtractor):
  12. _VALID_URL = r'http://www\.wat\.tv/video/(?P<display_id>.*)-(?P<short_id>.*?)_.*?\.html'
  13. IE_NAME = 'wat.tv'
  14. _TEST = {
  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. def download_video_info(self, real_id):
  28. # 'contentv4' is used in the website, but it also returns the related
  29. # videos, we don't need them
  30. info = self._download_json('http://www.wat.tv/interface/contentv3/' + real_id, real_id)
  31. return info['media']
  32. def _real_extract(self, url):
  33. def real_id_for_chapter(chapter):
  34. return chapter['tc_start'].split('-')[0]
  35. mobj = re.match(self._VALID_URL, url)
  36. short_id = mobj.group('short_id')
  37. display_id = mobj.group('display_id')
  38. webpage = self._download_webpage(url, display_id or short_id)
  39. real_id = self._search_regex(r'xtpage = ".*-(.*?)";', webpage, 'real id')
  40. video_info = self.download_video_info(real_id)
  41. if video_info.get('geolock'):
  42. self.report_warning(
  43. 'This content is marked as not available in your area. Trying anyway ..')
  44. chapters = video_info['chapters']
  45. first_chapter = chapters[0]
  46. files = video_info['files']
  47. first_file = files[0]
  48. if real_id_for_chapter(first_chapter) != real_id:
  49. self.to_screen('Multipart video detected')
  50. chapter_urls = []
  51. for chapter in chapters:
  52. chapter_id = real_id_for_chapter(chapter)
  53. # Yes, when we this chapter is processed by WatIE,
  54. # it will download the info again
  55. chapter_info = self.download_video_info(chapter_id)
  56. chapter_urls.append(chapter_info['url'])
  57. entries = [self.url_result(chapter_url) for chapter_url in chapter_urls]
  58. return self.playlist_result(entries, real_id, video_info['title'])
  59. upload_date = None
  60. if 'date_diffusion' in first_chapter:
  61. upload_date = unified_strdate(first_chapter['date_diffusion'])
  62. # Otherwise we can continue and extract just one part, we have to use
  63. # the short id for getting the video url
  64. formats = [{
  65. 'url': 'http://wat.tv/get/android5/%s.mp4' % real_id,
  66. 'format_id': 'Mobile',
  67. }]
  68. fmts = [('SD', 'web')]
  69. if first_file.get('hasHD'):
  70. fmts.append(('HD', 'webhd'))
  71. def compute_token(param):
  72. timestamp = '%08x' % int(time.time())
  73. magic = '9b673b13fa4682ed14c3cfa5af5310274b514c4133e9b3a81e6e3aba009l2564'
  74. return '%s/%s' % (hashlib.md5((magic + param + timestamp).encode('ascii')).hexdigest(), timestamp)
  75. for fmt in fmts:
  76. webid = '/%s/%s' % (fmt[1], real_id)
  77. video_url = self._download_webpage(
  78. 'http://www.wat.tv/get%s?token=%s&getURL=1' % (webid, compute_token(webid)),
  79. real_id,
  80. 'Downloding %s video URL' % fmt[0],
  81. 'Failed to download %s video URL' % fmt[0],
  82. False)
  83. if not video_url:
  84. continue
  85. formats.append({
  86. 'url': video_url,
  87. 'ext': 'mp4',
  88. 'format_id': fmt[0],
  89. })
  90. return {
  91. 'id': real_id,
  92. 'display_id': display_id,
  93. 'title': first_chapter['title'],
  94. 'thumbnail': first_chapter['preview'],
  95. 'description': first_chapter['description'],
  96. 'view_count': video_info['views'],
  97. 'upload_date': upload_date,
  98. 'duration': first_file['duration'],
  99. 'formats': formats,
  100. }