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.

68 lines
2.3 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. class PBSIE(InfoExtractor):
  5. _VALID_URL = r'''(?x)https?://
  6. (?:
  7. # Direct video URL
  8. video\.pbs\.org/video/(?P<id>[0-9]+)/? |
  9. # Article with embedded player
  10. (?:www\.)?pbs\.org/(?:[^/]+/){2,5}(?P<presumptive_id>[^/]+)/?(?:$|[?\#]) |
  11. # Player
  12. video\.pbs\.org/partnerplayer/(?P<player_id>[^/]+)/
  13. )
  14. '''
  15. _TEST = {
  16. 'url': 'http://www.pbs.org/tpt/constitution-usa-peter-sagal/watch/a-more-perfect-union/',
  17. 'md5': 'ce1888486f0908d555a8093cac9a7362',
  18. 'info_dict': {
  19. 'id': '2365006249',
  20. 'ext': 'mp4',
  21. 'title': 'A More Perfect Union',
  22. 'description': 'md5:ba0c207295339c8d6eced00b7c363c6a',
  23. 'duration': 3190,
  24. },
  25. }
  26. def _real_extract(self, url):
  27. mobj = re.match(self._VALID_URL, url)
  28. presumptive_id = mobj.group('presumptive_id')
  29. display_id = presumptive_id
  30. if presumptive_id:
  31. webpage = self._download_webpage(url, display_id)
  32. url = self._search_regex(
  33. r'<iframe\s+id=["\']partnerPlayer["\'].*?\s+src=["\'](.*?)["\']>',
  34. webpage, 'player URL')
  35. mobj = re.match(self._VALID_URL, url)
  36. player_id = mobj.group('player_id')
  37. if not display_id:
  38. display_id = player_id
  39. if player_id:
  40. player_page = self._download_webpage(
  41. url, display_id, note='Downloading player page',
  42. errnote='Could not download player page')
  43. video_id = self._search_regex(
  44. r'<div\s+id="video_([0-9]+)"', player_page, 'video ID')
  45. else:
  46. video_id = mobj.group('id')
  47. display_id = video_id
  48. info_url = 'http://video.pbs.org/videoInfo/%s?format=json' % video_id
  49. info = self._download_json(info_url, display_id)
  50. return {
  51. 'id': video_id,
  52. 'title': info['title'],
  53. 'url': info['alternate_encoding']['url'],
  54. 'ext': 'mp4',
  55. 'description': info['program'].get('description'),
  56. 'thumbnail': info.get('image_url'),
  57. 'duration': info.get('duration'),
  58. }