[oppetarkiv] Extract f4m formats and age limit
[youtube-dl] / youtube_dl / extractor / oppetarkiv.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import (
6     determine_ext,
7 )
8
9
10 class OppetArkivIE(InfoExtractor):
11     _VALID_URL = r'https?://(?:www\.)?oppetarkiv\.se/video/(?P<id>[0-9]+)'
12     _TEST = {
13         'url': 'http://www.oppetarkiv.se/video/1058509/rederiet-sasong-1-avsnitt-1-av-318',
14         'md5': '5c1eb616e59f733d4af77edc5177d2fe',
15         'info_dict': {
16             'id': '1058509',
17             'ext': 'flv',
18             'title': 'Farlig kryssning',
19             'duration': 2566,
20             'thumbnail': 're:^https?://.*[\.-]jpg$',
21             'age_limit': 0,
22         },
23         'skip': 'Only works from Sweden',
24     }
25
26     def _real_extract(self, url):
27         video_id = self._match_id(url)
28         info = self._download_json(
29             'http://www.oppetarkiv.se/video/%s?output=json' % video_id, video_id)
30
31         title = info['context']['title']
32         thumbnail = info['context'].get('thumbnailImage')
33
34         video_info = info['video']
35         formats = []
36         for vr in video_info['videoReferences']:
37             vurl = vr['url']
38             ext = determine_ext(vurl)
39             if ext == 'm3u8':
40                 formats.extend(self._extract_m3u8_formats(
41                     vurl, video_id,
42                     ext='mp4', entry_protocol='m3u8_native',
43                     m3u8_id=vr.get('playerType')))
44             elif ext == 'f4m':
45                 formats.extend(self._extract_f4m_formats(
46                     vurl + '?hdcore=3.3.0', video_id,
47                     f4m_id=vr.get('playerType')))
48             else:
49                 formats.append({
50                     'format_id': vr.get('playerType'),
51                     'url': vurl,
52                 })
53         self._sort_formats(formats)
54
55         duration = video_info.get('materialLength')
56
57         age_limit = 18 if video_info.get('inappropriateForChildren') else 0
58
59         return {
60             'id': video_id,
61             'title': title,
62             'formats': formats,
63             'thumbnail': thumbnail,
64             'duration': duration,
65             'age_limit': age_limit,
66         }