]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/ina.py
New upstream version 2020.06.16.1
[youtubedl] / youtube_dl / extractor / ina.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import (
6 determine_ext,
7 int_or_none,
8 strip_or_none,
9 xpath_attr,
10 xpath_text,
11 )
12
13
14 class InaIE(InfoExtractor):
15 _VALID_URL = r'https?://(?:www\.)?ina\.fr/(?:video|audio)/(?P<id>[A-Z0-9_]+)'
16 _TESTS = [{
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"',
23 'description': 'md5:3f09eb072a06cb286b8f7e4f77109663',
24 }
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,
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,
34 }]
35
36 def _real_extract(self, url):
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'))
44
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:
58 furl = get_furl('player') or content.attrib['url']
59 ext = determine_ext(furl)
60 formats = [{
61 'url': furl,
62 'vcodec': 'none' if ext == 'mp3' else None,
63 'ext': ext,
64 }]
65
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 })
76
77 return {
78 'id': video_id,
79 'formats': formats,
80 'title': title,
81 'description': strip_or_none(xpath_text(item, 'description')),
82 'thumbnails': thumbnails,
83 }