3 import xml.etree.ElementTree
5 from .common import InfoExtractor
12 class ArteTvIE(InfoExtractor):
14 There are two sources of video in arte.tv: videos.arte.tv and
15 www.arte.tv/guide, the extraction process is different for each one.
16 The videos expire in 7 days, so we can't add tests.
18 _EMISSION_URL = r'(?:http://)?www\.arte.tv/guide/(?P<lang>fr|de)/(?:(?:sendungen|emissions)/)?(?P<id>.*?)/(?P<name>.*?)(\?.*)?'
19 _VIDEOS_URL = r'(?:http://)?videos.arte.tv/(?P<lang>fr|de)/.*-(?P<id>.*?).html'
20 _LIVE_URL = r'index-[0-9]+\.html$'
25 def suitable(cls, url):
26 return any(re.match(regex, url) for regex in (cls._EMISSION_URL, cls._VIDEOS_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._EMISSION_URL, url)
59 lang = mobj.group('lang')
60 # This is not a real id, it can be for example AJT for the news
61 # http://www.arte.tv/guide/fr/emissions/AJT/arte-journal
62 video_id = mobj.group('id')
63 return self._extract_emission(url, video_id, lang)
65 mobj = re.match(self._VIDEOS_URL, url)
68 lang = mobj.group('lang')
69 return self._extract_video(url, id, lang)
71 if re.search(self._LIVE_URL, video_id) is not None:
72 raise ExtractorError(u'Arte live streams are not yet supported, sorry')
73 # self.extractLiveStream(url)
76 def _extract_emission(self, url, video_id, lang):
77 """Extract from www.arte.tv/guide"""
78 webpage = self._download_webpage(url, video_id)
79 json_url = self._html_search_regex(r'arte_vp_url="(.*?)"', webpage, 'json url')
81 json_info = self._download_webpage(json_url, video_id, 'Downloading info json')
82 self.report_extraction(video_id)
83 info = json.loads(json_info)
84 player_info = info['videoJsonPlayer']
86 info_dict = {'id': player_info['VID'],
87 'title': player_info['VTI'],
88 'description': player_info['VDE'],
89 'upload_date': unified_strdate(player_info['VDA'].split(' ')[0]),
90 'thumbnail': player_info['programImage'],
94 formats = player_info['VSR'].values()
96 # Return true if that format is in the language of the url
101 regexes = [r'VO?%s' % l, r'V%s-ST.' % l]
102 return any(re.match(r, f['versionCode']) for r in regexes)
103 # Some formats may not be in the same language as the url
104 formats = filter(_match_lang, formats)
105 # We order the formats by quality
106 formats = sorted(formats, key=lambda f: int(f['height']))
107 # Pick the best quality
108 format_info = formats[-1]
109 if format_info['mediaType'] == u'rtmp':
110 info_dict['url'] = format_info['streamer']
111 info_dict['play_path'] = 'mp4:' + format_info['url']
113 info_dict['url'] = format_info['url']
117 def _extract_video(self, url, video_id, lang):
118 """Extract from videos.arte.tv"""
119 ref_xml_url = url.replace('/videos/', '/do_delegate/videos/')
120 ref_xml_url = ref_xml_url.replace('.html', ',view,asPlayerXml.xml')
121 ref_xml = self._download_webpage(ref_xml_url, video_id, note=u'Downloading metadata')
122 ref_xml_doc = xml.etree.ElementTree.fromstring(ref_xml)
123 config_node = find_xpath_attr(ref_xml_doc, './/video', 'lang', lang)
124 config_xml_url = config_node.attrib['ref']
125 config_xml = self._download_webpage(config_xml_url, video_id, note=u'Downloading configuration')
127 video_urls = list(re.finditer(r'<url quality="(?P<quality>.*?)">(?P<url>.*?)</url>', config_xml))
129 quality = m.group('quality')
134 # We pick the best quality
135 video_urls = sorted(video_urls, key=_key)
136 video_url = list(video_urls)[-1].group('url')
138 title = self._html_search_regex(r'<name>(.*?)</name>', config_xml, 'title')
139 thumbnail = self._html_search_regex(r'<firstThumbnailUrl>(.*?)</firstThumbnailUrl>',
140 config_xml, 'thumbnail')
141 return {'id': video_id,
143 'thumbnail': thumbnail,