]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/ultimedia.py
[extractor/generic] Extend dailymotion embed regex
[yt-dlp.git] / youtube_dl / extractor / ultimedia.py
CommitLineData
3073a6d5
S
1# coding: utf-8
2from __future__ import unicode_literals
3
b30ef07c
S
4import re
5
3073a6d5 6from .common import InfoExtractor
6aeba407 7from ..utils import int_or_none
3073a6d5
S
8
9
10class UltimediaIE(InfoExtractor):
3da39996 11 _VALID_URL = r'''(?x)
12 https?://(?:www\.)?ultimedia\.com/
13 (?:
14 deliver/
15 (?P<embed_type>
16 generic|
17 musique
18 )
19 (?:/[^/]+)*/
20 (?:
21 src|
22 article
23 )|
24 default/index/video
25 (?P<site_type>
26 generic|
27 music
28 )
29 /id
30 )/(?P<id>[\d+a-z]+)'''
3073a6d5
S
31 _TESTS = [{
32 # news
3da39996 33 'url': 'https://www.ultimedia.com/default/index/videogeneric/id/s8uk0r',
3073a6d5
S
34 'md5': '276a0e49de58c7e85d32b057837952a2',
35 'info_dict': {
36 'id': 's8uk0r',
37 'ext': 'mp4',
38 'title': 'Loi sur la fin de vie: le texte prévoit un renforcement des directives anticipées',
3073a6d5 39 'thumbnail': 're:^https?://.*\.jpg',
6aeba407 40 'duration': 74,
3073a6d5 41 'upload_date': '20150317',
6aeba407 42 'timestamp': 1426604939,
43 'uploader_id': '3fszv',
3073a6d5
S
44 },
45 }, {
46 # music
3da39996 47 'url': 'https://www.ultimedia.com/default/index/videomusic/id/xvpfp8',
3073a6d5
S
48 'md5': '2ea3513813cf230605c7e2ffe7eca61c',
49 'info_dict': {
50 'id': 'xvpfp8',
51 'ext': 'mp4',
6aeba407 52 'title': 'Two - C\'est La Vie (clip)',
3073a6d5 53 'thumbnail': 're:^https?://.*\.jpg',
6aeba407 54 'duration': 233,
3073a6d5 55 'upload_date': '20150224',
6aeba407 56 'timestamp': 1424760500,
57 'uploader_id': '3rfzk',
3073a6d5
S
58 },
59 }]
60
6aeba407 61 @staticmethod
62 def _extract_url(webpage):
63 mobj = re.search(
64 r'<(?:iframe|script)[^>]+src=["\'](?P<url>(?:https?:)?//(?:www\.)?ultimedia\.com/deliver/(?:generic|musique)(?:/[^/]+)*/(?:src|article)/[\d+a-z]+)',
65 webpage)
66 if mobj:
67 return mobj.group('url')
3073a6d5 68
6aeba407 69 def _real_extract(self, url):
3da39996 70 mobj = re.match(self._VALID_URL, url)
71 video_id = mobj.group('id')
72 video_type = mobj.group('embed_type') or mobj.group('site_type')
73 if video_type == 'music':
74 video_type = 'musique'
3073a6d5 75
6aeba407 76 deliver_info = self._download_json(
77 'http://www.ultimedia.com/deliver/video?video=%s&topic=%s' % (video_id, video_type),
78 video_id)
3073a6d5 79
6aeba407 80 yt_id = deliver_info.get('yt_id')
81 if yt_id:
82 return self.url_result(yt_id, 'Youtube')
73900846 83
6aeba407 84 jwconf = deliver_info['jwconf']
3073a6d5 85
b30ef07c 86 formats = []
6aeba407 87 for source in jwconf['playlist'][0]['sources']:
b30ef07c 88 formats.append({
6aeba407 89 'url': source['file'],
90 'format_id': source.get('label'),
b30ef07c 91 })
3073a6d5 92
6aeba407 93 self._sort_formats(formats)
3073a6d5 94
6aeba407 95 title = deliver_info['title']
96 thumbnail = jwconf.get('image')
97 duration = int_or_none(deliver_info.get('duration'))
98 timestamp = int_or_none(deliver_info.get('release_time'))
99 uploader_id = deliver_info.get('owner_id')
3073a6d5
S
100
101 return {
102 'id': video_id,
103 'title': title,
3073a6d5 104 'thumbnail': thumbnail,
6aeba407 105 'duration': duration,
106 'timestamp': timestamp,
107 'uploader_id': uploader_id,
3073a6d5
S
108 'formats': formats,
109 }