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