]>
Commit | Line | Data |
---|---|---|
dcdb292f | 1 | # coding: utf-8 |
3798eadc PH |
2 | from __future__ import unicode_literals |
3 | ||
d5822b96 | 4 | import re |
d5822b96 PH |
5 | |
6 | from .common import InfoExtractor | |
ff0f4cfe | 7 | from ..compat import compat_str |
d5822b96 | 8 | from ..utils import ( |
c0892b2b | 9 | ExtractorError, |
d24a2b20 | 10 | int_or_none, |
aff2f4f4 | 11 | qualities, |
8cc1840c | 12 | try_get, |
c0892b2b | 13 | unified_strdate, |
d5822b96 PH |
14 | ) |
15 | ||
5f6a1245 | 16 | # There are different sources of video in arte.tv, the extraction process |
c40f5cf4 JMF |
17 | # is different for each one. The videos usually expire in 7 days, so we can't |
18 | # add tests. | |
19 | ||
d5822b96 | 20 | |
6e6b9f60 | 21 | class ArteTVBaseIE(InfoExtractor): |
46c329d6 | 22 | def _extract_from_json_url(self, json_url, video_id, lang, title=None): |
893f8832 | 23 | info = self._download_json(json_url, video_id) |
c40f5cf4 JMF |
24 | player_info = info['videoJsonPlayer'] |
25 | ||
8cc1840c | 26 | vsr = try_get(player_info, lambda x: x['VSR'], dict) |
6348671c | 27 | if not vsr: |
8cc1840c S |
28 | error = None |
29 | if try_get(player_info, lambda x: x['custom_msg']['type']) == 'error': | |
30 | error = try_get( | |
31 | player_info, lambda x: x['custom_msg']['msg'], compat_str) | |
32 | if not error: | |
33 | error = 'Video %s is not available' % player_info.get('VID') or video_id | |
34 | raise ExtractorError(error, expected=True) | |
c0892b2b | 35 | |
99b67fec PH |
36 | upload_date_str = player_info.get('shootingDate') |
37 | if not upload_date_str: | |
8bbd3d14 | 38 | upload_date_str = (player_info.get('VRA') or player_info.get('VDA') or '').split(' ')[0] |
99b67fec | 39 | |
46c329d6 | 40 | title = (player_info.get('VTI') or title or player_info['VID']).strip() |
74214d35 S |
41 | subtitle = player_info.get('VSU', '').strip() |
42 | if subtitle: | |
43 | title += ' - %s' % subtitle | |
44 | ||
c40f5cf4 JMF |
45 | info_dict = { |
46 | 'id': player_info['VID'], | |
74214d35 | 47 | 'title': title, |
c40f5cf4 | 48 | 'description': player_info.get('VDE'), |
99b67fec | 49 | 'upload_date': unified_strdate(upload_date_str), |
c40f5cf4 JMF |
50 | 'thumbnail': player_info.get('programImage') or player_info.get('VTU', {}).get('IUR'), |
51 | } | |
ff0f4cfe | 52 | qfunc = qualities(['MQ', 'HQ', 'EQ', 'SQ']) |
c40f5cf4 | 53 | |
08d65046 S |
54 | LANGS = { |
55 | 'fr': 'F', | |
56 | 'de': 'A', | |
57 | 'en': 'E[ANG]', | |
58 | 'es': 'E[ESP]', | |
ff0f4cfe RA |
59 | 'it': 'E[ITA]', |
60 | 'pl': 'E[POL]', | |
08d65046 S |
61 | } |
62 | ||
9c072d38 S |
63 | langcode = LANGS.get(lang, lang) |
64 | ||
aff2f4f4 | 65 | formats = [] |
c0892b2b | 66 | for format_id, format_dict in vsr.items(): |
aff2f4f4 PH |
67 | f = dict(format_dict) |
68 | versionCode = f.get('versionCode') | |
9c072d38 S |
69 | l = re.escape(langcode) |
70 | ||
71 | # Language preference from most to least priority | |
ff0f4cfe RA |
72 | # Reference: section 6.8 of |
73 | # https://www.arte.tv/sites/en/corporate/files/complete-technical-guidelines-arte-geie-v1-07-1.pdf | |
9c072d38 S |
74 | PREFERENCES = ( |
75 | # original version in requested language, without subtitles | |
76 | r'VO{0}$'.format(l), | |
77 | # original version in requested language, with partial subtitles in requested language | |
78 | r'VO{0}-ST{0}$'.format(l), | |
79 | # original version in requested language, with subtitles for the deaf and hard-of-hearing in requested language | |
80 | r'VO{0}-STM{0}$'.format(l), | |
81 | # non-original (dubbed) version in requested language, without subtitles | |
82 | r'V{0}$'.format(l), | |
83 | # non-original (dubbed) version in requested language, with subtitles partial subtitles in requested language | |
84 | r'V{0}-ST{0}$'.format(l), | |
85 | # non-original (dubbed) version in requested language, with subtitles for the deaf and hard-of-hearing in requested language | |
86 | r'V{0}-STM{0}$'.format(l), | |
87 | # original version in requested language, with partial subtitles in different language | |
88 | r'VO{0}-ST(?!{0}).+?$'.format(l), | |
89 | # original version in requested language, with subtitles for the deaf and hard-of-hearing in different language | |
90 | r'VO{0}-STM(?!{0}).+?$'.format(l), | |
91 | # original version in different language, with partial subtitles in requested language | |
92 | r'VO(?:(?!{0}).+?)?-ST{0}$'.format(l), | |
93 | # original version in different language, with subtitles for the deaf and hard-of-hearing in requested language | |
94 | r'VO(?:(?!{0}).+?)?-STM{0}$'.format(l), | |
95 | # original version in different language, without subtitles | |
96 | r'VO(?:(?!{0}))?$'.format(l), | |
97 | # original version in different language, with partial subtitles in different language | |
98 | r'VO(?:(?!{0}).+?)?-ST(?!{0}).+?$'.format(l), | |
99 | # original version in different language, with subtitles for the deaf and hard-of-hearing in different language | |
100 | r'VO(?:(?!{0}).+?)?-STM(?!{0}).+?$'.format(l), | |
101 | ) | |
102 | ||
103 | for pref, p in enumerate(PREFERENCES): | |
104 | if re.match(p, versionCode): | |
105 | lang_pref = len(PREFERENCES) - pref | |
106 | break | |
107 | else: | |
108 | lang_pref = -1 | |
109 | ||
aff2f4f4 PH |
110 | format = { |
111 | 'format_id': format_id, | |
112 | 'preference': -10 if f.get('videoFormat') == 'M3U8' else None, | |
113 | 'language_preference': lang_pref, | |
114 | 'format_note': '%s, %s' % (f.get('versionCode'), f.get('versionLibelle')), | |
115 | 'width': int_or_none(f.get('width')), | |
116 | 'height': int_or_none(f.get('height')), | |
117 | 'tbr': int_or_none(f.get('bitrate')), | |
1b7b1d6e | 118 | 'quality': qfunc(f.get('quality')), |
c40f5cf4 | 119 | } |
aff2f4f4 PH |
120 | |
121 | if f.get('mediaType') == 'rtmp': | |
122 | format['url'] = f['streamer'] | |
123 | format['play_path'] = 'mp4:' + f['url'] | |
124 | format['ext'] = 'flv' | |
c40f5cf4 | 125 | else: |
aff2f4f4 PH |
126 | format['url'] = f['url'] |
127 | ||
128 | formats.append(format) | |
129 | ||
c06a9f87 | 130 | self._check_formats(formats, video_id) |
aff2f4f4 | 131 | self._sort_formats(formats) |
c40f5cf4 | 132 | |
aff2f4f4 | 133 | info_dict['formats'] = formats |
c40f5cf4 JMF |
134 | return info_dict |
135 | ||
136 | ||
6e6b9f60 S |
137 | class ArteTVPlus7IE(ArteTVBaseIE): |
138 | IE_NAME = 'arte.tv:+7' | |
ff0f4cfe | 139 | _VALID_URL = r'https?://(?:www\.)?arte\.tv/(?P<lang>fr|de|en|es|it|pl)/videos/(?P<id>\d{6}-\d{3}-[AF])' |
24114fee | 140 | |
9c54ae33 | 141 | _TESTS = [{ |
ff0f4cfe | 142 | 'url': 'https://www.arte.tv/en/videos/088501-000-A/mexico-stealing-petrol-to-survive/', |
9c54ae33 | 143 | 'info_dict': { |
ff0f4cfe | 144 | 'id': '088501-000-A', |
9c54ae33 | 145 | 'ext': 'mp4', |
ff0f4cfe RA |
146 | 'title': 'Mexico: Stealing Petrol to Survive', |
147 | 'upload_date': '20190628', | |
69a0c470 | 148 | }, |
9c54ae33 | 149 | }] |
56a8ab7d | 150 | |
56a8ab7d | 151 | def _real_extract(self, url): |
ff0f4cfe RA |
152 | lang, video_id = re.match(self._VALID_URL, url).groups() |
153 | return self._extract_from_json_url( | |
154 | 'https://api.arte.tv/api/player/v1/config/%s/%s' % (lang, video_id), | |
155 | video_id, lang) | |
49625662 TJ |
156 | |
157 | ||
893f8832 PH |
158 | class ArteTVEmbedIE(ArteTVPlus7IE): |
159 | IE_NAME = 'arte.tv:embed' | |
160 | _VALID_URL = r'''(?x) | |
ff0f4cfe RA |
161 | https://www\.arte\.tv |
162 | /player/v3/index\.php\?json_url= | |
893f8832 | 163 | (?P<json_url> |
ff0f4cfe RA |
164 | https?://api\.arte\.tv/api/player/v1/config/ |
165 | (?P<lang>[^/]+)/(?P<id>\d{6}-\d{3}-[AF]) | |
893f8832 PH |
166 | ) |
167 | ''' | |
168 | ||
6e6b9f60 S |
169 | _TESTS = [] |
170 | ||
893f8832 | 171 | def _real_extract(self, url): |
ff0f4cfe | 172 | json_url, lang, video_id = re.match(self._VALID_URL, url).groups() |
893f8832 | 173 | return self._extract_from_json_url(json_url, video_id, lang) |
4b492e35 S |
174 | |
175 | ||
6e6b9f60 S |
176 | class ArteTVPlaylistIE(ArteTVBaseIE): |
177 | IE_NAME = 'arte.tv:playlist' | |
ff0f4cfe | 178 | _VALID_URL = r'https?://(?:www\.)?arte\.tv/(?P<lang>fr|de|en|es|it|pl)/videos/(?P<id>RC-\d{6})' |
6e6b9f60 S |
179 | |
180 | _TESTS = [{ | |
ff0f4cfe | 181 | 'url': 'https://www.arte.tv/en/videos/RC-016954/earn-a-living/', |
6e6b9f60 | 182 | 'info_dict': { |
ff0f4cfe RA |
183 | 'id': 'RC-016954', |
184 | 'title': 'Earn a Living', | |
185 | 'description': 'md5:d322c55011514b3a7241f7fb80d494c2', | |
6e6b9f60 S |
186 | }, |
187 | 'playlist_mincount': 6, | |
6e6b9f60 S |
188 | }] |
189 | ||
190 | def _real_extract(self, url): | |
ff0f4cfe | 191 | lang, playlist_id = re.match(self._VALID_URL, url).groups() |
6e6b9f60 S |
192 | collection = self._download_json( |
193 | 'https://api.arte.tv/api/player/v1/collectionData/%s/%s?source=videos' | |
194 | % (lang, playlist_id), playlist_id) | |
195 | title = collection.get('title') | |
196 | description = collection.get('shortDescription') or collection.get('teaserText') | |
197 | entries = [ | |
198 | self._extract_from_json_url( | |
199 | video['jsonUrl'], video.get('programId') or playlist_id, lang) | |
200 | for video in collection['videos'] if video.get('jsonUrl')] | |
201 | return self.playlist_result(entries, playlist_id, title, description) |