From 8cd10ac4efb5168f3ceb18ec94338bce73e166a7 Mon Sep 17 00:00:00 2001 From: Philipp Hagemeister Date: Wed, 28 Nov 2012 00:46:21 +0100 Subject: [PATCH] Fix printing title etc. --- test/test_utils.py | 2 +- youtube_dl/FileDownloader.py | 12 ++++++------ youtube_dl/InfoExtractors.py | 2 +- youtube_dl/utils.py | 7 ++++++- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/test/test_utils.py b/test/test_utils.py index b8fc13aef..e2f226bf1 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -13,7 +13,7 @@ from youtube_dl.utils import sanitize_filename from youtube_dl.utils import unescapeHTML 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') else: _compat_str = lambda s: s diff --git a/youtube_dl/FileDownloader.py b/youtube_dl/FileDownloader.py index 2b76a3b09..6ddbfc469 100644 --- a/youtube_dl/FileDownloader.py +++ b/youtube_dl/FileDownloader.py @@ -380,17 +380,17 @@ class FileDownloader(object): # Forced printings 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): - 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: - 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: - 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: - print(filename.encode(preferredencoding(), 'xmlcharrefreplace')) + compat_print(filename.encode(preferredencoding(), 'xmlcharrefreplace')) 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 if self.params.get('simulate', False): diff --git a/youtube_dl/InfoExtractors.py b/youtube_dl/InfoExtractors.py index 5c5430ad5..94803aa95 100644 --- a/youtube_dl/InfoExtractors.py +++ b/youtube_dl/InfoExtractors.py @@ -339,7 +339,7 @@ class YoutubeIE(InfoExtractor): return if 'token' not 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: self._downloader.trouble(u'ERROR: "token" parameter not in video info for unknown reason') return diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index 3fcb0927f..9db7b9d9d 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -61,7 +61,6 @@ try: except NameError: compat_chr = chr - std_headers = { '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', @@ -83,6 +82,12 @@ def preferredencoding(): 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): """Transforms an HTML entity to a character. -- 2.22.2