[pornovoisines] Add extractor
[youtube-dl] / youtube_dl / extractor / 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
46         webpage = self._download_webpage(url, video_id)
47
48         deliver_url = self._search_regex(
49             r'<iframe[^>]+src="(https?://(?:www\.)?ultimedia\.com/deliver/[^"]+)"',
50             webpage, 'deliver URL')
51
52         deliver_page = self._download_webpage(
53             deliver_url, video_id, 'Downloading iframe page')
54
55         if '>This video is currently not available' in deliver_page:
56             raise ExtractorError(
57                 'Video %s is currently not available' % video_id, expected=True)
58
59         player = self._parse_json(
60             self._search_regex(
61                 r"jwplayer\('player(?:_temp)?'\)\.setup\(({.+?})\)\.on", deliver_page, 'player'),
62             video_id)
63
64         quality = qualities(['flash', 'html5'])
65         formats = []
66         for mode in player['modes']:
67             video_url = mode.get('config', {}).get('file')
68             if not video_url:
69                 continue
70             if re.match(r'https?://www\.youtube\.com/.+?', video_url):
71                 return self.url_result(video_url, 'Youtube')
72             formats.append({
73                 'url': video_url,
74                 'format_id': mode.get('type'),
75                 'quality': quality(mode.get('type')),
76             })
77         self._sort_formats(formats)
78
79         thumbnail = player.get('image')
80
81         title = clean_html((
82             self._html_search_regex(
83                 r'(?s)<div\s+id="catArticle">.+?</div>(.+?)</h1>',
84                 webpage, 'title', default=None)
85             or self._search_regex(
86                 r"var\s+nameVideo\s*=\s*'([^']+)'",
87                 deliver_page, 'title')))
88
89         description = clean_html(self._html_search_regex(
90             r'(?s)<span>Description</span>(.+?)</p>', webpage,
91             'description', fatal=False))
92
93         upload_date = unified_strdate(self._search_regex(
94             r'Ajouté le\s*<span>([^<]+)', webpage,
95             'upload date', fatal=False))
96
97         return {
98             'id': video_id,
99             'title': title,
100             'description': description,
101             'thumbnail': thumbnail,
102             'upload_date': upload_date,
103             'formats': formats,
104         }