3 import xml.etree.ElementTree
5 from .common import InfoExtractor
13 # There are different sources of video in arte.tv, the extraction process
14 # is different for each one. The videos usually expire in 7 days, so we can't
17 class ArteTvIE(InfoExtractor):
18 _VIDEOS_URL = r'(?:http://)?videos.arte.tv/(?P<lang>fr|de)/.*-(?P<id>.*?).html'
19 _LIVEWEB_URL = r'(?:http://)?liveweb.arte.tv/(?P<lang>fr|de)/(?P<subpage>.+?)/(?P<name>.+)'
20 _LIVE_URL = r'index-[0-9]+\.html$'
25 def suitable(cls, url):
26 return any(re.match(regex, url) for regex in (cls._VIDEOS_URL, cls._LIVEWEB_URL))
28 # TODO implement Live Stream
29 # from ..utils import compat_urllib_parse
30 # def extractLiveStream(self, url):
31 # video_lang = url.split('/')[-4]
32 # info = self.grep_webpage(
34 # r'src="(.*?/videothek_js.*?\.js)',
37 # (1, 'url', u'Invalid URL: %s' % url)
40 # http_host = url.split('/')[2]
41 # next_url = 'http://%s%s' % (http_host, compat_urllib_parse.unquote(info.get('url')))
42 # info = self.grep_webpage(
44 # r'(s_artestras_scst_geoFRDE_' + video_lang + '.*?)\'.*?' +
45 # '(http://.*?\.swf).*?' +
49 # (1, 'path', u'could not extract video path: %s' % url),
50 # (2, 'player', u'could not extract video player: %s' % url),
51 # (3, 'url', u'could not extract video url: %s' % url)
54 # video_url = u'%s/%s' % (info.get('url'), info.get('path'))
56 def _real_extract(self, url):
57 mobj = re.match(self._VIDEOS_URL, url)
60 lang = mobj.group('lang')
61 return self._extract_video(url, id, lang)
63 mobj = re.match(self._LIVEWEB_URL, url)
65 name = mobj.group('name')
66 lang = mobj.group('lang')
67 return self._extract_liveweb(url, name, lang)
69 if re.search(self._LIVE_URL, video_id) is not None:
70 raise ExtractorError(u'Arte live streams are not yet supported, sorry')
71 # self.extractLiveStream(url)
74 def _extract_video(self, url, video_id, lang):
75 """Extract from videos.arte.tv"""
76 ref_xml_url = url.replace('/videos/', '/do_delegate/videos/')
77 ref_xml_url = ref_xml_url.replace('.html', ',view,asPlayerXml.xml')
78 ref_xml = self._download_webpage(ref_xml_url, video_id, note=u'Downloading metadata')
79 ref_xml_doc = xml.etree.ElementTree.fromstring(ref_xml)
80 config_node = find_xpath_attr(ref_xml_doc, './/video', 'lang', lang)
81 config_xml_url = config_node.attrib['ref']
82 config_xml = self._download_webpage(config_xml_url, video_id, note=u'Downloading configuration')
84 video_urls = list(re.finditer(r'<url quality="(?P<quality>.*?)">(?P<url>.*?)</url>', config_xml))
86 quality = m.group('quality')
91 # We pick the best quality
92 video_urls = sorted(video_urls, key=_key)
93 video_url = list(video_urls)[-1].group('url')
95 title = self._html_search_regex(r'<name>(.*?)</name>', config_xml, 'title')
96 thumbnail = self._html_search_regex(r'<firstThumbnailUrl>(.*?)</firstThumbnailUrl>',
97 config_xml, 'thumbnail')
98 return {'id': video_id,
100 'thumbnail': thumbnail,
105 def _extract_liveweb(self, url, name, lang):
106 """Extract form http://liveweb.arte.tv/"""
107 webpage = self._download_webpage(url, name)
108 video_id = self._search_regex(r'eventId=(\d+?)("|&)', webpage, u'event id')
109 config_xml = self._download_webpage('http://download.liveweb.arte.tv/o21/liveweb/events/event-%s.xml' % video_id,
110 video_id, u'Downloading information')
111 config_doc = xml.etree.ElementTree.fromstring(config_xml.encode('utf-8'))
112 event_doc = config_doc.find('event')
113 url_node = event_doc.find('video').find('urlHd')
115 url_node = video_doc.find('urlSd')
117 return {'id': video_id,
118 'title': event_doc.find('name%s' % lang.capitalize()).text,
119 'url': url_node.text.replace('MP4', 'mp4'),
121 'thumbnail': self._og_search_thumbnail(webpage),
125 class ArteTVPlus7IE(InfoExtractor):
126 IE_NAME = u'arte.tv:+7'
127 _VALID_URL = r'https?://www\.arte.tv/guide/(?P<lang>fr|de)/(?:(?:sendungen|emissions)/)?(?P<id>.*?)/(?P<name>.*?)(\?.*)?'
129 def _real_extract(self, url):
130 mobj = re.match(self._VALID_URL, url)
131 lang = mobj.group('lang')
132 # This is not a real id, it can be for example AJT for the news
133 # http://www.arte.tv/guide/fr/emissions/AJT/arte-journal
134 video_id = mobj.group('id')
136 webpage = self._download_webpage(url, video_id)
137 json_url = self._html_search_regex(r'arte_vp_url="(.*?)"', webpage, 'json url')
139 json_info = self._download_webpage(json_url, video_id, 'Downloading info json')
140 self.report_extraction(video_id)
141 info = json.loads(json_info)
142 player_info = info['videoJsonPlayer']
145 'id': player_info['VID'],
146 'title': player_info['VTI'],
147 'description': player_info.get('VDE'),
148 'upload_date': unified_strdate(player_info.get('VDA', '').split(' ')[0]),
149 'thumbnail': player_info.get('programImage') or player_info.get('VTU', {}).get('IUR'),
152 formats = player_info['VSR'].values()
154 if f.get('versionCode') is None:
156 # Return true if that format is in the language of the url
161 regexes = [r'VO?%s' % l, r'VO?.-ST%s' % l]
162 return any(re.match(r, f['versionCode']) for r in regexes)
163 # Some formats may not be in the same language as the url
164 formats = filter(_match_lang, formats)
165 # Some formats use the m3u8 protocol
166 formats = filter(lambda f: f.get('videoFormat') != 'M3U8', formats)
167 # We order the formats by quality
168 formats = sorted(formats, key=lambda f: int(f.get('height',-1)))
169 # Prefer videos without subtitles in the same language
170 formats = sorted(formats, key=lambda f: re.match(r'VO(F|A)-STM\1', f.get('versionCode', '')) is None)
171 # Pick the best quality
172 def _format(format_info):
174 'width': format_info.get('width'),
175 'height': format_info.get('height'),
177 if format_info['mediaType'] == u'rtmp':
178 info['url'] = format_info['streamer']
179 info['play_path'] = 'mp4:' + format_info['url']
182 info['url'] = format_info['url']
183 info['ext'] = determine_ext(info['url'])
185 info_dict['formats'] = [_format(f) for f in formats]
186 # TODO: Remove when #980 has been merged
187 info_dict.update(info_dict['formats'][-1])
192 # It also uses the arte_vp_url url from the webpage to extract the information
193 class ArteTVCreativeIE(ArteTVPlus7IE):
194 IE_NAME = u'arte.tv:creative'
195 _VALID_URL = r'https?://creative\.arte\.tv/(?P<lang>fr|de)/magazine?/(?P<id>.+)'
198 u'url': u'http://creative.arte.tv/de/magazin/agentur-amateur-corporate-design',
199 u'file': u'050489-002.mp4',
201 u'title': u'Agentur Amateur #2 - Corporate Design',