| 1 |
|
| 2 |
|
| 3 |
n |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
"""Extractors for https://vipergirls.to/""" |
| 10 |
|
| 11 |
from .common import Extractor, Message |
| 12 |
from .. import text, util |
| 13 |
|
| 14 |
BASE_PATTERN = (r"(?:https?://)?(?:www\.)?(?:viper(?:" |
| 15 |
r"(?:girls)?\.to|bb\.rocks|kats\.eu|ohilia\.art|proxy\.org" |
| 16 |
r"|vault\.link)|planetviper\.club)") |
| 17 |
|
| 18 |
|
| 19 |
class VipergirlsExtractor(Extractor): |
| 20 |
"""Base class for vipergirls extractors""" |
| 21 |
category = "vipergirls" |
| 22 |
root = "https://vipergirls.to" |
| 23 |
request_interval = 0.5 |
| 24 |
request_interval_min = 0.2 |
| 25 |
cookies_domain = ".vipergirls.to" |
| 26 |
cookies_names = ("vg_userid", "vg_password") |
| 27 |
|
| 28 |
def initialize(self): |
| 29 |
if domain := self.config("domain"): |
| 30 |
pos = domain.find("://") |
| 31 |
if pos >= 0: |
| 32 |
self.root = domain.rstrip("/") |
| 33 |
self.cookies_domain = "." + domain[pos+1:].strip("/") |
| 34 |
else: |
| 35 |
domain = domain.strip("/") |
| 36 |
self.root = "https://" + domain |
| 37 |
self.cookies_domain = "." + domain |
| 38 |
else: |
| 39 |
self.root = "https://viper.click" |
| 40 |
self.cookies_domain = ".viper.click" |
| 41 |
Extractor.initialize(self) |
| 42 |
|
| 43 |
def items(self): |
| 44 |
self.login() |
| 45 |
root = self.posts() |
| 46 |
try: |
| 47 |
forum_title = root[1].attrib["title"] |
| 48 |
thread_title = root[2].attrib["title"] |
| 49 |
except KeyError: |
| 50 |
if root[1].tag == "error": |
| 51 |
raise self.exc.AuthRequired( |
| 52 |
("username & password", "authenticated cookies"), |
| 53 |
"thread", root[1].attrib.get("details")) |
| 54 |
raise |
| 55 |
|
| 56 |
if like := self.config("like"): |
| 57 |
user_hash = root[0].get("hash") |
| 58 |
if len(user_hash) < 16: |
| 59 |
self.log.warning("Login required to like posts") |
| 60 |
like = False |
| 61 |
|
| 62 |
posts = root.iter("post") |
| 63 |
if (order := self.config("order-posts")) and \ |
| 64 |
order[0] not in ("d", "r"): |
| 65 |
if self.page: |
| 66 |
util.advance(posts, (text.parse_int(self.page[5:]) - 1) * 15) |
| 67 |
else: |
| 68 |
posts = list(posts) |
| 69 |
if self.page: |
| 70 |
offset = text.parse_int(self.page[5:]) * 15 |
| 71 |
posts = posts[:offset] |
| 72 |
posts.reverse() |
| 73 |
|
| 74 |
for post in posts: |
| 75 |
images = list(post) |
| 76 |
|
| 77 |
data = post.attrib |
| 78 |
data["forum_title"] = forum_title |
| 79 |
data["thread_id"] = self.thread_id |
| 80 |
data["thread_title"] = thread_title |
| 81 |
data["post_id"] = data.pop("id") |
| 82 |
data["post_num"] = data.pop("number") |
| 83 |
data["post_title"] = data.pop("title") |
| 84 |
data["count"] = len(images) |
| 85 |
del data["imagecount"] |
| 86 |
|
| 87 |
yield Message.Directory, "", data |
| 88 |
if images: |
| 89 |
for data["num"], image in enumerate(images, 1): |
| 90 |
yield Message.Queue, image.attrib["main_url"], data |
| 91 |
if like: |
| 92 |
self.like(post, user_hash) |
| 93 |
|
| 94 |
def login(self): |
| 95 |
if self.cookies_check(self.cookies_names): |
| 96 |
return |
| 97 |
|
| 98 |
username, password = self._get_auth_info() |
| 99 |
if username: |
| 100 |
return self.cookies_update(self.cache( |
| 101 |
self._login_impl, username, password, |
| 102 |
_exp=90*86400, _mem=False)) |
| 103 |
|
| 104 |
def _login_impl(self, username, password): |
| 105 |
self.log.info("Logging in as %s", username) |
| 106 |
|
| 107 |
root = self.root |
| 108 |
if root == "https://viper.click": |
| 109 |
root = VipergirlsExtractor.root |
| 110 |
|
| 111 |
url = root + "/login.php?do=login" |
| 112 |
data = { |
| 113 |
"vb_login_username": username, |
| 114 |
"vb_login_password": password, |
| 115 |
"do" : "login", |
| 116 |
"cookieuser" : "1", |
| 117 |
} |
| 118 |
|
| 119 |
response = self.request(url, method="POST", data=data) |
| 120 |
if not response.cookies.get("vg_password"): |
| 121 |
raise self.exc.AuthenticationError() |
| 122 |
|
| 123 |
return {cookie.name: cookie.value |
| 124 |
for cookie in response.cookies} |
| 125 |
|
| 126 |
def like(self, post, user_hash): |
| 127 |
url = self.root + "/post_thanks.php" |
| 128 |
params = { |
| 129 |
"do" : "post_thanks_add", |
| 130 |
"p" : post.get("id"), |
| 131 |
"securitytoken": user_hash, |
| 132 |
} |
| 133 |
|
| 134 |
with self.request(url, params=params, allow_redirects=False): |
| 135 |
pass |
| 136 |
|
| 137 |
|
| 138 |
class VipergirlsThreadExtractor(VipergirlsExtractor): |
| 139 |
"""Extractor for vipergirls threads""" |
| 140 |
subcategory = "thread" |
| 141 |
pattern = (BASE_PATTERN + |
| 142 |
r"/threads/(\d+)(?:-[^/?#]+)?(/page\d+)?(?:$|#|\?(?!p=))") |
| 143 |
example = "https://vipergirls.to/threads/12345-TITLE" |
| 144 |
|
| 145 |
def posts(self): |
| 146 |
self.thread_id, self.page = self.groups |
| 147 |
url = f"{self.root}/vr.php?t={self.thread_id}" |
| 148 |
return self.request_xml(url) |
| 149 |
|
| 150 |
|
| 151 |
class VipergirlsPostExtractor(VipergirlsExtractor): |
| 152 |
"""Extractor for vipergirls posts""" |
| 153 |
subcategory = "post" |
| 154 |
pattern = (BASE_PATTERN + |
| 155 |
r"/threads/(\d+)(?:-[^/?#]+)?\?p=\d+[^#]*#post(\d+)") |
| 156 |
example = "https://vipergirls.to/threads/12345-TITLE?p=23456#post23456" |
| 157 |
|
| 158 |
def posts(self): |
| 159 |
self.page = 0 |
| 160 |
self.thread_id, post_id = self.groups |
| 161 |
url = f"{self.root}/vr.php?p={post_id}" |
| 162 |
return self.request_xml(url) |