2018-08-08 10:53:01 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2023-06-30 17:19:53 +02:00
|
|
|
# Copyright 2018-2023 Mike Fährmann
|
2018-08-08 10:53:01 +02:00
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
|
2019-08-24 20:37:33 +02:00
|
|
|
"""Extractors for https://piczel.tv/"""
|
2018-08-08 10:53:01 +02:00
|
|
|
|
|
|
|
from .common import Extractor, Message
|
|
|
|
from .. import text
|
|
|
|
|
|
|
|
|
|
|
|
class PiczelExtractor(Extractor):
|
|
|
|
"""Base class for piczel extractors"""
|
|
|
|
category = "piczel"
|
2019-02-08 13:45:40 +01:00
|
|
|
directory_fmt = ("{category}", "{user[username]}")
|
2018-08-08 10:53:01 +02:00
|
|
|
filename_fmt = "{category}_{id}_{title}_{num:>02}.{extension}"
|
|
|
|
archive_fmt = "{id}_{num}"
|
|
|
|
root = "https://piczel.tv"
|
2024-11-14 23:44:15 +01:00
|
|
|
root_api = root
|
2018-08-08 10:53:01 +02:00
|
|
|
|
|
|
|
def items(self):
|
2020-02-27 02:13:33 +01:00
|
|
|
for post in self.posts():
|
|
|
|
post["tags"] = [t["title"] for t in post["tags"] if t["title"]]
|
|
|
|
post["date"] = text.parse_datetime(
|
|
|
|
post["created_at"], "%Y-%m-%dT%H:%M:%S.%f%z")
|
|
|
|
|
|
|
|
if post["multi"]:
|
|
|
|
images = post["images"]
|
|
|
|
del post["images"]
|
|
|
|
yield Message.Directory, post
|
|
|
|
for post["num"], image in enumerate(images):
|
|
|
|
if "id" in image:
|
|
|
|
del image["id"]
|
|
|
|
post.update(image)
|
|
|
|
url = post["image"]["url"]
|
|
|
|
yield Message.Url, url, text.nameext_from_url(url, post)
|
|
|
|
|
2018-08-08 10:53:01 +02:00
|
|
|
else:
|
2020-02-27 02:13:33 +01:00
|
|
|
yield Message.Directory, post
|
|
|
|
post["num"] = 0
|
|
|
|
url = post["image"]["url"]
|
|
|
|
yield Message.Url, url, text.nameext_from_url(url, post)
|
2018-08-08 10:53:01 +02:00
|
|
|
|
2020-02-27 02:13:33 +01:00
|
|
|
def posts(self):
|
|
|
|
"""Return an iterable with all relevant post objects"""
|
2018-08-08 10:53:01 +02:00
|
|
|
|
2019-08-24 20:37:33 +02:00
|
|
|
def _pagination(self, url, folder_id=None):
|
|
|
|
params = {
|
|
|
|
"from_id" : None,
|
|
|
|
"folder_id": folder_id,
|
|
|
|
}
|
|
|
|
|
|
|
|
while True:
|
|
|
|
data = self.request(url, params=params).json()
|
2020-02-27 02:13:33 +01:00
|
|
|
if not data:
|
2019-08-24 20:37:33 +02:00
|
|
|
return
|
|
|
|
params["from_id"] = data[-1]["id"]
|
2020-03-17 17:12:28 +01:00
|
|
|
|
|
|
|
for post in data:
|
|
|
|
if not folder_id or folder_id == post["folder_id"]:
|
|
|
|
yield post
|
2019-08-24 20:37:33 +02:00
|
|
|
|
2018-08-08 10:53:01 +02:00
|
|
|
|
|
|
|
class PiczelUserExtractor(PiczelExtractor):
|
|
|
|
"""Extractor for all images from a user's gallery"""
|
|
|
|
subcategory = "user"
|
2020-10-22 23:12:59 +02:00
|
|
|
pattern = r"(?:https?://)?(?:www\.)?piczel\.tv/gallery/([^/?#]+)/?$"
|
2023-09-11 16:30:55 +02:00
|
|
|
example = "https://piczel.tv/gallery/USER"
|
2018-08-08 10:53:01 +02:00
|
|
|
|
2019-08-24 20:37:33 +02:00
|
|
|
def __init__(self, match):
|
|
|
|
PiczelExtractor.__init__(self, match)
|
|
|
|
self.user = match.group(1)
|
|
|
|
|
2020-02-27 02:13:33 +01:00
|
|
|
def posts(self):
|
2024-11-14 23:44:15 +01:00
|
|
|
url = "{}/api/users/{}/gallery".format(self.root_api, self.user)
|
2019-08-24 20:37:33 +02:00
|
|
|
return self._pagination(url)
|
2018-08-08 10:53:01 +02:00
|
|
|
|
|
|
|
|
|
|
|
class PiczelFolderExtractor(PiczelExtractor):
|
|
|
|
"""Extractor for images inside a user's folder"""
|
|
|
|
subcategory = "folder"
|
2019-02-08 13:45:40 +01:00
|
|
|
directory_fmt = ("{category}", "{user[username]}", "{folder[name]}")
|
2018-08-08 10:53:01 +02:00
|
|
|
archive_fmt = "f{folder[id]}_{id}_{num}"
|
2019-02-08 13:45:40 +01:00
|
|
|
pattern = (r"(?:https?://)?(?:www\.)?piczel\.tv"
|
2020-10-22 23:12:59 +02:00
|
|
|
r"/gallery/(?!image)([^/?#]+)/(\d+)")
|
2023-09-11 16:30:55 +02:00
|
|
|
example = "https://piczel.tv/gallery/USER/12345"
|
2018-08-08 10:53:01 +02:00
|
|
|
|
2019-08-24 20:37:33 +02:00
|
|
|
def __init__(self, match):
|
|
|
|
PiczelExtractor.__init__(self, match)
|
|
|
|
self.user, self.folder_id = match.groups()
|
|
|
|
|
2020-02-27 02:13:33 +01:00
|
|
|
def posts(self):
|
2024-11-14 23:44:15 +01:00
|
|
|
url = "{}/api/users/{}/gallery".format(self.root_api, self.user)
|
2020-03-17 17:12:28 +01:00
|
|
|
return self._pagination(url, int(self.folder_id))
|
2018-08-08 10:53:01 +02:00
|
|
|
|
|
|
|
|
|
|
|
class PiczelImageExtractor(PiczelExtractor):
|
|
|
|
"""Extractor for individual images"""
|
|
|
|
subcategory = "image"
|
2019-02-08 13:45:40 +01:00
|
|
|
pattern = r"(?:https?://)?(?:www\.)?piczel\.tv/gallery/image/(\d+)"
|
2023-09-11 16:30:55 +02:00
|
|
|
example = "https://piczel.tv/gallery/image/12345"
|
2018-08-08 10:53:01 +02:00
|
|
|
|
2019-08-24 20:37:33 +02:00
|
|
|
def __init__(self, match):
|
|
|
|
PiczelExtractor.__init__(self, match)
|
|
|
|
self.image_id = match.group(1)
|
|
|
|
|
2020-02-27 02:13:33 +01:00
|
|
|
def posts(self):
|
2024-11-14 23:44:15 +01:00
|
|
|
url = "{}/api/gallery/{}".format(self.root_api, self.image_id)
|
2020-03-31 22:47:23 +02:00
|
|
|
return (self.request(url).json(),)
|