diff options
author | Philipp Hagemeister <phihag@phihag.de> | 2014-02-25 01:43:17 +0100 |
---|---|---|
committer | Philipp Hagemeister <phihag@phihag.de> | 2014-02-25 01:43:17 +0100 |
commit | 62e609ab771140b185e98ed085445d40b751cbfc (patch) | |
tree | 9daee9760c5d77d8acc9bdef877ac8fbbeb07488 /youtube_dl/utils.py | |
parent | f6acbdecf483513166287a41cba5eed928404dc2 (diff) |
Ignore BOM in batch files (Fixes #2450)
Diffstat (limited to 'youtube_dl/utils.py')
-rw-r--r-- | youtube_dl/utils.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index 25e40a837..0c482631a 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -1,6 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +import contextlib import ctypes import datetime import email.utils @@ -1245,3 +1246,19 @@ except TypeError: else: struct_pack = struct.pack struct_unpack = struct.unpack + + +def read_batch_urls(batch_fd): + def fixup(url): + if not isinstance(url, compat_str): + url = url.decode('utf-8', 'replace') + BOM_UTF8 = u'\xef\xbb\xbf' + if url.startswith(BOM_UTF8): + url = url[len(BOM_UTF8):] + url = url.strip() + if url.startswith(('#', ';', ']')): + return False + return url + + with contextlib.closing(batch_fd) as fd: + return [url for url in map(fixup, fd) if url] |