X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=youtube_dl%2Futils.py;h=b97e62ae9307f7e2380db7ec9c723e8ae8517708;hb=8f0c8fb45282caa706c267700f51734bb474fefc;hp=2a93d3e34a13d473c9438dced5a3051338325708;hpb=acd69589a54d03f60a018a298c74a4c8aef2abc2;p=youtube-dl diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index 2a93d3e34..b97e62ae9 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -540,6 +540,16 @@ def encodeFilename(s, for_subprocess=False): encoding = 'utf-8' return s.encode(encoding, 'ignore') + +def encodeArgument(s): + if not isinstance(s, compat_str): + # Legacy code that uses byte strings + # Uncomment the following line after fixing all post processors + #assert False, 'Internal error: %r should be of type %r, is %r' % (s, compat_str, type(s)) + s = s.decode('ascii') + return encodeFilename(s, True) + + def decodeOption(optval): if optval is None: return optval @@ -926,7 +936,11 @@ def _windows_write_string(s, out): 2: -12, } - fileno = out.fileno() + try: + fileno = out.fileno() + except AttributeError: + # If the output stream doesn't have a fileno, it's virtual + return False if fileno not in WIN_OUTPUT_IDS: return False @@ -1425,3 +1439,15 @@ def qualities(quality_ids): DEFAULT_OUTTMPL = '%(title)s-%(id)s.%(ext)s' + +try: + subprocess_check_output = subprocess.check_output +except AttributeError: + def subprocess_check_output(*args, **kwargs): + assert 'input' not in kwargs + p = subprocess.Popen(*args, stdout=subprocess.PIPE, **kwargs) + output, _ = p.communicate() + ret = p.poll() + if ret: + raise subprocess.CalledProcessError(ret, p.args, output=output) + return output