1
0
mirror of https://codeberg.org/polarisfm/youtube-dl synced 2024-11-04 17:34:32 +01:00

Save and restore console title (Fixes #1782)

This commit is contained in:
Philipp Hagemeister 2013-11-17 21:05:14 +01:00
parent ce02ed60f2
commit bdde425cbe
2 changed files with 68 additions and 48 deletions

View File

@ -213,6 +213,25 @@ class YoutubeDL(object):
elif 'TERM' in os.environ: elif 'TERM' in os.environ:
self.to_screen('\033]0;%s\007' % message, skip_eol=True) self.to_screen('\033]0;%s\007' % message, skip_eol=True)
def save_console_title(self):
if not self.params.get('consoletitle', False):
return
if 'TERM' in os.environ:
self.to_screen('\033[22t')
def restore_console_title(self):
if not self.params.get('consoletitle', False):
return
if 'TERM' in os.environ:
self.to_screen('\033[23t')
def __enter__(self):
self.save_console_title()
return self
def __exit__(self, *args):
self.restore_console_title()
def fixed_template(self): def fixed_template(self):
"""Checks if the output template is fixed.""" """Checks if the output template is fixed."""
return (re.search(u'(?u)%\\(.+?\\)s', self.params['outtmpl']) is None) return (re.search(u'(?u)%\\(.+?\\)s', self.params['outtmpl']) is None)

View File

@ -603,8 +603,7 @@ def _real_main(argv=None):
u' file! Use "%%(ext)s" instead of %r' % u' file! Use "%%(ext)s" instead of %r' %
determine_ext(outtmpl, u'')) determine_ext(outtmpl, u''))
# YoutubeDL ydl_opts = {
ydl = YoutubeDL({
'usenetrc': opts.usenetrc, 'usenetrc': opts.usenetrc,
'username': opts.username, 'username': opts.username,
'password': opts.password, 'password': opts.password,
@ -667,8 +666,9 @@ def _real_main(argv=None):
'youtube_print_sig_code': opts.youtube_print_sig_code, 'youtube_print_sig_code': opts.youtube_print_sig_code,
'age_limit': opts.age_limit, 'age_limit': opts.age_limit,
'download_archive': opts.download_archive, 'download_archive': opts.download_archive,
}) }
with YoutubeDL(ydl_opts) as ydl:
if opts.verbose: if opts.verbose:
write_string(u'[debug] youtube-dl version ' + __version__ + u'\n') write_string(u'[debug] youtube-dl version ' + __version__ + u'\n')
try: try:
@ -685,7 +685,8 @@ def _real_main(argv=None):
sys.exc_clear() sys.exc_clear()
except: except:
pass pass
write_string(u'[debug] Python version %s - %s' %(platform.python_version(), platform_name()) + u'\n') write_string(u'[debug] Python version %s - %s' %
(platform.python_version(), platform_name()) + u'\n')
proxy_map = {} proxy_map = {}
for handler in opener.handlers: for handler in opener.handlers: