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.

97 lines
3.5 KiB

  1. from __future__ import unicode_literals
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. parse_duration,
  5. parse_iso8601,
  6. )
  7. from ..compat import compat_str
  8. class DiscoveryIE(InfoExtractor):
  9. _VALID_URL = r'''(?x)https?://(?:www\.)?(?:
  10. discovery|
  11. investigationdiscovery|
  12. discoverylife|
  13. animalplanet|
  14. ahctv|
  15. destinationamerica|
  16. sciencechannel|
  17. tlc|
  18. velocity
  19. )\.com/(?:[^/]+/)*(?P<id>[^./?#]+)'''
  20. _TESTS = [{
  21. 'url': 'http://www.discovery.com/tv-shows/mythbusters/videos/mission-impossible-outtakes.htm',
  22. 'info_dict': {
  23. 'id': '20769',
  24. 'ext': 'mp4',
  25. 'title': 'Mission Impossible Outtakes',
  26. 'description': ('Watch Jamie Hyneman and Adam Savage practice being'
  27. ' each other -- to the point of confusing Jamie\'s dog -- and '
  28. 'don\'t miss Adam moon-walking as Jamie ... behind Jamie\'s'
  29. ' back.'),
  30. 'duration': 156,
  31. 'timestamp': 1302032462,
  32. 'upload_date': '20110405',
  33. 'uploader_id': '103207',
  34. },
  35. 'params': {
  36. 'skip_download': True, # requires ffmpeg
  37. }
  38. }, {
  39. 'url': 'http://www.discovery.com/tv-shows/mythbusters/videos/mythbusters-the-simpsons',
  40. 'info_dict': {
  41. 'id': 'mythbusters-the-simpsons',
  42. 'title': 'MythBusters: The Simpsons',
  43. },
  44. 'playlist_mincount': 10,
  45. }, {
  46. 'url': 'http://www.animalplanet.com/longfin-eels-maneaters/',
  47. 'info_dict': {
  48. 'id': '78326',
  49. 'ext': 'mp4',
  50. 'title': 'Longfin Eels: Maneaters?',
  51. 'description': 'Jeremy Wade tests whether or not New Zealand\'s longfin eels are man-eaters by covering himself in fish guts and getting in the water with them.',
  52. 'upload_date': '20140725',
  53. 'timestamp': 1406246400,
  54. 'duration': 116,
  55. 'uploader_id': '103207',
  56. },
  57. 'params': {
  58. 'skip_download': True, # requires ffmpeg
  59. }
  60. }]
  61. def _real_extract(self, url):
  62. display_id = self._match_id(url)
  63. info = self._download_json(url + '?flat=1', display_id)
  64. video_title = info.get('playlist_title') or info.get('video_title')
  65. entries = []
  66. for idx, video_info in enumerate(info['playlist']):
  67. subtitles = {}
  68. caption_url = video_info.get('captionsUrl')
  69. if caption_url:
  70. subtitles = {
  71. 'en': [{
  72. 'url': caption_url,
  73. }]
  74. }
  75. entries.append({
  76. '_type': 'url_transparent',
  77. 'url': 'http://players.brightcove.net/103207/default_default/index.html?videoId=ref:%s' % video_info['referenceId'],
  78. 'id': compat_str(video_info['id']),
  79. 'title': video_info['title'],
  80. 'description': video_info.get('description'),
  81. 'duration': parse_duration(video_info.get('video_length')),
  82. 'webpage_url': video_info.get('href') or video_info.get('url'),
  83. 'thumbnail': video_info.get('thumbnailURL'),
  84. 'alt_title': video_info.get('secondary_title'),
  85. 'timestamp': parse_iso8601(video_info.get('publishedDate')),
  86. 'subtitles': subtitles,
  87. })
  88. return self.playlist_result(entries, display_id, video_title)