Skip to content

Commit

Permalink
[reactor] detect "circular" redirects (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Jan 9, 2019
1 parent e53cdfd commit 1734a6c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
13 changes: 12 additions & 1 deletion gallery_dl/extractor/reactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,18 @@ def posts(self):
def _pagination(self, url):
while True:
time.sleep(random.uniform(self.wait_min, self.wait_max))
page = self.request(url).text

response = self.request(url)
if response.history:
# sometimes there is a redirect from
# the last page of a listing (.../tag/<tag>/1)
# to the first page (.../tag/<tag>)
# which could cause an endless loop
cnt_old = response.history[0].url.count("/")
cnt_new = response.url.count("/")
if cnt_old == 5 and cnt_new == 4:
return
page = response.text

yield from text.extract_iter(
page, '<div class="uhead">', '<div class="ufoot">')
Expand Down
4 changes: 2 additions & 2 deletions test/test_results.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# Copyright 2015-2018 Mike Fährmann
# Copyright 2015-2019 Mike Fährmann
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
Expand All @@ -16,7 +16,7 @@

# these don't work on Travis CI
TRAVIS_SKIP = {
"exhentai", "kissmanga", "mangafox", "dynastyscans", "nijie",
"exhentai", "kissmanga", "mangafox", "dynastyscans", "nijie", "bobx",
"archivedmoe", "archiveofsins", "thebarchive", "fireden",
"sankaku", "idolcomplex", "mangahere", "readcomiconline",
}
Expand Down

0 comments on commit 1734a6c

Please sign in to comment.