]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/deuxm.py
[ie/orf:on] Improve extraction (#9677)
[yt-dlp.git] / yt_dlp / extractor / deuxm.py
CommitLineData
cc1d3bf9
C
1from .common import InfoExtractor
2from ..utils import url_or_none
3
4
5class DeuxMIE(InfoExtractor):
6 _VALID_URL = r'https?://(?:www\.)?2m\.ma/[^/]+/replay/single/(?P<id>([\w.]{1,24})+)'
7
8 _TESTS = [{
9 'url': 'https://2m.ma/fr/replay/single/6351d439b15e1a613b3debe8',
10 'md5': '5f761f04c9d686e553b685134dca5d32',
11 'info_dict': {
12 'id': '6351d439b15e1a613b3debe8',
13 'ext': 'mp4',
14 'title': 'Grand Angle : Jeudi 20 Octobre 2022',
15 'thumbnail': r're:^https?://2msoread-ww.amagi.tv/mediasfiles/videos/images/.*\.png$'
16 }
17 }, {
18 'url': 'https://2m.ma/fr/replay/single/635c0aeab4eec832622356da',
19 'md5': 'ad6af2f5e4d5b2ad2194a84b6e890b4c',
20 'info_dict': {
21 'id': '635c0aeab4eec832622356da',
22 'ext': 'mp4',
23 'title': 'Journal Amazigh : Vendredi 28 Octobre 2022',
24 'thumbnail': r're:^https?://2msoread-ww.amagi.tv/mediasfiles/videos/images/.*\.png$'
25 }
26 }]
27
28 def _real_extract(self, url):
29 video_id = self._match_id(url)
30 video = self._download_json(
31 f'https://2m.ma/api/watchDetail/{video_id}', video_id)['response']['News']
32 return {
33 'id': video_id,
34 'title': video.get('titre'),
35 'url': video['url'],
36 'description': video.get('description'),
37 'thumbnail': url_or_none(video.get('image')),
38 }
39
40
41class DeuxMNewsIE(InfoExtractor):
42 _VALID_URL = r'https?://(?:www\.)?2m\.ma/(?P<lang>\w+)/news/(?P<id>[^/#?]+)'
43
44 _TESTS = [{
45 'url': 'https://2m.ma/fr/news/Kan-Ya-Mkan-d%C3%A9poussi%C3%A8re-l-histoire-du-phare-du-Cap-Beddouza-20221028',
46 'md5': '43d5e693a53fa0b71e8a5204c7d4542a',
47 'info_dict': {
48 'id': '635c5d1233b83834e35b282e',
49 'ext': 'mp4',
50 'title': 'Kan Ya Mkan d\u00e9poussi\u00e8re l\u2019histoire du phare du Cap Beddouza',
51 'description': 'md5:99dcf29b82f1d7f2a4acafed1d487527',
52 'thumbnail': r're:^https?://2msoread-ww.amagi.tv/mediasfiles/videos/images/.*\.png$'
53 }
54 }, {
55 'url': 'https://2m.ma/fr/news/Interview-Casablanca-hors-des-sentiers-battus-avec-Abderrahim-KASSOU-Replay--20221017',
56 'md5': '7aca29f02230945ef635eb8290283c0c',
57 'info_dict': {
58 'id': '634d9e108b70d40bc51a844b',
59 'ext': 'mp4',
60 'title': 'Interview: Casablanca hors des sentiers battus avec Abderrahim KASSOU (Replay) ',
61 'description': 'md5:3b8e78111de9fcc6ef7f7dd6cff2430c',
62 'thumbnail': r're:^https?://2msoread-ww.amagi.tv/mediasfiles/videos/images/.*\.png$'
63 }
64 }]
65
66 def _real_extract(self, url):
67 article_name, lang = self._match_valid_url(url).group('id', 'lang')
68 video = self._download_json(
69 f'https://2m.ma/api/articlesByUrl?lang={lang}&url=/news/{article_name}', article_name)['response']['article'][0]
70 return {
71 'id': video['id'],
72 'title': video.get('title'),
73 'url': video['image'][0],
74 'description': video.get('content'),
75 'thumbnail': url_or_none(video.get('cover')),
76 }