mirror of
https://github.com/l1ving/youtube-dl
synced 2025-03-09 13:17:21 +08:00
Changes after code review
This commit is contained in:
parent
3bf4f7268c
commit
cefd22c648
30
youtube-dl
30
youtube-dl
@ -110,18 +110,6 @@ def sanitize_open(filename, open_mode):
|
|||||||
stream = open(filename, open_mode)
|
stream = open(filename, open_mode)
|
||||||
return (stream, filename)
|
return (stream, filename)
|
||||||
|
|
||||||
def sanitize_html_message(message):
|
|
||||||
"""Sanitize message so it will be printed as it supposed to look in html
|
|
||||||
(i.e. remove multiple spaces)"""
|
|
||||||
|
|
||||||
# Remove repeated spaces
|
|
||||||
words = message.split(' ')
|
|
||||||
stripped_words = []
|
|
||||||
for word in words:
|
|
||||||
if len(word.strip()) > 0:
|
|
||||||
stripped_words.append(word.strip())
|
|
||||||
return ' '.join(stripped_words)
|
|
||||||
|
|
||||||
class DownloadError(Exception):
|
class DownloadError(Exception):
|
||||||
"""Download Error exception.
|
"""Download Error exception.
|
||||||
|
|
||||||
@ -170,13 +158,6 @@ class ContentTooShortError(Exception):
|
|||||||
self.downloaded = downloaded
|
self.downloaded = downloaded
|
||||||
self.expected = expected
|
self.expected = expected
|
||||||
|
|
||||||
class DownloadRestrictionError(Exception):
|
|
||||||
"""Download Restriction Error exception.
|
|
||||||
|
|
||||||
Some services may restrict downloading in different ways. For example
|
|
||||||
they may limit amount of downloads per period of time.
|
|
||||||
"""
|
|
||||||
|
|
||||||
class FileDownloader(object):
|
class FileDownloader(object):
|
||||||
"""File Downloader class.
|
"""File Downloader class.
|
||||||
|
|
||||||
@ -2126,7 +2107,7 @@ class DepositFilesIE(InfoExtractor):
|
|||||||
|
|
||||||
# Retrieve file webpage with 'Free download' button pressed
|
# Retrieve file webpage with 'Free download' button pressed
|
||||||
free_download_indication = { 'gateway_result' : '1' }
|
free_download_indication = { 'gateway_result' : '1' }
|
||||||
request = urllib2.Request(url, urllib.urlencode(free_download_indication))
|
request = urllib2.Request(url, urllib.urlencode(free_download_indication), std_headers)
|
||||||
try:
|
try:
|
||||||
self.report_download_webpage(file_id)
|
self.report_download_webpage(file_id)
|
||||||
webpage = urllib2.urlopen(request).read()
|
webpage = urllib2.urlopen(request).read()
|
||||||
@ -2140,8 +2121,9 @@ class DepositFilesIE(InfoExtractor):
|
|||||||
# Try to figure out reason of the error.
|
# Try to figure out reason of the error.
|
||||||
mobj = re.search(r'<strong>(Attention.*?)</strong>', webpage, re.DOTALL)
|
mobj = re.search(r'<strong>(Attention.*?)</strong>', webpage, re.DOTALL)
|
||||||
if (mobj is not None) and (mobj.group(1) is not None):
|
if (mobj is not None) and (mobj.group(1) is not None):
|
||||||
raise DownloadRestrictionError(sanitize_html_message(mobj.group(1)))
|
restriction_message = re.sub('\s+', ' ', mobj.group(1)).strip()
|
||||||
|
self._downloader.trouble(u'ERROR: %s' % restriction_message)
|
||||||
|
else:
|
||||||
self._downloader.trouble(u'ERROR: unable to extract download URL from: %s' % url)
|
self._downloader.trouble(u'ERROR: unable to extract download URL from: %s' % url)
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -2153,7 +2135,7 @@ class DepositFilesIE(InfoExtractor):
|
|||||||
if mobj is None:
|
if mobj is None:
|
||||||
self._downloader.trouble(u'ERROR: unable to extract title')
|
self._downloader.trouble(u'ERROR: unable to extract title')
|
||||||
return
|
return
|
||||||
file_title = simple_title = mobj.group(1).decode('utf-8')
|
file_title = mobj.group(1).decode('utf-8')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Process file information
|
# Process file information
|
||||||
@ -2163,7 +2145,7 @@ class DepositFilesIE(InfoExtractor):
|
|||||||
'uploader': u'NA',
|
'uploader': u'NA',
|
||||||
'upload_date': u'NA',
|
'upload_date': u'NA',
|
||||||
'title': file_title,
|
'title': file_title,
|
||||||
'stitle': simple_title,
|
'stitle': file_title,
|
||||||
'ext': file_extension.decode('utf-8'),
|
'ext': file_extension.decode('utf-8'),
|
||||||
'format': u'NA',
|
'format': u'NA',
|
||||||
'player_url': None,
|
'player_url': None,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user