[screencast] Add new extractor (Fixes #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     compat_parse_qs,
9     compat_urllib_request,
10 )
11
12
13 class ScreencastIE(InfoExtractor):
14     _VALID_URL = r'https?://www\.screencast\.com/t/(?P<id>[a-zA-Z0-9]+)'
15     _TEST = {
16         'url': 'http://www.screencast.com/t/3ZEjQXlT',
17         'md5': '917df1c13798a3e96211dd1561fded83',
18         'info_dict': {
19             'id': '3ZEjQXlT',
20             'ext': 'm4v',
21             'title': 'Color Measurement with Ocean Optics Spectrometers',
22             'description': 'md5:240369cde69d8bed61349a199c5fb153',
23             'thumbnail': 're:^https?://.*\.jpg$'
24         }
25     }
26
27     def _real_extract(self, url):
28         mobj = re.match(self._VALID_URL, url)
29         video_id = mobj.group('id')
30         webpage = self._download_webpage(url, video_id)
31
32         flash_vars_s = self._html_search_regex(
33             r'<param name="flashVars" value="([^"]+)"', webpage, 'flash vars')
34         flash_vars = compat_parse_qs(flash_vars_s)
35
36         thumbnail = flash_vars.get('thumb', [None])[0]
37         video_url_raw = compat_urllib_request.quote(flash_vars['content'][0])
38         video_url = video_url_raw.replace('http%3A', 'http:')
39         title = self._og_search_title(webpage)
40         description = self._og_search_description(webpage)
41
42         return {
43             'id': video_id,
44             'url': video_url,
45             'title': title,
46             'description': description,
47             'thumbnail': thumbnail,
48         }