Repository: ytdl-org/youtube-dl

Issue:
console title should change after youtube-dl finishes [fails in Terminal.app]
Reported by @joeschmoe40:

If you use --console-title, the console title is left changed (messed up)
after the program exits (at least on Mac OSX).



Discussion:
Can you elaborate _messed up_? What would you expect to see if youtube-dl finishes? As far as I understand console titles, a program can just set them, not get or unset them.

I don't claim to be particularly knowledgeable about these things, but I think it _is_ possible for a program to set it to something special while the program is running but then have it revert to whatever it was before when the program exits.  I've seen other programs that do this.

And, by "messed up", I mean, it still says something like "YouTube.DL 100% of 3 Mb or whatever or whatever", in the console title, after it has returned to the shell prompt.

Note, BTW, that I can fix this (on the Mac), after the shell prompt has returned, by typing Shift/Command/I, then Enter and Ctrl/W.  But this is obviously not optimal.

On Sunday, November 17, 2013 6:32 AM, Philipp Hagemeister notifications@github.com wrote:

Can you elaborate messed up? What would you expect to see if youtube-dl finishes? As far as I understand console titles, a program can just set them, not get or unset them.
—
Reply to this email directly or view it on GitHub.

Can you name at least one program that you've seen that does this?

Well, to answer your specific question: Not in a way that you would find useful.

However, I Googled "retrieve xterm window title" and this URL:

http://www.perlmonks.org/?node_id=792957

seems to speak to the problem and suggests that it is possible.  The context is Perl, but it seems generic.  I did not take the time to follow all the ins-and-outs of that article/thread, but you might find it useful.

On Sunday, November 17, 2013 9:04 AM, Philipp Hagemeister notifications@github.com wrote:

Can you name at least one program that you've seen that does this?
—
Reply to this email directly or view it on GitHub.

Thank you for the report. This has been fixed in youtube-dl 2013.11.17. Type `sudo youtube-dl -U` to update.

Alas, it doesn't work (at least on Mac OSX):

$ python --version
Python 2.7.2
$ youtube-dl.py --version
2013.11.17
$ youtube-dl.py --console-title --no-mtime --write-description -q -o xxx.flv "http://www.youtube.com/watch?..."

downloads the file, but leaves my console title as:

youtube-dl - 100.0% of 6.84MiB at 1.12MiB/s ETA 00:00  -- bash -- 84x25

(which I then need to fix manually, using the Command/Shit/I interface)

On Sunday, November 17, 2013 4:26 PM, Philipp Hagemeister notifications@github.com wrote:

Thank you for the report. This has been fixed in youtube-dl 2013.11.17. Type sudo youtube-dl -U to update.
—
Reply to this email directly or view it on GitHub.

Mmm, that's unfortunate. You're using Terminal.App instead of xterm, right? Unfortunately I can't find a way to buy Mac OS X online, let alone get a free trial. Sorry, but that means that we'll have to wait until someone to test it. vim seems to use `XGetWMName`, but that's only useful for X-based applications. I can't find the title-restoring code in the vim OSX code.

Well, it was worth a shot (and thanks for the effort, BTW).

Yes, I am using the Terminal App.  I can also use xterm (it is installed on this machine; I've debated various workarounds for this issue that involve launching an xterm to do the actual downloading - it is on the plate...)

BTW, I just tested it now in an xterm and it does work correctly.  Unfortunately, I never got around to doing this test using the older version, so I can't be sure that the fix took place as scheduled.  Is there any way to get hold of older versions from the site? (If not, no big deal, I think I can find it somewhere else...)

For what it is worth, when you first asked if I knew of any app that does this correctly, my first thought was "vi", because when I launch vi from the shell prompt (in Terminal), the console title changes to something that indicates vi is running, then changes back to something containing "bash" after vi exits.  But I don't think this is being done by the "vi" app; it seems to be just a functionality of bash (as implemented on Mac OSX) and/or the Terminal App itself.  Further, note that other command line apps seem to have the same problem - they change the console title, but don't fix it on exit and it stays "messed up" until I manually fix it.  "ssh" is one such - if I "ssh" to another machine, on exit, the console title contains a complicated string including the name of the user and machine that I "ssh"'d to.  As noted, this persists until fixed manually.

Anyway, I guess we can call this "closed" at least for the time being...

On Monday, November 18, 2013 8:48 AM, Philipp Hagemeister notifications@github.com wrote:

Mmm, that's unfortunate. You're using Terminal.App instead of xterm, right? Unfortunately I can't find a way to buy Mac OS X online, let alone get a free trial. Sorry, but that means that we'll have to wait until someone to test it. vim seems to use XGetWMName, but that's only useful for X-based applications. I can't find the title-restoring code in the vim OSX code.
—
Reply to this email directly or view it on GitHub.

Update: Just tested the old version in an xterm.  It does leave the console title messed up.  So, the fix did work - for xterms.  (But not for Terminals...)

On , J S joeschmoe40@yahoo.com wrote:

Well, it was worth a shot (and thanks for the effort, BTW).

Yes, I am using the Terminal App.  I can also use xterm (it is installed on this machine; I've debated various workarounds for this issue that involve launching an xterm to do the actual downloading - it is on the plate...)

BTW, I just tested it now in an xterm and it does work correctly.  Unfortunately, I never got around to doing this test using the older version, so I can't be sure that the fix took place as scheduled.  Is there any way to get hold of older versions from the site? (If not, no big deal, I think I can find it somewhere else...)

For what it is worth, when you first asked if I knew of any app that does this correctly, my first thought was "vi", because when I launch vi from the shell prompt (in Terminal), the console title changes to something that indicates vi is running, then changes back to something containing "bash" after vi exits.  But I don't think this is being done by the "vi" app; it seems to be just a functionality of bash (as implemented on Mac OSX) and/or the Terminal App itself.  Further, note that other command line apps seem to have the same problem - they change the console title, but don't fix it on exit and it stays "messed up" until I manually fix it.  "ssh" is one such - if I "ssh" to another machine, on exit, the console title contains a complicated string including the name of the user and machine that I "ssh"'d to.  As noted, this persists until fixed manually.

Anyway, I guess we can call this "closed" at least for the time being...

On Monday, November 18, 2013 8:48 AM, Philipp Hagemeister notifications@github.com wrote:

Mmm, that's unfortunate. You're using Terminal.App instead of xterm, right? Unfortunately I can't find a way to buy Mac OS X online, let alone get a free trial. Sorry, but that means that we'll have to wait until someone to test it. vim seems to use XGetWMName, but that's only useful for X-based applications. I can't find the title-restoring code in the vim OSX code.
—
Reply to this email directly or view it on GitHub.


Resolving patch:
diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py
--- a/youtube_dl/YoutubeDL.py
+++ b/youtube_dl/YoutubeDL.py
@@ -217,13 +217,15 @@ def save_console_title(self):
         if not self.params.get('consoletitle', False):
             return
         if 'TERM' in os.environ:
-            write_string(u'\033[22t', self._screen_file)
+            # Save the title on stack
+            write_string(u'\033[22;0t', self._screen_file)
 
     def restore_console_title(self):
         if not self.params.get('consoletitle', False):
             return
         if 'TERM' in os.environ:
-            write_string(u'\033[23t', self._screen_file)
+            # Restore the title from stack
+            write_string(u'\033[23;0t', self._screen_file)
 
     def __enter__(self):
         self.save_console_title()


Test patch: