merged pep8_whitespace

This commit is contained in:
Philipp Hagemeister 2011-09-06 17:19:23 +02:00
commit ef53099e35

View file

@ -201,6 +201,7 @@ def preferredencoding():
yield pref
return yield_preferredencoding().next()
def htmlentity_transform(matchobj):
"""Transforms an HTML entity to a Unicode character.
@ -227,11 +228,13 @@ def htmlentity_transform(matchobj):
# Unknown entity in name, return its literal representation
return (u'&%s;' % entity)
def sanitize_title(utitle):
"""Sanitizes a video title so it could be used as part of a filename."""
utitle = re.sub(ur'(?u)&(.+?);', htmlentity_transform, utitle)
return utitle.replace(unicode(os.sep), u'%')
def sanitize_open(filename, open_mode):
"""Try to open the given filename, and slightly tweak it if this fails.
@ -258,6 +261,7 @@ def sanitize_open(filename, open_mode):
stream = open(filename, open_mode)
return (stream, filename)
def timeconvert(timestr):
"""Convert RFC 2822 defined time string into system timestamp"""
timestamp = None
@ -266,6 +270,7 @@ def timeconvert(timestr):
timestamp = email.utils.mktime_tz(timetuple)
return timestamp
class DownloadError(Exception):
"""Download Error exception.
@ -275,6 +280,7 @@ class DownloadError(Exception):
"""
pass
class SameFileError(Exception):
"""Same File exception.
@ -283,6 +289,7 @@ class SameFileError(Exception):
"""
pass
class PostProcessingError(Exception):
"""Post Processing exception.
@ -291,6 +298,7 @@ class PostProcessingError(Exception):
"""
pass
class UnavailableVideoError(Exception):
"""Unavailable Format exception.
@ -299,6 +307,7 @@ class UnavailableVideoError(Exception):
"""
pass
class ContentTooShortError(Exception):
"""Content Too Short exception.
@ -314,6 +323,7 @@ class ContentTooShortError(Exception):
self.downloaded = downloaded
self.expected = expected
class YoutubeDLHandler(urllib2.HTTPHandler):
"""Handler for HTTP requests and responses.
@ -372,6 +382,7 @@ class YoutubeDLHandler(urllib2.HTTPHandler):
resp.msg = old_resp.msg
return resp
class FileDownloader(object):
"""File Downloader class.
@ -465,7 +476,7 @@ class FileDownloader(object):
else:
exponent = long(math.log(bytes, 1024.0))
suffix = 'bkMGTPEZY'[exponent]
converted = float(bytes) / float(1024**exponent)
converted = float(bytes) / float(1024 ** exponent)
return '%.2f%s' % (converted, suffix)
@staticmethod
@ -617,7 +628,7 @@ class FileDownloader(object):
if filetime is None:
return
try:
os.utime(filename,(time.time(), filetime))
os.utime(filename, (time.time(), filetime))
except:
pass
@ -859,7 +870,7 @@ class FileDownloader(object):
# Request parameters in case of being able to resume
if self.params.get('continuedl', False) and resume_len != 0:
self.report_resuming_byte(resume_len)
request.add_header('Range','bytes=%d-' % resume_len)
request.add_header('Range', 'bytes=%d-' % resume_len)
open_mode = 'ab'
count = 0
@ -967,6 +978,7 @@ class FileDownloader(object):
return True
class InfoExtractor(object):
"""Information Extractor class.
@ -1038,6 +1050,7 @@ class InfoExtractor(object):
"""Real extraction process. Redefine in subclasses."""
pass
class YoutubeIE(InfoExtractor):
"""Information extractor for youtube.com."""
@ -1561,6 +1574,7 @@ class DailymotionIE(InfoExtractor):
except UnavailableVideoError:
self._downloader.trouble(u'\nERROR: unable to download video')
class GoogleIE(InfoExtractor):
"""Information extractor for video.google.com."""
@ -1654,7 +1668,6 @@ class GoogleIE(InfoExtractor):
else: # we need something to pass to process_info
video_thumbnail = ''
try:
# Process video information
self._downloader.process_info({
@ -1854,7 +1867,8 @@ class YahooIE(InfoExtractor):
self._downloader.trouble(u'ERROR: unable to extract video description')
return
video_description = mobj.group(1).decode('utf-8')
if not video_description: video_description = 'No description available.'
if not video_description:
video_description = 'No description available.'
# Extract video height and width
mobj = re.search(r'<meta name="video_height" content="([0-9]+)" />', webpage)
@ -2220,6 +2234,7 @@ class YoutubeSearchIE(InfoExtractor):
pagenum = pagenum + 1
class GoogleSearchIE(InfoExtractor):
"""Information Extractor for Google Video search queries."""
_VALID_QUERY = r'gvsearch(\d+|all)?:[\s\S]+'
@ -2311,6 +2326,7 @@ class GoogleSearchIE(InfoExtractor):
pagenum = pagenum + 1
class YahooSearchIE(InfoExtractor):
"""Information Extractor for Yahoo! Video search queries."""
_VALID_QUERY = r'yvsearch(\d+|all)?:[\s\S]+'
@ -2402,6 +2418,7 @@ class YahooSearchIE(InfoExtractor):
pagenum = pagenum + 1
class YoutubePlaylistIE(InfoExtractor):
"""Information Extractor for YouTube playlists."""
@ -2478,6 +2495,7 @@ class YoutubePlaylistIE(InfoExtractor):
self._youtube_ie.extract('http://www.youtube.com/watch?v=%s' % id)
return
class YoutubeUserIE(InfoExtractor):
"""Information Extractor for YouTube users."""
@ -2648,6 +2666,7 @@ class DepositFilesIE(InfoExtractor):
except UnavailableVideoError, err:
self._downloader.trouble(u'ERROR: unable to download file')
class FacebookIE(InfoExtractor):
"""Information Extractor for Facebook"""
@ -2989,6 +3008,7 @@ class PostProcessor(object):
"""
return information # by default, do nothing
class FFmpegExtractAudioPP(PostProcessor):
def __init__(self, downloader=None, preferredcodec=None):