From 692d0c95ccabee31ae58c36e0d53dd9569b23f5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Mon, 2 Nov 2015 15:51:32 +0100 Subject: [PATCH] reimplement text.extract_all --- gallery_dl/text.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/gallery_dl/text.py b/gallery_dl/text.py index c276dabe..7cf996fa 100644 --- a/gallery_dl/text.py +++ b/gallery_dl/text.py @@ -61,13 +61,14 @@ def extract(txt, begin, end, pos=0): except ValueError: return None, pos -def extract_all(txt, begin, end, pos=0): - try: - first = txt.index(begin, pos) - last = txt.index(end, first + len(begin)) + len(end) - return txt[first:last], last - except ValueError: - return None, pos +def extract_all(txt, rules, pos=0): + """Calls extract for each rule and returns the result in a dict""" + values = {} + for key, begin, end in rules: + result, pos = extract(txt, begin, end, pos) + if key: + values[key] = result + return values, pos if platform.system() == "Windows": clean_path = clean_path_windows