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