]>
Commit | Line | Data |
---|---|---|
1 | import json | |
2 | import math | |
3 | ||
4 | from .common import InfoExtractor | |
5 | from ..utils import ( | |
6 | InAdvancePagedList, | |
7 | traverse_obj, | |
8 | ) | |
9 | ||
10 | ||
11 | class LeFigaroVideoEmbedIE(InfoExtractor): | |
12 | _VALID_URL = r'https?://video\.lefigaro\.fr/embed/[^?#]+/(?P<id>[\w-]+)' | |
13 | ||
14 | _TESTS = [{ | |
15 | 'url': 'https://video.lefigaro.fr/embed/figaro/video/les-francais-ne-veulent-ils-plus-travailler-suivez-en-direct-le-club-le-figaro-idees/', | |
16 | 'md5': 'a0c3069b7e4c4526abf0053a7713f56f', | |
17 | 'info_dict': { | |
18 | 'id': 'g9j7Eovo', | |
19 | 'title': 'Les Français ne veulent-ils plus travailler ? Retrouvez Le Club Le Figaro Idées', | |
20 | 'description': 'md5:862b8813148ba4bf10763a65a69dfe41', | |
21 | 'upload_date': '20230216', | |
22 | 'timestamp': 1676581615, | |
23 | 'duration': 3076, | |
24 | 'thumbnail': r're:^https?://[^?#]+\.(?:jpeg|jpg)', | |
25 | 'ext': 'mp4', | |
26 | }, | |
27 | }, { | |
28 | 'url': 'https://video.lefigaro.fr/embed/figaro/video/intelligence-artificielle-faut-il-sen-mefier/', | |
29 | 'md5': '319c662943dd777bab835cae1e2d73a5', | |
30 | 'info_dict': { | |
31 | 'id': 'LeAgybyc', | |
32 | 'title': 'Intelligence artificielle : faut-il s’en méfier ?', | |
33 | 'description': 'md5:249d136e3e5934a67c8cb704f8abf4d2', | |
34 | 'upload_date': '20230124', | |
35 | 'timestamp': 1674584477, | |
36 | 'duration': 860, | |
37 | 'thumbnail': r're:^https?://[^?#]+\.(?:jpeg|jpg)', | |
38 | 'ext': 'mp4', | |
39 | }, | |
40 | }] | |
41 | ||
42 | _WEBPAGE_TESTS = [{ | |
43 | 'url': 'https://video.lefigaro.fr/figaro/video/suivez-en-direct-le-club-le-figaro-international-avec-philippe-gelie-9/', | |
44 | 'md5': '6289f9489efb969e38245f31721596fe', | |
45 | 'info_dict': { | |
46 | 'id': 'QChnbPYA', | |
47 | 'title': 'Où en est le couple franco-allemand ? Retrouvez Le Club Le Figaro International', | |
48 | 'description': 'md5:6f47235b7e7c93b366fd8ebfa10572ac', | |
49 | 'upload_date': '20230123', | |
50 | 'timestamp': 1674503575, | |
51 | 'duration': 3153, | |
52 | 'thumbnail': r're:^https?://[^?#]+\.(?:jpeg|jpg)', | |
53 | 'age_limit': 0, | |
54 | 'ext': 'mp4', | |
55 | }, | |
56 | }, { | |
57 | 'url': 'https://video.lefigaro.fr/figaro/video/la-philosophe-nathalie-sarthou-lajus-est-linvitee-du-figaro-live/', | |
58 | 'md5': 'f6df814cae53e85937621599d2967520', | |
59 | 'info_dict': { | |
60 | 'id': 'QJzqoNbf', | |
61 | 'title': 'La philosophe Nathalie Sarthou-Lajus est l’invitée du Figaro Live', | |
62 | 'description': 'md5:c586793bb72e726c83aa257f99a8c8c4', | |
63 | 'upload_date': '20230217', | |
64 | 'timestamp': 1676661986, | |
65 | 'duration': 1558, | |
66 | 'thumbnail': r're:^https?://[^?#]+\.(?:jpeg|jpg)', | |
67 | 'age_limit': 0, | |
68 | 'ext': 'mp4', | |
69 | }, | |
70 | }] | |
71 | ||
72 | def _real_extract(self, url): | |
73 | display_id = self._match_id(url) | |
74 | webpage = self._download_webpage(url, display_id) | |
75 | ||
76 | player_data = self._search_nextjs_data( | |
77 | webpage, display_id)['props']['pageProps']['initialProps']['pageData']['playerData'] | |
78 | ||
79 | return self.url_result( | |
80 | f'jwplatform:{player_data["videoId"]}', title=player_data.get('title'), | |
81 | description=player_data.get('description'), thumbnail=player_data.get('poster')) | |
82 | ||
83 | ||
84 | class LeFigaroVideoSectionIE(InfoExtractor): | |
85 | _VALID_URL = r'https?://video\.lefigaro\.fr/figaro/(?P<id>[\w-]+)/?(?:[#?]|$)' | |
86 | ||
87 | _TESTS = [{ | |
88 | 'url': 'https://video.lefigaro.fr/figaro/le-club-le-figaro-idees/', | |
89 | 'info_dict': { | |
90 | 'id': 'le-club-le-figaro-idees', | |
91 | 'title': 'Le Club Le Figaro Idées', | |
92 | }, | |
93 | 'playlist_mincount': 14, | |
94 | }, { | |
95 | 'url': 'https://video.lefigaro.fr/figaro/factu/', | |
96 | 'info_dict': { | |
97 | 'id': 'factu', | |
98 | 'title': 'Factu', | |
99 | }, | |
100 | 'playlist_mincount': 519, | |
101 | }] | |
102 | ||
103 | _PAGE_SIZE = 20 | |
104 | ||
105 | def _get_api_response(self, display_id, page_num, note=None): | |
106 | return self._download_json( | |
107 | 'https://api-graphql.lefigaro.fr/graphql', display_id, note=note, | |
108 | query={ | |
109 | 'id': 'flive-website_UpdateListPage_1fb260f996bca2d78960805ac382544186b3225f5bedb43ad08b9b8abef79af6', | |
110 | 'variables': json.dumps({ | |
111 | 'slug': display_id, | |
112 | 'videosLimit': self._PAGE_SIZE, | |
113 | 'sort': 'DESC', | |
114 | 'order': 'PUBLISHED_AT', | |
115 | 'page': page_num, | |
116 | }).encode(), | |
117 | }) | |
118 | ||
119 | def _real_extract(self, url): | |
120 | display_id = self._match_id(url) | |
121 | initial_response = self._get_api_response(display_id, page_num=1)['data']['playlist'] | |
122 | ||
123 | def page_func(page_num): | |
124 | api_response = self._get_api_response(display_id, page_num + 1, note=f'Downloading page {page_num + 1}') | |
125 | ||
126 | return [self.url_result( | |
127 | video['embedUrl'], LeFigaroVideoEmbedIE, **traverse_obj(video, { | |
128 | 'title': 'name', | |
129 | 'description': 'description', | |
130 | 'thumbnail': 'thumbnailUrl', | |
131 | })) for video in api_response['data']['playlist']['jsonLd'][0]['itemListElement']] | |
132 | ||
133 | entries = InAdvancePagedList( | |
134 | page_func, math.ceil(initial_response['videoCount'] / self._PAGE_SIZE), self._PAGE_SIZE) | |
135 | ||
136 | return self.playlist_result(entries, playlist_id=display_id, playlist_title=initial_response.get('title')) |