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.

40 lines
1.4 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': 'mission-impossible-outtakes.mp4',
  10. 'md5': 'e12614f9ee303a6ccef415cb0793eba2',
  11. 'info_dict': {
  12. 'title': 'MythBusters: Mission Impossible Outtakes'
  13. }
  14. }
  15. def _real_extract(self, url):
  16. mobj = re.match(self._VALID_URL, url)
  17. video_id = mobj.group('id')
  18. webpage = self._download_webpage(url, video_id)
  19. title = self._search_regex(
  20. r'(?<=\"name\": ")(?P<title>.*?)(?=\"\,)', webpage, r'Filename')
  21. duration = int(self._search_regex(
  22. r'(?<=\"duration\"\: )(?P<duration>.*?)(?=,)', webpage, r'Duration'))
  23. formats_raw = self._search_regex(
  24. r'(?<=\"mp4\":)(.*?)(}])', webpage, r'formats') + '}]'
  25. formats_json = json.loads(formats_raw)
  26. formats = []
  27. for f in formats_json:
  28. formats.append(
  29. {'url': f['src'], r'ext': r'mp4', 'tbr': int(f['bitrate'][:-1])})
  30. return {
  31. 'id': video_id,
  32. 'duration': duration,
  33. 'title': title,
  34. 'formats': formats
  35. }