2018-08-08 10:53:01 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2019-02-08 13:45:40 +01:00
|
|
|
# Copyright 2018-2019 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.
|
|
|
|
|
|
|
|
"""Extract images from https://piczel.tv/"""
|
|
|
|
|
|
|
|
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"
|
|
|
|
api_root = "https://apollo.piczel.tv"
|
|
|
|
|
|
|
|
def __init__(self, match):
|
2019-02-11 13:31:10 +01:00
|
|
|
Extractor.__init__(self, match)
|
2018-08-08 10:53:01 +02:00
|
|
|
self.item_id = match.group(1)
|
|
|
|
|
|
|
|
def items(self):
|
|
|
|
first = True
|
|
|
|
yield Message.Version, 1
|
|
|
|
for image in self.unpack(self.get_images()):
|
|
|
|
if first:
|
|
|
|
yield Message.Directory, image
|
|
|
|
first = False
|
|
|
|
path = image["image"]["image"]["url"]
|
|
|
|
url = "{}/static/{}".format(self.api_root, path)
|
|
|
|
yield Message.Url, url, text.nameext_from_url(url, image)
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def unpack(images):
|
|
|
|
"""Unpack 'images' into individual image objects"""
|
|
|
|
for image in images:
|
|
|
|
if image["multi"]:
|
|
|
|
multi = image["images"]
|
|
|
|
del image["images"]
|
|
|
|
for image["num"], img in enumerate(multi):
|
|
|
|
image["image"] = img
|
|
|
|
yield image
|
|
|
|
else:
|
|
|
|
image["num"] = 0
|
|
|
|
yield image
|
|
|
|
|
|
|
|
def get_images(self):
|
|
|
|
"""Return an iterable with all relevant image objects"""
|
|
|
|
|
|
|
|
|
|
|
|
class PiczelUserExtractor(PiczelExtractor):
|
|
|
|
"""Extractor for all images from a user's gallery"""
|
|
|
|
subcategory = "user"
|
2019-02-08 13:45:40 +01:00
|
|
|
pattern = r"(?:https?://)?(?:www\.)?piczel\.tv/gallery/([^/?&#]+)/?$"
|
|
|
|
test = ("https://piczel.tv/gallery/Lulena", {
|
2018-08-08 10:53:01 +02:00
|
|
|
"count": ">= 13",
|
2019-02-08 13:45:40 +01:00
|
|
|
})
|
2018-08-08 10:53:01 +02:00
|
|
|
|
|
|
|
def get_images(self):
|
|
|
|
url = "{}/api/users/{}/gallery".format(self.api_root, self.item_id)
|
|
|
|
return self.request(url).json()
|
|
|
|
|
|
|
|
|
|
|
|
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"
|
|
|
|
r"/gallery/(?!image)[^/?&#]+/(\d+)")
|
|
|
|
test = ("https://piczel.tv/gallery/Lulena/1114", {
|
2018-08-08 10:53:01 +02:00
|
|
|
"count": ">= 4",
|
2019-02-08 13:45:40 +01:00
|
|
|
})
|
2018-08-08 10:53:01 +02:00
|
|
|
|
|
|
|
def get_images(self):
|
|
|
|
url = "{}/api/gallery/folder/{}".format(self.api_root, self.item_id)
|
|
|
|
images = self.request(url).json()
|
|
|
|
images.reverse()
|
|
|
|
return images
|
|
|
|
|
|
|
|
|
|
|
|
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+)"
|
|
|
|
test = ("https://piczel.tv/gallery/image/7807", {
|
2018-12-09 14:54:55 +01:00
|
|
|
"url": "9b9e416b6ab7e58676fab84453d5028f306ece34",
|
2018-08-08 10:53:01 +02:00
|
|
|
"content": "df9a053a24234474a19bce2b7e27e0dec23bff87",
|
|
|
|
"keyword": {
|
|
|
|
"created_at": "2018-07-22T05:13:58.000Z",
|
|
|
|
"description": None,
|
|
|
|
"extension": "png",
|
|
|
|
"favorites_count": int,
|
|
|
|
"folder": dict,
|
|
|
|
"folder_id": 1113,
|
|
|
|
"id": 7807,
|
|
|
|
"is_flash": False,
|
|
|
|
"is_video": False,
|
|
|
|
"multi": False,
|
|
|
|
"nsfw": False,
|
|
|
|
"num": 0,
|
|
|
|
"password_protected": False,
|
|
|
|
"tags": "fanart, commission, altair, recreators, ",
|
|
|
|
"title": "Altair",
|
|
|
|
"user": dict,
|
|
|
|
"views": int,
|
|
|
|
},
|
2019-02-08 13:45:40 +01:00
|
|
|
})
|
2018-08-08 10:53:01 +02:00
|
|
|
|
|
|
|
def get_images(self):
|
|
|
|
url = "{}/api/gallery/image/{}".format(self.api_root, self.item_id)
|
|
|
|
return (self.request(url).json(),)
|