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.

80 lines
3.0 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)http://(?: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. },
  34. 'params': {
  35. 'skip_download': True, # requires ffmpeg
  36. }
  37. }, {
  38. 'url': 'http://www.discovery.com/tv-shows/mythbusters/videos/mythbusters-the-simpsons',
  39. 'info_dict': {
  40. 'id': 'mythbusters-the-simpsons',
  41. 'title': 'MythBusters: The Simpsons',
  42. },
  43. 'playlist_mincount': 10,
  44. }, {
  45. 'url': 'http://www.animalplanet.com/longfin-eels-maneaters/',
  46. 'info_dict': {
  47. 'id': '78326',
  48. 'ext': 'mp4',
  49. 'title': 'Longfin Eels: Maneaters?',
  50. '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.',
  51. 'upload_date': '20140725',
  52. 'timestamp': 1406246400,
  53. 'duration': 116,
  54. },
  55. }]
  56. def _real_extract(self, url):
  57. display_id = self._match_id(url)
  58. info = self._download_json(url + '?flat=1', display_id)
  59. video_title = info.get('playlist_title') or info.get('video_title')
  60. entries = [{
  61. 'id': compat_str(video_info['id']),
  62. 'formats': self._extract_m3u8_formats(
  63. video_info['src'], display_id, 'mp4', 'm3u8_native', m3u8_id='hls',
  64. note='Download m3u8 information for video %d' % (idx + 1)),
  65. 'title': video_info['title'],
  66. 'description': video_info.get('description'),
  67. 'duration': parse_duration(video_info.get('video_length')),
  68. 'webpage_url': video_info.get('href') or video_info.get('url'),
  69. 'thumbnail': video_info.get('thumbnailURL'),
  70. 'alt_title': video_info.get('secondary_title'),
  71. 'timestamp': parse_iso8601(video_info.get('publishedDate')),
  72. } for idx, video_info in enumerate(info['playlist'])]
  73. return self.playlist_result(entries, display_id, video_title)