]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/arte.py
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 # TODO implement Live Stream
52 # def extractLiveStream(self, url):
53 # video_lang = url.split('/')[-4]
54 # info = self.grep_webpage(
56 # r'src="(.*?/videothek_js.*?\.js)',
59 # (1, 'url', u'Invalid URL: %s' % url)
62 # http_host = url.split('/')[2]
63 # next_url = 'http://%s%s' % (http_host, compat_urllib_parse.unquote(info.get('url')))
64 # info = self.grep_webpage(
66 # r'(s_artestras_scst_geoFRDE_' + video_lang + '.*?)\'.*?' +
67 # '(http://.*?\.swf).*?' +
71 # (1, 'path', u'could not extract video path: %s' % url),
72 # (2, 'player', u'could not extract video player: %s' % url),
73 # (3, 'url', u'could not extract video url: %s' % url)
76 # video_url = u'%s/%s' % (info.get('url'), info.get('path'))
78 def extractPlus7Stream(self
, url
):
79 video_lang
= url
.split('/')[-3]
80 info
= self
.grep_webpage(
82 r
'param name="movie".*?videorefFileUrl=(http[^\'"&]*)',
85 (1, 'url', u'Invalid URL: %s' % url)
88 next_url = compat_urllib_parse.unquote(info.get('url'))
89 info = self.grep_webpage(
91 r'<video lang="%s" ref="(http
[^
\'"&]*)' % video_lang,
94 (1, 'url', u'Could not find <video> tag: %s' % url)
97 next_url = compat_urllib_parse.unquote(info.get('url'))
99 info = self.grep_webpage(
101 r'<video id="(.*?
)".*?>.*?' +
102 '<name>(.*?)</name>.*?' +
103 '<dateVideo>(.*?)</dateVideo>.*?' +
104 '<url quality="hd
">(.*?)</url>',
107 (1, 'id', u'could not extract video id: %s' % url),
108 (2, 'title', u'could not extract video title: %s' % url),
109 (3, 'date', u'could not extract video date: %s' % url),
110 (4, 'url', u'could not extract video url: %s' % url)
115 'id': info.get('id'),
116 'url': compat_urllib_parse.unquote(info.get('url')),
117 'uploader': u'arte.tv',
118 'upload_date': unified_strdate(info.get('date')),
119 'title': info.get('title').decode('utf-8'),
125 def _real_extract(self, url):
126 video_id = url.split('/')[-1]
127 self.report_extraction(video_id)
129 if re.search(self._LIVE_URL, video_id) is not None:
130 raise ExtractorError(u'Arte live streams are not yet supported, sorry')
131 # self.extractLiveStream(url)
134 info = self.extractPlus7Stream(url)