wat.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import json
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. compat_urllib_parse,
  6. )
  7. class WatIE(InfoExtractor):
  8. _VALID_URL=r'http://www.wat.tv/.*-(?P<shortID>.*?)_.*?.html'
  9. IE_NAME = 'wat.tv'
  10. _TEST = {
  11. u'url': u'http://www.wat.tv/video/world-war-philadelphia-vost-6bv55_2fjr7_.html',
  12. u'file': u'6bv55.mp4',
  13. u'md5': u'0a4fe7870f31eaeabb5e25fd8da8414a',
  14. u'info_dict': {
  15. u"title": u"World War Z - Philadelphia VOST"
  16. }
  17. }
  18. def _real_extract(self, url):
  19. mobj = re.match(self._VALID_URL, url)
  20. short_id = mobj.group('shortID')
  21. player_data = compat_urllib_parse.urlencode({'shortVideoId': short_id,
  22. 'html5': '1'})
  23. player_info = self._download_webpage('http://www.wat.tv/player?' + player_data,
  24. short_id, u'Downloading player info')
  25. player = json.loads(player_info)['player']
  26. html5_player = self._html_search_regex(r'iframe src="(.*?)"', player,
  27. 'html5 player')
  28. player_webpage = self._download_webpage(html5_player, short_id,
  29. u'Downloading player webpage')
  30. video_url = self._search_regex(r'urlhtml5 : "(.*?)"', player_webpage,
  31. 'video url')
  32. title = self._search_regex(r'contentTitle : "(.*?)"', player_webpage,
  33. 'title')
  34. thumbnail = self._search_regex(r'previewMedia : "(.*?)"', player_webpage,
  35. 'thumbnail')
  36. return {'id': short_id,
  37. 'url': video_url,
  38. 'ext': 'mp4',
  39. 'title': title,
  40. 'thumbnail': thumbnail,
  41. }