[helsinki] Simplify
[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     IE_DESC = 'helsinki.fi'
12     _VALID_URL = r'https?://video\.helsinki\.fi/Arkisto/flash\.php\?id=(?P<id>\d+)'
13     _TEST = {
14         'url': 'http://video.helsinki.fi/Arkisto/flash.php?id=20258',
15         'info_dict': {
16             'id': '20258',
17             'ext': 'mp4',
18             'title': 'Tietotekniikkafoorumi-iltapäivä',
19             'description': 'md5:f5c904224d43c133225130fe156a5ee0',
20         },
21         'params': {
22             'skip_download': True,  # RTMP
23         }
24     }
25
26     def _real_extract(self, url):
27         mobj = re.match(self._VALID_URL, url)
28         video_id = mobj.group('id')
29         webpage = self._download_webpage(url, video_id)
30         formats = []
31
32         mobj = re.search(r'file=((\w+):[^&]+)', webpage)
33         if mobj:
34             formats.append({
35                 'ext': mobj.group(2),
36                 'play_path': mobj.group(1),
37                 'url': 'rtmp://flashvideo.it.helsinki.fi/vod/',
38                 'player_url': 'http://video.helsinki.fi/player.swf',
39                 'format_note': 'sd',
40                 'quality': 0,
41             })
42
43         mobj = re.search(r'hd\.file=((\w+):[^&]+)', webpage)
44         if mobj:
45             formats.append({
46                 'ext': mobj.group(2),
47                 'play_path': mobj.group(1),
48                 'url': 'rtmp://flashvideo.it.helsinki.fi/vod/',
49                 'player_url': 'http://video.helsinki.fi/player.swf',
50                 'format_note': 'hd',
51                 'quality': 1,
52             })
53
54         self._sort_formats(formats)
55
56         return {
57             'id': video_id,
58             'title': self._og_search_title(webpage).replace('Video: ', ''),
59             'description': self._og_search_description(webpage),
60             'thumbnail': self._og_search_thumbnail(webpage),
61             'formats': formats,
62         }