Add support for video.helsinki.fi archives
[youtube-dl] / youtube_dl / extractor / helsinki.py
1 # -*- coding: utf-8 -*-
2
3 from __future__ import unicode_literals
4
5 import re
6
7 from .common import InfoExtractor
8
9
10 class HelsinkiIE(InfoExtractor):
11     _VALID_URL = r'https?://video\.helsinki\.fi/Arkisto/flash\.php\?id=(?P<id>\d+)'
12     _TEST = {
13         'url': 'http://video.helsinki.fi/Arkisto/flash.php?id=20258',
14         'md5': 'cd829201b890905682eb194cbdea55d7',
15         'info_dict': {
16             'id': '20258',
17             'ext': 'mp4',
18             'title': 'Tietotekniikkafoorumi-iltapäivä',
19         }
20     }
21
22     def _real_extract(self, url):
23         mobj = re.match(self._VALID_URL, url)
24         vid = mobj.group('id')
25         webpage = self._download_webpage(url, vid)
26         formats = []
27         mobj = re.search('file=((\w+):[^&]+)', webpage)
28         if mobj: formats.append({
29             'ext': mobj.group(2),
30             'play_path': mobj.group(1),
31             'url': 'rtmp://flashvideo.it.helsinki.fi/vod/',
32             'player_url': 'http://video.helsinki.fi/player.swf',
33             'format_note': 'sd'
34         })
35
36         mobj = re.search('hd\.file=((\w+):[^&]+)', webpage)
37         if mobj: formats.append({
38             'ext': mobj.group(2),
39             'play_path': mobj.group(1),
40             'url': 'rtmp://flashvideo.it.helsinki.fi/vod/',
41             'player_url': 'http://video.helsinki.fi/player.swf',
42             'format_note': 'hd'
43         })
44
45         return {
46             'id': vid,
47             'title': self._og_search_title(webpage).replace('Video: ', ''),
48             'description': self._og_search_description(webpage),
49             'thumbnail': self._og_search_thumbnail(webpage),
50             'formats': formats
51         }