[youtube] added vcodec/acodec/abr for multiple itags
[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 int_or_none
8
9
10 class UltimediaIE(InfoExtractor):
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]+)'''
31     _TESTS = [{
32         # news
33         'url': 'https://www.ultimedia.com/default/index/videogeneric/id/s8uk0r',
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',
39             'thumbnail': 're:^https?://.*\.jpg',
40             'duration': 74,
41             'upload_date': '20150317',
42             'timestamp': 1426604939,
43             'uploader_id': '3fszv',
44         },
45     }, {
46         # music
47         'url': 'https://www.ultimedia.com/default/index/videomusic/id/xvpfp8',
48         'md5': '2ea3513813cf230605c7e2ffe7eca61c',
49         'info_dict': {
50             'id': 'xvpfp8',
51             'ext': 'mp4',
52             'title': 'Two - C\'est La Vie (clip)',
53             'thumbnail': 're:^https?://.*\.jpg',
54             'duration': 233,
55             'upload_date': '20150224',
56             'timestamp': 1424760500,
57             'uploader_id': '3rfzk',
58         },
59     }]
60
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')
68
69     def _real_extract(self, url):
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'
75
76         deliver_info = self._download_json(
77             'http://www.ultimedia.com/deliver/video?video=%s&topic=%s' % (video_id, video_type),
78             video_id)
79
80         yt_id = deliver_info.get('yt_id')
81         if yt_id:
82             return self.url_result(yt_id, 'Youtube')
83
84         jwconf = deliver_info['jwconf']
85
86         formats = []
87         for source in jwconf['playlist'][0]['sources']:
88             formats.append({
89                 'url': source['file'],
90                 'format_id': source.get('label'),
91             })
92
93         self._sort_formats(formats)
94
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')
100
101         return {
102             'id': video_id,
103             'title': title,
104             'thumbnail': thumbnail,
105             'duration': duration,
106             'timestamp': timestamp,
107             'uploader_id': uploader_id,
108             'formats': formats,
109         }