wat.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. unified_strdate,
  7. )
  8. class WatIE(InfoExtractor):
  9. _VALID_URL = r'http://www\.wat\.tv/.*-(?P<shortID>.*?)_.*?\.html'
  10. IE_NAME = 'wat.tv'
  11. _TEST = {
  12. 'url': 'http://www.wat.tv/video/world-war-philadelphia-vost-6bv55_2fjr7_.html',
  13. 'info_dict': {
  14. 'id': '10631273',
  15. 'ext': 'mp4',
  16. 'title': 'World War Z - Philadelphia VOST',
  17. 'description': 'La menace est partout. Que se passe-t-il à Philadelphia ?\r\nWORLD WAR Z, avec Brad Pitt, au cinéma le 3 juillet.\r\nhttp://www.worldwarz.fr',
  18. },
  19. 'params': {
  20. # Sometimes wat serves the whole file with the --test option
  21. 'skip_download': True,
  22. },
  23. }
  24. def download_video_info(self, real_id):
  25. # 'contentv4' is used in the website, but it also returns the related
  26. # videos, we don't need them
  27. info = self._download_json('http://www.wat.tv/interface/contentv3/' + real_id, real_id)
  28. return info['media']
  29. def _real_extract(self, url):
  30. def real_id_for_chapter(chapter):
  31. return chapter['tc_start'].split('-')[0]
  32. mobj = re.match(self._VALID_URL, url)
  33. short_id = mobj.group('shortID')
  34. webpage = self._download_webpage(url, short_id)
  35. real_id = self._search_regex(r'xtpage = ".*-(.*?)";', webpage, 'real id')
  36. video_info = self.download_video_info(real_id)
  37. chapters = video_info['chapters']
  38. first_chapter = chapters[0]
  39. if real_id_for_chapter(first_chapter) != real_id:
  40. self.to_screen('Multipart video detected')
  41. chapter_urls = []
  42. for chapter in chapters:
  43. chapter_id = real_id_for_chapter(chapter)
  44. # Yes, when we this chapter is processed by WatIE,
  45. # it will download the info again
  46. chapter_info = self.download_video_info(chapter_id)
  47. chapter_urls.append(chapter_info['url'])
  48. entries = [self.url_result(chapter_url) for chapter_url in chapter_urls]
  49. return self.playlist_result(entries, real_id, video_info['title'])
  50. upload_date = None
  51. if 'date_diffusion' in first_chapter:
  52. upload_date = unified_strdate(first_chapter['date_diffusion'])
  53. # Otherwise we can continue and extract just one part, we have to use
  54. # the short id for getting the video url
  55. return {
  56. 'id': real_id,
  57. 'url': 'http://wat.tv/get/android5/%s.mp4' % real_id,
  58. 'title': first_chapter['title'],
  59. 'thumbnail': first_chapter['preview'],
  60. 'description': first_chapter['description'],
  61. 'view_count': video_info['views'],
  62. 'upload_date': upload_date,
  63. }