[Rte] Improve extractor
[youtube-dl] / youtube_dl / extractor / rte.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5
6 from ..utils import (
7     float_or_none,
8 )
9
10
11 class RteIE(InfoExtractor):
12     _VALID_URL = r'http?://(?:www\.)?rte\.ie/player/in/show/(?P<id>[0-9]+)/'
13     _TEST = {
14         'url': 'http://www.rte.ie/player/in/show/10336191/',
15         'info_dict': {
16             'id': '10336191',
17             'ext': 'mp4',
18             'title': 'Nine News',
19             'thumbnail': 're:^https?://.*\.jpg$',
20             'description': 'The One O\'Clock News followed by Weather.',
21             'duration': 1622.963,
22         }
23     }
24     
25     def _real_extract(self, url):
26         video_id = self._match_id(url)
27
28         webpage = self._download_webpage(url, video_id)
29         title = self._og_search_title(webpage)
30         
31         description = self._search_regex(r'<meta name="description" content="(.*?)" />', webpage, 'description')
32         duration = float_or_none(self._html_search_meta('duration', webpage, 'duration'), 1000)
33         
34         thumbnail_id = self._search_regex(r'<meta name="thumbnail" content="uri:irus:(.*?)" />', webpage, 'thumbnail')
35         thumbnail = 'http://img.rasset.ie/' + thumbnail_id + '.jpg' 
36         
37         feeds_url = self._html_search_meta("feeds-prefix", webpage, 'feeds url') + video_id
38         json_string = self._download_json(feeds_url, video_id)
39         
40         # f4m_url = server + relative_url
41         f4m_url = json_string['shows'][0]['media:group'][0]['rte:server'] + json_string['shows'][0]['media:group'][0]['url']
42         f4m_formats = self._extract_f4m_formats(f4m_url, video_id)
43         f4m_formats = [{
44             'format_id': f['format_id'],
45             'url': f['url'],
46             'ext': 'mp4',
47             'width': f['width'],
48             'height': f['height'],
49         } for f in f4m_formats ]
50         
51         return {
52             'id': video_id,
53             'title': title,
54             'formats': f4m_formats,
55             'description': description,
56             'thumbnail': thumbnail,
57             'duration': duration,
58         }