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.

47 lines
1.7 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. import json
  4. from .common import InfoExtractor
  5. class DiscoveryIE(InfoExtractor):
  6. _VALID_URL = r'http://www\.discovery\.com\/[a-zA-Z0-9\-]*/[a-zA-Z0-9\-]*/videos/(?P<id>[a-zA-Z0-9\-]*)(.htm)?'
  7. _TEST = {
  8. 'url': 'http://www.discovery.com/tv-shows/mythbusters/videos/mission-impossible-outtakes.htm',
  9. 'md5': 'e12614f9ee303a6ccef415cb0793eba2',
  10. 'info_dict': {
  11. 'id': '614784',
  12. 'ext': 'mp4',
  13. 'title': 'MythBusters: Mission Impossible Outtakes',
  14. 'description': ('Watch Jamie Hyneman and Adam Savage practice being'
  15. ' each other -- to the point of confusing Jamie\'s dog -- and '
  16. 'don\'t miss Adam moon-walking as Jamie ... behind Jamie\'s'
  17. ' back.'),
  18. 'duration': 156,
  19. },
  20. }
  21. def _real_extract(self, url):
  22. mobj = re.match(self._VALID_URL, url)
  23. video_id = mobj.group('id')
  24. webpage = self._download_webpage(url, video_id)
  25. video_list_json = self._search_regex(r'var videoListJSON = ({.*?});',
  26. webpage, 'video list', flags=re.DOTALL)
  27. video_list = json.loads(video_list_json)
  28. info = video_list['clips'][0]
  29. formats = []
  30. for f in info['mp4']:
  31. formats.append(
  32. {'url': f['src'], 'ext': 'mp4', 'tbr': int(f['bitrate'][:-1])})
  33. return {
  34. 'id': info['contentId'],
  35. 'title': video_list['name'],
  36. 'formats': formats,
  37. 'description': info['videoCaption'],
  38. 'thumbnail': info.get('videoStillURL') or info.get('thumbnailURL'),
  39. 'duration': info['duration'],
  40. }