| 1 |
# -*- coding: utf-8 -*- |
| 2 |
|
| 3 |
# Copyright 2021-2025 Mike Fährmann |
| 4 |
# |
| 5 |
# This program is free software; you can redistribute it and/or modify |
| 6 |
# it under the terms of the GNU General Public License version 2 as |
| 7 |
# published by the Free Software Foundation. |
| 8 |
|
| 9 |
"""Extractors for https://picarto.tv/""" |
| 10 |
|
| 11 |
from .common import Extractor, Message |
| 12 |
from .. import text |
| 13 |
|
| 14 |
|
| 15 |
class PicartoGalleryExtractor(Extractor): |
| 16 |
"""Extractor for picarto galleries""" |
| 17 |
category = "picarto" |
| 18 |
subcategory = "gallery" |
| 19 |
root = "https://picarto.tv" |
| 20 |
directory_fmt = ("{category}", "{channel[name]}") |
| 21 |
filename_fmt = "{id} {title}.{extension}" |
| 22 |
archive_fmt = "{id}" |
| 23 |
pattern = r"(?:https?://)?picarto\.tv/([^/?#]+)/gallery" |
| 24 |
example = "https://picarto.tv/USER/gallery/TITLE/" |
| 25 |
|
| 26 |
def __init__(self, match): |
| 27 |
Extractor.__init__(self, match) |
| 28 |
self.username = match[1] |
| 29 |
|
| 30 |
def items(self): |
| 31 |
for post in self.posts(): |
| 32 |
post["date"] = self.parse_datetime_iso(post["created_at"]) |
| 33 |
variations = post.pop("variations", ()) |
| 34 |
yield Message.Directory, "", post |
| 35 |
|
| 36 |
image = post["default_image"] |
| 37 |
if not image: |
| 38 |
continue |
| 39 |
url = "https://images.picarto.tv/gallery/" + image["name"] |
| 40 |
text.nameext_from_url(url, post) |
| 41 |
yield Message.Url, url, post |
| 42 |
|
| 43 |
for variation in variations: |
| 44 |
post.update(variation) |
| 45 |
image = post["default_image"] |
| 46 |
url = "https://images.picarto.tv/gallery/" + image["name"] |
| 47 |
text.nameext_from_url(url, post) |
| 48 |
yield Message.Url, url, post |
| 49 |
|
| 50 |
def posts(self): |
| 51 |
url = "https://ptvintern.picarto.tv/api/channel-gallery" |
| 52 |
params = { |
| 53 |
"first": "30", |
| 54 |
"page": 1, |
| 55 |
"filter_params[album_id]": "", |
| 56 |
"filter_params[channel_name]": self.username, |
| 57 |
"filter_params[q]": "", |
| 58 |
"filter_params[visibility]": "", |
| 59 |
"order_by[field]": "published_at", |
| 60 |
"order_by[order]": "DESC", |
| 61 |
} |
| 62 |
|
| 63 |
while True: |
| 64 |
posts = self.request_json(url, params=params) |
| 65 |
if not posts: |
| 66 |
return |
| 67 |
yield from posts |
| 68 |
params["page"] += 1 |