ciscolive.py 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import (
  6. compat_urllib_parse_urlparse,
  7. compat_parse_qs
  8. )
  9. from ..utils import (
  10. clean_html,
  11. int_or_none,
  12. try_get,
  13. urlencode_postdata,
  14. )
  15. class CiscoLiveIE(InfoExtractor):
  16. IE_NAME = 'ciscolive'
  17. _VALID_URL = r'(?:https?://)?ciscolive\.cisco\.com/on-demand-library/\??(?P<query>[^#]+)#/(?:session/(?P<id>.+))?$'
  18. _TESTS = [
  19. {
  20. 'url': 'https://ciscolive.cisco.com/on-demand-library/?#/session/1423353499155001FoSs',
  21. 'md5': 'c98acf395ed9c9f766941c70f5352e22',
  22. 'info_dict': {
  23. 'id': '5803694304001',
  24. 'ext': 'mp4',
  25. 'title': '13 Smart Automations to Monitor Your Cisco IOS Network',
  26. 'description': 'md5:ec4a436019e09a918dec17714803f7cc',
  27. 'timestamp': 1530305395,
  28. 'uploader_id': '5647924234001',
  29. 'upload_date': '20180629',
  30. 'location': '16B Mezz.',
  31. },
  32. },
  33. {
  34. 'url': 'https://ciscolive.cisco.com/on-demand-library/?search.event=ciscoliveus2018&search.technicallevel=scpsSkillLevel_aintroductory&search.focus=scpsSessionFocus_designAndDeployment#/',
  35. 'md5': '993d4cf051f6174059328b1dce8e94bd',
  36. 'info_dict': {
  37. 'upload_date': '20180629',
  38. 'title': 'DevNet Panel-Applying Design Thinking to Building Products in Cisco',
  39. 'timestamp': 1530316421,
  40. 'uploader_id': '5647924234001',
  41. 'id': '5803751616001',
  42. 'description': 'md5:5f144575cd6848117fe2f756855b038b',
  43. 'location': 'WoS, DevNet Theater',
  44. 'ext': 'mp4',
  45. },
  46. },
  47. {
  48. 'url': 'https://ciscolive.cisco.com/on-demand-library/?search.technology=scpsTechnology_applicationDevelopment&search.technology=scpsTechnology_ipv6&search.focus=scpsSessionFocus_troubleshootingTroubleshooting#/',
  49. 'md5': '80e0c3b87e373fe3a3316b934b8915bf',
  50. 'info_dict': {
  51. 'upload_date': '20180629',
  52. 'title': 'Beating the CCIE Routing & Switching',
  53. 'timestamp': 1530311842,
  54. 'uploader_id': '5647924234001',
  55. 'id': '5803735679001',
  56. 'description': 'md5:e71970799e92d7f5ff57ae23f64b0929',
  57. 'location': 'Tulúm 02',
  58. 'ext': 'mp4',
  59. },
  60. }
  61. ]
  62. # These appear to be constant across all Cisco Live presentations
  63. # and are not tied to any user session or event
  64. RAINFOCUS_API_URL = 'https://events.rainfocus.com/api/%s'
  65. RAINFOCUS_APIPROFILEID = 'Na3vqYdAlJFSxhYTYQGuMbpafMqftalz'
  66. RAINFOCUS_WIDGETID = 'n6l4Lo05R8fiy3RpUBm447dZN8uNWoye'
  67. BRIGHTCOVE_URL_TEMPLATE = 'http://players.brightcove.net/5647924234001/SyK2FdqjM_default/index.html?videoId=%s'
  68. def _parse_rf_item(self, rf_item):
  69. ''' Parses metadata and passes to Brightcove extractor '''
  70. event_name = rf_item.get('eventName')
  71. title = rf_item['title']
  72. description = clean_html(rf_item.get('abstract'))
  73. presenter_name = try_get(rf_item, lambda x: x['participants'][0]['fullName'])
  74. bc_id = rf_item['videos'][0]['url']
  75. bc_url = self.BRIGHTCOVE_URL_TEMPLATE % bc_id
  76. duration = int_or_none(try_get(rf_item, lambda x: x['times'][0]['length']))
  77. location = try_get(rf_item, lambda x: x['times'][0]['room'])
  78. if duration:
  79. duration = duration * 60
  80. return {
  81. '_type': 'url_transparent',
  82. 'creator': presenter_name,
  83. 'description': description,
  84. 'duration': duration,
  85. 'ie_key': 'BrightcoveNew',
  86. 'location': location,
  87. 'series': event_name,
  88. 'title': title,
  89. 'url': bc_url,
  90. }
  91. def _check_bc_id_exists(self, rf_item):
  92. ''' Checks for the existence of a Brightcove URL in an API result '''
  93. bc_id = try_get(rf_item, lambda x: x['videos'][0]['url'])
  94. if bc_id:
  95. if bc_id.strip().isdigit():
  96. return rf_item
  97. def _real_extract(self, url):
  98. mobj = re.match(self._VALID_URL, url)
  99. HEADERS = {
  100. 'Origin': 'https://ciscolive.cisco.com',
  101. 'rfApiProfileId': self.RAINFOCUS_APIPROFILEID,
  102. 'rfWidgetId': self.RAINFOCUS_WIDGETID,
  103. 'Referer': url,
  104. }
  105. # Single session URL (single video)
  106. if mobj.group('id'):
  107. rf_id = mobj.group('id')
  108. request = self.RAINFOCUS_API_URL % 'session'
  109. data = urlencode_postdata({'id': rf_id})
  110. rf_result = self._download_json(request, rf_id, data=data, headers=HEADERS)
  111. rf_item = self._check_bc_id_exists(rf_result['items'][0])
  112. return self._parse_rf_item(rf_item)
  113. else:
  114. # Filter query URL (multiple videos)
  115. rf_query = compat_parse_qs((compat_urllib_parse_urlparse(url).query))
  116. rf_query['type'] = 'session'
  117. rf_query['size'] = 1000
  118. data = urlencode_postdata(rf_query)
  119. request = self.RAINFOCUS_API_URL % 'search'
  120. rf_results = self._download_json(request, 'Filter query', data=data, headers=HEADERS)
  121. entries = [
  122. self._parse_rf_item(rf_item)
  123. for rf_item
  124. in rf_results['sectionList'][0]['items']
  125. if self._check_bc_id_exists(rf_item)
  126. ]
  127. return self.playlist_result(entries, 'Filter query')