| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
"""Extractors for https://fapachi.com/""" |
| 8 |
|
| 9 |
from .common import Extractor, Message |
| 10 |
from .. import text |
| 11 |
|
| 12 |
|
| 13 |
class FapachiPostExtractor(Extractor): |
| 14 |
"""Extractor for individual posts on fapachi.com""" |
| 15 |
category = "fapachi" |
| 16 |
subcategory = "post" |
| 17 |
root = "https://fapachi.com" |
| 18 |
directory_fmt = ("{category}", "{user}") |
| 19 |
filename_fmt = "{user}_{id}.{extension}" |
| 20 |
archive_fmt = "{user}_{id}" |
| 21 |
pattern = (r"(?:https?://)?(?:www\.)?fapachi\.com" |
| 22 |
r"/(?!search/)([^/?#]+)/media/(\d+)") |
| 23 |
example = "https://fapachi.com/MODEL/media/12345" |
| 24 |
|
| 25 |
def __init__(self, match): |
| 26 |
Extractor.__init__(self, match) |
| 27 |
self.user, self.id = match.groups() |
| 28 |
|
| 29 |
def items(self): |
| 30 |
data = { |
| 31 |
"user": self.user, |
| 32 |
"id" : self.id, |
| 33 |
} |
| 34 |
page = self.request(f"{self.root}/{self.user}/media/{self.id}").text |
| 35 |
url = self.root + text.extract( |
| 36 |
page, 'data-src="', '"', page.index('class="media-img'))[0] |
| 37 |
yield Message.Directory, "", data |
| 38 |
yield Message.Url, url, text.nameext_from_url(url, data) |
| 39 |
|
| 40 |
|
| 41 |
class FapachiUserExtractor(Extractor): |
| 42 |
"""Extractor for all posts from a fapachi user""" |
| 43 |
category = "fapachi" |
| 44 |
subcategory = "user" |
| 45 |
root = "https://fapachi.com" |
| 46 |
pattern = (r"(?:https?://)?(?:www\.)?fapachi\.com" |
| 47 |
r"/(?!search(?:/|$))([^/?#]+)(?:/page/(\d+))?$") |
| 48 |
example = "https://fapachi.com/MODEL" |
| 49 |
|
| 50 |
def __init__(self, match): |
| 51 |
Extractor.__init__(self, match) |
| 52 |
self.user = match[1] |
| 53 |
self.num = text.parse_int(match[2], 1) |
| 54 |
|
| 55 |
def items(self): |
| 56 |
data = {"_extractor": FapachiPostExtractor} |
| 57 |
while True: |
| 58 |
url = f"{self.root}/{self.user}/page/{self.num}" |
| 59 |
page = self.request(url).text |
| 60 |
for post in text.extract_iter(page, 'model-media-prew">', ">"): |
| 61 |
if path := text.extr(post, '<a href="', '"'): |
| 62 |
yield Message.Queue, self.root + path, data |
| 63 |
|
| 64 |
if '">Next page</a>' not in page: |
| 65 |
return |
| 66 |
self.num += 1 |