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.

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