2023-02-17 14:53:12 +01: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://www.pornpics.com/"""
|
|
|
|
|
2023-02-17 23:03:14 +01:00
|
|
|
from .common import GalleryExtractor, Extractor, Message
|
2023-02-17 14:53:12 +01:00
|
|
|
from .. import text
|
|
|
|
|
2023-02-17 23:03:14 +01:00
|
|
|
BASE_PATTERN = r"(?:https?://)?(?:www\.)?pornpics\.com(?:/\w\w)?"
|
2023-02-17 14:53:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
class PornpicsExtractor(Extractor):
|
|
|
|
"""Base class for pornpics extractors"""
|
|
|
|
category = "pornpics"
|
2023-02-17 23:03:14 +01:00
|
|
|
root = "https://www.pornpics.com"
|
|
|
|
request_interval = (0.5, 1.5)
|
2023-02-17 14:53:12 +01:00
|
|
|
|
|
|
|
def __init__(self, match):
|
|
|
|
super().__init__(match)
|
2023-02-18 22:38:21 +01:00
|
|
|
self.item = match.group(1)
|
2023-07-25 20:09:44 +02:00
|
|
|
|
2023-02-17 23:03:14 +01:00
|
|
|
def items(self):
|
|
|
|
for gallery in self.galleries():
|
|
|
|
gallery["_extractor"] = PornpicsGalleryExtractor
|
|
|
|
yield Message.Queue, gallery["g_url"], gallery
|
|
|
|
|
2023-02-18 22:38:21 +01:00
|
|
|
def _pagination(self, url, params=None):
|
|
|
|
if params is None:
|
2023-02-17 23:03:14 +01:00
|
|
|
# fetch first 20 galleries from HTML
|
|
|
|
# since '"offset": 0' does not return a JSON response
|
|
|
|
page = self.request(url).text
|
|
|
|
for path in text.extract_iter(
|
|
|
|
page, 'class="rel-link" href="', '"'):
|
|
|
|
yield {"g_url": self.root + path}
|
|
|
|
del page
|
2023-02-18 22:38:21 +01:00
|
|
|
params = {"offset": 20}
|
|
|
|
|
|
|
|
limit = params["limit"] = 20
|
|
|
|
|
|
|
|
headers = {
|
|
|
|
"Accept": "application/json, text/javascript, */*; q=0.01",
|
|
|
|
"Referer": url if params["offset"] else self.root + "/",
|
|
|
|
"X-Requested-With": "XMLHttpRequest",
|
|
|
|
}
|
2023-02-17 23:03:14 +01:00
|
|
|
|
|
|
|
while True:
|
|
|
|
galleries = self.request(
|
|
|
|
url, params=params, headers=headers).json()
|
|
|
|
yield from galleries
|
|
|
|
|
|
|
|
if len(galleries) < limit:
|
|
|
|
return
|
|
|
|
params["offset"] += limit
|
|
|
|
|
2023-02-17 14:53:12 +01:00
|
|
|
|
|
|
|
class PornpicsGalleryExtractor(PornpicsExtractor, GalleryExtractor):
|
|
|
|
"""Extractor for pornpics galleries"""
|
2023-02-17 23:03:14 +01:00
|
|
|
pattern = BASE_PATTERN + r"(/galleries/(?:[^/?#]+-)?(\d+))"
|
2023-09-11 16:30:55 +02:00
|
|
|
example = "https://www.pornpics.com/galleries/TITLE-12345/"
|
2023-02-17 14:53:12 +01:00
|
|
|
|
|
|
|
def __init__(self, match):
|
|
|
|
PornpicsExtractor.__init__(self, match)
|
2023-02-17 23:03:14 +01:00
|
|
|
self.gallery_id = match.group(2)
|
|
|
|
|
|
|
|
items = GalleryExtractor.items
|
2023-02-17 14:53:12 +01:00
|
|
|
|
|
|
|
def metadata(self, page):
|
|
|
|
extr = text.extract_from(page)
|
|
|
|
|
|
|
|
return {
|
|
|
|
"gallery_id": text.parse_int(self.gallery_id),
|
|
|
|
"slug" : extr("/galleries/", "/").rpartition("-")[0],
|
|
|
|
"title" : text.unescape(extr("<h1>", "<")),
|
2024-02-13 23:48:46 +01:00
|
|
|
"channel" : text.split_html(extr(">Channel: ", '</div>')),
|
2023-02-17 14:53:12 +01:00
|
|
|
"models" : text.split_html(extr(
|
|
|
|
">Models:", '<span class="suggest')),
|
|
|
|
"categories": text.split_html(extr(
|
|
|
|
">Categories:", '<span class="suggest')),
|
|
|
|
"tags" : text.split_html(extr(
|
|
|
|
">Tags List:", ' </div>')),
|
|
|
|
"views" : text.parse_int(extr(">Views:", "<").replace(",", "")),
|
|
|
|
}
|
|
|
|
|
|
|
|
def images(self, page):
|
|
|
|
return [
|
|
|
|
(url, None)
|
|
|
|
for url in text.extract_iter(page, "class='rel-link' href='", "'")
|
|
|
|
]
|
2023-02-17 23:03:14 +01:00
|
|
|
|
|
|
|
|
|
|
|
class PornpicsTagExtractor(PornpicsExtractor):
|
|
|
|
"""Extractor for galleries from pornpics tag searches"""
|
|
|
|
subcategory = "tag"
|
|
|
|
pattern = BASE_PATTERN + r"/tags/([^/?#]+)"
|
2023-09-11 16:30:55 +02:00
|
|
|
example = "https://www.pornpics.com/tags/TAGS/"
|
2023-02-17 23:03:14 +01:00
|
|
|
|
|
|
|
def galleries(self):
|
2023-02-18 22:38:21 +01:00
|
|
|
url = "{}/tags/{}/".format(self.root, self.item)
|
|
|
|
return self._pagination(url)
|
2023-02-17 23:03:14 +01:00
|
|
|
|
|
|
|
|
|
|
|
class PornpicsSearchExtractor(PornpicsExtractor):
|
2023-02-18 22:38:21 +01:00
|
|
|
"""Extractor for galleries from pornpics search results"""
|
2023-02-17 23:03:14 +01:00
|
|
|
subcategory = "search"
|
2023-02-18 22:38:21 +01:00
|
|
|
pattern = BASE_PATTERN + r"/(?:\?q=|pornstars/|channels/)([^/&#]+)"
|
2023-09-11 16:30:55 +02:00
|
|
|
example = "https://www.pornpics.com/?q=QUERY"
|
2023-02-17 23:03:14 +01:00
|
|
|
|
|
|
|
def galleries(self):
|
|
|
|
url = self.root + "/search/srch.php"
|
|
|
|
params = {
|
2023-02-18 22:38:21 +01:00
|
|
|
"q" : self.item.replace("-", " "),
|
2023-02-17 23:03:14 +01:00
|
|
|
"lang" : "en",
|
|
|
|
"offset": 0,
|
|
|
|
}
|
|
|
|
return self._pagination(url, params)
|