]> git.bitcoin.ninja Git - youtube-dl/blobdiff - youtube_dl/utils.py
Apply --no-overwrites for --write-* files as well (Fixes #1980)
[youtube-dl] / youtube_dl / utils.py
index 5ba06d965fdd0ca3ca2be9624948c359ce7c5bf5..4e8a84a56a5b717db73e986c91c2621920fcba47 100644 (file)
@@ -15,6 +15,7 @@ import platform
 import re
 import ssl
 import socket
+import subprocess
 import sys
 import traceback
 import zlib
@@ -1024,6 +1025,40 @@ def format_bytes(bytes):
     converted = float(bytes) / float(1024 ** exponent)
     return u'%.2f%s' % (converted, suffix)
 
+
 def str_to_int(int_str):
     int_str = re.sub(r'[,\.]', u'', int_str)
     return int(int_str)
+
+
+def get_term_width():
+    columns = os.environ.get('COLUMNS', None)
+    if columns:
+        return int(columns)
+
+    try:
+        sp = subprocess.Popen(
+            ['stty', 'size'],
+            stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+        out, err = sp.communicate()
+        return int(out.split()[1])
+    except:
+        pass
+    return None
+
+
+def month_by_name(name):
+    """ Return the number of a month by (locale-independently) English name """
+
+    ENGLISH_NAMES = [
+        u'January', u'February', u'March', u'April', u'May', u'June',
+        u'July', u'August', u'September', u'October', u'November', u'December']
+    try:
+        return ENGLISH_NAMES.index(name) + 1
+    except ValueError:
+        return None
+
+
+def fix_xml_all_ampersand(xml_str):
+    """Replace all the '&' by '&' in XML"""
+    return xml_str.replace(u'&', u'&')