screencast.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import urllib.parse
  2. from .common import InfoExtractor
  3. from ..utils import ExtractorError
  4. class ScreencastIE(InfoExtractor):
  5. _VALID_URL = r'https?://(?:www\.)?screencast\.com/t/(?P<id>[a-zA-Z0-9]+)'
  6. _TESTS = [{
  7. 'url': 'http://www.screencast.com/t/3ZEjQXlT',
  8. 'md5': '917df1c13798a3e96211dd1561fded83',
  9. 'info_dict': {
  10. 'id': '3ZEjQXlT',
  11. 'ext': 'm4v',
  12. 'title': 'Color Measurement with Ocean Optics Spectrometers',
  13. 'description': 'md5:240369cde69d8bed61349a199c5fb153',
  14. 'thumbnail': r're:^https?://.*\.(?:gif|jpg)$',
  15. },
  16. }, {
  17. 'url': 'http://www.screencast.com/t/V2uXehPJa1ZI',
  18. 'md5': 'e8e4b375a7660a9e7e35c33973410d34',
  19. 'info_dict': {
  20. 'id': 'V2uXehPJa1ZI',
  21. 'ext': 'mov',
  22. 'title': 'The Amadeus Spectrometer',
  23. 'description': 're:^In this video, our friends at.*To learn more about Amadeus, visit',
  24. 'thumbnail': r're:^https?://.*\.(?:gif|jpg)$',
  25. },
  26. }, {
  27. 'url': 'http://www.screencast.com/t/aAB3iowa',
  28. 'md5': 'dedb2734ed00c9755761ccaee88527cd',
  29. 'info_dict': {
  30. 'id': 'aAB3iowa',
  31. 'ext': 'mp4',
  32. 'title': 'Google Earth Export',
  33. 'description': 'Provides a demo of a CommunityViz export to Google Earth, one of the 3D viewing options.',
  34. 'thumbnail': r're:^https?://.*\.(?:gif|jpg)$',
  35. },
  36. }, {
  37. 'url': 'http://www.screencast.com/t/X3ddTrYh',
  38. 'md5': '669ee55ff9c51988b4ebc0877cc8b159',
  39. 'info_dict': {
  40. 'id': 'X3ddTrYh',
  41. 'ext': 'wmv',
  42. 'title': 'Toolkit 6 User Group Webinar (2014-03-04) - Default Judgment and First Impression',
  43. 'description': 'md5:7b9f393bc92af02326a5c5889639eab0',
  44. 'thumbnail': r're:^https?://.*\.(?:gif|jpg)$',
  45. },
  46. }, {
  47. 'url': 'http://screencast.com/t/aAB3iowa',
  48. 'only_matching': True,
  49. }]
  50. def _real_extract(self, url):
  51. video_id = self._match_id(url)
  52. webpage = self._download_webpage(url, video_id)
  53. video_url = self._html_search_regex(
  54. r'<embed name="Video".*?src="([^"]+)"', webpage,
  55. 'QuickTime embed', default=None)
  56. if video_url is None:
  57. flash_vars_s = self._html_search_regex(
  58. r'<param name="flashVars" value="([^"]+)"', webpage, 'flash vars',
  59. default=None)
  60. if not flash_vars_s:
  61. flash_vars_s = self._html_search_regex(
  62. r'<param name="initParams" value="([^"]+)"', webpage, 'flash vars',
  63. default=None)
  64. if flash_vars_s:
  65. flash_vars_s = flash_vars_s.replace(',', '&')
  66. if flash_vars_s:
  67. flash_vars = urllib.parse.parse_qs(flash_vars_s)
  68. video_url_raw = urllib.parse.quote(
  69. flash_vars['content'][0])
  70. video_url = video_url_raw.replace('http%3A', 'http:')
  71. if video_url is None:
  72. video_meta = self._html_search_meta(
  73. 'og:video', webpage, default=None)
  74. if video_meta:
  75. video_url = self._search_regex(
  76. r'src=(.*?)(?:$|&)', video_meta,
  77. 'meta tag video URL', default=None)
  78. if video_url is None:
  79. video_url = self._html_search_regex(
  80. r'MediaContentUrl["\']\s*:(["\'])(?P<url>(?:(?!\1).)+)\1',
  81. webpage, 'video url', default=None, group='url')
  82. if video_url is None:
  83. video_url = self._html_search_meta(
  84. 'og:video', webpage, default=None)
  85. if video_url is None:
  86. raise ExtractorError('Cannot find video')
  87. title = self._og_search_title(webpage, default=None)
  88. if title is None:
  89. title = self._html_search_regex(
  90. [r'<b>Title:</b> ([^<]+)</div>',
  91. r'class="tabSeperator">></span><span class="tabText">(.+?)<',
  92. r'<title>([^<]+)</title>'],
  93. webpage, 'title')
  94. thumbnail = self._og_search_thumbnail(webpage)
  95. description = self._og_search_description(webpage, default=None)
  96. if description is None:
  97. description = self._html_search_meta('description', webpage)
  98. return {
  99. 'id': video_id,
  100. 'url': video_url,
  101. 'title': title,
  102. 'description': description,
  103. 'thumbnail': thumbnail,
  104. }