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.

95 lines
3.4 KiB

  1. # -*- coding: utf-8 -*-
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. ExtractorError,
  7. compat_parse_qs,
  8. compat_urllib_request,
  9. )
  10. class ScreencastIE(InfoExtractor):
  11. _VALID_URL = r'https?://www\.screencast\.com/t/(?P<id>[a-zA-Z0-9]+)'
  12. _TESTS = [{
  13. 'url': 'http://www.screencast.com/t/3ZEjQXlT',
  14. 'md5': '917df1c13798a3e96211dd1561fded83',
  15. 'info_dict': {
  16. 'id': '3ZEjQXlT',
  17. 'ext': 'm4v',
  18. 'title': 'Color Measurement with Ocean Optics Spectrometers',
  19. 'description': 'md5:240369cde69d8bed61349a199c5fb153',
  20. 'thumbnail': 're:^https?://.*\.(?:gif|jpg)$',
  21. }
  22. }, {
  23. 'url': 'http://www.screencast.com/t/V2uXehPJa1ZI',
  24. 'md5': 'e8e4b375a7660a9e7e35c33973410d34',
  25. 'info_dict': {
  26. 'id': 'V2uXehPJa1ZI',
  27. 'ext': 'mov',
  28. 'title': 'The Amadeus Spectrometer',
  29. 'description': 're:^In this video, our friends at.*To learn more about Amadeus, visit',
  30. 'thumbnail': 're:^https?://.*\.(?:gif|jpg)$',
  31. }
  32. }, {
  33. 'url': 'http://www.screencast.com/t/aAB3iowa',
  34. 'md5': 'dedb2734ed00c9755761ccaee88527cd',
  35. 'info_dict': {
  36. 'id': 'aAB3iowa',
  37. 'ext': 'mp4',
  38. 'title': 'Google Earth Export',
  39. 'description': 'Provides a demo of a CommunityViz export to Google Earth, one of the 3D viewing options.',
  40. 'thumbnail': 're:^https?://.*\.(?:gif|jpg)$',
  41. }
  42. },
  43. ]
  44. def _real_extract(self, url):
  45. mobj = re.match(self._VALID_URL, url)
  46. video_id = mobj.group('id')
  47. webpage = self._download_webpage(url, video_id)
  48. video_url = self._html_search_regex(
  49. r'<embed name="Video".*?src="([^"]+)"', webpage,
  50. 'QuickTime embed', default=None)
  51. if video_url is None:
  52. flash_vars_s = self._html_search_regex(
  53. r'<param name="flashVars" value="([^"]+)"', webpage, 'flash vars',
  54. default=None)
  55. if flash_vars_s:
  56. flash_vars = compat_parse_qs(flash_vars_s)
  57. video_url_raw = compat_urllib_request.quote(
  58. flash_vars['content'][0])
  59. video_url = video_url_raw.replace('http%3A', 'http:')
  60. if video_url is None:
  61. video_meta = self._html_search_meta(
  62. 'og:video', webpage, default=None)
  63. if video_meta:
  64. video_url = self._search_regex(
  65. r'src=(.*?)(?:$|&)', video_meta,
  66. 'meta tag video URL', default=None)
  67. if video_url is None:
  68. raise ExtractorError('Cannot find video')
  69. title = self._og_search_title(webpage, default=None)
  70. if title is None:
  71. title = self._html_search_regex(
  72. r'class="tabSeperator">></span><span class="tabText">(.*?)<',
  73. webpage, 'title')
  74. thumbnail = self._og_search_thumbnail(webpage)
  75. description = self._og_search_description(webpage, default=None)
  76. if description is None:
  77. description = self._html_search_meta('description', webpage)
  78. return {
  79. 'id': video_id,
  80. 'url': video_url,
  81. 'title': title,
  82. 'description': description,
  83. 'thumbnail': thumbnail,
  84. }