2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
11 get_element_by_attribute
,
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 ArteTvIE(InfoExtractor
):
22 _VALID_URL
= r
'http://videos\.arte\.tv/(?P<lang>fr|de)/.*-(?P<id>.*?)\.html'
25 def _real_extract(self
, url
):
26 mobj
= re
.match(self
._VALID
_URL
, url
)
27 lang
= mobj
.group('lang')
28 video_id
= mobj
.group('id')
30 ref_xml_url
= url
.replace('/videos/', '/do_delegate/videos/')
31 ref_xml_url
= ref_xml_url
.replace('.html', ',view,asPlayerXml.xml')
32 ref_xml_doc
= self
._download
_xml
(
33 ref_xml_url
, video_id
, note
='Downloading metadata')
34 config_node
= find_xpath_attr(ref_xml_doc
, './/video', 'lang', lang
)
35 config_xml_url
= config_node
.attrib
['ref']
36 config
= self
._download
_xml
(
37 config_xml_url
, video_id
, note
='Downloading configuration')
40 'format_id': q
.attrib
['quality'],
41 # The playpath starts at 'mp4:', if we don't manually
42 # split the url, rtmpdump will incorrectly parse them
43 'url': q
.text
.split('mp4:', 1)[0],
44 'play_path': 'mp4:' + q
.text
.split('mp4:', 1)[1],
46 'quality': 2 if q
.attrib
['quality'] == 'hd' else 1,
47 } for q
in config
.findall('./urls/url')]
48 self
._sort
_formats
(formats
)
50 title
= config
.find('.//name').text
51 thumbnail
= config
.find('.//firstThumbnailUrl').text
55 'thumbnail': thumbnail
,
60 class ArteTVPlus7IE(InfoExtractor
):
61 IE_NAME
= 'arte.tv:+7'
62 _VALID_URL
= r
'https?://(?:www\.)?arte\.tv/guide/(?P<lang>fr|de)/(?:(?:sendungen|emissions)/)?(?P<id>.*?)/(?P<name>.*?)(\?.*)?'
65 def _extract_url_info(cls
, url
):
66 mobj
= re
.match(cls
._VALID
_URL
, url
)
67 lang
= mobj
.group('lang')
68 # This is not a real id, it can be for example AJT for the news
69 # http://www.arte.tv/guide/fr/emissions/AJT/arte-journal
70 video_id
= mobj
.group('id')
73 def _real_extract(self
, url
):
74 video_id
, lang
= self
._extract
_url
_info
(url
)
75 webpage
= self
._download
_webpage
(url
, video_id
)
76 return self
._extract
_from
_webpage
(webpage
, video_id
, lang
)
78 def _extract_from_webpage(self
, webpage
, video_id
, lang
):
79 json_url
= self
._html
_search
_regex
(
80 [r
'arte_vp_url=["\'](.*?
)["\']', r'data-url=["\']([^
"]+)["\']'],
81 webpage, 'json vp url
')
82 return self._extract_from_json_url(json_url, video_id, lang)
84 def _extract_from_json_url(self, json_url, video_id, lang):
85 info = self._download_json(json_url, video_id)
86 player_info = info['videoJsonPlayer
']
88 upload_date_str = player_info.get('shootingDate
')
89 if not upload_date_str:
90 upload_date_str = player_info.get('VDA
', '').split(' ')[0]
92 title = player_info['VTI
'].strip()
93 subtitle = player_info.get('VSU
', '').strip()
95 title += ' - %s' % subtitle
98 'id': player_info['VID
'],
100 'description
': player_info.get('VDE
'),
101 'upload_date
': unified_strdate(upload_date_str),
102 'thumbnail
': player_info.get('programImage
') or player_info.get('VTU
', {}).get('IUR
'),
104 qfunc = qualities(['HQ
', 'MQ
', 'EQ
', 'SQ
'])
107 for format_id, format_dict in player_info['VSR
'].items():
108 f = dict(format_dict)
109 versionCode = f.get('versionCode
')
115 lang_rexs = [r'VO?
%s' % langcode, r'VO?
.-ST
%s' % langcode]
117 None if versionCode is None else (
118 10 if any(re.match(r, versionCode) for r in lang_rexs)
121 if versionCode is not None:
122 # The original version with subtitles has lower relevance
123 if re.match(r'VO
-ST(F|A
)', versionCode):
125 # The version with sourds/mal subtitles has also lower relevance
126 elif re.match(r'VO?
(F|A
)-STM\
1', versionCode):
129 'format_id
': format_id,
130 'preference
': -10 if f.get('videoFormat
') == 'M3U8
' else None,
131 'language_preference
': lang_pref,
132 'format_note
': '%s, %s' % (f.get('versionCode
'), f.get('versionLibelle
')),
133 'width
': int_or_none(f.get('width
')),
134 'height
': int_or_none(f.get('height
')),
135 'tbr
': int_or_none(f.get('bitrate
')),
136 'quality
': qfunc(f.get('quality
')),
137 'source_preference
': source_pref,
140 if f.get('mediaType
') == 'rtmp
':
141 format['url
'] = f['streamer
']
142 format['play_path
'] = 'mp4
:' + f['url
']
143 format['ext
'] = 'flv
'
145 format['url
'] = f['url
']
147 formats.append(format)
149 self._check_formats(formats, video_id)
150 self._sort_formats(formats)
152 info_dict['formats
'] = formats
156 # It also uses the arte_vp_url url from the webpage to extract the information
157 class ArteTVCreativeIE(ArteTVPlus7IE):
158 IE_NAME = 'arte
.tv
:creative
'
159 _VALID_URL = r'https?
://creative\
.arte\
.tv
/(?P
<lang
>fr|de
)/(?
:magazine?
/)?
(?P
<id>[^?
#]+)'
162 'url': 'http://creative.arte.tv/de/magazin/agentur-amateur-corporate-design',
166 'title': 'Folge 2 - Corporate Design',
167 'upload_date': '20131004',
170 'url': 'http://creative.arte.tv/fr/Monty-Python-Reunion',
174 'title': 'Monty Python live (mostly)',
175 'description': 'Événement ! Quarante-cinq ans après leurs premiers succès, les légendaires Monty Python remontent sur scène.\n',
176 'upload_date': '20140805',
181 class ArteTVFutureIE(ArteTVPlus7IE
):
182 IE_NAME
= 'arte.tv:future'
183 _VALID_URL
= r
'https?://future\.arte\.tv/(?P<lang>fr|de)/(thema|sujet)/.*?#article-anchor-(?P<id>\d+)'
186 'url': 'http://future.arte.tv/fr/sujet/info-sciences#article-anchor-7081',
190 'title': 'Les champignons au secours de la planète',
191 'upload_date': '20131101',
195 def _real_extract(self
, url
):
196 anchor_id
, lang
= self
._extract
_url
_info
(url
)
197 webpage
= self
._download
_webpage
(url
, anchor_id
)
198 row
= get_element_by_id(anchor_id
, webpage
)
199 return self
._extract
_from
_webpage
(row
, anchor_id
, lang
)
202 class ArteTVDDCIE(ArteTVPlus7IE
):
203 IE_NAME
= 'arte.tv:ddc'
204 _VALID_URL
= r
'https?://ddc\.arte\.tv/(?P<lang>emission|folge)/(?P<id>.+)'
206 def _real_extract(self
, url
):
207 video_id
, lang
= self
._extract
_url
_info
(url
)
210 elif lang
== 'emission':
212 webpage
= self
._download
_webpage
(url
, video_id
)
213 scriptElement
= get_element_by_attribute('class', 'visu_video_block', webpage
)
214 script_url
= self
._html
_search
_regex
(r
'src="(.*?)"', scriptElement
, 'script url')
215 javascriptPlayerGenerator
= self
._download
_webpage
(script_url
, video_id
, 'Download javascript player generator')
216 json_url
= self
._search
_regex
(r
"json_url=(.*)&rendering_place.*", javascriptPlayerGenerator
, 'json url')
217 return self
._extract
_from
_json
_url
(json_url
, video_id
, lang
)
220 class ArteTVConcertIE(ArteTVPlus7IE
):
221 IE_NAME
= 'arte.tv:concert'
222 _VALID_URL
= r
'https?://concert\.arte\.tv/(?P<lang>de|fr)/(?P<id>.+)'
225 'url': 'http://concert.arte.tv/de/notwist-im-pariser-konzertclub-divan-du-monde',
226 'md5': '9ea035b7bd69696b67aa2ccaaa218161',
230 'title': 'The Notwist im Pariser Konzertclub "Divan du Monde"',
231 'upload_date': '20140128',
232 'description': 'md5:486eb08f991552ade77439fe6d82c305',
237 class ArteTVEmbedIE(ArteTVPlus7IE
):
238 IE_NAME
= 'arte.tv:embed'
239 _VALID_URL
= r
'''(?x)
241 /playerv2/embed\.php\?json_url=
243 http://arte\.tv/papi/tvguide/videos/stream/player/
244 (?P<lang>[^/]+)/(?P<id>[^/]+)[^&]*
248 def _real_extract(self
, url
):
249 mobj
= re
.match(self
._VALID
_URL
, url
)
250 video_id
= mobj
.group('id')
251 lang
= mobj
.group('lang')
252 json_url
= mobj
.group('json_url')
253 return self
._extract
_from
_json
_url
(json_url
, video_id
, lang
)