screencast.py 4.5 KB

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