Skip to content

Commit

Permalink
[joyreactor] fix and improve pagination (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Jan 3, 2019
1 parent 8753627 commit 1737d7f
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions gallery_dl/extractor/joyreactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,12 @@ def _pagination(self, url):
yield from text.extract_iter(
page, '<div class="uhead">', '<div class="ufoot">')

pos = page.find("<span class='current'>")
if pos == -1 or page[pos+21:pos+24] == ">1<":
return
path = text.extract(page, "href='", "'", pos)[0]
if not path:
try:
pos = page.index("class='next'")
pos = page.rindex("class='current'", 0, pos)
url = self.root + text.extract(page, "href='", "'", pos)[0]
except (ValueError, TypeError):
return
url = self.root + path

def _parse_post(self, post):
post, _, script = post.partition('<script type="application/ld+json">')
Expand All @@ -75,7 +74,7 @@ def _parse_post(self, post):
script = script.translate(mapping).replace("\\", "\\\\")
data = json.loads(script)
except ValueError as exc:
self.log.warning("Unable to parse post: %s", exc)
self.log.warning("Unable to parse JSON data: %s", exc)
return

num = 0
Expand Down Expand Up @@ -148,10 +147,11 @@ class JoyreactorSearchExtractor(JoyreactorTagExtractor):
pattern = [BASE_PATTERN + r"/search(?:/|\?q=)([^/?&#]+)"]
test = [
("http://joyreactor.com/search?q=Cirno+Gifs", {
"count": ">= 0",
"count": 0, # no search results on joyreactor.com
}),
("http://joyreactor.cc/search/Cirno+Gifs", {
"count": ">= 0",
"range": "1-25",
"count": ">= 20",
}),
]

Expand Down

0 comments on commit 1737d7f

Please sign in to comment.