diff options
author | Sergey M․ <dstftw@gmail.com> | 2015-09-05 00:34:49 +0600 |
---|---|---|
committer | Sergey M․ <dstftw@gmail.com> | 2015-09-05 00:34:49 +0600 |
commit | 8e636da4990643084de17c03c6a0639e9aa4085e (patch) | |
tree | 2de8c702cea3c67cbdd02795321f6b2afda3e216 /youtube_dl/utils.py | |
parent | 22889ab175d990d50050603fb983b1db7d1615d6 (diff) |
[utils] Improve xpath_text
Diffstat (limited to 'youtube_dl/utils.py')
-rw-r--r-- | youtube_dl/utils.py | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index 86b757103..cc792be6a 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -181,7 +181,7 @@ def xpath_element(node, xpath, name=None, fatal=False, default=NO_DEFAULT): xpath = xpath.encode('ascii') n = node.find(xpath) - if n is None or n.text is None: + if n is None: if default is not NO_DEFAULT: return default elif fatal: @@ -193,7 +193,18 @@ def xpath_element(node, xpath, name=None, fatal=False, default=NO_DEFAULT): def xpath_text(node, xpath, name=None, fatal=False, default=NO_DEFAULT): - return xpath_element(node, xpath, name, fatal=fatal, default=default).text + n = xpath_element(node, xpath, name, fatal=fatal, default=default) + if n is None or n == default: + return n + if n.text is None: + if default is not NO_DEFAULT: + return default + elif fatal: + name = xpath if name is None else name + raise ExtractorError('Could not find XML element\'s text %s' % name) + else: + return None + return n.text def xpath_attr(node, xpath, key, name=None, fatal=False, default=NO_DEFAULT): |