Compare commits

..

4 Commits

Author SHA1 Message Date
Ricardo Garcia
ad0525b3e6 Bump version number 2010-10-31 11:24:52 +01:00
Ricardo Garcia
30edbf89e4 Report final URL with -g and do not print URLs normally (fixes issue #49) 2010-10-31 11:24:52 +01:00
Ricardo Garcia
eae2666cb4 Handle weird OSX locale settings gracefully (fixes issue #43) 2010-10-31 11:24:52 +01:00
Ricardo Garcia
2a04438c7c Restore INTERNAL version number 2010-10-31 11:24:52 +01:00
2 changed files with 27 additions and 14 deletions

View File

@@ -1 +1 @@
2009.09.08
2009.09.13

View File

@@ -27,6 +27,22 @@ std_headers = {
simple_title_chars = string.ascii_letters.decode('ascii') + string.digits.decode('ascii')
def preferredencoding():
"""Get preferred encoding.
Returns the best encoding scheme for the system, based on
locale.getpreferredencoding() and some further tweaks.
"""
try:
pref = locale.getpreferredencoding()
# Mac OSX systems have this problem sometimes
if pref == '':
return 'UTF-8'
return pref
except:
sys.stderr.write('WARNING: problem obtaining preferred encoding. Falling back to UTF-8.\n')
return 'UTF-8'
class DownloadError(Exception):
"""Download Error exception.
@@ -205,11 +221,13 @@ class FileDownloader(object):
@staticmethod
def verify_url(url):
"""Verify a URL is valid and data could be downloaded."""
"""Verify a URL is valid and data could be downloaded. Return real data URL."""
request = urllib2.Request(url, None, std_headers)
data = urllib2.urlopen(request)
data.read(1)
url = data.geturl()
data.close()
return url
def add_info_extractor(self, ie):
"""Add an InfoExtractor object to the end of the list."""
@@ -224,12 +242,12 @@ class FileDownloader(object):
def to_stdout(self, message, skip_eol=False):
"""Print message to stdout if not in quiet mode."""
if not self.params.get('quiet', False):
print (u'%s%s' % (message, [u'\n', u''][skip_eol])).encode(locale.getpreferredencoding()),
print (u'%s%s' % (message, [u'\n', u''][skip_eol])).encode(preferredencoding()),
sys.stdout.flush()
def to_stderr(self, message):
"""Print message to stderr."""
print >>sys.stderr, message.encode(locale.getpreferredencoding())
print >>sys.stderr, message.encode(preferredencoding())
def fixed_template(self):
"""Checks if the output template is fixed."""
@@ -291,15 +309,15 @@ class FileDownloader(object):
# Do nothing else if in simulate mode
if self.params.get('simulate', False):
try:
self.verify_url(info_dict['url'])
info_dict['url'] = self.verify_url(info_dict['url'])
except (OSError, IOError, urllib2.URLError, httplib.HTTPException, socket.error), err:
raise UnavailableFormatError
# Forced printings
if self.params.get('forcetitle', False):
print info_dict['title'].encode(locale.getpreferredencoding())
print info_dict['title'].encode(preferredencoding())
if self.params.get('forceurl', False):
print info_dict['url'].encode(locale.getpreferredencoding())
print info_dict['url'].encode(preferredencoding())
return
@@ -567,10 +585,6 @@ class YoutubeIE(InfoExtractor):
"""Report attempt to extract video information."""
self._downloader.to_stdout(u'[youtube] %s: Extracting video information' % video_id)
def report_video_url(self, video_id, video_real_url):
"""Report extracted video URL."""
self._downloader.to_stdout(u'[youtube] %s: URL: %s' % (video_id, video_real_url))
def report_unavailable_format(self, video_id, format):
"""Report extracted video URL."""
self._downloader.to_stdout(u'[youtube] %s: Format %s not available' % (video_id, format))
@@ -696,7 +710,6 @@ class YoutubeIE(InfoExtractor):
video_real_url = 'http://www.youtube.com/get_video?video_id=%s&t=%s&eurl=&el=detailpage&ps=default&gl=US&hl=en' % (video_id, token)
if format_param is not None:
video_real_url = '%s&fmt=%s' % (video_real_url, format_param)
self.report_video_url(video_id, video_real_url)
# uploader
mobj = re.search(r'(?m)&author=([^&]+)(?:&|$)', video_info_webpage)
@@ -1084,7 +1097,7 @@ if __name__ == '__main__':
# Parse command line
parser = optparse.OptionParser(
usage='Usage: %prog [options] url...',
version='2009.09.08',
version='2009.09.13',
conflict_handler='resolve',
)
@@ -1191,7 +1204,7 @@ if __name__ == '__main__':
'forcetitle': opts.gettitle,
'simulate': (opts.simulate or opts.geturl or opts.gettitle),
'format': opts.format,
'outtmpl': ((opts.outtmpl is not None and opts.outtmpl.decode(locale.getpreferredencoding()))
'outtmpl': ((opts.outtmpl is not None and opts.outtmpl.decode(preferredencoding()))
or (opts.usetitle and u'%(stitle)s-%(id)s.%(ext)s')
or (opts.useliteral and u'%(title)s-%(id)s.%(ext)s')
or u'%(id)s.%(ext)s'),