2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
14 get_element_by_attribute
,
17 # There are different sources of video in arte.tv, the extraction process
18 # is different for each one. The videos usually expire in 7 days, so we can't
22 class ArteTvIE(InfoExtractor
):
23 _VALID_URL
= r
'http://videos\.arte\.tv/(?P<lang>fr|de)/.*-(?P<id>.*?)\.html'
26 def _real_extract(self
, url
):
27 mobj
= re
.match(self
._VALID
_URL
, url
)
28 lang
= mobj
.group('lang')
29 video_id
= mobj
.group('id')
31 ref_xml_url
= url
.replace('/videos/', '/do_delegate/videos/')
32 ref_xml_url
= ref_xml_url
.replace('.html', ',view,asPlayerXml.xml')
33 ref_xml_doc
= self
._download
_xml
(
34 ref_xml_url
, video_id
, note
='Downloading metadata')
35 config_node
= find_xpath_attr(ref_xml_doc
, './/video', 'lang', lang
)
36 config_xml_url
= config_node
.attrib
['ref']
37 config
= self
._download
_xml
(
38 config_xml_url
, video_id
, note
='Downloading configuration')
41 'forma_id': q
.attrib
['quality'],
42 # The playpath starts at 'mp4:', if we don't manually
43 # split the url, rtmpdump will incorrectly parse them
44 'url': q
.text
.split('mp4:', 1)[0],
45 'play_path': 'mp4:' + q
.text
.split('mp4:', 1)[1],
47 'quality': 2 if q
.attrib
['quality'] == 'hd' else 1,
48 } for q
in config
.findall('./urls/url')]
49 self
._sort
_formats
(formats
)
51 title
= config
.find('.//name').text
52 thumbnail
= config
.find('.//firstThumbnailUrl').text
56 'thumbnail': thumbnail
,
61 class ArteTVPlus7IE(InfoExtractor
):
62 IE_NAME
= 'arte.tv:+7'
63 _VALID_URL
= r
'https?://(?:www\.)?arte\.tv/guide/(?P<lang>fr|de)/(?:(?:sendungen|emissions)/)?(?P<id>.*?)/(?P<name>.*?)(\?.*)?'
66 def _extract_url_info(cls
, url
):
67 mobj
= re
.match(cls
._VALID
_URL
, url
)
68 lang
= mobj
.group('lang')
69 # This is not a real id, it can be for example AJT for the news
70 # http://www.arte.tv/guide/fr/emissions/AJT/arte-journal
71 video_id
= mobj
.group('id')
74 def _real_extract(self
, url
):
75 video_id
, lang
= self
._extract
_url
_info
(url
)
76 webpage
= self
._download
_webpage
(url
, video_id
)
77 return self
._extract
_from
_webpage
(webpage
, video_id
, lang
)
79 def _extract_from_webpage(self
, webpage
, video_id
, lang
):
80 json_url
= self
._html
_search
_regex
(
81 r
'arte_vp_url="(.*?)"', 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']
89 'id': player_info
['VID'],
90 'title': player_info
['VTI'],
91 'description': player_info
.get('VDE'),
92 'upload_date': unified_strdate(player_info
.get('VDA', '').split(' ')[0]),
93 'thumbnail': player_info
.get('programImage') or player_info
.get('VTU', {}).get('IUR'),
96 all_formats
= player_info
['VSR'].values()
97 # Some formats use the m3u8 protocol
98 all_formats
= list(filter(lambda f
: f
.get('videoFormat') != 'M3U8', all_formats
))
100 if f
.get('versionCode') is None:
102 # Return true if that format is in the language of the url
109 regexes
= [r
'VO?%s' % l
, r
'VO?.-ST%s' % l
]
110 return any(re
.match(r
, f
['versionCode']) for r
in regexes
)
111 # Some formats may not be in the same language as the url
112 # TODO: Might want not to drop videos that does not match requested language
113 # but to process those formats with lower precedence
114 formats
= filter(_match_lang
, all_formats
)
115 formats
= list(formats
) # in python3 filter returns an iterator
117 # Some videos are only available in the 'Originalversion'
118 # they aren't tagged as being in French or German
119 # Sometimes there are neither videos of requested lang code
120 # nor original version videos available
121 # For such cases we just take all_formats as is
122 formats
= all_formats
124 raise ExtractorError('The formats list is empty')
126 if re
.match(r
'[A-Z]Q', formats
[0]['quality']) is not None:
128 return ['HQ', 'MQ', 'EQ', 'SQ'].index(f
['quality'])
131 versionCode
= f
.get('versionCode')
132 if versionCode
is None:
135 # Sort first by quality
136 int(f
.get('height', -1)),
137 int(f
.get('bitrate', -1)),
138 # The original version with subtitles has lower relevance
139 re
.match(r
'VO-ST(F|A)', versionCode
) is None,
140 # The version with sourds/mal subtitles has also lower relevance
141 re
.match(r
'VO?(F|A)-STM\1', versionCode
) is None,
142 # Prefer http downloads over m3u8
143 0 if f
['url'].endswith('m3u8') else 1,
145 formats
= sorted(formats
, key
=sort_key
)
146 def _format(format_info
):
148 height
= format_info
.get('height')
149 if height
is not None:
150 quality
= compat_str(height
)
151 bitrate
= format_info
.get('bitrate')
152 if bitrate
is not None:
153 quality
+= '-%d' % bitrate
154 if format_info
.get('versionCode') is not None:
155 format_id
= '%s-%s' % (quality
, format_info
['versionCode'])
159 'format_id': format_id
,
160 'format_note': format_info
.get('versionLibelle'),
161 'width': format_info
.get('width'),
164 if format_info
['mediaType'] == 'rtmp':
165 info
['url'] = format_info
['streamer']
166 info
['play_path'] = 'mp4:' + format_info
['url']
169 info
['url'] = format_info
['url']
170 info
['ext'] = determine_ext(info
['url'])
172 info_dict
['formats'] = [_format(f
) for f
in formats
]
177 # It also uses the arte_vp_url url from the webpage to extract the information
178 class ArteTVCreativeIE(ArteTVPlus7IE
):
179 IE_NAME
= 'arte.tv:creative'
180 _VALID_URL
= r
'https?://creative\.arte\.tv/(?P<lang>fr|de)/magazine?/(?P<id>.+)'
183 'url': 'http://creative.arte.tv/de/magazin/agentur-amateur-corporate-design',
187 'title': 'Agentur Amateur / Agence Amateur #2 : Corporate Design',
192 class ArteTVFutureIE(ArteTVPlus7IE
):
193 IE_NAME
= 'arte.tv:future'
194 _VALID_URL
= r
'https?://future\.arte\.tv/(?P<lang>fr|de)/(thema|sujet)/.*?#article-anchor-(?P<id>\d+)'
197 'url': 'http://future.arte.tv/fr/sujet/info-sciences#article-anchor-7081',
201 'title': 'Les champignons au secours de la planète',
202 'upload_date': '20131101',
206 def _real_extract(self
, url
):
207 anchor_id
, lang
= self
._extract
_url
_info
(url
)
208 webpage
= self
._download
_webpage
(url
, anchor_id
)
209 row
= get_element_by_id(anchor_id
, webpage
)
210 return self
._extract
_from
_webpage
(row
, anchor_id
, lang
)
213 class ArteTVDDCIE(ArteTVPlus7IE
):
214 IE_NAME
= 'arte.tv:ddc'
215 _VALID_URL
= r
'https?://ddc\.arte\.tv/(?P<lang>emission|folge)/(?P<id>.+)'
217 def _real_extract(self
, url
):
218 video_id
, lang
= self
._extract
_url
_info
(url
)
221 elif lang
== 'emission':
223 webpage
= self
._download
_webpage
(url
, video_id
)
224 scriptElement
= get_element_by_attribute('class', 'visu_video_block', webpage
)
225 script_url
= self
._html
_search
_regex
(r
'src="(.*?)"', scriptElement
, 'script url')
226 javascriptPlayerGenerator
= self
._download
_webpage
(script_url
, video_id
, 'Download javascript player generator')
227 json_url
= self
._search
_regex
(r
"json_url=(.*)&rendering_place.*", javascriptPlayerGenerator
, 'json url')
228 return self
._extract
_from
_json
_url
(json_url
, video_id
, lang
)
231 class ArteTVConcertIE(ArteTVPlus7IE
):
232 IE_NAME
= 'arte.tv:concert'
233 _VALID_URL
= r
'https?://concert\.arte\.tv/(?P<lang>de|fr)/(?P<id>.+)'
236 'url': 'http://concert.arte.tv/de/notwist-im-pariser-konzertclub-divan-du-monde',
237 'md5': '9ea035b7bd69696b67aa2ccaaa218161',
241 'title': 'The Notwist im Pariser Konzertclub "Divan du Monde"',
242 'upload_date': '20140128',
243 'description': 'md5:486eb08f991552ade77439fe6d82c305',
248 class ArteTVEmbedIE(ArteTVPlus7IE
):
249 IE_NAME
= 'arte.tv:embed'
250 _VALID_URL
= r
'''(?x)
252 /playerv2/embed\.php\?json_url=
254 http://arte\.tv/papi/tvguide/videos/stream/player/
255 (?P<lang>[^/]+)/(?P<id>[^/]+)[^&]*
259 def _real_extract(self
, url
):
260 mobj
= re
.match(self
._VALID
_URL
, url
)
261 video_id
= mobj
.group('id')
262 lang
= mobj
.group('lang')
263 json_url
= mobj
.group('json_url')
264 return self
._extract
_from
_json
_url
(json_url
, video_id
, lang
)