]> git.bitcoin.ninja Git - youtube-dl/commitdiff
Fix printing title etc.
authorPhilipp Hagemeister <phihag@phihag.de>
Tue, 27 Nov 2012 23:46:21 +0000 (00:46 +0100)
committerPhilipp Hagemeister <phihag@phihag.de>
Tue, 27 Nov 2012 23:46:21 +0000 (00:46 +0100)
test/test_utils.py
youtube_dl/FileDownloader.py
youtube_dl/InfoExtractors.py
youtube_dl/utils.py

index b8fc13aefca50d375d7ae4140f3fd9b26639ac61..e2f226bf1dd81a25d3f863e89fa33c1512aadbc4 100644 (file)
@@ -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
index 2b76a3b09b16b9bf5bcd4c37e22fb32ccc1aae71..6ddbfc469e7bca556ec25521aa897738f892bda9 100644 (file)
@@ -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):
index 5c5430ad5e0fcfa211118aa4e318d0c2f6f72f48..94803aa95bc834c6454c32ad595f7ce256a7db93 100644 (file)
@@ -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
index 3fcb0927faa7436419d30bfc407b76cd2c44bd4b..9db7b9d9dcbfdd5d105ab5d6739dec2d9f52a5af 100644 (file)
@@ -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.