[tests/extractor] ensure Extractor classes match
This commit is contained in:
@@ -204,58 +204,6 @@ class PinterestExtractor(Extractor):
|
||||
return media
|
||||
|
||||
|
||||
class PinterestPinExtractor(PinterestExtractor):
|
||||
"""Extractor for images from a single pin from pinterest.com"""
|
||||
subcategory = "pin"
|
||||
pattern = BASE_PATTERN + r"/pin/([^/?#]+)(?!.*#related$)"
|
||||
example = "https://www.pinterest.com/pin/12345/"
|
||||
|
||||
def __init__(self, match):
|
||||
PinterestExtractor.__init__(self, match)
|
||||
self.pin_id = match[1]
|
||||
self.pin = None
|
||||
|
||||
def metadata(self):
|
||||
self.pin = self.api.pin(self.pin_id)
|
||||
return self.pin
|
||||
|
||||
def pins(self):
|
||||
return (self.pin,)
|
||||
|
||||
|
||||
class PinterestBoardExtractor(PinterestExtractor):
|
||||
"""Extractor for images from a board from pinterest.com"""
|
||||
subcategory = "board"
|
||||
directory_fmt = ("{category}", "{board[owner][username]}", "{board[name]}")
|
||||
archive_fmt = "{board[id]}_{id}"
|
||||
pattern = (BASE_PATTERN + r"/(?!pin/)([^/?#]+)"
|
||||
r"/(?!_saved|_created|pins/)([^/?#]+)/?(?:$|\?|#)")
|
||||
example = "https://www.pinterest.com/USER/BOARD/"
|
||||
|
||||
def __init__(self, match):
|
||||
PinterestExtractor.__init__(self, match)
|
||||
self.user = text.unquote(match[1])
|
||||
self.board_name = text.unquote(match[2])
|
||||
self.board = None
|
||||
|
||||
def metadata(self):
|
||||
self.board = self.api.board(self.user, self.board_name)
|
||||
return {"board": self.board}
|
||||
|
||||
def pins(self):
|
||||
board = self.board
|
||||
pins = self.api.board_pins(board["id"])
|
||||
|
||||
if board["section_count"] and self.config("sections", True):
|
||||
base = f"{self.root}{board['url']}id:"
|
||||
data = {"_extractor": PinterestSectionExtractor}
|
||||
sections = [(base + section["id"], data)
|
||||
for section in self.api.board_sections(board["id"])]
|
||||
pins = itertools.chain(pins, sections)
|
||||
|
||||
return pins
|
||||
|
||||
|
||||
class PinterestUserExtractor(PinterestExtractor):
|
||||
"""Extractor for a user's boards"""
|
||||
subcategory = "user"
|
||||
@@ -357,6 +305,58 @@ class PinterestSearchExtractor(PinterestExtractor):
|
||||
return self.api.search(self.search)
|
||||
|
||||
|
||||
class PinterestPinExtractor(PinterestExtractor):
|
||||
"""Extractor for images from a single pin from pinterest.com"""
|
||||
subcategory = "pin"
|
||||
pattern = BASE_PATTERN + r"/pin/([^/?#]+)(?!.*#related$)"
|
||||
example = "https://www.pinterest.com/pin/12345/"
|
||||
|
||||
def __init__(self, match):
|
||||
PinterestExtractor.__init__(self, match)
|
||||
self.pin_id = match[1]
|
||||
self.pin = None
|
||||
|
||||
def metadata(self):
|
||||
self.pin = self.api.pin(self.pin_id)
|
||||
return self.pin
|
||||
|
||||
def pins(self):
|
||||
return (self.pin,)
|
||||
|
||||
|
||||
class PinterestBoardExtractor(PinterestExtractor):
|
||||
"""Extractor for images from a board from pinterest.com"""
|
||||
subcategory = "board"
|
||||
directory_fmt = ("{category}", "{board[owner][username]}", "{board[name]}")
|
||||
archive_fmt = "{board[id]}_{id}"
|
||||
pattern = (BASE_PATTERN + r"/(?!pin/)([^/?#]+)"
|
||||
r"/([^/?#]+)/?(?!.*#related$)")
|
||||
example = "https://www.pinterest.com/USER/BOARD/"
|
||||
|
||||
def __init__(self, match):
|
||||
PinterestExtractor.__init__(self, match)
|
||||
self.user = text.unquote(match[1])
|
||||
self.board_name = text.unquote(match[2])
|
||||
self.board = None
|
||||
|
||||
def metadata(self):
|
||||
self.board = self.api.board(self.user, self.board_name)
|
||||
return {"board": self.board}
|
||||
|
||||
def pins(self):
|
||||
board = self.board
|
||||
pins = self.api.board_pins(board["id"])
|
||||
|
||||
if board["section_count"] and self.config("sections", True):
|
||||
base = f"{self.root}{board['url']}id:"
|
||||
data = {"_extractor": PinterestSectionExtractor}
|
||||
sections = [(base + section["id"], data)
|
||||
for section in self.api.board_sections(board["id"])]
|
||||
pins = itertools.chain(pins, sections)
|
||||
|
||||
return pins
|
||||
|
||||
|
||||
class PinterestRelatedPinExtractor(PinterestPinExtractor):
|
||||
"""Extractor for related pins of another pin from pinterest.com"""
|
||||
subcategory = "related-pin"
|
||||
|
||||
@@ -156,6 +156,9 @@ class TestExtractorModule(unittest.TestCase):
|
||||
self.fail(f"{cls.__name__} pattern does not match "
|
||||
f"example URL '{cls.example}'")
|
||||
|
||||
self.assertEqual(cls, extr.__class__)
|
||||
self.assertEqual(cls, extractor.find(cls.example).__class__)
|
||||
|
||||
extr.request = fail_request
|
||||
extr.initialize()
|
||||
extr.finalize()
|
||||
|
||||
Reference in New Issue
Block a user