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.

72 lines
2.8 KiB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
  1. # coding: utf-8
  2. import json
  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. u'url': u'http://www.wat.tv/video/world-war-philadelphia-vost-6bv55_2fjr7_.html',
  13. u'file': u'10631273.mp4',
  14. u'md5': u'd8b2231e1e333acd12aad94b80937e19',
  15. u'info_dict': {
  16. u'title': u'World War Z - Philadelphia VOST',
  17. u'description': u'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. u'skip': u'Sometimes wat serves the whole file with the --test option',
  20. }
  21. def download_video_info(self, real_id):
  22. # 'contentv4' is used in the website, but it also returns the related
  23. # videos, we don't need them
  24. info = self._download_webpage('http://www.wat.tv/interface/contentv3/' + real_id, real_id, 'Downloading video info')
  25. info = json.loads(info)
  26. return info['media']
  27. def _real_extract(self, url):
  28. def real_id_for_chapter(chapter):
  29. return chapter['tc_start'].split('-')[0]
  30. mobj = re.match(self._VALID_URL, url)
  31. short_id = mobj.group('shortID')
  32. webpage = self._download_webpage(url, short_id)
  33. real_id = self._search_regex(r'xtpage = ".*-(.*?)";', webpage, 'real id')
  34. video_info = self.download_video_info(real_id)
  35. chapters = video_info['chapters']
  36. first_chapter = chapters[0]
  37. if real_id_for_chapter(first_chapter) != real_id:
  38. self.to_screen('Multipart video detected')
  39. chapter_urls = []
  40. for chapter in chapters:
  41. chapter_id = real_id_for_chapter(chapter)
  42. # Yes, when we this chapter is processed by WatIE,
  43. # it will download the info again
  44. chapter_info = self.download_video_info(chapter_id)
  45. chapter_urls.append(chapter_info['url'])
  46. entries = [self.url_result(chapter_url) for chapter_url in chapter_urls]
  47. return self.playlist_result(entries, real_id, video_info['title'])
  48. # Otherwise we can continue and extract just one part, we have to use
  49. # the short id for getting the video url
  50. info = {'id': real_id,
  51. 'url': 'http://wat.tv/get/android5/%s.mp4' % real_id,
  52. 'ext': 'mp4',
  53. 'title': first_chapter['title'],
  54. 'thumbnail': first_chapter['preview'],
  55. 'description': first_chapter['description'],
  56. 'view_count': video_info['views'],
  57. }
  58. if 'date_diffusion' in first_chapter:
  59. info['upload_date'] = unified_strdate(first_chapter['date_diffusion'])
  60. return info