diff --git a/gallery_dl/extractor/hitomi.py b/gallery_dl/extractor/hitomi.py index 64ae1e12..a7014fd7 100644 --- a/gallery_dl/extractor/hitomi.py +++ b/gallery_dl/extractor/hitomi.py @@ -24,7 +24,7 @@ class HitomiGalleryExtractor(ChapterExtractor): test = [ ("https://hitomi.la/galleries/867789.html", { "url": "cb759868d090fe0e2655c3e29ebf146054322b6d", - "keyword": "b1e66ff971fc8cb80240a687f508f3b74053f799", + "keyword": "85e453d01ee7f137669e75a764ccdc65ca092ad2", }), ("https://hitomi.la/reader/867789.html", None), ] diff --git a/gallery_dl/text.py b/gallery_dl/text.py index 82c56a8b..7e5cb29f 100644 --- a/gallery_dl/text.py +++ b/gallery_dl/text.py @@ -130,7 +130,11 @@ def extract_iter(txt, begin, end, pos=0): def parse_query(qs): """Parse a query string into key-value pairs""" - return {key: vlist[0] for key, vlist in urllib.parse.parse_qs(qs).items()} + result = {} + for key, value in urllib.parse.parse_qsl(qs): + if key not in result: + result[key] = value + return result if os.name == "nt": diff --git a/test/test_text.py b/test/test_text.py index e26dde76..767952fd 100644 --- a/test/test_text.py +++ b/test/test_text.py @@ -123,6 +123,37 @@ class TestText(unittest.TestCase): result = ["c", "b", "a", "d"] self.assertEqual(list(text.extract_iter(txt, "[", "]")), result) + def test_parse_query(self): + # standard stuff + self.assertEqual( + text.parse_query(""), {}) + self.assertEqual( + text.parse_query("foo=1"), {"foo": "1"}) + self.assertEqual( + text.parse_query("foo=1&bar=2"), {"foo": "1", "bar": "2"}) + + # missing value + self.assertEqual( + text.parse_query("bar"), {}) + self.assertEqual( + text.parse_query("foo=1&bar"), {"foo": "1"}) + self.assertEqual( + text.parse_query("foo=1&bar&baz=3"), {"foo": "1", "baz": "3"}) + + # keys with identical names + self.assertEqual( + text.parse_query("foo=1&foo=2"), {"foo": "1"}) + self.assertEqual( + text.parse_query("foo=1&bar=2&foo=3&bar=4"), + {"foo": "1", "bar": "2"}, + ) + + # non-string arguments + self.assertEqual(text.parse_query(()), {}) + self.assertEqual(text.parse_query([]), {}) + self.assertEqual(text.parse_query({}), {}) + self.assertEqual(text.parse_query(None), {}) + if __name__ == '__main__': unittest.main()