diff options
author | Sergey M․ <dstftw@gmail.com> | 2018-07-21 18:01:06 +0700 |
---|---|---|
committer | Sergey M․ <dstftw@gmail.com> | 2018-07-21 18:03:58 +0700 |
commit | af03000ad5a445f03fbacb63ce626f8dcfe785c7 (patch) | |
tree | 131b5dbb5b375b354e20f92db4ad55f78174cf18 /youtube_dl | |
parent | b96b4be4619b1e090650212380a92fb068f2fd21 (diff) |
[utils] Introduce url_or_none
Diffstat (limited to 'youtube_dl')
-rw-r--r-- | youtube_dl/utils.py | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index b8700efcb..b84436ed6 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -1866,6 +1866,13 @@ def strip_or_none(v): return None if v is None else v.strip() +def url_or_none(url): + if not url or not isinstance(url, compat_str): + return None + url = url.strip() + return url if re.match(r'^(?:[a-zA-Z][\da-zA-Z.+-]*:)?//', url) else None + + def parse_duration(s): if not isinstance(s, compat_basestring): return None |