]>
Commit | Line | Data |
---|---|---|
22354455 HL |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
4 | from .common import InfoExtractor | |
5 | from ..compat import compat_urllib_parse_urlparse | |
9414338a S |
6 | from ..utils import ( |
7 | determine_ext, | |
db75f14d | 8 | ExtractorError, |
9414338a | 9 | int_or_none, |
22889ab1 | 10 | xpath_attr, |
9414338a S |
11 | xpath_text, |
12 | ) | |
22354455 HL |
13 | |
14 | ||
15 | class RuutuIE(InfoExtractor): | |
73498a89 | 16 | _VALID_URL = r'https?://(?:www\.)?(?:ruutu|supla)\.fi/(?:video|supla)/(?P<id>\d+)' |
22354455 HL |
17 | _TESTS = [ |
18 | { | |
22889ab1 | 19 | 'url': 'http://www.ruutu.fi/video/2058907', |
22354455 HL |
20 | 'md5': 'ab2093f39be1ca8581963451b3c0234f', |
21 | 'info_dict': { | |
9414338a | 22 | 'id': '2058907', |
22354455 HL |
23 | 'ext': 'mp4', |
24 | 'title': 'Oletko aina halunnut tietää mitä tapahtuu vain hetki ennen lähetystä? - Nyt se selvisi!', | |
9414338a | 25 | 'description': 'md5:cfc6ccf0e57a814360df464a91ff67d6', |
ec85ded8 | 26 | 'thumbnail': r're:^https?://.*\.jpg$', |
9414338a S |
27 | 'duration': 114, |
28 | 'age_limit': 0, | |
22354455 | 29 | }, |
22354455 HL |
30 | }, |
31 | { | |
c482b3c6 | 32 | 'url': 'http://www.ruutu.fi/video/2057306', |
22354455 HL |
33 | 'md5': '065a10ae4d5b8cfd9d0c3d332465e3d9', |
34 | 'info_dict': { | |
9414338a | 35 | 'id': '2057306', |
22354455 HL |
36 | 'ext': 'mp4', |
37 | 'title': 'Superpesis: katso koko kausi Ruudussa', | |
73498a89 | 38 | 'description': 'md5:bfb7336df2a12dc21d18fa696c9f8f23', |
ec85ded8 | 39 | 'thumbnail': r're:^https?://.*\.jpg$', |
9414338a S |
40 | 'duration': 40, |
41 | 'age_limit': 0, | |
22354455 | 42 | }, |
22354455 | 43 | }, |
73498a89 | 44 | { |
45 | 'url': 'http://www.supla.fi/supla/2231370', | |
46 | 'md5': 'df14e782d49a2c0df03d3be2a54ef949', | |
47 | 'info_dict': { | |
48 | 'id': '2231370', | |
49 | 'ext': 'mp4', | |
50 | 'title': 'Osa 1: Mikael Jungner', | |
51 | 'description': 'md5:7d90f358c47542e3072ff65d7b1bcffe', | |
ec85ded8 | 52 | 'thumbnail': r're:^https?://.*\.jpg$', |
73498a89 | 53 | 'age_limit': 0, |
54 | }, | |
55 | }, | |
2e25f80d TV |
56 | # Episode where <SourceFile> is "NOT-USED", but has other |
57 | # downloadable sources available. | |
58 | { | |
59 | 'url': 'http://www.ruutu.fi/video/3193728', | |
60 | 'only_matching': True, | |
61 | }, | |
22354455 HL |
62 | ] |
63 | ||
64 | def _real_extract(self, url): | |
22889ab1 | 65 | video_id = self._match_id(url) |
22354455 | 66 | |
22889ab1 S |
67 | video_xml = self._download_xml( |
68 | 'http://gatling.ruutu.fi/media-xml-cache?id=%s' % video_id, video_id) | |
22354455 HL |
69 | |
70 | formats = [] | |
9414338a S |
71 | processed_urls = [] |
72 | ||
73 | def extract_formats(node): | |
74 | for child in node: | |
75 | if child.tag.endswith('Files'): | |
76 | extract_formats(child) | |
77 | elif child.tag.endswith('File'): | |
78 | video_url = child.text | |
5d6c3d6a S |
79 | if (not video_url or video_url in processed_urls or |
80 | any(p in video_url for p in ('NOT_USED', 'NOT-USED'))): | |
2e25f80d | 81 | continue |
9414338a S |
82 | processed_urls.append(video_url) |
83 | ext = determine_ext(video_url) | |
84 | if ext == 'm3u8': | |
7e5edcfd S |
85 | formats.extend(self._extract_m3u8_formats( |
86 | video_url, video_id, 'mp4', m3u8_id='hls', fatal=False)) | |
9414338a | 87 | elif ext == 'f4m': |
7e5edcfd S |
88 | formats.extend(self._extract_f4m_formats( |
89 | video_url, video_id, f4m_id='hds', fatal=False)) | |
dadb8361 | 90 | elif ext == 'mpd': |
4d345bf1 S |
91 | # video-only and audio-only streams are of different |
92 | # duration resulting in out of sync issue | |
93 | continue | |
dadb8361 RA |
94 | formats.extend(self._extract_mpd_formats( |
95 | video_url, video_id, mpd_id='dash', fatal=False)) | |
9414338a S |
96 | else: |
97 | proto = compat_urllib_parse_urlparse(video_url).scheme | |
98 | if not child.tag.startswith('HTTP') and proto != 'rtmp': | |
99 | continue | |
100 | preference = -1 if proto == 'rtmp' else 1 | |
101 | label = child.get('label') | |
102 | tbr = int_or_none(child.get('bitrate')) | |
76a353c9 S |
103 | format_id = '%s-%s' % (proto, label if label else tbr) if label or tbr else proto |
104 | if not self._is_valid_url(video_url, video_id, format_id): | |
105 | continue | |
59a9efe8 | 106 | width, height = [int_or_none(x) for x in child.get('resolution', 'x').split('x')[:2]] |
9414338a | 107 | formats.append({ |
76a353c9 | 108 | 'format_id': format_id, |
9414338a S |
109 | 'url': video_url, |
110 | 'width': width, | |
111 | 'height': height, | |
112 | 'tbr': tbr, | |
113 | 'preference': preference, | |
114 | }) | |
22354455 | 115 | |
9414338a | 116 | extract_formats(video_xml.find('./Clip')) |
db75f14d S |
117 | |
118 | drm = xpath_text(video_xml, './Clip/DRM', default=None) | |
119 | if not formats and drm: | |
120 | raise ExtractorError('This video is DRM protected.', expected=True) | |
121 | ||
22354455 HL |
122 | self._sort_formats(formats) |
123 | ||
124 | return { | |
125 | 'id': video_id, | |
22889ab1 S |
126 | 'title': xpath_attr(video_xml, './/Behavior/Program', 'program_name', 'title', fatal=True), |
127 | 'description': xpath_attr(video_xml, './/Behavior/Program', 'description', 'description'), | |
128 | 'thumbnail': xpath_attr(video_xml, './/Behavior/Startpicture', 'href', 'thumbnail'), | |
9414338a S |
129 | 'duration': int_or_none(xpath_text(video_xml, './/Runtime', 'duration')), |
130 | 'age_limit': int_or_none(xpath_text(video_xml, './/AgeLimit', 'age limit')), | |
131 | 'formats': formats, | |
22354455 | 132 | } |