2 from __future__ import unicode_literals
4 from .common import InfoExtractor
5 from ..compat import compat_urllib_parse_urlparse
13 class RuutuIE(InfoExtractor):
14 _VALID_URL = r'http://(?:www\.)?ruutu\.fi/ohjelmat/(?:[^/?#]+/)*(?P<id>[^/?#]+)'
17 'url': 'http://www.ruutu.fi/ohjelmat/oletko-aina-halunnut-tietaa-mita-tapahtuu-vain-hetki-ennen-lahetysta-nyt-se-selvisi',
18 'md5': 'ab2093f39be1ca8581963451b3c0234f',
21 'display_id': 'oletko-aina-halunnut-tietaa-mita-tapahtuu-vain-hetki-ennen-lahetysta-nyt-se-selvisi',
23 'title': 'Oletko aina halunnut tietää mitä tapahtuu vain hetki ennen lähetystä? - Nyt se selvisi!',
24 'description': 'md5:cfc6ccf0e57a814360df464a91ff67d6',
25 'thumbnail': 're:^https?://.*\.jpg$',
31 'url': 'http://www.ruutu.fi/ohjelmat/superpesis/superpesis-katso-koko-kausi-ruudussa',
32 'md5': '065a10ae4d5b8cfd9d0c3d332465e3d9',
35 'display_id': 'superpesis-katso-koko-kausi-ruudussa',
37 'title': 'Superpesis: katso koko kausi Ruudussa',
38 'description': 'md5:44c44a99fdbe5b380ab74ebd75f0af77',
39 'thumbnail': 're:^https?://.*\.jpg$',
46 def _real_extract(self, url):
47 display_id = self._match_id(url)
49 webpage = self._download_webpage(url, display_id)
51 video_id = self._search_regex(
52 r'data-media-id="(\d+)"', webpage, 'media id')
56 media_data = self._search_regex(
57 r'jQuery\.extend\([^,]+,\s*(.+?)\);', webpage,
58 'media data', default=None)
60 media_json = self._parse_json(media_data, display_id, fatal=False)
62 xml_url = media_json.get('ruutuplayer', {}).get('xmlUrl')
64 video_xml_url = xml_url.replace('{ID}', video_id)
67 video_xml_url = 'http://gatling.ruutu.fi/media-xml-cache?id=%s' % video_id
69 video_xml = self._download_xml(video_xml_url, video_id)
74 def extract_formats(node):
76 if child.tag.endswith('Files'):
77 extract_formats(child)
78 elif child.tag.endswith('File'):
79 video_url = child.text
80 if not video_url or video_url in processed_urls or 'NOT_USED' in video_url:
82 processed_urls.append(video_url)
83 ext = determine_ext(video_url)
85 formats.extend(self._extract_m3u8_formats(
86 video_url, video_id, 'mp4', m3u8_id='hls'))
88 formats.extend(self._extract_f4m_formats(
89 video_url, video_id, f4m_id='hds'))
91 proto = compat_urllib_parse_urlparse(video_url).scheme
92 if not child.tag.startswith('HTTP') and proto != 'rtmp':
94 preference = -1 if proto == 'rtmp' else 1
95 label = child.get('label')
96 tbr = int_or_none(child.get('bitrate'))
97 width, height = [int_or_none(x) for x in child.get('resolution', '').split('x')]
99 'format_id': '%s-%s' % (proto, label if label else tbr),
104 'preference': preference,
107 extract_formats(video_xml.find('./Clip'))
108 self._sort_formats(formats)
112 'display_id': display_id,
113 'title': self._og_search_title(webpage),
114 'description': self._og_search_description(webpage),
115 'thumbnail': self._og_search_thumbnail(webpage),
116 'duration': int_or_none(xpath_text(video_xml, './/Runtime', 'duration')),
117 'age_limit': int_or_none(xpath_text(video_xml, './/AgeLimit', 'age limit')),