diff options
Diffstat (limited to 'youtube_dl/utils.py')
| -rw-r--r-- | youtube_dl/utils.py | 39 | 
1 files changed, 22 insertions, 17 deletions
| diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index 1f3bfef7d..7426e2a1f 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -35,7 +35,6 @@ import zlib  from .compat import (      compat_basestring,      compat_chr, -    compat_getenv,      compat_html_entities,      compat_http_client,      compat_parse_qs, @@ -306,6 +305,7 @@ def sanitize_filename(s, restricted=False, is_id=False):              result = result[2:]          if result.startswith('-'):              result = '_' + result[len('-'):] +        result = result.lstrip('.')          if not result:              result = '_'      return result @@ -1173,22 +1173,6 @@ def parse_filesize(s):      return int(float(num_str) * mult) -def get_term_width(): -    columns = compat_getenv('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 """ @@ -1784,3 +1768,24 @@ def match_filter_func(filter_str):              video_title = info_dict.get('title', info_dict.get('id', 'video'))              return '%s does not pass filter %s, skipping ..' % (video_title, filter_str)      return _match_func + + +class PerRequestProxyHandler(compat_urllib_request.ProxyHandler): +    def __init__(self, proxies=None): +        # Set default handlers +        for type in ('http', 'https'): +            setattr(self, '%s_open' % type, +                    lambda r, proxy='__noproxy__', type=type, meth=self.proxy_open: +                        meth(r, proxy, type)) +        return compat_urllib_request.ProxyHandler.__init__(self, proxies) + +    def proxy_open(self, req, proxy, type): +        req_proxy = req.headers.get('Ytdl-request-proxy') +        if req_proxy is not None: +            proxy = req_proxy +            del req.headers['Ytdl-request-proxy'] + +        if proxy == '__noproxy__': +            return None  # No Proxy +        return compat_urllib_request.ProxyHandler.proxy_open( +            self, req, proxy, type) | 
