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.

82 lines
2.7 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. parse_duration,
  6. unified_strdate,
  7. )
  8. class HuffPostIE(InfoExtractor):
  9. IE_DESC = 'Huffington Post'
  10. _VALID_URL = r'''(?x)
  11. https?://(embed\.)?live\.huffingtonpost\.com/
  12. (?:
  13. r/segment/[^/]+/|
  14. HPLEmbedPlayer/\?segmentId=
  15. )
  16. (?P<id>[0-9a-f]+)'''
  17. _TEST = {
  18. 'url': 'http://live.huffingtonpost.com/r/segment/legalese-it/52dd3e4b02a7602131000677',
  19. 'md5': '55f5e8981c1c80a64706a44b74833de8',
  20. 'info_dict': {
  21. 'id': '52dd3e4b02a7602131000677',
  22. 'ext': 'mp4',
  23. 'title': 'Legalese It! with @MikeSacksHP',
  24. '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. ',
  25. 'duration': 1549,
  26. 'upload_date': '20140124',
  27. }
  28. }
  29. def _real_extract(self, url):
  30. video_id = self._match_id(url)
  31. api_url = 'http://embed.live.huffingtonpost.com/api/segments/%s.json' % video_id
  32. data = self._download_json(api_url, video_id)['data']
  33. video_title = data['title']
  34. duration = parse_duration(data['running_time'])
  35. upload_date = unified_strdate(data['schedule']['starts_at'])
  36. description = data.get('description')
  37. thumbnails = []
  38. for url in data['images'].values():
  39. m = re.match('.*-([0-9]+x[0-9]+)\.', url)
  40. if not m:
  41. continue
  42. thumbnails.append({
  43. 'url': url,
  44. 'resolution': m.group(1),
  45. })
  46. formats = [{
  47. 'format': key,
  48. 'format_id': key.replace('/', '.'),
  49. 'ext': 'mp4',
  50. 'url': url,
  51. 'vcodec': 'none' if key.startswith('audio/') else None,
  52. } for key, url in data['sources']['live'].items()]
  53. if data.get('fivemin_id'):
  54. fid = data['fivemin_id']
  55. fcat = str(int(fid) // 100 + 1)
  56. furl = 'http://avideos.5min.com/2/' + fcat[-3:] + '/' + fcat + '/' + fid + '.mp4'
  57. formats.append({
  58. 'format': 'fivemin',
  59. 'url': furl,
  60. 'preference': 1,
  61. })
  62. self._sort_formats(formats)
  63. return {
  64. 'id': video_id,
  65. 'title': video_title,
  66. 'description': description,
  67. 'formats': formats,
  68. 'duration': duration,
  69. 'upload_date': upload_date,
  70. 'thumbnails': thumbnails,
  71. }