Set process title to youtube-dl
authorPhilipp Hagemeister <phihag@phihag.de>
Mon, 16 Dec 2013 04:04:12 +0000 (05:04 +0100)
committerPhilipp Hagemeister <phihag@phihag.de>
Mon, 16 Dec 2013 04:04:55 +0000 (05:04 +0100)
This allows killing all youtube-dl processes with killall youtube-dl, and shows up nicer in some programs.

youtube_dl/__init__.py
youtube_dl/utils.py

index d5c0a36439bdc2aa45174f5a0ee40a9bb6e71ed5..09a99f0db4a0109d985df2e6760d1ca8e8cbc4ba 100644 (file)
@@ -62,6 +62,7 @@ from .utils import (
     MaxDownloadsReached,
     preferredencoding,
     SameFileError,
+    setproctitle,
     std_headers,
     write_string,
 )
@@ -471,12 +472,15 @@ def parseOpts(overrideArguments=None):
 
     return parser, opts, args
 
+
 def _real_main(argv=None):
     # Compatibility fixes for Windows
     if sys.platform == 'win32':
         # https://github.com/rg3/youtube-dl/issues/820
         codecs.register(lambda name: codecs.lookup('utf-8') if name == 'cp65001' else None)
 
+    setproctitle(u'youtube-dl')
+
     parser, opts, args = parseOpts(argv)
 
     # Set user agent
index 4e8a84a56a5b717db73e986c91c2621920fcba47..bd46a2da2ad4d3de81b3d4788cbd2bd0bf8b49e8 100644 (file)
@@ -1,6 +1,7 @@
 #!/usr/bin/env python
 # -*- coding: utf-8 -*-
 
+import ctypes
 import datetime
 import email.utils
 import errno
@@ -1062,3 +1063,17 @@ def month_by_name(name):
 def fix_xml_all_ampersand(xml_str):
     """Replace all the '&' by '&amp;' in XML"""
     return xml_str.replace(u'&', u'&amp;')
+
+
+def setproctitle(title):
+    try:
+        libc = ctypes.cdll.LoadLibrary("libc.so.6")
+    except OSError:
+        return
+    title = title
+    buf = ctypes.create_string_buffer(len(title) + 1)
+    buf.value = title
+    try:
+        libc.prctl(15, ctypes.byref(buf), 0, 0, 0)
+    except AttributeError:
+        return  # Strange libc, just skip this