]>
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, | |
8 | int_or_none, | |
22889ab1 | 9 | xpath_attr, |
9414338a S |
10 | xpath_text, |
11 | ) | |
22354455 HL |
12 | |
13 | ||
14 | class RuutuIE(InfoExtractor): | |
22889ab1 | 15 | _VALID_URL = r'https?://(?:www\.)?ruutu\.fi/video/(?P<id>\d+)' |
22354455 HL |
16 | _TESTS = [ |
17 | { | |
22889ab1 | 18 | 'url': 'http://www.ruutu.fi/video/2058907', |
22354455 HL |
19 | 'md5': 'ab2093f39be1ca8581963451b3c0234f', |
20 | 'info_dict': { | |
9414338a | 21 | 'id': '2058907', |
22354455 HL |
22 | 'ext': 'mp4', |
23 | 'title': 'Oletko aina halunnut tietää mitä tapahtuu vain hetki ennen lähetystä? - Nyt se selvisi!', | |
9414338a S |
24 | 'description': 'md5:cfc6ccf0e57a814360df464a91ff67d6', |
25 | 'thumbnail': 're:^https?://.*\.jpg$', | |
26 | 'duration': 114, | |
27 | 'age_limit': 0, | |
22354455 | 28 | }, |
22354455 HL |
29 | }, |
30 | { | |
c482b3c6 | 31 | 'url': 'http://www.ruutu.fi/video/2057306', |
22354455 HL |
32 | 'md5': '065a10ae4d5b8cfd9d0c3d332465e3d9', |
33 | 'info_dict': { | |
9414338a | 34 | 'id': '2057306', |
22354455 HL |
35 | 'ext': 'mp4', |
36 | 'title': 'Superpesis: katso koko kausi Ruudussa', | |
22889ab1 | 37 | 'description': 'md5:da2736052fef3b2bd5e0005e63c25eac', |
9414338a S |
38 | 'thumbnail': 're:^https?://.*\.jpg$', |
39 | 'duration': 40, | |
40 | 'age_limit': 0, | |
22354455 | 41 | }, |
22354455 HL |
42 | }, |
43 | ] | |
44 | ||
45 | def _real_extract(self, url): | |
22889ab1 | 46 | video_id = self._match_id(url) |
22354455 | 47 | |
22889ab1 S |
48 | video_xml = self._download_xml( |
49 | 'http://gatling.ruutu.fi/media-xml-cache?id=%s' % video_id, video_id) | |
22354455 HL |
50 | |
51 | formats = [] | |
9414338a S |
52 | processed_urls = [] |
53 | ||
54 | def extract_formats(node): | |
55 | for child in node: | |
56 | if child.tag.endswith('Files'): | |
57 | extract_formats(child) | |
58 | elif child.tag.endswith('File'): | |
59 | video_url = child.text | |
5d6c3d6a S |
60 | if (not video_url or video_url in processed_urls or |
61 | any(p in video_url for p in ('NOT_USED', 'NOT-USED'))): | |
9414338a S |
62 | return |
63 | processed_urls.append(video_url) | |
64 | ext = determine_ext(video_url) | |
65 | if ext == 'm3u8': | |
7e5edcfd S |
66 | formats.extend(self._extract_m3u8_formats( |
67 | video_url, video_id, 'mp4', m3u8_id='hls', fatal=False)) | |
9414338a | 68 | elif ext == 'f4m': |
7e5edcfd S |
69 | formats.extend(self._extract_f4m_formats( |
70 | video_url, video_id, f4m_id='hds', fatal=False)) | |
9414338a S |
71 | else: |
72 | proto = compat_urllib_parse_urlparse(video_url).scheme | |
73 | if not child.tag.startswith('HTTP') and proto != 'rtmp': | |
74 | continue | |
75 | preference = -1 if proto == 'rtmp' else 1 | |
76 | label = child.get('label') | |
77 | tbr = int_or_none(child.get('bitrate')) | |
76a353c9 S |
78 | format_id = '%s-%s' % (proto, label if label else tbr) if label or tbr else proto |
79 | if not self._is_valid_url(video_url, video_id, format_id): | |
80 | continue | |
59a9efe8 | 81 | width, height = [int_or_none(x) for x in child.get('resolution', 'x').split('x')[:2]] |
9414338a | 82 | formats.append({ |
76a353c9 | 83 | 'format_id': format_id, |
9414338a S |
84 | 'url': video_url, |
85 | 'width': width, | |
86 | 'height': height, | |
87 | 'tbr': tbr, | |
88 | 'preference': preference, | |
89 | }) | |
22354455 | 90 | |
9414338a | 91 | extract_formats(video_xml.find('./Clip')) |
22354455 HL |
92 | self._sort_formats(formats) |
93 | ||
94 | return { | |
95 | 'id': video_id, | |
22889ab1 S |
96 | 'title': xpath_attr(video_xml, './/Behavior/Program', 'program_name', 'title', fatal=True), |
97 | 'description': xpath_attr(video_xml, './/Behavior/Program', 'description', 'description'), | |
98 | 'thumbnail': xpath_attr(video_xml, './/Behavior/Startpicture', 'href', 'thumbnail'), | |
9414338a S |
99 | 'duration': int_or_none(xpath_text(video_xml, './/Runtime', 'duration')), |
100 | 'age_limit': int_or_none(xpath_text(video_xml, './/AgeLimit', 'age limit')), | |
101 | 'formats': formats, | |
22354455 | 102 | } |