discovery.py 3.6 KB

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