2020-04-08 21:38:02 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# Copyright 2020 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://aryion.com/"""
|
|
|
|
|
|
|
|
from .common import Extractor, Message
|
2020-08-27 22:45:30 +02:00
|
|
|
from .. import text, util, exception
|
|
|
|
from ..cache import cache
|
2020-04-08 21:38:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
BASE_PATTERN = r"(?:https?://)?(?:www\.)?aryion\.com/g4"
|
|
|
|
|
|
|
|
|
|
|
|
class AryionExtractor(Extractor):
|
|
|
|
"""Base class for aryion extractors"""
|
|
|
|
category = "aryion"
|
2020-04-10 21:58:46 +02:00
|
|
|
directory_fmt = ("{category}", "{user!l}", "{path:J - }")
|
2020-04-08 21:38:02 +02:00
|
|
|
filename_fmt = "{id} {title}.{extension}"
|
|
|
|
archive_fmt = "{id}"
|
2020-08-27 22:45:30 +02:00
|
|
|
cookiedomain = ".aryion.com"
|
|
|
|
cookienames = ("phpbb3_rl7a3_sid",)
|
2020-04-08 21:38:02 +02:00
|
|
|
root = "https://aryion.com"
|
|
|
|
|
|
|
|
def __init__(self, match):
|
|
|
|
Extractor.__init__(self, match)
|
|
|
|
self.user = match.group(1)
|
2020-06-26 22:05:02 +02:00
|
|
|
self.recursive = True
|
2020-09-06 22:17:23 +02:00
|
|
|
self._needle = "class='gallery-item' id='"
|
2020-04-08 21:38:02 +02:00
|
|
|
|
2020-08-27 22:45:30 +02:00
|
|
|
def login(self):
|
|
|
|
username, password = self._get_auth_info()
|
|
|
|
if username:
|
|
|
|
self._update_cookies(self._login_impl(username, password))
|
|
|
|
|
|
|
|
@cache(maxage=14*24*3600, keyarg=1)
|
|
|
|
def _login_impl(self, username, password):
|
|
|
|
self.log.info("Logging in as %s", username)
|
|
|
|
|
|
|
|
url = self.root + "/forum/ucp.php?mode=login"
|
|
|
|
data = {
|
|
|
|
"username": username,
|
|
|
|
"password": password,
|
|
|
|
"login": "Login",
|
|
|
|
}
|
|
|
|
|
|
|
|
response = self.request(url, method="POST", data=data)
|
|
|
|
if b"You have been successfully logged in." not in response.content:
|
|
|
|
raise exception.AuthenticationError()
|
|
|
|
return {c: response.cookies[c] for c in self.cookienames}
|
|
|
|
|
2020-06-26 22:05:02 +02:00
|
|
|
def items(self):
|
2020-08-27 22:45:30 +02:00
|
|
|
self.login()
|
|
|
|
|
2020-06-26 22:05:02 +02:00
|
|
|
for post_id in self.posts():
|
|
|
|
post = self._parse_post(post_id)
|
|
|
|
if post:
|
|
|
|
yield Message.Directory, post
|
|
|
|
yield Message.Url, post["url"], post
|
|
|
|
elif post is False and self.recursive:
|
|
|
|
base = self.root + "/g4/view/"
|
|
|
|
data = {"_extractor": AryionPostExtractor}
|
|
|
|
for post_id in self._pagination(base + post_id):
|
|
|
|
yield Message.Queue, base + post_id, data
|
|
|
|
|
|
|
|
def posts(self):
|
|
|
|
"""Yield relevant post IDs"""
|
|
|
|
|
|
|
|
def _pagination(self, url):
|
2020-04-18 01:25:54 +02:00
|
|
|
while True:
|
|
|
|
page = self.request(url).text
|
|
|
|
yield from text.extract_iter(
|
2020-09-06 22:17:23 +02:00
|
|
|
page, self._needle, "'")
|
2020-04-08 21:38:02 +02:00
|
|
|
|
2020-04-18 01:25:54 +02:00
|
|
|
pos = page.find("Next >>")
|
|
|
|
if pos < 0:
|
|
|
|
return
|
|
|
|
url = self.root + text.rextract(page, "href='", "'", pos)[0]
|
2020-04-08 21:38:02 +02:00
|
|
|
|
2020-06-26 22:05:02 +02:00
|
|
|
def _parse_post(self, post_id):
|
2020-04-10 22:08:45 +02:00
|
|
|
url = "{}/g4/data.php?id={}".format(self.root, post_id)
|
|
|
|
with self.request(url, method="HEAD", fatal=False) as response:
|
2020-04-08 21:38:02 +02:00
|
|
|
|
2020-04-10 22:08:45 +02:00
|
|
|
if response.status_code >= 400:
|
2020-06-26 22:05:02 +02:00
|
|
|
self.log.warning(
|
|
|
|
"Unable to fetch post %s ('%s %s')",
|
|
|
|
post_id, response.status_code, response.reason)
|
2020-04-10 22:08:45 +02:00
|
|
|
return None
|
|
|
|
headers = response.headers
|
|
|
|
|
2020-04-18 01:25:54 +02:00
|
|
|
# folder
|
|
|
|
if headers["content-type"] in (
|
|
|
|
"application/x-folder",
|
2020-08-16 22:30:15 +02:00
|
|
|
"application/x-comic-folder",
|
2020-04-18 01:25:54 +02:00
|
|
|
"application/x-comic-folder-nomerge",
|
|
|
|
):
|
|
|
|
return False
|
2020-04-10 22:08:45 +02:00
|
|
|
|
2020-04-18 01:25:54 +02:00
|
|
|
# get filename from 'Content-Disposition' header
|
2020-04-10 22:08:45 +02:00
|
|
|
cdis = headers["content-disposition"]
|
|
|
|
fname, _, ext = text.extract(
|
|
|
|
cdis, 'filename="', '"')[0].rpartition(".")
|
|
|
|
if not fname:
|
|
|
|
fname, ext = ext, fname
|
|
|
|
|
2020-04-18 01:25:54 +02:00
|
|
|
# get file size from 'Content-Length' header
|
|
|
|
clen = headers.get("content-length")
|
|
|
|
|
|
|
|
# fix 'Last-Modified' header
|
2020-04-10 22:26:55 +02:00
|
|
|
lmod = headers["last-modified"]
|
|
|
|
if lmod[22] != ":":
|
|
|
|
lmod = "{}:{} GMT".format(lmod[:22], lmod[22:24])
|
|
|
|
|
2020-04-10 22:08:45 +02:00
|
|
|
post_url = "{}/g4/view/{}".format(self.root, post_id)
|
|
|
|
extr = text.extract_from(self.request(post_url).text)
|
2020-04-08 21:38:02 +02:00
|
|
|
|
|
|
|
title, _, artist = text.unescape(extr(
|
2020-04-10 22:08:45 +02:00
|
|
|
"<title>g4 :: ", "<")).rpartition(" by ")
|
|
|
|
data = {
|
2020-04-08 21:38:02 +02:00
|
|
|
"id" : text.parse_int(post_id),
|
|
|
|
"url" : url,
|
|
|
|
"user" : self.user or artist,
|
|
|
|
"title" : title,
|
|
|
|
"artist": artist,
|
|
|
|
"path" : text.split_html(extr("cookiecrumb'>", '</span'))[4:-1:2],
|
|
|
|
"date" : extr("class='pretty-date' title='", "'"),
|
2020-04-18 01:25:54 +02:00
|
|
|
"size" : text.parse_int(clen),
|
2020-04-08 21:38:02 +02:00
|
|
|
"views" : text.parse_int(extr("Views</b>:", "<").replace(",", "")),
|
|
|
|
"width" : text.parse_int(extr("Resolution</b>:", "x")),
|
|
|
|
"height": text.parse_int(extr("", "<")),
|
|
|
|
"comments" : text.parse_int(extr("Comments</b>:", "<")),
|
|
|
|
"favorites": text.parse_int(extr("Favorites</b>:", "<")),
|
2020-04-10 22:08:45 +02:00
|
|
|
"tags" : text.split_html(extr("class='taglist'>", "</span>")),
|
|
|
|
"description": text.unescape(text.remove_html(extr(
|
|
|
|
"<p>", "</p>"), "", "")),
|
2020-04-18 01:25:54 +02:00
|
|
|
"filename" : fname,
|
|
|
|
"extension": ext,
|
|
|
|
"_mtime" : lmod,
|
2020-04-10 22:08:45 +02:00
|
|
|
}
|
2020-04-08 21:38:02 +02:00
|
|
|
|
|
|
|
d1, _, d2 = data["date"].partition(",")
|
2020-04-11 02:08:05 +02:00
|
|
|
data["date"] = text.parse_datetime(
|
|
|
|
d1[:-2] + d2, "%b %d %Y %I:%M %p", -5)
|
2020-04-08 21:38:02 +02:00
|
|
|
|
|
|
|
return data
|
|
|
|
|
|
|
|
|
|
|
|
class AryionGalleryExtractor(AryionExtractor):
|
|
|
|
"""Extractor for a user's gallery on eka's portal"""
|
|
|
|
subcategory = "gallery"
|
2020-06-26 22:05:02 +02:00
|
|
|
categorytransfer = True
|
2020-10-22 23:12:59 +02:00
|
|
|
pattern = BASE_PATTERN + r"/(?:gallery/|user/|latest.php\?name=)([^/?#]+)"
|
2020-04-08 21:38:02 +02:00
|
|
|
test = (
|
|
|
|
("https://aryion.com/g4/gallery/jameshoward", {
|
2020-06-26 22:05:02 +02:00
|
|
|
"options": (("recursive", False),),
|
2020-04-10 22:08:45 +02:00
|
|
|
"pattern": r"https://aryion\.com/g4/data\.php\?id=\d+$",
|
2020-04-08 21:38:02 +02:00
|
|
|
"range": "48-52",
|
|
|
|
"count": 5,
|
|
|
|
}),
|
|
|
|
("https://aryion.com/g4/user/jameshoward"),
|
|
|
|
("https://aryion.com/g4/latest.php?name=jameshoward"),
|
|
|
|
)
|
|
|
|
|
2020-06-26 22:05:02 +02:00
|
|
|
def __init__(self, match):
|
|
|
|
AryionExtractor.__init__(self, match)
|
|
|
|
self.recursive = self.config("recursive", True)
|
|
|
|
self.offset = 0
|
|
|
|
|
2020-04-18 01:25:54 +02:00
|
|
|
def skip(self, num):
|
2020-06-26 22:05:02 +02:00
|
|
|
if self.recursive:
|
|
|
|
num = 0
|
2020-04-18 01:25:54 +02:00
|
|
|
self.offset += num
|
|
|
|
return num
|
2020-04-08 21:38:02 +02:00
|
|
|
|
2020-06-26 22:05:02 +02:00
|
|
|
def posts(self):
|
|
|
|
if self.recursive:
|
|
|
|
url = "{}/g4/gallery/{}".format(self.root, self.user)
|
|
|
|
return self._pagination(url)
|
|
|
|
else:
|
2020-09-06 22:17:23 +02:00
|
|
|
self._needle = "class='thumb' href='/g4/view/"
|
2020-06-26 22:05:02 +02:00
|
|
|
url = "{}/g4/latest.php?name={}".format(self.root, self.user)
|
|
|
|
return util.advance(self._pagination(url), self.offset)
|
2020-04-08 21:38:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
class AryionPostExtractor(AryionExtractor):
|
|
|
|
"""Extractor for individual posts on eka's portal"""
|
|
|
|
subcategory = "post"
|
|
|
|
pattern = BASE_PATTERN + r"/view/(\d+)"
|
2020-04-18 01:25:54 +02:00
|
|
|
test = (
|
|
|
|
("https://aryion.com/g4/view/510079", {
|
|
|
|
"url": "f233286fa5558c07ae500f7f2d5cb0799881450e",
|
|
|
|
"keyword": {
|
|
|
|
"artist" : "jameshoward",
|
|
|
|
"user" : "jameshoward",
|
|
|
|
"filename" : "jameshoward-510079-subscribestar_150",
|
|
|
|
"extension": "jpg",
|
|
|
|
"id" : 510079,
|
|
|
|
"width" : 1665,
|
|
|
|
"height" : 1619,
|
|
|
|
"size" : 784239,
|
|
|
|
"title" : "I'm on subscribestar now too!",
|
|
|
|
"description": r"re:Doesn't hurt to have a backup, right\?",
|
|
|
|
"tags" : ["Non-Vore", "subscribestar"],
|
|
|
|
"date" : "dt:2019-02-16 19:30:00",
|
|
|
|
"path" : [],
|
|
|
|
"views" : int,
|
|
|
|
"favorites": int,
|
|
|
|
"comments" : int,
|
|
|
|
"_mtime" : "Sat, 16 Feb 2019 19:30:34 GMT",
|
|
|
|
},
|
|
|
|
}),
|
2020-08-16 22:30:15 +02:00
|
|
|
# x-folder (#694)
|
2020-04-18 01:25:54 +02:00
|
|
|
("https://aryion.com/g4/view/588928", {
|
|
|
|
"pattern": pattern,
|
|
|
|
"count": ">= 8",
|
|
|
|
}),
|
2020-08-16 22:30:15 +02:00
|
|
|
# x-comic-folder (#945)
|
|
|
|
("https://aryion.com/g4/view/537379", {
|
|
|
|
"pattern": pattern,
|
|
|
|
"count": 2,
|
|
|
|
}),
|
2020-04-18 01:25:54 +02:00
|
|
|
)
|
|
|
|
|
2020-06-26 22:05:02 +02:00
|
|
|
def posts(self):
|
|
|
|
post_id, self.user = self.user, None
|
|
|
|
return (post_id,)
|