diff options
author | Random User <rndusr@posteo.de> | 2017-03-25 21:36:59 +0100 |
---|---|---|
committer | Random User <rndusr@posteo.de> | 2017-03-25 21:36:59 +0100 |
commit | 4f06c1c9fcbfbc74b81b5fa89a616914b5ce5aad (patch) | |
tree | a51b702e001d350b908780a119f76d8ea706d511 /youtube_dl/utils.py | |
parent | c73e330e7adc9c0c15ac51aeea8fbb7dad95351a (diff) | |
parent | 942b44a0525f677924c660bcb00902d705d91fc2 (diff) |
Merge branch 'master' of github.com-rndusr:rg3/youtube-dl into fix/str-item-assignment
Diffstat (limited to 'youtube_dl/utils.py')
-rw-r--r-- | youtube_dl/utils.py | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index 807183f4a..2340bc306 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -39,6 +39,7 @@ from .compat import ( compat_basestring, compat_chr, compat_etree_fromstring, + compat_expanduser, compat_html_entities, compat_html_entities_html5, compat_http_client, @@ -473,7 +474,8 @@ def timeconvert(timestr): def sanitize_filename(s, restricted=False, is_id=False): """Sanitizes a string so it could be used as part of a filename. If restricted is set, use a stricter subset of allowed characters. - Set is_id if this is not an arbitrary string, but an ID that should be kept if possible + Set is_id if this is not an arbitrary string, but an ID that should be kept + if possible. """ def replace_insane(char): if restricted and char in ACCENT_CHARS: @@ -538,6 +540,11 @@ def sanitized_Request(url, *args, **kwargs): return compat_urllib_request.Request(sanitize_url(url), *args, **kwargs) +def expand_path(s): + """Expand shell variables and ~""" + return os.path.expandvars(compat_expanduser(s)) + + def orderedSet(iterable): """ Remove all duplicates from the input iterable """ res = [] @@ -1747,11 +1754,16 @@ def base_url(url): def urljoin(base, path): + if isinstance(path, bytes): + path = path.decode('utf-8') if not isinstance(path, compat_str) or not path: return None if re.match(r'^(?:https?:)?//', path): return path - if not isinstance(base, compat_str) or not re.match(r'^(?:https?:)?//', base): + if isinstance(base, bytes): + base = base.decode('utf-8') + if not isinstance(base, compat_str) or not re.match( + r'^(?:https?:)?//', base): return None return compat_urlparse.urljoin(base, path) |