]>
Commit | Line | Data |
---|---|---|
dcdb292f | 1 | # coding: utf-8 |
de563c9d JMF |
2 | from __future__ import unicode_literals |
3 | ||
9fe4de34 | 4 | from .common import InfoExtractor |
b27a71e6 | 5 | from ..utils import ( |
c4c88869 | 6 | determine_ext, |
b27a71e6 RA |
7 | int_or_none, |
8 | strip_or_none, | |
9 | xpath_attr, | |
10 | xpath_text, | |
11 | ) | |
9fe4de34 PH |
12 | |
13 | ||
14 | class InaIE(InfoExtractor): | |
c4c88869 | 15 | _VALID_URL = r'https?://(?:www\.)?ina\.fr/(?:video|audio)/(?P<id>[A-Z0-9_]+)' |
b27a71e6 | 16 | _TESTS = [{ |
de563c9d JMF |
17 | 'url': 'http://www.ina.fr/video/I12055569/francois-hollande-je-crois-que-c-est-clair-video.html', |
18 | 'md5': 'a667021bf2b41f8dc6049479d9bb38a3', | |
19 | 'info_dict': { | |
20 | 'id': 'I12055569', | |
21 | 'ext': 'mp4', | |
22 | 'title': 'François Hollande "Je crois que c\'est clair"', | |
b27a71e6 | 23 | 'description': 'md5:3f09eb072a06cb286b8f7e4f77109663', |
6f5ac90c | 24 | } |
b27a71e6 RA |
25 | }, { |
26 | 'url': 'https://www.ina.fr/video/S806544_001/don-d-organes-des-avancees-mais-d-importants-besoins-video.html', | |
27 | 'only_matching': True, | |
c4c88869 RA |
28 | }, { |
29 | 'url': 'https://www.ina.fr/audio/P16173408', | |
30 | 'only_matching': True, | |
31 | }, { | |
32 | 'url': 'https://www.ina.fr/video/P16173408-video.html', | |
33 | 'only_matching': True, | |
b27a71e6 | 34 | }] |
9fe4de34 | 35 | |
de563c9d | 36 | def _real_extract(self, url): |
b27a71e6 RA |
37 | video_id = self._match_id(url) |
38 | info_doc = self._download_xml( | |
39 | 'http://player.ina.fr/notices/%s.mrss' % video_id, video_id) | |
40 | item = info_doc.find('channel/item') | |
41 | title = xpath_text(item, 'title', fatal=True) | |
42 | media_ns_xpath = lambda x: self._xpath_ns(x, 'http://search.yahoo.com/mrss/') | |
43 | content = item.find(media_ns_xpath('content')) | |
9fe4de34 | 44 | |
b27a71e6 RA |
45 | get_furl = lambda x: xpath_attr(content, media_ns_xpath(x), 'url') |
46 | formats = [] | |
47 | for q, w, h in (('bq', 400, 300), ('mq', 512, 384), ('hq', 768, 576)): | |
48 | q_url = get_furl(q) | |
49 | if not q_url: | |
50 | continue | |
51 | formats.append({ | |
52 | 'format_id': q, | |
53 | 'url': q_url, | |
54 | 'width': w, | |
55 | 'height': h, | |
56 | }) | |
57 | if not formats: | |
c4c88869 RA |
58 | furl = get_furl('player') or content.attrib['url'] |
59 | ext = determine_ext(furl) | |
b27a71e6 | 60 | formats = [{ |
c4c88869 RA |
61 | 'url': furl, |
62 | 'vcodec': 'none' if ext == 'mp3' else None, | |
63 | 'ext': ext, | |
b27a71e6 | 64 | }] |
9fe4de34 | 65 | |
b27a71e6 RA |
66 | thumbnails = [] |
67 | for thumbnail in content.findall(media_ns_xpath('thumbnail')): | |
68 | thumbnail_url = thumbnail.get('url') | |
69 | if not thumbnail_url: | |
70 | continue | |
71 | thumbnails.append({ | |
72 | 'url': thumbnail_url, | |
73 | 'height': int_or_none(thumbnail.get('height')), | |
74 | 'width': int_or_none(thumbnail.get('width')), | |
75 | }) | |
9fe4de34 | 76 | |
de563c9d JMF |
77 | return { |
78 | 'id': video_id, | |
b27a71e6 RA |
79 | 'formats': formats, |
80 | 'title': title, | |
81 | 'description': strip_or_none(xpath_text(item, 'description')), | |
82 | 'thumbnails': thumbnails, | |
de563c9d | 83 | } |