mirror of
https://github.com/l1ving/youtube-dl
synced 2024-11-25 20:22:57 +08:00
_download_webpage helper function
This commit is contained in:
parent
1c256f7047
commit
d830b7c297
@ -105,6 +105,20 @@ class InfoExtractor(object):
|
|||||||
def IE_NAME(self):
|
def IE_NAME(self):
|
||||||
return type(self).__name__[:-2]
|
return type(self).__name__[:-2]
|
||||||
|
|
||||||
|
def _download_webpage(self, url, video_id, note=None, errnote=None):
|
||||||
|
if note is None:
|
||||||
|
note = u'Downloading video webpage'
|
||||||
|
self._downloader.to_screen(u'[%s] %s: %s' % (self.IE_NAME, video_id, note))
|
||||||
|
try:
|
||||||
|
urlh = compat_urllib_request.urlopen(url)
|
||||||
|
webpage_bytes = urlh.read()
|
||||||
|
return webpage_bytes.decode('utf-8', 'replace')
|
||||||
|
except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
|
||||||
|
if errnote is None:
|
||||||
|
errnote = u'Unable to download webpage'
|
||||||
|
raise ExtractorError(u'%s: %s' % (errnote, compat_str(err)))
|
||||||
|
|
||||||
|
|
||||||
class YoutubeIE(InfoExtractor):
|
class YoutubeIE(InfoExtractor):
|
||||||
"""Information extractor for youtube.com."""
|
"""Information extractor for youtube.com."""
|
||||||
|
|
||||||
@ -3803,12 +3817,7 @@ class UstreamIE(InfoExtractor):
|
|||||||
m = re.match(self._VALID_URL, url)
|
m = re.match(self._VALID_URL, url)
|
||||||
video_id = m.group('videoID')
|
video_id = m.group('videoID')
|
||||||
video_url = u'http://tcdn.ustream.tv/video/%s' % video_id
|
video_url = u'http://tcdn.ustream.tv/video/%s' % video_id
|
||||||
try:
|
webpage = self._download_webpage(url, video_id)
|
||||||
urlh = compat_urllib_request.urlopen(url)
|
|
||||||
webpage_bytes = urlh.read()
|
|
||||||
webpage = webpage_bytes.decode('utf-8', 'ignore')
|
|
||||||
except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
|
|
||||||
raise ExtractorError(u'unable to download webpage: %s' % compat_str(err))
|
|
||||||
m = re.search(r'data-title="(?P<title>.+)"',webpage)
|
m = re.search(r'data-title="(?P<title>.+)"',webpage)
|
||||||
title = m.group('title')
|
title = m.group('title')
|
||||||
m = re.search(r'<a class="state" data-content-type="channel" data-content-id="(?P<uploader>\d+)"',webpage)
|
m = re.search(r'<a class="state" data-content-type="channel" data-content-id="(?P<uploader>\d+)"',webpage)
|
||||||
|
Loading…
Reference in New Issue
Block a user