[booru] consistent order for "popular" results
This commit is contained in:
@@ -58,7 +58,7 @@ class ThreedeebooruPopularExtractor(ThreedeebooruExtractor,
|
|||||||
pattern = [r"(?:https?://)?(?:www\.)?behoimi\.org/post/popular_"
|
pattern = [r"(?:https?://)?(?:www\.)?behoimi\.org/post/popular_"
|
||||||
r"(by_(?:day|week|month)|recent)(?:\?([^#]*))?"]
|
r"(by_(?:day|week|month)|recent)(?:\?([^#]*))?"]
|
||||||
test = [("http://behoimi.org/post/popular_by_month?month=2&year=2013", {
|
test = [("http://behoimi.org/post/popular_by_month?month=2&year=2013", {
|
||||||
"url": "dfe779d6e6336bd8f67078483bc14b2af1a5aee8",
|
"url": "e5a75f8fa6cbe96109bceca25af3745a25102f3f",
|
||||||
"count": 20,
|
"count": 20,
|
||||||
})]
|
})]
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ from .. import text
|
|||||||
import xml.etree.ElementTree as ET
|
import xml.etree.ElementTree as ET
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
import datetime
|
import datetime
|
||||||
|
import operator
|
||||||
|
|
||||||
|
|
||||||
class BooruExtractor(SharedConfigExtractor):
|
class BooruExtractor(SharedConfigExtractor):
|
||||||
@@ -81,10 +82,15 @@ class BooruExtractor(SharedConfigExtractor):
|
|||||||
|
|
||||||
class JSONBooruExtractor(BooruExtractor):
|
class JSONBooruExtractor(BooruExtractor):
|
||||||
"""Base class for JSON based API responses"""
|
"""Base class for JSON based API responses"""
|
||||||
|
sort = False
|
||||||
|
|
||||||
def items_impl(self):
|
def items_impl(self):
|
||||||
self.update_page(reset=True)
|
self.update_page(reset=True)
|
||||||
while True:
|
while True:
|
||||||
images = self.request(self.api_url, params=self.params).json()
|
images = self.request(self.api_url, params=self.params).json()
|
||||||
|
if self.sort:
|
||||||
|
images.sort(key=operator.itemgetter("score", "id"),
|
||||||
|
reverse=True)
|
||||||
yield from images
|
yield from images
|
||||||
if len(images) < self.params["limit"]:
|
if len(images) < self.params["limit"]:
|
||||||
return
|
return
|
||||||
@@ -151,6 +157,7 @@ class BooruPopularExtractor(BooruExtractor):
|
|||||||
|
|
||||||
def __init__(self, match):
|
def __init__(self, match):
|
||||||
BooruExtractor.__init__(self)
|
BooruExtractor.__init__(self)
|
||||||
|
self.sort = True
|
||||||
self.scale = match.group(1)
|
self.scale = match.group(1)
|
||||||
self.params.update(text.parse_query(match.group(2)))
|
self.params.update(text.parse_query(match.group(2)))
|
||||||
|
|
||||||
|
|||||||
@@ -95,11 +95,11 @@ class ImgurAlbumExtractor(ImgurExtractor):
|
|||||||
test = [
|
test = [
|
||||||
("https://imgur.com/a/TcBmP", {
|
("https://imgur.com/a/TcBmP", {
|
||||||
"url": "ce3552f550a5b5316bd9c7ae02e21e39f30c0563",
|
"url": "ce3552f550a5b5316bd9c7ae02e21e39f30c0563",
|
||||||
"keyword": "e2eaae0e62d3c5d76df9c870140d1ef466bbec59",
|
"keyword": "4fb9d3089810ce5d230f2706b3b37edf529061bf",
|
||||||
}),
|
}),
|
||||||
("https://imgur.com/gallery/eD9CT", { # large album
|
("https://imgur.com/gallery/eD9CT", { # large album
|
||||||
"url": "4ee94de31ff26be416271bc0b1ea27b9349c9937",
|
"url": "4ee94de31ff26be416271bc0b1ea27b9349c9937",
|
||||||
"keyword": "c73a4a7e0fb2c3f00b30f9798327c34a8fbf1aac",
|
"keyword": "577f15a6320b7717bd9fd04e7fde56f9519e3def",
|
||||||
}),
|
}),
|
||||||
("https://imgur.com/a/TcBmQ", {
|
("https://imgur.com/a/TcBmQ", {
|
||||||
"exception": exception.NotFoundError,
|
"exception": exception.NotFoundError,
|
||||||
|
|||||||
Reference in New Issue
Block a user