4 from .common import InfoExtractor
10 compat_urllib_request,
16 class ArteTvIE(InfoExtractor):
17 """arte.tv information extractor."""
19 _VALID_URL = r'(?:http://)?videos\.arte\.tv/(?:fr|de)/videos/.*'
20 _LIVE_URL = r'index-[0-9]+\.html$'
24 def fetch_webpage(self, url):
25 request = compat_urllib_request.Request(url)
27 self.report_download_webpage(url)
28 webpage = compat_urllib_request.urlopen(request).read()
29 except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
30 raise ExtractorError(u'Unable to retrieve video webpage: %s' % compat_str(err))
31 except ValueError as err:
32 raise ExtractorError(u'Invalid URL: %s' % url)
35 def grep_webpage(self, url, regex, regexFlags, matchTuples):
36 page = self.fetch_webpage(url)
37 mobj = re.search(regex, page, regexFlags)
41 raise ExtractorError(u'Invalid URL: %s' % url)
43 for (i, key, err) in matchTuples:
44 if mobj.group(i) is None:
45 raise ExtractorError(err)
47 info[key] = mobj.group(i)
51 def extractLiveStream(self, url):
52 video_lang = url.split('/')[-4]
53 info = self.grep_webpage(
55 r'src="(.*?/videothek_js.*?\.js)',
58 (1, 'url', u'Invalid URL: %s' % url)
61 http_host = url.split('/')[2]
62 next_url = 'http://%s%s' % (http_host, compat_urllib_parse.unquote(info.get('url')))
63 info = self.grep_webpage(
65 r'(s_artestras_scst_geoFRDE_' + video_lang + '.*?)\'.*?' +
66 '(http://.*?\.swf).*?' +
70 (1, 'path', u'could not extract video path: %s' % url),
71 (2, 'player', u'could not extract video player: %s' % url),
72 (3, 'url', u'could not extract video url: %s' % url)
75 video_url = u'%s/%s' % (info.get('url'), info.get('path'))
77 def extractPlus7Stream(self, url):
78 video_lang = url.split('/')[-3]
79 info = self.grep_webpage(
81 r'param name="movie".*?videorefFileUrl=(http[^\'"&]*)',
84 (1, 'url', u'Invalid URL: %s' % url)
87 next_url = compat_urllib_parse.unquote(info.get('url'))
88 info = self.grep_webpage(
90 r'<video lang="%s" ref="(http[^\'"&]*)' % video_lang,
93 (1, 'url', u'Could not find <video> tag: %s' % url)
96 next_url = compat_urllib_parse.unquote(info.get('url'))
98 info = self.grep_webpage(
100 r'<video id="(.*?)".*?>.*?' +
101 '<name>(.*?)</name>.*?' +
102 '<dateVideo>(.*?)</dateVideo>.*?' +
103 '<url quality="hd">(.*?)</url>',
106 (1, 'id', u'could not extract video id: %s' % url),
107 (2, 'title', u'could not extract video title: %s' % url),
108 (3, 'date', u'could not extract video date: %s' % url),
109 (4, 'url', u'could not extract video url: %s' % url)
114 'id': info.get('id'),
115 'url': compat_urllib_parse.unquote(info.get('url')),
116 'uploader': u'arte.tv',
117 'upload_date': unified_strdate(info.get('date')),
118 'title': info.get('title').decode('utf-8'),
124 def _real_extract(self, url):
125 video_id = url.split('/')[-1]
126 self.report_extraction(video_id)
128 if re.search(self._LIVE_URL, video_id) is not None:
129 self.extractLiveStream(url)
132 info = self.extractPlus7Stream(url)