2023-04-19 15:28:26 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# Copyright 2023 Mike Fährmann
|
|
|
|
#
|
|
|
|
# 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://vipergirls.to/"""
|
|
|
|
|
|
|
|
from .common import Extractor, Message
|
2023-06-13 21:05:09 +02:00
|
|
|
from .. import text, util, exception
|
|
|
|
from ..cache import cache
|
2023-06-13 20:54:02 +02:00
|
|
|
|
|
|
|
from xml.etree import ElementTree
|
2023-04-19 15:28:26 +02:00
|
|
|
|
|
|
|
BASE_PATTERN = r"(?:https?://)?(?:www\.)?vipergirls\.to"
|
|
|
|
|
|
|
|
|
|
|
|
class VipergirlsExtractor(Extractor):
|
|
|
|
"""Base class for vipergirls extractors"""
|
|
|
|
category = "vipergirls"
|
|
|
|
root = "https://vipergirls.to"
|
2023-06-10 17:57:04 +02:00
|
|
|
request_interval = 0.5
|
|
|
|
request_interval_min = 0.2
|
2023-07-21 22:38:39 +02:00
|
|
|
cookies_domain = ".vipergirls.to"
|
|
|
|
cookies_names = ("vg_userid", "vg_password")
|
2023-04-19 15:28:26 +02:00
|
|
|
|
2024-03-18 16:53:02 +01:00
|
|
|
def _init(self):
|
|
|
|
domain = self.config("domain")
|
|
|
|
if domain:
|
|
|
|
self.root = text.ensure_http_scheme(domain)
|
|
|
|
|
2023-04-19 15:28:26 +02:00
|
|
|
def items(self):
|
2023-06-13 21:05:09 +02:00
|
|
|
self.login()
|
2024-03-18 16:35:09 +01:00
|
|
|
posts = self.posts()
|
2023-06-13 21:05:09 +02:00
|
|
|
|
2024-03-18 16:35:09 +01:00
|
|
|
like = self.config("like")
|
|
|
|
if like:
|
|
|
|
user_hash = posts[0].get("hash")
|
|
|
|
if len(user_hash) < 16:
|
|
|
|
self.log.warning("Login required to like posts")
|
|
|
|
like = False
|
|
|
|
|
|
|
|
posts = posts.iter("post")
|
|
|
|
if self.page:
|
|
|
|
util.advance(posts, (text.parse_int(self.page[5:]) - 1) * 15)
|
|
|
|
|
|
|
|
for post in posts:
|
2023-06-13 20:54:02 +02:00
|
|
|
data = post.attrib
|
|
|
|
data["thread_id"] = self.thread_id
|
2023-04-19 15:28:26 +02:00
|
|
|
|
|
|
|
yield Message.Directory, data
|
2024-03-18 16:35:09 +01:00
|
|
|
|
|
|
|
image = None
|
2023-06-13 20:54:02 +02:00
|
|
|
for image in post:
|
|
|
|
yield Message.Queue, image.attrib["main_url"], data
|
2023-04-19 15:28:26 +02:00
|
|
|
|
2024-03-18 16:35:09 +01:00
|
|
|
if image is not None and like:
|
|
|
|
self.like(post, user_hash)
|
|
|
|
|
2023-06-13 21:05:09 +02:00
|
|
|
def login(self):
|
2023-07-21 22:38:39 +02:00
|
|
|
if self.cookies_check(self.cookies_names):
|
|
|
|
return
|
|
|
|
|
|
|
|
username, password = self._get_auth_info()
|
|
|
|
if username:
|
|
|
|
self.cookies_update(self._login_impl(username, password))
|
2023-06-13 21:05:09 +02:00
|
|
|
|
2023-12-18 23:19:44 +01:00
|
|
|
@cache(maxage=90*86400, keyarg=1)
|
2023-06-13 21:05:09 +02:00
|
|
|
def _login_impl(self, username, password):
|
|
|
|
self.log.info("Logging in as %s", username)
|
|
|
|
|
|
|
|
url = "{}/login.php?do=login".format(self.root)
|
|
|
|
data = {
|
|
|
|
"vb_login_username": username,
|
|
|
|
"vb_login_password": password,
|
|
|
|
"do" : "login",
|
|
|
|
"cookieuser" : "1",
|
|
|
|
}
|
|
|
|
|
|
|
|
response = self.request(url, method="POST", data=data)
|
|
|
|
if not response.cookies.get("vg_password"):
|
|
|
|
raise exception.AuthenticationError()
|
|
|
|
|
|
|
|
return {cookie.name: cookie.value
|
|
|
|
for cookie in response.cookies}
|
|
|
|
|
2024-03-18 16:35:09 +01:00
|
|
|
def like(self, post, user_hash):
|
|
|
|
url = self.root + "/post_thanks.php"
|
|
|
|
params = {
|
|
|
|
"do" : "post_thanks_add",
|
|
|
|
"p" : post.get("id"),
|
|
|
|
"securitytoken": user_hash,
|
|
|
|
}
|
|
|
|
|
|
|
|
with self.request(url, params=params, allow_redirects=False):
|
|
|
|
pass
|
|
|
|
|
2023-04-19 15:28:26 +02:00
|
|
|
|
|
|
|
class VipergirlsThreadExtractor(VipergirlsExtractor):
|
|
|
|
"""Extractor for vipergirls threads"""
|
|
|
|
subcategory = "thread"
|
2024-06-29 17:38:57 +02:00
|
|
|
pattern = (BASE_PATTERN +
|
|
|
|
r"/threads/(\d+)(?:-[^/?#]+)?(/page\d+)?(?:$|#|\?(?!p=))")
|
2023-09-11 16:30:55 +02:00
|
|
|
example = "https://vipergirls.to/threads/12345-TITLE"
|
2023-04-19 15:28:26 +02:00
|
|
|
|
|
|
|
def __init__(self, match):
|
|
|
|
VipergirlsExtractor.__init__(self, match)
|
|
|
|
self.thread_id, self.page = match.groups()
|
|
|
|
|
|
|
|
def posts(self):
|
2023-06-13 20:54:02 +02:00
|
|
|
url = "{}/vr.php?t={}".format(self.root, self.thread_id)
|
2024-03-18 16:35:09 +01:00
|
|
|
return ElementTree.fromstring(self.request(url).text)
|
2023-04-19 15:28:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
class VipergirlsPostExtractor(VipergirlsExtractor):
|
|
|
|
"""Extractor for vipergirls posts"""
|
|
|
|
subcategory = "post"
|
|
|
|
pattern = (BASE_PATTERN +
|
2023-06-13 20:54:02 +02:00
|
|
|
r"/threads/(\d+)(?:-[^/?#]+)?\?p=\d+[^#]*#post(\d+)")
|
2023-09-11 16:30:55 +02:00
|
|
|
example = "https://vipergirls.to/threads/12345-TITLE?p=23456#post23456"
|
2023-04-19 15:28:26 +02:00
|
|
|
|
|
|
|
def __init__(self, match):
|
|
|
|
VipergirlsExtractor.__init__(self, match)
|
2023-06-13 20:54:02 +02:00
|
|
|
self.thread_id, self.post_id = match.groups()
|
2024-03-18 16:35:09 +01:00
|
|
|
self.page = 0
|
2023-04-19 15:28:26 +02:00
|
|
|
|
|
|
|
def posts(self):
|
2023-06-13 20:54:02 +02:00
|
|
|
url = "{}/vr.php?p={}".format(self.root, self.post_id)
|
2024-03-18 16:35:09 +01:00
|
|
|
return ElementTree.fromstring(self.request(url).text)
|