diff --git a/src/you_get/common.py b/src/you_get/common.py index 30bafe5d..0c5fa86f 100755 --- a/src/you_get/common.py +++ b/src/you_get/common.py @@ -126,6 +126,10 @@ if sys.stdout.isatty(): else: default_encoding = locale.getpreferredencoding().lower() +def maybe_print(s): + try: print(s) + except: pass + def tr(s): if default_encoding == 'utf-8': return s @@ -953,8 +957,8 @@ def print_info(site_info, title, type, size): else: type_info = "Unknown type (%s)" % type - print("Site: ", site_info) - print("Title: ", unescape_html(tr(title))) + maybe_print("Site: ", site_info) + maybe_print("Title: ", unescape_html(tr(title))) print("Type: ", type_info) print("Size: ", round(size / 1048576, 2), "MiB (" + str(size) + " Bytes)") print() diff --git a/src/you_get/extractor.py b/src/you_get/extractor.py index 5ca7fe67..23bb2ac3 100644 --- a/src/you_get/extractor.py +++ b/src/you_get/extractor.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -from .common import match1, download_urls, get_filename, parse_host, set_proxy, unset_proxy +from .common import match1, maybe_print, download_urls, get_filename, parse_host, set_proxy, unset_proxy from .util import log from . import json_output import os @@ -111,14 +111,14 @@ class VideoExtractor(): else: stream = self.dash_streams[stream_id] - print(" - title: %s" % self.title) + maybe_print(" - title: %s" % self.title) print(" size: %s MiB (%s bytes)" % (round(stream['size'] / 1048576, 1), stream['size'])) print(" url: %s" % self.url) print() def p(self, stream_id=None): - print("site: %s" % self.__class__.name) - print("title: %s" % self.title) + maybe_print("site: %s" % self.__class__.name) + maybe_print("title: %s" % self.title) if stream_id: # Print the stream print("stream:") @@ -151,7 +151,7 @@ class VideoExtractor(): print(" download-url: {}\n".format(i['url'])) def p_playlist(self, stream_id=None): - print("site: %s" % self.__class__.name) + maybe_print("site: %s" % self.__class__.name) print("playlist: %s" % self.title) print("videos:")