mirror of https://github.com/yt-dlp/yt-dlp.git
Added --console-title to display download progress in console window title.
This uses SetConsoleTitle() Win32 API for Windows Console, and Xterm escape sequence otherwise.
This commit is contained in:
parent
e7cf18cb6b
commit
ccbd296bee
18
youtube-dl
18
youtube-dl
|
@ -6,6 +6,7 @@
|
||||||
# Author: Vasyl' Vavrychuk
|
# Author: Vasyl' Vavrychuk
|
||||||
# License: Public domain code
|
# License: Public domain code
|
||||||
import cookielib
|
import cookielib
|
||||||
|
import ctypes
|
||||||
import datetime
|
import datetime
|
||||||
import htmlentitydefs
|
import htmlentitydefs
|
||||||
import httplib
|
import httplib
|
||||||
|
@ -208,6 +209,7 @@ class FileDownloader(object):
|
||||||
playliststart: Playlist item to start at.
|
playliststart: Playlist item to start at.
|
||||||
playlistend: Playlist item to end at.
|
playlistend: Playlist item to end at.
|
||||||
logtostderr: Log messages to stderr instead of stdout.
|
logtostderr: Log messages to stderr instead of stdout.
|
||||||
|
consoletitle: Display progress in console window's titlebar.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
params = None
|
params = None
|
||||||
|
@ -332,6 +334,17 @@ class FileDownloader(object):
|
||||||
"""Print message to stderr."""
|
"""Print message to stderr."""
|
||||||
print >>sys.stderr, message.encode(preferredencoding())
|
print >>sys.stderr, message.encode(preferredencoding())
|
||||||
|
|
||||||
|
def to_cons_title(self, message):
|
||||||
|
"""Set console/terminal window title to message."""
|
||||||
|
if not self.params.get('consoletitle', False):
|
||||||
|
return
|
||||||
|
if os.name == 'nt' and ctypes.windll.kernel32.GetConsoleWindow():
|
||||||
|
# c_wchar_p() might not be necessary if `message` is
|
||||||
|
# already of type unicode()
|
||||||
|
ctypes.windll.kernel32.SetConsoleTitleW(ctypes.c_wchar_p(message))
|
||||||
|
elif 'TERM' in os.environ:
|
||||||
|
sys.stderr.write('\033]0;%s\007' % message.encode(preferredencoding()))
|
||||||
|
|
||||||
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(ur'(?u)%\(.+?\)s', self.params['outtmpl']) is None)
|
return (re.search(ur'(?u)%\(.+?\)s', self.params['outtmpl']) is None)
|
||||||
|
@ -380,6 +393,8 @@ class FileDownloader(object):
|
||||||
return
|
return
|
||||||
self.to_screen(u'\r[download] %s of %s at %s ETA %s' %
|
self.to_screen(u'\r[download] %s of %s at %s ETA %s' %
|
||||||
(percent_str, data_len_str, speed_str, eta_str), skip_eol=True)
|
(percent_str, data_len_str, speed_str, eta_str), skip_eol=True)
|
||||||
|
self.to_cons_title(u'youtube-dl - %s of %s at %s ETA %s' %
|
||||||
|
(percent_str.strip(), data_len_str.strip(), speed_str.strip(), eta_str.strip()))
|
||||||
|
|
||||||
def report_resuming_byte(self, resume_len):
|
def report_resuming_byte(self, resume_len):
|
||||||
"""Report attempt to resume at given byte."""
|
"""Report attempt to resume at given byte."""
|
||||||
|
@ -2293,6 +2308,8 @@ if __name__ == '__main__':
|
||||||
action='store_true', dest='getdescription', help='simulate, quiet but print video description', default=False)
|
action='store_true', dest='getdescription', help='simulate, quiet but print video description', default=False)
|
||||||
verbosity.add_option('--no-progress',
|
verbosity.add_option('--no-progress',
|
||||||
action='store_true', dest='noprogress', help='do not print progress bar', default=False)
|
action='store_true', dest='noprogress', help='do not print progress bar', default=False)
|
||||||
|
verbosity.add_option('--console-title',
|
||||||
|
action='store_true', dest='consoletitle', help='display progress in console titlebar', default=False)
|
||||||
parser.add_option_group(verbosity)
|
parser.add_option_group(verbosity)
|
||||||
|
|
||||||
filesystem = optparse.OptionGroup(parser, 'Filesystem Options')
|
filesystem = optparse.OptionGroup(parser, 'Filesystem Options')
|
||||||
|
@ -2434,6 +2451,7 @@ if __name__ == '__main__':
|
||||||
'playliststart': opts.playliststart,
|
'playliststart': opts.playliststart,
|
||||||
'playlistend': opts.playlistend,
|
'playlistend': opts.playlistend,
|
||||||
'logtostderr': opts.outtmpl == '-',
|
'logtostderr': opts.outtmpl == '-',
|
||||||
|
'consoletitle': opts.consoletitle,
|
||||||
})
|
})
|
||||||
fd.add_info_extractor(youtube_search_ie)
|
fd.add_info_extractor(youtube_search_ie)
|
||||||
fd.add_info_extractor(youtube_pl_ie)
|
fd.add_info_extractor(youtube_pl_ie)
|
||||||
|
|
Loading…
Reference in New Issue