]> git.bitcoin.ninja Git - youtube-dl/blob - ultimedia.py
96c809eaf7155290210e0f8b18d3a2c7c948ba97
[youtube-dl] / ultimedia.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import (
8     ExtractorError,
9     qualities,
10     unified_strdate,
11     clean_html,
12 )
13
14
15 class UltimediaIE(InfoExtractor):
16     _VALID_URL = r'https?://(?:www\.)?ultimedia\.com/default/index/video[^/]+/id/(?P<id>[\d+a-z]+)'
17     _TESTS = [{
18         # news
19         'url': 'https://www.ultimedia.com/default/index/videogeneric/id/s8uk0r',
20         'md5': '276a0e49de58c7e85d32b057837952a2',
21         'info_dict': {
22             'id': 's8uk0r',
23             'ext': 'mp4',
24             'title': 'Loi sur la fin de vie: le texte prévoit un renforcement des directives anticipées',
25             'description': 'md5:3e5c8fd65791487333dda5db8aed32af',
26             'thumbnail': 're:^https?://.*\.jpg',
27             'upload_date': '20150317',
28         },
29     }, {
30         # music
31         'url': 'https://www.ultimedia.com/default/index/videomusic/id/xvpfp8',
32         'md5': '2ea3513813cf230605c7e2ffe7eca61c',
33         'info_dict': {
34             'id': 'xvpfp8',
35             'ext': 'mp4',
36             'title': "Two - C'est la vie (Clip)",
37             'description': 'Two',
38             'thumbnail': 're:^https?://.*\.jpg',
39             'upload_date': '20150224',
40         },
41     }]
42
43     def _real_extract(self, url):
44         video_id = self._match_id(url)
45         webpage = self._download_webpage(url, video_id)
46
47         deliver_url = self._search_regex(
48             r'<iframe[^>]+src="(https?://(?:www\.)?ultimedia\.com/deliver/[^"]+)"',
49             webpage, 'deliver URL')
50
51         deliver_page = self._download_webpage(
52             deliver_url, video_id, 'Downloading iframe page')
53
54         if '>This video is currently not available' in deliver_page:
55             raise ExtractorError(
56                 'Video %s is currently not available' % video_id, expected=True)
57
58         player = self._parse_json(
59             self._search_regex(
60                 r"jwplayer\('player(?:_temp)?'\)\.setup\(({.+?})\)\.on", deliver_page, 'player'),
61             video_id)
62
63         quality = qualities(['flash', 'html5'])
64         formats = []
65         for mode in player['modes']:
66             video_url = mode.get('config', {}).get('file')
67             if not video_url:
68                 continue
69             if re.match(r'https?://www\.youtube\.com/.+?', video_url):
70                 return self.url_result(video_url, 'Youtube')
71             formats.append({
72                 'url': video_url,
73                 'format_id': mode.get('type'),
74                 'quality': quality(mode.get('type')),
75             })
76         self._sort_formats(formats)
77
78         thumbnail = player.get('image')
79
80         title = clean_html((
81             self._html_search_regex(
82                 r'(?s)<div\s+id="catArticle">.+?</div>(.+?)</h1>',
83                 webpage, 'title', default=None) or
84             self._search_regex(
85                 r"var\s+nameVideo\s*=\s*'([^']+)'",
86                 deliver_page, 'title')))
87
88         description = clean_html(self._html_search_regex(
89             r'(?s)<span>Description</span>(.+?)</p>', webpage,
90             'description', fatal=False))
91
92         upload_date = unified_strdate(self._search_regex(
93             r'Ajouté le\s*<span>([^<]+)', webpage,
94             'upload date', fatal=False))
95
96         return {
97             'id': video_id,
98             'title': title,
99             'description': description,
100             'thumbnail': thumbnail,
101             'upload_date': upload_date,
102             'formats': formats,
103         }