Fix printing title etc.

This commit is contained in:
Philipp Hagemeister 2012-11-28 00:46:21 +01:00
parent 64a57846d3
commit 8cd10ac4ef
4 changed files with 14 additions and 9 deletions

View file

@ -13,7 +13,7 @@
from youtube_dl.utils import unescapeHTML from youtube_dl.utils import unescapeHTML
from youtube_dl.utils import orderedSet from youtube_dl.utils import orderedSet
if sys.version < (3,0): if sys.version_info < (3,0):
_compat_str = lambda b: b.decode('unicode-escape') _compat_str = lambda b: b.decode('unicode-escape')
else: else:
_compat_str = lambda s: s _compat_str = lambda s: s

View file

@ -380,17 +380,17 @@ def process_info(self, info_dict):
# Forced printings # Forced printings
if self.params.get('forcetitle', False): if self.params.get('forcetitle', False):
print(info_dict['title'].encode(preferredencoding(), 'xmlcharrefreplace')) compat_print(info_dict['title'].encode(preferredencoding(), 'xmlcharrefreplace'))
if self.params.get('forceurl', False): if self.params.get('forceurl', False):
print(info_dict['url'].encode(preferredencoding(), 'xmlcharrefreplace')) compat_print(info_dict['url'].encode(preferredencoding(), 'xmlcharrefreplace'))
if self.params.get('forcethumbnail', False) and 'thumbnail' in info_dict: if self.params.get('forcethumbnail', False) and 'thumbnail' in info_dict:
print(info_dict['thumbnail'].encode(preferredencoding(), 'xmlcharrefreplace')) compat_print(info_dict['thumbnail'].encode(preferredencoding(), 'xmlcharrefreplace'))
if self.params.get('forcedescription', False) and 'description' in info_dict: if self.params.get('forcedescription', False) and 'description' in info_dict:
print(info_dict['description'].encode(preferredencoding(), 'xmlcharrefreplace')) compat_print(info_dict['description'].encode(preferredencoding(), 'xmlcharrefreplace'))
if self.params.get('forcefilename', False) and filename is not None: if self.params.get('forcefilename', False) and filename is not None:
print(filename.encode(preferredencoding(), 'xmlcharrefreplace')) compat_print(filename.encode(preferredencoding(), 'xmlcharrefreplace'))
if self.params.get('forceformat', False): if self.params.get('forceformat', False):
print(info_dict['format'].encode(preferredencoding(), 'xmlcharrefreplace')) compat_print(info_dict['format'].encode(preferredencoding(), 'xmlcharrefreplace'))
# Do nothing else if in simulate mode # Do nothing else if in simulate mode
if self.params.get('simulate', False): if self.params.get('simulate', False):

View file

@ -339,7 +339,7 @@ def _real_extract(self, url):
return return
if 'token' not in video_info: if 'token' not in video_info:
if 'reason' in video_info: if 'reason' in video_info:
self._downloader.trouble(u'ERROR: YouTube said: %s' % video_info['reason'][0].decode('utf-8')) self._downloader.trouble(u'ERROR: YouTube said: %s' % video_info['reason'][0])
else: else:
self._downloader.trouble(u'ERROR: "token" parameter not in video info for unknown reason') self._downloader.trouble(u'ERROR: "token" parameter not in video info for unknown reason')
return return

View file

@ -61,7 +61,6 @@
except NameError: except NameError:
compat_chr = chr compat_chr = chr
std_headers = { std_headers = {
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:10.0) Gecko/20100101 Firefox/10.0', 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:10.0) Gecko/20100101 Firefox/10.0',
'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7', 'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
@ -83,6 +82,12 @@ def preferredencoding():
return pref return pref
if sys.version_info < (3,0):
def compat_print(s):
print(s.encode(preferredencoding(), 'xmlcharrefreplace'))
else:
def compat_print(s):
print(s)
def htmlentity_transform(matchobj): def htmlentity_transform(matchobj):
"""Transforms an HTML entity to a character. """Transforms an HTML entity to a character.