logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

huffpost.py (3389B)


  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. determine_ext,
  6. parse_duration,
  7. unified_strdate,
  8. )
  9. class HuffPostIE(InfoExtractor):
  10. IE_DESC = 'Huffington Post'
  11. _VALID_URL = r'''(?x)
  12. https?://(embed\.)?live\.huffingtonpost\.com/
  13. (?:
  14. r/segment/[^/]+/|
  15. HPLEmbedPlayer/\?segmentId=
  16. )
  17. (?P<id>[0-9a-f]+)'''
  18. _TEST = {
  19. 'url': 'http://live.huffingtonpost.com/r/segment/legalese-it/52dd3e4b02a7602131000677',
  20. 'md5': '55f5e8981c1c80a64706a44b74833de8',
  21. 'info_dict': {
  22. 'id': '52dd3e4b02a7602131000677',
  23. 'ext': 'mp4',
  24. 'title': 'Legalese It! with @MikeSacksHP',
  25. 'description': 'This week on Legalese It, Mike talks to David Bosco about his new book on the ICC, "Rough Justice," he also discusses the Virginia AG\'s historic stance on gay marriage, the execution of Edgar Tamayo, the ICC\'s delay of Kenya\'s President and more. ',
  26. 'duration': 1549,
  27. 'upload_date': '20140124',
  28. },
  29. 'params': {
  30. # m3u8 download
  31. 'skip_download': True,
  32. },
  33. 'expected_warnings': ['HTTP Error 404: Not Found'],
  34. }
  35. def _real_extract(self, url):
  36. video_id = self._match_id(url)
  37. api_url = 'http://embed.live.huffingtonpost.com/api/segments/%s.json' % video_id
  38. data = self._download_json(api_url, video_id)['data']
  39. video_title = data['title']
  40. duration = parse_duration(data.get('running_time'))
  41. upload_date = unified_strdate(
  42. data.get('schedule', {}).get('starts_at') or data.get('segment_start_date_time'))
  43. description = data.get('description')
  44. thumbnails = []
  45. for url in filter(None, data['images'].values()):
  46. m = re.match(r'.*-([0-9]+x[0-9]+)\.', url)
  47. if not m:
  48. continue
  49. thumbnails.append({
  50. 'url': url,
  51. 'resolution': m.group(1),
  52. })
  53. formats = []
  54. sources = data.get('sources', {})
  55. live_sources = list(sources.get('live', {}).items()) + list(sources.get('live_again', {}).items())
  56. for key, url in live_sources:
  57. ext = determine_ext(url)
  58. if ext == 'm3u8':
  59. formats.extend(self._extract_m3u8_formats(
  60. url, video_id, ext='mp4', m3u8_id='hls', fatal=False))
  61. elif ext == 'f4m':
  62. formats.extend(self._extract_f4m_formats(
  63. url + '?hdcore=2.9.5', video_id, f4m_id='hds', fatal=False))
  64. else:
  65. formats.append({
  66. 'format': key,
  67. 'format_id': key.replace('/', '.'),
  68. 'ext': 'mp4',
  69. 'url': url,
  70. 'vcodec': 'none' if key.startswith('audio/') else None,
  71. })
  72. if not formats and data.get('fivemin_id'):
  73. return self.url_result('5min:%s' % data['fivemin_id'])
  74. self._sort_formats(formats)
  75. return {
  76. 'id': video_id,
  77. 'title': video_title,
  78. 'description': description,
  79. 'formats': formats,
  80. 'duration': duration,
  81. 'upload_date': upload_date,
  82. 'thumbnails': thumbnails,
  83. }