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.

34 lines
1.1 KiB

  1. import re
  2. import json
  3. from .common import InfoExtractor
  4. class PBSIE(InfoExtractor):
  5. _VALID_URL = r'https?://video\.pbs\.org/video/(?P<id>\d+)/?'
  6. _TEST = {
  7. u'url': u'http://video.pbs.org/video/2365006249/',
  8. u'file': u'2365006249.mp4',
  9. u'md5': 'ce1888486f0908d555a8093cac9a7362',
  10. u'info_dict': {
  11. u'title': u'A More Perfect Union',
  12. u'description': u'md5:ba0c207295339c8d6eced00b7c363c6a',
  13. u'duration': 3190,
  14. },
  15. }
  16. def _real_extract(self, url):
  17. mobj = re.match(self._VALID_URL, url)
  18. video_id = mobj.group('id')
  19. info_url = 'http://video.pbs.org/videoInfo/%s?format=json' % video_id
  20. info_page = self._download_webpage(info_url, video_id)
  21. info =json.loads(info_page)
  22. return {'id': video_id,
  23. 'title': info['title'],
  24. 'url': info['alternate_encoding']['url'],
  25. 'ext': 'mp4',
  26. 'description': info['program'].get('description'),
  27. 'thumbnail': info.get('image_url'),
  28. 'duration': info.get('duration'),
  29. }