]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/arte.py
2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
7 from ..compat
import compat_str
16 # There are different sources of video in arte.tv, the extraction process
17 # is different for each one. The videos usually expire in 7 days, so we can't
21 class ArteTVBaseIE(InfoExtractor
):
22 def _extract_from_json_url(self
, json_url
, video_id
, lang
, title
=None):
23 info
= self
._download
_json
(json_url
, video_id
)
24 player_info
= info
['videoJsonPlayer']
26 vsr
= try_get(player_info
, lambda x
: x
['VSR'], dict)
29 if try_get(player_info
, lambda x
: x
['custom_msg']['type']) == 'error':
31 player_info
, lambda x
: x
['custom_msg']['msg'], compat_str
)
33 error
= 'Video %s is not available' % player_info
.get('VID') or video_id
34 raise ExtractorError(error
, expected
=True)
36 upload_date_str
= player_info
.get('shootingDate')
37 if not upload_date_str
:
38 upload_date_str
= (player_info
.get('VRA') or player_info
.get('VDA') or '').split(' ')[0]
40 title
= (player_info
.get('VTI') or title
or player_info
['VID']).strip()
41 subtitle
= player_info
.get('VSU', '').strip()
43 title
+= ' - %s' % subtitle
46 'id': player_info
['VID'],
48 'description': player_info
.get('VDE'),
49 'upload_date': unified_strdate(upload_date_str
),
50 'thumbnail': player_info
.get('programImage') or player_info
.get('VTU', {}).get('IUR'),
52 qfunc
= qualities(['MQ', 'HQ', 'EQ', 'SQ'])
63 langcode
= LANGS
.get(lang
, lang
)
66 for format_id
, format_dict
in vsr
.items():
68 versionCode
= f
.get('versionCode')
69 l
= re
.escape(langcode
)
71 # Language preference from most to least priority
72 # Reference: section 6.8 of
73 # https://www.arte.tv/sites/en/corporate/files/complete-technical-guidelines-arte-geie-v1-07-1.pdf
75 # original version in requested language, without subtitles
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
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
),
103 for pref
, p
in enumerate(PREFERENCES
):
104 if re
.match(p
, versionCode
):
105 lang_pref
= len(PREFERENCES
) - pref
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')),
118 'quality': qfunc(f
.get('quality')),
121 if f
.get('mediaType') == 'rtmp':
122 format
['url'] = f
['streamer']
123 format
['play_path'] = 'mp4:' + f
['url']
124 format
['ext'] = 'flv'
126 format
['url'] = f
['url']
128 formats
.append(format
)
130 self
._check
_formats
(formats
, video_id
)
131 self
._sort
_formats
(formats
)
133 info_dict
['formats'] = formats
137 class ArteTVPlus7IE(ArteTVBaseIE
):
138 IE_NAME
= 'arte.tv:+7'
139 _VALID_URL
= r
'https?://(?:www\.)?arte\.tv/(?P<lang>fr|de|en|es|it|pl)/videos/(?P<id>\d{6}-\d{3}-[AF])'
142 'url': 'https://www.arte.tv/en/videos/088501-000-A/mexico-stealing-petrol-to-survive/',
144 'id': '088501-000-A',
146 'title': 'Mexico: Stealing Petrol to Survive',
147 'upload_date': '20190628',
151 def _real_extract(self
, url
):
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
),
158 class ArteTVEmbedIE(ArteTVPlus7IE
):
159 IE_NAME
= 'arte.tv:embed'
160 _VALID_URL
= r
'''(?x)
161 https://www\.arte\.tv
162 /player/v3/index\.php\?json_url=
164 https?://api\.arte\.tv/api/player/v1/config/
165 (?P<lang>[^/]+)/(?P<id>\d{6}-\d{3}-[AF])
171 def _real_extract(self
, url
):
172 json_url
, lang
, video_id
= re
.match(self
._VALID
_URL
, url
).groups()
173 return self
._extract
_from
_json
_url
(json_url
, video_id
, lang
)
176 class ArteTVPlaylistIE(ArteTVBaseIE
):
177 IE_NAME
= 'arte.tv:playlist'
178 _VALID_URL
= r
'https?://(?:www\.)?arte\.tv/(?P<lang>fr|de|en|es|it|pl)/videos/(?P<id>RC-\d{6})'
181 'url': 'https://www.arte.tv/en/videos/RC-016954/earn-a-living/',
184 'title': 'Earn a Living',
185 'description': 'md5:d322c55011514b3a7241f7fb80d494c2',
187 'playlist_mincount': 6,
190 def _real_extract(self
, url
):
191 lang
, playlist_id
= re
.match(self
._VALID
_URL
, url
).groups()
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')
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
)