]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/digiteka.py
[extractor] Support multiple archive ids for one video (#4307)
[yt-dlp.git] / yt_dlp / extractor / digiteka.py
1 import re
2
3 from .common import InfoExtractor
4 from ..utils import int_or_none
5
6
7 class DigitekaIE(InfoExtractor):
8 _VALID_URL = r'''(?x)
9 https?://(?:www\.)?(?:digiteka\.net|ultimedia\.com)/
10 (?:
11 deliver/
12 (?P<embed_type>
13 generic|
14 musique
15 )
16 (?:/[^/]+)*/
17 (?:
18 src|
19 article
20 )|
21 default/index/video
22 (?P<site_type>
23 generic|
24 music
25 )
26 /id
27 )/(?P<id>[\d+a-z]+)'''
28 _TESTS = [{
29 # news
30 'url': 'https://www.ultimedia.com/default/index/videogeneric/id/s8uk0r',
31 'md5': '276a0e49de58c7e85d32b057837952a2',
32 'info_dict': {
33 'id': 's8uk0r',
34 'ext': 'mp4',
35 'title': 'Loi sur la fin de vie: le texte prévoit un renforcement des directives anticipées',
36 'thumbnail': r're:^https?://.*\.jpg',
37 'duration': 74,
38 'upload_date': '20150317',
39 'timestamp': 1426604939,
40 'uploader_id': '3fszv',
41 },
42 }, {
43 # music
44 'url': 'https://www.ultimedia.com/default/index/videomusic/id/xvpfp8',
45 'md5': '2ea3513813cf230605c7e2ffe7eca61c',
46 'info_dict': {
47 'id': 'xvpfp8',
48 'ext': 'mp4',
49 'title': 'Two - C\'est La Vie (clip)',
50 'thumbnail': r're:^https?://.*\.jpg',
51 'duration': 233,
52 'upload_date': '20150224',
53 'timestamp': 1424760500,
54 'uploader_id': '3rfzk',
55 },
56 }, {
57 'url': 'https://www.digiteka.net/deliver/generic/iframe/mdtk/01637594/src/lqm3kl/zone/1/showtitle/1/autoplay/yes',
58 'only_matching': True,
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 = self._match_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 }