mirror of
https://github.com/soimort/you-get.git
synced 2025-01-23 21:45:02 +03:00
[common] maybe_print() ignores any non-printable characters (which used to cause an exception, which is not intuitive)
This commit is contained in:
parent
1a8f332712
commit
cd5cfc775f
@ -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()
|
||||
|
@ -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:")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user