logo

youtube-dl

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

ciscolive.py (6024B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import itertools
  4. from .common import InfoExtractor
  5. from ..compat import (
  6. compat_parse_qs,
  7. compat_urllib_parse_urlparse,
  8. )
  9. from ..utils import (
  10. clean_html,
  11. float_or_none,
  12. int_or_none,
  13. try_get,
  14. urlencode_postdata,
  15. )
  16. class CiscoLiveBaseIE(InfoExtractor):
  17. # These appear to be constant across all Cisco Live presentations
  18. # and are not tied to any user session or event
  19. RAINFOCUS_API_URL = 'https://events.rainfocus.com/api/%s'
  20. RAINFOCUS_API_PROFILE_ID = 'Na3vqYdAlJFSxhYTYQGuMbpafMqftalz'
  21. RAINFOCUS_WIDGET_ID = 'n6l4Lo05R8fiy3RpUBm447dZN8uNWoye'
  22. BRIGHTCOVE_URL_TEMPLATE = 'http://players.brightcove.net/5647924234001/SyK2FdqjM_default/index.html?videoId=%s'
  23. HEADERS = {
  24. 'Origin': 'https://ciscolive.cisco.com',
  25. 'rfApiProfileId': RAINFOCUS_API_PROFILE_ID,
  26. 'rfWidgetId': RAINFOCUS_WIDGET_ID,
  27. }
  28. def _call_api(self, ep, rf_id, query, referrer, note=None):
  29. headers = self.HEADERS.copy()
  30. headers['Referer'] = referrer
  31. return self._download_json(
  32. self.RAINFOCUS_API_URL % ep, rf_id, note=note,
  33. data=urlencode_postdata(query), headers=headers)
  34. def _parse_rf_item(self, rf_item):
  35. event_name = rf_item.get('eventName')
  36. title = rf_item['title']
  37. description = clean_html(rf_item.get('abstract'))
  38. presenter_name = try_get(rf_item, lambda x: x['participants'][0]['fullName'])
  39. bc_id = rf_item['videos'][0]['url']
  40. bc_url = self.BRIGHTCOVE_URL_TEMPLATE % bc_id
  41. duration = float_or_none(try_get(rf_item, lambda x: x['times'][0]['length']))
  42. location = try_get(rf_item, lambda x: x['times'][0]['room'])
  43. if duration:
  44. duration = duration * 60
  45. return {
  46. '_type': 'url_transparent',
  47. 'url': bc_url,
  48. 'ie_key': 'BrightcoveNew',
  49. 'title': title,
  50. 'description': description,
  51. 'duration': duration,
  52. 'creator': presenter_name,
  53. 'location': location,
  54. 'series': event_name,
  55. }
  56. class CiscoLiveSessionIE(CiscoLiveBaseIE):
  57. _VALID_URL = r'https?://(?:www\.)?ciscolive(?:\.cisco)?\.com/[^#]*#/session/(?P<id>[^/?&]+)'
  58. _TESTS = [{
  59. 'url': 'https://ciscolive.cisco.com/on-demand-library/?#/session/1423353499155001FoSs',
  60. 'md5': 'c98acf395ed9c9f766941c70f5352e22',
  61. 'info_dict': {
  62. 'id': '5803694304001',
  63. 'ext': 'mp4',
  64. 'title': '13 Smart Automations to Monitor Your Cisco IOS Network',
  65. 'description': 'md5:ec4a436019e09a918dec17714803f7cc',
  66. 'timestamp': 1530305395,
  67. 'upload_date': '20180629',
  68. 'uploader_id': '5647924234001',
  69. 'location': '16B Mezz.',
  70. },
  71. }, {
  72. 'url': 'https://www.ciscolive.com/global/on-demand-library.html?search.event=ciscoliveemea2019#/session/15361595531500013WOU',
  73. 'only_matching': True,
  74. }, {
  75. 'url': 'https://www.ciscolive.com/global/on-demand-library.html?#/session/1490051371645001kNaS',
  76. 'only_matching': True,
  77. }]
  78. def _real_extract(self, url):
  79. rf_id = self._match_id(url)
  80. rf_result = self._call_api('session', rf_id, {'id': rf_id}, url)
  81. return self._parse_rf_item(rf_result['items'][0])
  82. class CiscoLiveSearchIE(CiscoLiveBaseIE):
  83. _VALID_URL = r'https?://(?:www\.)?ciscolive(?:\.cisco)?\.com/(?:global/)?on-demand-library(?:\.html|/)'
  84. _TESTS = [{
  85. 'url': 'https://ciscolive.cisco.com/on-demand-library/?search.event=ciscoliveus2018&search.technicallevel=scpsSkillLevel_aintroductory&search.focus=scpsSessionFocus_designAndDeployment#/',
  86. 'info_dict': {
  87. 'title': 'Search query',
  88. },
  89. 'playlist_count': 5,
  90. }, {
  91. 'url': 'https://ciscolive.cisco.com/on-demand-library/?search.technology=scpsTechnology_applicationDevelopment&search.technology=scpsTechnology_ipv6&search.focus=scpsSessionFocus_troubleshootingTroubleshooting#/',
  92. 'only_matching': True,
  93. }, {
  94. 'url': 'https://www.ciscolive.com/global/on-demand-library.html?search.technicallevel=scpsSkillLevel_aintroductory&search.event=ciscoliveemea2019&search.technology=scpsTechnology_dataCenter&search.focus=scpsSessionFocus_bestPractices#/',
  95. 'only_matching': True,
  96. }]
  97. @classmethod
  98. def suitable(cls, url):
  99. return False if CiscoLiveSessionIE.suitable(url) else super(CiscoLiveSearchIE, cls).suitable(url)
  100. @staticmethod
  101. def _check_bc_id_exists(rf_item):
  102. return int_or_none(try_get(rf_item, lambda x: x['videos'][0]['url'])) is not None
  103. def _entries(self, query, url):
  104. query['size'] = 50
  105. query['from'] = 0
  106. for page_num in itertools.count(1):
  107. results = self._call_api(
  108. 'search', None, query, url,
  109. 'Downloading search JSON page %d' % page_num)
  110. sl = try_get(results, lambda x: x['sectionList'][0], dict)
  111. if sl:
  112. results = sl
  113. items = results.get('items')
  114. if not items or not isinstance(items, list):
  115. break
  116. for item in items:
  117. if not isinstance(item, dict):
  118. continue
  119. if not self._check_bc_id_exists(item):
  120. continue
  121. yield self._parse_rf_item(item)
  122. size = int_or_none(results.get('size'))
  123. if size is not None:
  124. query['size'] = size
  125. total = int_or_none(results.get('total'))
  126. if total is not None and query['from'] + query['size'] > total:
  127. break
  128. query['from'] += query['size']
  129. def _real_extract(self, url):
  130. query = compat_parse_qs(compat_urllib_parse_urlparse(url).query)
  131. query['type'] = 'session'
  132. return self.playlist_result(
  133. self._entries(query, url), playlist_title='Search query')